constructMCDeck

repo: valeriecodes/c-poker

original_code:
Deck * constructMCDeck(Hand * hand){
 int i;
 Deck * d = buildDeck();
 for (i = 0; i < 5; i++){
  Card handCard = hand->cards[i];
  int pos = (handCard.suit * 13) + handCard.rank - 1 - i;
  swap((char *) d->cards,(char *) d->cards + (pos * sizeof(Card)), sizeof(Card));
  deal(d);
  shrinkDeck(d);
 }
 return d;
}

canonical_original_code:
struct Deck *constructMCDeck(struct Hand *hand){
 int i;
 struct Deck *d = buildDeck();
 for (i = 0; i < 5; i++){
  struct Card handCard = hand->cards[i];
  int pos = (handCard.suit * 13) + handCard.rank - 1 - i;
  swap((char *) d->cards,(char *) d->cards + (pos * sizeof(Card)), sizeof(Card));
  deal(d);
  shrinkDeck(d);
 }
 return d;
}

variable_types: struct Hand { int score; struct Card cards[5]; int value; enum Class { HighCard=0, OnePair=1, TwoPair=2, ThreeofKind=3, Straight=4, Flush=5, FullHouse=6, FourofKind=7, StraightFlush=8, RoyalFlush=9 } class; enum rank { Joker=0, Deuce=1, Three=2, Four=3, Five=4, Six=5, Seven=6, Eight=7, Nine=8, Ten=9, Jack=10, Queen=11, King=12, Ace=13 } ranks[5]; } *

variable_types: struct Deck { struct Card { enum suit { Hearts=0, Diamonds=1, Spades=2, Clubs=3 } suit; enum rank { Joker=0, Deuce=1, Three=2, Four=3, Five=4, Six=5, Seven=6, Eight=7, Nine=8, Ten=9, Jack=10, Queen=11, King=12, Ace=13 } rank; } *originalCards; struct Card *cards; int front; int rear; int cardCount; int cardCapacity; } *

variable_types: pos int

user_defined_types: struct Card { enum suit suit; enum rank rank; }

user_defined_types: struct Hand { int score; struct Card cards[5]; int value; enum Class class; enum rank ranks[5]; }

user_defined_types: struct Deck { struct Card *originalCards; struct Card *cards; int front; int rear; int cardCount; int cardCapacity; }


runSimulation

original_code:
int runSimulation(int action, Hand hand, Deck deck){
 int i = 0;
 int j = 0;
 shuffleCards(deck.cards, 47);
 while (action != 0){
  int move = action & 1;
  action = action >> 1;
  if (move){
   hand.cards[i] = deck.cards[j];
   j++;
  }
  i++;
 }
 return handScore(&hand);
}

canonical_original_code:
int runSimulation(int action, struct Hand hand, struct Deck deck){
 int i = 0;
 int j = 0;
 shuffleCards(deck.cards, 47);
 while (action != 0){
  int move = action & 1;
  action = action >> 1;
  if (move){
   hand.cards[i] = deck.cards[j];
   j++;
  }
  i++;
 }
 return handScore(&hand);
}

variable_types: action int

variable_types: struct Hand { int score; struct Card { enum suit { Hearts=0, Diamonds=1, Spades=2, Clubs=3 } suit; enum rank { Joker=0, Deuce=1, Three=2, Four=3, Five=4, Six=5, Seven=6, Eight=7, Nine=8, Ten=9, Jack=10, Queen=11, King=12, Ace=13 } rank; } cards[5]; int value; enum Class { HighCard=0, OnePair=1, TwoPair=2, ThreeofKind=3, Straight=4, Flush=5, FullHouse=6, FourofKind=7, StraightFlush=8, RoyalFlush=9 } class; enum rank { Joker=0, Deuce=1, Three=2, Four=3, Five=4, Six=5, Seven=6, Eight=7, Nine=8, Ten=9, Jack=10, Queen=11, King=12, Ace=13 } ranks[5]; }

variable_types: struct Deck { struct Card *originalCards; struct Card *cards; int front; int rear; int cardCount; int cardCapacity; }

variable_types: i int

variable_types: j int

variable_types: move int

return_type: int


monteCarloSimulation

original_code:
int monteCarloSimulation(Hand * hand, float results[32]){
 Deck * deck = constructMCDeck(hand);
 results[0] = handScore(hand);
 int max = 0;
 int i;
 for (i = 1; i < 32; i++){
  int newresult = 0;
  int j;
  for (j = 0; j < 10000; j++){
   newresult = runSimulation(i, *hand, *deck) + newresult;
  }
  results[i] = (float) newresult/(float) 10000;
  if (results[i] > results[max]){
   max = i;
  }
 }
 destroyDeck(deck);
 return max;
}

canonical_original_code:
int monteCarloSimulation(struct Hand *hand, float results[32]){
 struct Deck *deck = constructMCDeck(hand);
 results[0] = handScore(hand);
 int max = 0;
 int i;
 for (i = 1; i < 32; i++){
  int newresult = 0;
  int j;
  for (j = 0; j < 10000; j++){
   newresult = runSimulation(i, *hand, *deck) + newresult;
  }
  results[i] = (float) newresult/(float) 10000;
  if (results[i] > results[max]){
   max = i;
  }
 }
 destroyDeck(deck);
 return max;
}

variable_types: struct Hand { int score; struct Card { enum suit { Hearts=0, Diamonds=1, Spades=2, Clubs=3 } suit; enum rank { Joker=0, Deuce=1, Three=2, Four=3, Five=4, Six=5, Seven=6, Eight=7, Nine=8, Ten=9, Jack=10, Queen=11, King=12, Ace=13 } rank; } cards[5]; int value; enum Class { HighCard=0, OnePair=1, TwoPair=2, ThreeofKind=3, Straight=4, Flush=5, FullHouse=6, FourofKind=7, StraightFlush=8, RoyalFlush=9 } class; enum rank { Joker=0, Deuce=1, Three=2, Four=3, Five=4, Six=5, Seven=6, Eight=7, Nine=8, Ten=9, Jack=10, Queen=11, King=12, Ace=13 } ranks[5]; } *

variable_types:
results
float [32]

variable_types: max int

variable_types: newresult int


monteCarloAdvisor

decompiled_code:
int __fastcall monteCarloAdvisor(const __m128i *a1)
{
int v1; // ebx
float v3[34]; // [rsp+0h] [rbp-88h] BYREF

v1 = monteCarloSimulation(a1, v3);
puts("The Monte Carlo advisor suggests:");
if ( !v1 )
{
printf("Keeping all cards");
return printf(" for an expected final hand score of %.2f. Your current hand score is %.0f.\n", v3[v1], v3[0]);
}
printf("Discarding ");
if ( (v1 & 1) != 0 )
{
putchar(97);
if ( (v1 & 0x1E) != 0 )
putchar(44);
}
if ( (v1 & 2) != 0 )
{
putchar(98);
if ( (v1 & 0x1C) != 0 )
putchar(44);
}
if ( (v1 & 4) != 0 )
{
putchar(99);
if ( (v1 & 0x18) != 0 )
putchar(44);
}
if ( (v1 & 8) != 0 )
{
putchar(100);
if ( (v1 & 0x10) == 0 )
return printf(" for an expected final hand score of %.2f. Your current hand score is %.0f.\n", v3[v1], v3[0]);
putchar(44);
goto LABEL_7;
}
if ( (v1 & 0x10) != 0 )
LABEL_7:
putchar(101);
return printf(" for an expected final hand score of %.2f. Your current hand score is %.0f.\n", v3[v1], v3[0]);
}

canonical_decompiled_code:
int __fastcall func3(const __m128i *a1)
{
int v1; // ebx
float v3[34]; // [rsp+0h] [rbp-88h] BYREF

v1 = func2(a1, v3);
puts("The Monte Carlo advisor suggests:");
if ( !v1 )
{
printf("Keeping all cards");
return printf(" for an expected final hand score of %.2f. Your current hand score is %.0f.\n", v3[v1], v3[0]);
}
printf("Discarding ");
if ( (v1 & 1) != 0 )
{
putchar(97);
if ( (v1 & 0x1E) != 0 )
putchar(44);
}
if ( (v1 & 2) != 0 )
{
putchar(98);
if ( (v1 & 0x1C) != 0 )
putchar(44);
}
if ( (v1 & 4) != 0 )
{
putchar(99);
if ( (v1 & 0x18) != 0 )
putchar(44);
}
if ( (v1 & 8) != 0 )
{
putchar(100);
if ( (v1 & 0x10) == 0 )
return printf(" for an expected final hand score of %.2f. Your current hand score is %.0f.\n", v3[v1], v3[0]);
putchar(44);
goto LABEL_7;
}
if ( (v1 & 0x10) != 0 )
LABEL_7:
putchar(101);
return printf(" for an expected final hand score of %.2f. Your current hand score is %.0f.\n", v3[v1], v3[0]);
}

original_code:
void monteCarloAdvisor(Hand * hand){
 float results[32];
 int suggestedMove = monteCarloSimulation(hand, results);
 printf("The Monte Carlo advisor suggests:\n");
 if (suggestedMove){
  printf("Discarding ");
  if (suggestedMove & 1){
   printf("a");
   if (suggestedMove & 30){
    printf(",");
   }
  }
  if (suggestedMove & 2){
   printf("b");
   if (suggestedMove & 28){
    printf(",");
   }
  }
  if (suggestedMove & 4){
   printf("c");
   if (suggestedMove & 24){
    printf(",");
   }
  }
  if (suggestedMove & 8){
   printf("d");
   if (suggestedMove & 16){
    printf(",");
   }
  }
  if (suggestedMove & 16){
   printf("e");
  }
 }
 else {
  printf("Keeping all cards");
 }
 printf(" for an expected final hand score of %.2f. Your current hand score is %.0f.\n", results[suggestedMove], results[0]);
}

canonical_original_code:
void monteCarloAdvisor(struct Hand *hand){
 float results[32];
 int suggestedMove = monteCarloSimulation(hand, results);
 printf("The Monte Carlo advisor suggests:\n");
 if (suggestedMove){
  printf("Discarding ");
  if (suggestedMove & 1){
   printf("a");
   if (suggestedMove & 30){
    printf(",");
   }
  }
  if (suggestedMove & 2){
   printf("b");
   if (suggestedMove & 28){
    printf(",");
   }
  }
  if (suggestedMove & 4){
   printf("c");
   if (suggestedMove & 24){
    printf(",");
   }
  }
  if (suggestedMove & 8){
   printf("d");
   if (suggestedMove & 16){
    printf(",");
   }
  }
  if (suggestedMove & 16){
   printf("e");
  }
 }
 else {
  printf("Keeping all cards");
 }
 printf(" for an expected final hand score of %.2f. Your current hand score is %.0f.\n", results[suggestedMove], results[0]);
}

variable_types: suggestedMove int

return_type: void

user_defined_types: enum Class { HighCard=0, OnePair=1, TwoPair=2, ThreeofKind=3, Straight=4, Flush=5, FullHouse=6, FourofKind=7, StraightFlush=8, RoyalFlush=9 }

user_defined_types: enum rank { Joker=0, Deuce=1, Three=2, Four=3, Five=4, Six=5, Seven=6, Eight=7, Nine=8, Ten=9, Jack=10, Queen=11, King=12, Ace=13 }

user_defined_types: enum suit { Hearts=0, Diamonds=1, Spades=2, Clubs=3 }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
time_t v3; // rdi

v3 = time(0LL);
srand(v3);
gameLoop(v3, argv);
return 0;
}

original_code:
int main(void){
 srand(time(((void *)0)));
 gameLoop();
 return 0;
}

canonical_original_code:
int main(){
 srand(time(((void *)0)));
 gameLoop();
 return 0;
}


repo: vanthonguyen/chat-curses

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
size_t v4; // rax
size_t v5; // rax
size_t v6; // rax
pthread_t v8; // [rsp+0h] [rbp-48h] BYREF
pthread_t v9; // [rsp+8h] [rbp-40h] BYREF
pthread_t v10; // [rsp+10h] [rbp-38h] BYREF
pthread_t th; // [rsp+18h] [rbp-30h] BYREF
pthread_t newthread; // [rsp+20h] [rbp-28h] BYREF
void *arg[4]; // [rsp+28h] [rbp-20h] BYREF

if ( argc <= 1 )
{
perror("Enter nickname!");
exit(1);
}
v3 = argv[1];
v4 = strlen(v3);
arg[0] = malloc(v4 + 1);
v5 = strlen(v3);
memset(arg[0], 0, v5 + 1);
v6 = strlen(v3);
strncpy((char *)arg[0], v3, v6);
create_interface();
printHelp();
pthread_create(&newthread, 0LL, (void *(*)(void *))&send_message_hello, arg);
pthread_create(&th, 0LL, (void *(*)(void *))&receive_message_hello, 0LL);
pthread_create(&v10, 0LL, (void *(*)(void *))&handle_input, arg);
pthread_create(&v9, 0LL, (void *(*)(void *))&receive_tcp, 0LL);
pthread_create(&v8, 0LL, (void *(*)(void *))&updateBuddyList, 0LL);
pthread_join(newthread, 0LL);
pthread_join(th, 0LL);
pthread_join(v10, 0LL);
pthread_join(v9, 0LL);
pthread_join(v8, 0LL);
return 0;
}

original_code:
int main(int argc, char ** argv){
    if(argc < 2){
        perror("Enter nickname!");
        exit(1);
    }
    char *nick = (char *)malloc((strlen(argv[1]) + 1)*sizeof(char));
    memset(nick, '\0', strlen(argv[1]) + 1);
    strncpy(nick, argv[1], strlen(argv[1]));
    create_interface();
    printHelp();
    pthread_t send_thread,
              receive_thread,
              input_thread,
              receive_tcp_thread,
              ui_thread;
    void *send_message_hello(), *receive_message_hello(), *handle_input(), *receive_tcp();
    void *updateBuddyList();
    pthread_create(&send_thread, ((void *)0), (void *)send_message_hello, (void *)&nick);
    pthread_create(&receive_thread, ((void *)0), (void *)receive_message_hello,((void *)0));
    pthread_create(&input_thread, ((void *)0), (void *) handle_input, (void *) &nick);
    pthread_create(&receive_tcp_thread, ((void *)0), (void *)receive_tcp , ((void *)0));
    pthread_create(&ui_thread, ((void *)0), (void *)updateBuddyList, ((void *)0));
    pthread_join(send_thread, ((void *)0));
    pthread_join(receive_thread, ((void *)0));
    pthread_join(input_thread, ((void *)0));
    pthread_join(receive_tcp_thread, ((void *)0));
    pthread_join(ui_thread, ((void *)0));
    return 0;
}

canonical_original_code:
int main(int argc, char **argv){
    if(argc < 2){
        perror("Enter nickname!");
        exit(1);
    }
    char *nick = (char *)malloc((strlen(argv[1]) + 1)*sizeof(char));
    memset(nick, '\0', strlen(argv[1]) + 1);
    strncpy(nick, argv[1], strlen(argv[1]));
    create_interface();
    printHelp();
    unsigned long send_thread; unsigned long receive_thread; unsigned long input_thread; unsigned long receive_tcp_thread; unsigned long ui_thread;
    void *send_message_hello(); void *receive_message_hello(); void *handle_input(); void *receive_tcp();
    void *updateBuddyList();
    pthread_create(&send_thread, ((void *)0), (void *)send_message_hello, (void *)&nick);
    pthread_create(&receive_thread, ((void *)0), (void *)receive_message_hello,((void *)0));
    pthread_create(&input_thread, ((void *)0), (void *) handle_input, (void *) &nick);
    pthread_create(&receive_tcp_thread, ((void *)0), (void *)receive_tcp , ((void *)0));
    pthread_create(&ui_thread, ((void *)0), (void *)updateBuddyList, ((void *)0));
    pthread_join(send_thread, ((void *)0));
    pthread_join(receive_thread, ((void *)0));
    pthread_join(input_thread, ((void *)0));
    pthread_join(receive_tcp_thread, ((void *)0));
    pthread_join(ui_thread, ((void *)0));
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
nick
char *

variable_types:
updateBuddyList
void *()


original_code:
double compute_serie_a_sin(double delaunay_arguments[], int multipliers[], double coefficients[], int n)
{
    double acc;
    double arg;
    int i, j;
    for (i = 0, acc = 0.0; i < n; i++){
        for (j = D, arg = 0.0; j <= F; j++)
            arg += multipliers[i * 4 + j] * delaunay_arguments[j];
        arg *= 3.14159265358979323846 / 648000.0;
        acc += coefficients[i * 7] * sin(arg);
    }
    return acc;
}

canonical_original_code:
double compute_serie_a_sin(double delaunay_arguments[], int multipliers[], double coefficients[], int n)
{
    double acc;
    double arg;
    int i; int j;
    for (i = 0, acc = 0.0; i < n; i++){
        for (j = D, arg = 0.0; j <= F; j++)
            arg += multipliers[i * 4 + j] * delaunay_arguments[j];
        arg *= 3.14159265358979323846 / 648000.0;
        acc += coefficients[i * 7] * sin(arg);
    }
    return acc;
}

variable_types:
multipliers
int []

variable_types:
coefficients
double []

variable_types: n int

variable_types: acc double

variable_types: arg double

return_type: double


original_code:
double compute_serie_a_cos(double delaunay_arguments[], int multipliers[], double coefficients[], int n)
{
    double acc;
    double arg;
    int i, j;
    for (i = 0, acc = 0.0; i < n; i++){
        for (j = D, arg = 0.0; j <= F; j++)
            arg += multipliers[i * 4 + j] * delaunay_arguments[j];
        arg *= 3.14159265358979323846 / 648000.0;
        acc += coefficients[i * 7] * cos(arg);
    }
    return acc;
}

canonical_original_code:
double compute_serie_a_cos(double delaunay_arguments[], int multipliers[], double coefficients[], int n)
{
    double acc;
    double arg;
    int i; int j;
    for (i = 0, acc = 0.0; i < n; i++){
        for (j = D, arg = 0.0; j <= F; j++)
            arg += multipliers[i * 4 + j] * delaunay_arguments[j];
        arg *= 3.14159265358979323846 / 648000.0;
        acc += coefficients[i * 7] * cos(arg);
    }
    return acc;
}

variable_types: i int


original_code:
double compute_serie_c(double planetary_arguments[], double delaunay_arguments[], int multipliers[], double coefficients[], int n)
{
    double acc;
    double arg;
    int i, j;
    for (i = 0, acc = 0.0; i < n; i++){
        for (j = 0, arg = 0.0; j <= 7; j++)
            arg += multipliers[i * 11 + j] * planetary_arguments[j];
        arg += multipliers[i * 11 + j + 1] * delaunay_arguments[D];
        arg += multipliers[i * 11 + j + 1] * delaunay_arguments[L];
        arg += multipliers[i * 11 + j + 1] * delaunay_arguments[F];
        arg += coefficients[i * 3];
        arg *= 3.14159265358979323846 / 648000.0;
        acc += coefficients[i * 3 + 1] * sin(arg);
    }
    return acc;
}

canonical_original_code:
double compute_serie_c(double planetary_arguments[], double delaunay_arguments[], int multipliers[], double coefficients[], int n)
{
    double acc;
    double arg;
    int i; int j;
    for (i = 0, acc = 0.0; i < n; i++){
        for (j = 0, arg = 0.0; j <= 7; j++)
            arg += multipliers[i * 11 + j] * planetary_arguments[j];
        arg += multipliers[i * 11 + j + 1] * delaunay_arguments[D];
        arg += multipliers[i * 11 + j + 1] * delaunay_arguments[L];
        arg += multipliers[i * 11 + j + 1] * delaunay_arguments[F];
        arg += coefficients[i * 3];
        arg *= 3.14159265358979323846 / 648000.0;
        acc += coefficients[i * 3 + 1] * sin(arg);
    }
    return acc;
}

variable_types: j int


original_code:
double compute_serie_d(double planetary_arguments[], double delaunay_arguments[], int multipliers[], double coefficients[], int n)
{
    double acc;
    double arg;
    int i, j;
    for (i = 0, acc=0.0; i < n; i++) {
        for (j = 0, arg = 0.0; j <= 6; j++)
            arg += multipliers[i * 11 + j] * planetary_arguments[j];
        for (j = D; j <= F; j++)
            arg += multipliers[i * 11 + 8 + j] * delaunay_arguments[j];
        arg += coefficients[i * 3];
        arg *= 3.14159265358979323846 / 648000.0;
        acc += coefficients[i * 3 + 1] * sin(arg);
    }
    return acc;
}

canonical_original_code:
double compute_serie_d(double planetary_arguments[], double delaunay_arguments[], int multipliers[], double coefficients[], int n)
{
    double acc;
    double arg;
    int i; int j;
    for (i = 0, acc=0.0; i < n; i++) {
        for (j = 0, arg = 0.0; j <= 6; j++)
            arg += multipliers[i * 11 + j] * planetary_arguments[j];
        for (j = D; j <= F; j++)
            arg += multipliers[i * 11 + 8 + j] * delaunay_arguments[j];
        arg += coefficients[i * 3];
        arg *= 3.14159265358979323846 / 648000.0;
        acc += coefficients[i * 3 + 1] * sin(arg);
    }
    return acc;
}


repo: vasconde/StereoM

decompiled_code:
void *__fastcall ml_alocar_M(int a1, int a2)
{
return calloc(a2 * a1, 8uLL);
}

canonical_decompiled_code:
void *__fastcall func0(int a1, int a2)
{
return calloc(a2 * a1, 8uLL);
}

original_code:
double *ml_alocar_M (int m, int n)
{
  double *M = (double *)calloc(m*n,sizeof(double));
  return M;
}

canonical_original_code:
double *ml_alocar_M(int m, int n)
{
  double *M = (double *)calloc(m*n,sizeof(double));
  return M;
}

variable_types: m int

variable_types:
M
double *

return_type: double *


decompiled_code:
void __fastcall ml_set_entry_M(__int64 a1, int a2, int a3, int a4, double a5)
{
*(double *)(a1 + 8LL * (a4 + a2 * a3)) = a5;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2, int a3, int a4, double a5)
{
*(double *)(a1 + 8LL * (a4 + a2 * a3)) = a5;
}

original_code:
void ml_set_entry_M(double *M, int n, int i, int j, double val)
{
  M[j+i*n] = val;
}

variable_types: val double


decompiled_code:
double __fastcall ml_get_entry_M(__int64 a1, int a2, int a3, int a4)
{
return *(double *)(a1 + 8LL * (a4 + a2 * a3));
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1, int a2, int a3, int a4)
{
return *(double *)(a1 + 8LL * (a4 + a2 * a3));
}

original_code:
double ml_get_entry_M(const double *M, int n, int i, int j)
{
  return M[j+i*n];
}

canonical_original_code:
double ml_get_entry_M(double *M, int n, int i, int j)
{
  return M[j+i*n];
}


decompiled_code:
void __fastcall ml_free_M(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
free(a1);
}

original_code:
void ml_free_M (double *M)
{
  free(M);
}

canonical_original_code:
void ml_free_M(double *M)
{
  free(M);
}


original_code:
void ml_AeqB (double *A, double *B, int m, int n)
{
  int i;
  int dim = m * n;
  for (i = 0; i < dim; i++)
    {
      A[i] = B[i];
    }
}

canonical_original_code:
void ml_AeqB(double *A, double *B, int m, int n)
{
  int i;
  int dim = m * n;
  for (i = 0; i < dim; i++)
    {
      A[i] = B[i];
    }
}

variable_types:
A
double *

variable_types:
B
double *

variable_types: dim int


decompiled_code:
__int64 __fastcall ml_AB(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, int a5, unsigned int a6, __int64 a7)
{
__int64 v7; // rax
__int64 v8; // r9

v7 = a6;
v8 = 0LL;
if ( (_DWORD)a3 == a5 )
{
cblas_dgemm(101LL, 111LL, 111LL, a2, (unsigned int)v7, (unsigned int)a3, 1.0, 0.0, a1, a3, a4, v7, a7, v7);
v8 = a7;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, int a5, unsigned int a6, __int64 a7)
{
__int64 v7; // rax
__int64 v8; // r9

v7 = a6;
v8 = 0LL;
if ( (_DWORD)a3 == a5 )
{
cblas_dgemm(101LL, 111LL, 111LL, a2, (unsigned int)v7, (unsigned int)a3, 1.0, 0.0, a1, a3, a4, v7, a7, v7);
v8 = a7;
}
return v8;
}

original_code:
double *ml_AB (double *A, const int ma, const int na, double *B, const int mb, const int nb, double *C)
{
  if(na != mb)
    return ((void *)0);
  cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, ma, nb, na, 1.0, A, na, B, nb, 0.0, C, nb);
  return C;
}

canonical_original_code:
double *ml_AB(double *A, int ma, int na, double *B, int mb, int nb, double *C)
{
  if(na != mb)
    return ((void *)0);
  cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, ma, nb, na, 1.0, A, na, B, nb, 0.0, C, nb);
  return C;
}

variable_types: ma int

variable_types: mb int

variable_types: nb int

variable_types:
C
double *


decompiled_code:
__int64 __fastcall ml_ABtt(__int64 a1, unsigned int a2, __int64 a3, int a4, __int64 a5, unsigned int a6, unsigned int a7, int a8, __int64 a9)
{
__int64 v11; // r8
__int64 v12; // r9
unsigned int v13; // ebx

v11 = a6;
if ( a4 )
{
v12 = a2;
a2 = a3;
v13 = 112;
}
else
{
v12 = (unsigned int)a3;
v13 = 111;
}
if ( !a8 )
v11 = a7;
return cblas_dgemm(101LL, v13, 112 - (unsigned int)(a8 == 0), a2, v11, v12, 1.0, 0.0, a1, a3, a5, a7, a9, v11);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, __int64 a3, int a4, __int64 a5, unsigned int a6, unsigned int a7, int a8, __int64 a9)
{
__int64 v11; // r8
__int64 v12; // r9
unsigned int v13; // ebx

v11 = a6;
if ( a4 )
{
v12 = a2;
a2 = a3;
v13 = 112;
}
else
{
v12 = (unsigned int)a3;
v13 = 111;
}
if ( !a8 )
v11 = a7;
return cblas_dgemm(101LL, v13, 112 - (unsigned int)(a8 == 0), a2, v11, v12, 1.0, 0.0, a1, a3, a5, a7, a9, v11);
}

original_code:
void ml_ABtt (double *A, int ma, int na, int ta, double *B, int mb, int nb, int tb, double *C)
{
  int aux;
  int saltoa = na, saltob = nb, saltoc = nb;
  enum CBLAS_ORDER transposeA = CblasNoTrans;
  enum CBLAS_ORDER transposeB = CblasNoTrans;
  if(ta != 0)
    {
      transposeA = CblasTrans;
      aux = ma;
      ma = na;
      na = aux;
    }
  if(tb != 0)
    {
      saltoc = mb;
      transposeB = CblasTrans;
      aux = mb;
      mb = nb;
      nb = aux;
    }
  cblas_dgemm(CblasRowMajor, transposeA, transposeB, ma, nb, na, 1.0, A, saltoa, B, saltob, 0.0, C, saltoc);
}

canonical_original_code:
void ml_ABtt(double *A, int ma, int na, int ta, double *B, int mb, int nb, int tb, double *C)
{
  int aux;
  int saltoa = na; int saltob = nb; int saltoc = nb;
  enum CBLAS_ORDER transposeA = CblasNoTrans;
  enum CBLAS_ORDER transposeB = CblasNoTrans;
  if(ta != 0)
    {
      transposeA = CblasTrans;
      aux = ma;
      ma = na;
      na = aux;
    }
  if(tb != 0)
    {
      saltoc = mb;
      transposeB = CblasTrans;
      aux = mb;
      mb = nb;
      nb = aux;
    }
  cblas_dgemm(CblasRowMajor, transposeA, transposeB, ma, nb, na, 1.0, A, saltoa, B, saltob, 0.0, C, saltoc);
}

variable_types: ta int

variable_types: tb int

variable_types: aux int

variable_types: saltoa int

variable_types: saltob int

variable_types: saltoc int

variable_types: enum CBLAS_ORDER { CblasRowMajor=101, CblasColMajor=102 }


decompiled_code:
void __fastcall ml_invM(__int64 a1, int a2)
{
void *v2; // rbp
void *v3; // rbx
int v4[3]; // [rsp+Ch] [rbp-3Ch] BYREF
char v5[4]; // [rsp+18h] [rbp-30h] BYREF
int v6[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v4[0] = a2;
v2 = calloc(a2 + 1, 4uLL);
v6[0] = a2 * a2;
v3 = calloc(a2 * a2, 8uLL);
dgetrf_(v4, v4, a1, v4, v2, v5);
dgetri_(v4, a1, v4, v2, v3, v6, v5);
free(v2);
free(v3);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2)
{
void *v2; // rbp
void *v3; // rbx
int v4[3]; // [rsp+Ch] [rbp-3Ch] BYREF
char v5[4]; // [rsp+18h] [rbp-30h] BYREF
int v6[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v4[0] = a2;
v2 = calloc(a2 + 1, 4uLL);
v6[0] = a2 * a2;
v3 = calloc(a2 * a2, 8uLL);
dgetrf_(v4, v4, a1, v4, v2, v5);
dgetri_(v4, a1, v4, v2, v3, v6, v5);
free(v2);
free(v3);
}

original_code:
void ml_invM(double* A, int N)
{
    int *IPIV = (int *)calloc(N+1,sizeof(int));
    int LWORK = N*N;
    double *WORK = (double *)calloc(LWORK,sizeof(double));
    int INFO;
    dgetrf_(&N,&N,A,&N,IPIV,&INFO);
    dgetri_(&N,A,&N,IPIV,WORK,&LWORK,&INFO);
    free(IPIV);
    free(WORK);
}

canonical_original_code:
void ml_invM(double *A, int N)
{
    int *IPIV = (int *)calloc(N+1,sizeof(int));
    int LWORK = N*N;
    double *WORK = (double *)calloc(LWORK,sizeof(double));
    int INFO;
    dgetrf_(&N,&N,A,&N,IPIV,&INFO);
    dgetri_(&N,A,&N,IPIV,WORK,&LWORK,&INFO);
    free(IPIV);
    free(WORK);
}

variable_types: N int

variable_types:
IPIV
int *

variable_types: LWORK int

variable_types:
WORK
double *

variable_types: INFO int


decompiled_code:
void __fastcall ml_aM(double *a1, int a2, int a3, double a4)
{
int v4; // edx
double *v5; // rax
__int64 v6; // rdx

v4 = a2 * a3;
if ( v4 > 0 )
{
v5 = a1;
v6 = (__int64)&a1[(unsigned int)(v4 - 1) + 1];
do
{
*v5 = a4 * *v5;
++v5;
}
while ( v5 != (double *)v6 );
}
}

canonical_decompiled_code:
void __fastcall func9(double *a1, int a2, int a3, double a4)
{
int v4; // edx
double *v5; // rax
__int64 v6; // rdx

v4 = a2 * a3;
if ( v4 > 0 )
{
v5 = a1;
v6 = (__int64)&a1[(unsigned int)(v4 - 1) + 1];
do
{
*v5 = a4 * *v5;
++v5;
}
while ( v5 != (double *)v6 );
}
}

original_code:
void ml_aM (double a, double *M, int m, int n)
{
  int i;
  int dim = m*n;
  for(i=0; i < dim; i++)
    M[i] *= a;
}

canonical_original_code:
void ml_aM(double a, double *M, int m, int n)
{
  int i;
  int dim = m*n;
  for(i=0; i < dim; i++)
    M[i] *= a;
}

variable_types: a double

variable_types:
M
double *

variable_types: m int

variable_types: n int

variable_types: i int

variable_types: dim int


original_code:
void ml_AmmB (int op, double *A, double *B, int m, int n, double *C)
{
  int i;
  int dim = m*n;
  if(op == 0)
    for(i=0; i < dim; i++)
      C[i] = A[i] + B[i];
  else
    for(i=0; i < dim; i++)
      C[i] = A[i] - B[i];
}

canonical_original_code:
void ml_AmmB(int op, double *A, double *B, int m, int n, double *C)
{
  int i;
  int dim = m*n;
  if(op == 0)
    for(i=0; i < dim; i++)
      C[i] = A[i] + B[i];
  else
    for(i=0; i < dim; i++)
      C[i] = A[i] - B[i];
}

variable_types: op int

variable_types:
A
double *

variable_types:
B
double *

variable_types:
C
double *


original_code:
void ml_svd(double* Ain, int ma, int na, double* Uout, double* Sout, double* Vt)
{
  char op = 'A';
  int info;
  int lwork;
  double wkopt;
  double* work;
  double *A = ml_alocar_M (na, ma);
  double *U = ml_alocar_M (ma, ma);
  double *S = ml_alocar_M (1, na);
  ml_Mt (Ain, ma, na, A);
  ml_Mt (Uout, ma, ma, U);
  ml_Mt (Sout, na, 1, S);
  lwork = -1;
  dgesvd_(&op, &op, &ma, &na, A, &ma, S, U, &ma, Vt, &na, &wkopt, &lwork, &info);
  lwork = (int)wkopt;
  work = (double*)malloc(lwork*sizeof(double));
  dgesvd_(&op, &op, &ma, &na, A, &ma, S, U, &ma, Vt, &na, work, &lwork, &info);
  ml_Mt (A, na, ma, Ain);
  ml_Mt (U, ma, ma, Uout);
  ml_Mt (S, 1, na, Sout);
  ml_free_M (A);
  ml_free_M (U);
  ml_free_M (S);
  if(info != 0)
    printf("ARDEU\n");
  free(work);
}

canonical_original_code:
void ml_svd(double *Ain, int ma, int na, double *Uout, double *Sout, double *Vt)
{
  char op = 'A';
  int info;
  int lwork;
  double wkopt;
  double *work;
  double *A = ml_alocar_M (na, ma);
  double *U = ml_alocar_M (ma, ma);
  double *S = ml_alocar_M (1, na);
  ml_Mt (Ain, ma, na, A);
  ml_Mt (Uout, ma, ma, U);
  ml_Mt (Sout, na, 1, S);
  lwork = -1;
  dgesvd_(&op, &op, &ma, &na, A, &ma, S, U, &ma, Vt, &na, &wkopt, &lwork, &info);
  lwork = (int)wkopt;
  work = (double *)malloc(lwork*sizeof(double));
  dgesvd_(&op, &op, &ma, &na, A, &ma, S, U, &ma, Vt, &na, work, &lwork, &info);
  ml_Mt (A, na, ma, Ain);
  ml_Mt (U, ma, ma, Uout);
  ml_Mt (S, 1, na, Sout);
  ml_free_M (A);
  ml_free_M (U);
  ml_free_M (S);
  if(info != 0)
    printf("ARDEU\n");
  free(work);
}

variable_types:
Ain
double *

variable_types: ma int

variable_types:
Uout
double *

variable_types:
Sout
double *

variable_types:
Vt
double *

variable_types: op char

variable_types: info int

variable_types: lwork int

variable_types: wkopt double

variable_types:
work
double *

variable_types:
U
double *

variable_types:
S
double *


decompiled_code:
void __fastcall ph_libertar_photo(void *ptr)
{
int v1; // ebp
int v2; // er12

v1 = *(_DWORD *)ptr;
v2 = *((_DWORD *)ptr + 1);
ph_libertar_m(*(_DWORD *)ptr, v2, *((void ***)ptr + 1));
ph_libertar_m(v1, v2, *((void ***)ptr + 2));
ph_libertar_m(v1, v2, *((void ***)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
int v1; // ebp
int v2; // er12

v1 = *(_DWORD *)ptr;
v2 = *((_DWORD *)ptr + 1);
func0(*(_DWORD *)ptr, v2, *((void ***)ptr + 1));
func0(v1, v2, *((void ***)ptr + 2));
func0(v1, v2, *((void ***)ptr + 3));
free(ptr);
}

original_code:
void ph_libertar_photo (p_ph_photo photo_alocada)
{
  int height = photo_alocada->height;
  int width = photo_alocada->width;
  ph_libertar_m(height, width, photo_alocada->R);
  ph_libertar_m(height, width, photo_alocada->G);
  ph_libertar_m(height, width, photo_alocada->B);
  free(photo_alocada);
}

canonical_original_code:
void ph_libertar_photo(struct ph_photo *photo_alocada)
{
  int height = photo_alocada->height;
  int width = photo_alocada->width;
  ph_libertar_m(height, width, photo_alocada->R);
  ph_libertar_m(height, width, photo_alocada->G);
  ph_libertar_m(height, width, photo_alocada->B);
  free(photo_alocada);
}

variable_types: struct ph_photo { int height; int width; unsigned char **R; unsigned char **G; unsigned char **B; } *

variable_types: height int

variable_types: width int


decompiled_code:
void __fastcall ph_libertar_par_photo(void *ptr)
{
ph_libertar_photo(*(void **)ptr);
ph_libertar_photo(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
func1(*(void **)ptr);
func1(*((void **)ptr + 1));
free(ptr);
}

original_code:
void ph_libertar_par_photo (p_ph_par_photo par)
{
  ph_libertar_photo (par->photo1);
  ph_libertar_photo (par->photo2);
  free(par);
}

canonical_original_code:
void ph_libertar_par_photo(struct ph_par_photo *par)
{
  ph_libertar_photo (par->photo1);
  ph_libertar_photo (par->photo2);
  free(par);
}

variable_types: struct ph_par_photo { struct ph_photo { int height; int width; unsigned char **R; unsigned char **G; unsigned char **B; } *photo1; struct ph_photo *photo2; } *

user_defined_types: struct ph_par_photo { struct ph_photo *photo1; struct ph_photo *photo2; }


decompiled_code:
__int64 __fastcall ph_componente_photo(_QWORD *a1, char a2)
{
switch ( a2 )
{
case 'G':
return a1[2];
case 'R':
return a1[1];
case 'B':
return a1[3];
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, char a2)
{
switch ( a2 )
{
case 'G':
return a1[2];
case 'R':
return a1[1];
case 'B':
return a1[3];
}
return 0LL;
}

original_code:
unsigned char **ph_componente_photo (p_ph_photo photo, char nome_comp)
{
  unsigned char **componente = ((void *)0);
  switch(nome_comp)
    {
    case 'R':
      componente = photo->R;
      break;
    case 'G':
      componente = photo->G;
      break;
    case 'B':
      componente = photo->B;
      break;
    }
  return componente;
}

canonical_original_code:
unsigned char **ph_componente_photo(struct ph_photo *photo, char nome_comp)
{
  unsigned char **componente = ((void *)0);
  switch(nome_comp)
    {
    case 'R':
      componente = photo->R;
      break;
    case 'G':
      componente = photo->G;
      break;
    case 'B':
      componente = photo->B;
      break;
    }
  return componente;
}

variable_types:
componente
unsigned char **

return_type: unsigned char **

user_defined_types: struct ph_photo { int height; int width; unsigned char **R; unsigned char **G; unsigned char **B; }


decompiled_code:
__int64 __fastcall ph_height_photo(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
return *a1;
}

original_code:
int ph_height_photo (p_ph_photo photo)
{
  return photo->height;
}

canonical_original_code:
int ph_height_photo(struct ph_photo *photo)
{
  return photo->height;
}


decompiled_code:
__int64 __fastcall ph_width_photo(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

original_code:
int ph_width_photo (p_ph_photo photo)
{
  return photo->width;
}

canonical_original_code:
int ph_width_photo(struct ph_photo *photo)
{
  return photo->width;
}


original_code:
void ep_fundamentalMatrix (int np, double* left, double* right, double* FM)
{
  int i;
  double *A = ml_alocar_M (np, 9);
  double *U = ml_alocar_M (np, np);
  double *S = ml_alocar_M (np, 1);
  double *V = ml_alocar_M (9, 9);
  double *F = ml_alocar_M (3, 3);
  double *FU = ml_alocar_M (3, 3);
  double *FS_ = ml_alocar_M (3, 1);
  double *FV = ml_alocar_M (3, 3);
  double *FS = ml_alocar_M_I (3);
  double *FSn = ml_alocar_M_I (3);
  double *Aux = ml_alocar_M (3, 3);
  double x1, y1, x2, y2;
  for(i = 0; i < np; i++)
    {
      x1 = left[(0 +i*2)];
      y1 = left[(1 +i*2)];
      x2 = right[(0 +i*2)];
      y2 = right[(1 +i*2)];
      A[(0 +i*9)] = x1*x2;
      A[(1 +i*9)] = y1*x2;
      A[(2 +i*9)] = x2;
      A[(3 +i*9)] = x1*y2;
      A[(4 +i*9)] = y1*y2;
      A[(5 +i*9)] = y2;
      A[(6 +i*9)] = x1;
      A[(7 +i*9)] = y1;
      A[(8 +i*9)] = 1.0;
    }
  ml_svd(A, np, 9, U, S, V);
  for(i=0; i < 9; i++)
    F[i] = V[(8 +i*9)];
  ml_svd(F, 3, 3, FU, FS_, FV);
  FS[(0 +0*3)] = FS_[0];
  FS[(1 +1*3)] = FS_[1];
  FS[(2 +2*3)] = FS_[2];
  ml_AeqB (FSn, FS, 3, 3);
  FSn[(2 +2*3)] = 0.0;
  ml_ABtt (FU, 3, 3, 0, FSn, 3, 3, 0, Aux);
  ml_ABtt (Aux, 3, 3, 0, FV, 3, 3, 1, FM);
  ml_free_M (A);
  ml_free_M (U);
  ml_free_M (S);
  ml_free_M (V);
  ml_free_M (F);
  ml_free_M (FU);
  ml_free_M (FS_);
  ml_free_M (FV);
  ml_free_M (FS);
  ml_free_M (FSn);
}

canonical_original_code:
void ep_fundamentalMatrix(int np, double *left, double *right, double *FM)
{
  int i;
  double *A = ml_alocar_M (np, 9);
  double *U = ml_alocar_M (np, np);
  double *S = ml_alocar_M (np, 1);
  double *V = ml_alocar_M (9, 9);
  double *F = ml_alocar_M (3, 3);
  double *FU = ml_alocar_M (3, 3);
  double *FS_ = ml_alocar_M (3, 1);
  double *FV = ml_alocar_M (3, 3);
  double *FS = ml_alocar_M_I (3);
  double *FSn = ml_alocar_M_I (3);
  double *Aux = ml_alocar_M (3, 3);
  double x1; double y1; double x2; double y2;
  for(i = 0; i < np; i++)
    {
      x1 = left[(0 +i*2)];
      y1 = left[(1 +i*2)];
      x2 = right[(0 +i*2)];
      y2 = right[(1 +i*2)];
      A[(0 +i*9)] = x1*x2;
      A[(1 +i*9)] = y1*x2;
      A[(2 +i*9)] = x2;
      A[(3 +i*9)] = x1*y2;
      A[(4 +i*9)] = y1*y2;
      A[(5 +i*9)] = y2;
      A[(6 +i*9)] = x1;
      A[(7 +i*9)] = y1;
      A[(8 +i*9)] = 1.0;
    }
  ml_svd(A, np, 9, U, S, V);
  for(i=0; i < 9; i++)
    F[i] = V[(8 +i*9)];
  ml_svd(F, 3, 3, FU, FS_, FV);
  FS[(0 +0*3)] = FS_[0];
  FS[(1 +1*3)] = FS_[1];
  FS[(2 +2*3)] = FS_[2];
  ml_AeqB (FSn, FS, 3, 3);
  FSn[(2 +2*3)] = 0.0;
  ml_ABtt (FU, 3, 3, 0, FSn, 3, 3, 0, Aux);
  ml_ABtt (Aux, 3, 3, 0, FV, 3, 3, 1, FM);
  ml_free_M (A);
  ml_free_M (U);
  ml_free_M (S);
  ml_free_M (V);
  ml_free_M (F);
  ml_free_M (FU);
  ml_free_M (FS_);
  ml_free_M (FV);
  ml_free_M (FS);
  ml_free_M (FSn);
}

variable_types: np int

variable_types:
left
double *

variable_types:
right
double *

variable_types:
FM
double *

variable_types: i int

variable_types:
A
double *

variable_types:
V
double *

variable_types:
F
double *

variable_types:
FU
double *

variable_types:
FV
double *

variable_types:
FS
double *

variable_types:
FSn
double *

variable_types:
Aux
double *


decompiled_code:
__int64 __fastcall ep_lepipolar(__int64 a1, _QWORD *a2, _QWORD *a3, _QWORD *a4, double a5, double a6)
{
__int64 v8; // rbp
_QWORD *v9; // rbx

v8 = ml_alocar_M(3LL, 1LL);
v9 = (_QWORD *)ml_alocar_M(3LL, 1LL);
*(double *)v8 = a5;
*(double *)(v8 + 8) = a6;
*(_QWORD *)(v8 + 16) = LC2;
ml_ABtt(a1, 3LL, 3LL, 0LL, v8, 3LL, 1LL, 0LL, v9);
*a2 = *v9;
*a3 = v9[1];
*a4 = v9[2];
ml_free_M(v8);
return ml_free_M(v9);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2, _QWORD *a3, _QWORD *a4, double a5, double a6)
{
__int64 v8; // rbp
_QWORD *v9; // rbx

v8 = ml_alocar_M(3LL, 1LL);
v9 = (_QWORD *)ml_alocar_M(3LL, 1LL);
*(double *)v8 = a5;
*(double *)(v8 + 8) = a6;
*(_QWORD *)(v8 + 16) = LC2;
ml_ABtt(a1, 3LL, 3LL, 0LL, v8, 3LL, 1LL, 0LL, v9);
*a2 = *v9;
*a3 = v9[1];
*a4 = v9[2];
ml_free_M(v8);
return ml_free_M(v9);
}

original_code:
void ep_lepipolar (double* FM, double xl, double yl, double* a, double* b, double* c)
{
    double *Pl = ml_alocar_M (3, 1);
    double *u = ml_alocar_M (3, 1);
    Pl[0] = xl;
    Pl[1] = yl;
    Pl[2] = 1.0;
    ml_ABtt (FM, 3, 3, 0, Pl, 3, 1, 0, u);
    *a = u[0];
    *b = u[1];
    *c = u[2];
    ml_free_M (Pl);
    ml_free_M (u);
}

canonical_original_code:
void ep_lepipolar(double *FM, double xl, double yl, double *a, double *b, double *c)
{
    double *Pl = ml_alocar_M (3, 1);
    double *u = ml_alocar_M (3, 1);
    Pl[0] = xl;
    Pl[1] = yl;
    Pl[2] = 1.0;
    ml_ABtt (FM, 3, 3, 0, Pl, 3, 1, 0, u);
    *a = u[0];
    *b = u[1];
    *c = u[2];
    ml_free_M (Pl);
    ml_free_M (u);
}

variable_types: xl double

variable_types: yl double

variable_types:
a
double *

variable_types:
b
double *

variable_types:
c
double *

variable_types:
Pl
double *

variable_types:
u
double *


decompiled_code:
double __fastcall abm_media(unsigned __int8 **a1, int a2, int a3)
{
int v4; // er10
unsigned __int8 **v5; // rsi
__int64 v6; // r8
double v7; // xmm0_8
unsigned __int8 *v8; // rax

v4 = a3 * a2;
if ( a2 <= 0 )
{
v7 = 0.0;
}
else
{
v5 = a1;
v6 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v7 = 0.0;
do
{
if ( a3 > 0 )
{
v8 = *v5;
do
v7 = v7 + (double)*v8++;
while ( v8 != &(*v5)[a3] );
}
++v5;
}
while ( v5 != (unsigned __int8 **)v6 );
}
return v7 / (double)v4;
}

canonical_decompiled_code:
double __fastcall func0(unsigned __int8 **a1, int a2, int a3)
{
int v4; // er10
unsigned __int8 **v5; // rsi
__int64 v6; // r8
double v7; // xmm0_8
unsigned __int8 *v8; // rax

v4 = a3 * a2;
if ( a2 <= 0 )
{
v7 = 0.0;
}
else
{
v5 = a1;
v6 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v7 = 0.0;
do
{
if ( a3 > 0 )
{
v8 = *v5;
do
v7 = v7 + (double)*v8++;
while ( v8 != &(*v5)[a3] );
}
++v5;
}
while ( v5 != (unsigned __int8 **)v6 );
}
return v7 / (double)v4;
}

original_code:
double abm_media (unsigned char **im, int height, int width)
{
  int i, j;
  double media = 0;
  int n_px = height * width;
  for(i=0; i < height; i++)
    {
      for(j=0; j < width; j++)
 media += (double)im[i][j];
    }
  media /= n_px;
  return media;
}

canonical_original_code:
double abm_media(unsigned char **im, int height, int width)
{
  int i; int j;
  double media = 0;
  int n_px = height * width;
  for(i=0; i < height; i++)
    {
      for(j=0; j < width; j++)
 media += (double)im[i][j];
    }
  media /= n_px;
  return media;
}

variable_types:
im
unsigned char **

variable_types: height int

variable_types: width int

variable_types: j int

variable_types: media double


decompiled_code:
double __fastcall abm_desvio_padrao(unsigned __int8 **a1, int a2, int a3)
{
int v5; // ebp
double v6; // xmm0_8
unsigned __int8 **v7; // rsi
__int64 v8; // rdi
double v9; // xmm1_8
unsigned __int8 *v10; // rax
double v11; // xmm1_8
double result; // xmm0_8

v5 = a3 * a2;
v6 = abm_media(a1, a2, a3);
if ( a2 <= 0 )
{
v9 = 0.0;
}
else
{
v7 = a1;
v8 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v9 = 0.0;
do
{
if ( a3 > 0 )
{
v10 = *v7;
do
{
v9 = v9 + ((double)*v10 - v6) * ((double)*v10 - v6);
++v10;
}
while ( &(*v7)[a3] != v10 );
}
++v7;
}
while ( v7 != (unsigned __int8 **)v8 );
}
v11 = v9 / (double)(v5 - 1);
if ( v11 < 0.0 )
result = sqrt(v11);
else
result = sqrt(v11);
return result;
}

canonical_decompiled_code:
double __fastcall func1(unsigned __int8 **a1, int a2, int a3)
{
int v5; // ebp
double v6; // xmm0_8
unsigned __int8 **v7; // rsi
__int64 v8; // rdi
double v9; // xmm1_8
unsigned __int8 *v10; // rax
double v11; // xmm1_8
double result; // xmm0_8

v5 = a3 * a2;
v6 = func0(a1, a2, a3);
if ( a2 <= 0 )
{
v9 = 0.0;
}
else
{
v7 = a1;
v8 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v9 = 0.0;
do
{
if ( a3 > 0 )
{
v10 = *v7;
do
{
v9 = v9 + ((double)*v10 - v6) * ((double)*v10 - v6);
++v10;
}
while ( &(*v7)[a3] != v10 );
}
++v7;
}
while ( v7 != (unsigned __int8 **)v8 );
}
v11 = v9 / (double)(v5 - 1);
if ( v11 < 0.0 )
result = sqrt(v11);
else
result = sqrt(v11);
return result;
}

original_code:
double abm_desvio_padrao (unsigned char **im, int height, int width)
{
  int i, j;
  double media;
  double despad = 0;
  int n_px = height * width;
  media = abm_media(im, height, width);
  for(i=0; i < height; i++)
    {
      for(j=0; j < width; j++)
 despad += pow(((double)im[i][j] - media),2);
    }
  despad /= (n_px - 1);
  despad = sqrt(despad);
  return despad;
}

canonical_original_code:
double abm_desvio_padrao(unsigned char **im, int height, int width)
{
  int i; int j;
  double media;
  double despad = 0;
  int n_px = height * width;
  media = abm_media(im, height, width);
  for(i=0; i < height; i++)
    {
      for(j=0; j < width; j++)
 despad += pow(((double)im[i][j] - media),2);
    }
  despad /= (n_px - 1);
  despad = sqrt(despad);
  return despad;
}

variable_types: i int

variable_types: despad double


decompiled_code:
double __fastcall abm_coef_correlacao(unsigned __int8 **a1, unsigned __int8 **a2, int a3, int a4)
{
double v6; // r14
double v7; // r15

v6 = abm_desvio_padrao(a1, a3, a4);
v7 = abm_desvio_padrao(a2, a3, a4);
return COERCE_DOUBLE(abm_covariancia(a1, a2, a3, a4)) / (v6 * v7);
}

canonical_decompiled_code:
double __fastcall func2(unsigned __int8 **a1, unsigned __int8 **a2, int a3, int a4)
{
double v6; // r14
double v7; // r15

v6 = func1(a1, a3, a4);
v7 = func1(a2, a3, a4);
return COERCE_DOUBLE(abm_covariancia(a1, a2, a3, a4)) / (v6 * v7);
}

original_code:
double abm_coef_correlacao (unsigned char **im1, unsigned char **im2, int height, int width)
{
  double despad1, despad2;
  double cov;
  despad1 = abm_desvio_padrao(im1, height, width);
  despad2 = abm_desvio_padrao(im2, height, width);
  cov = abm_covariancia (im1, im2, height, width);
  return cov / (despad1 * despad2);
}

canonical_original_code:
double abm_coef_correlacao(unsigned char **im1, unsigned char **im2, int height, int width)
{
  double despad1; double despad2;
  double cov;
  despad1 = abm_desvio_padrao(im1, height, width);
  despad2 = abm_desvio_padrao(im2, height, width);
  cov = abm_covariancia (im1, im2, height, width);
  return cov / (despad1 * despad2);
}

variable_types: cov double


decompiled_code:
void __fastcall abm_libertar_sub_matrix(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func4(void *a1)
{
free(a1);
}

original_code:
void abm_libertar_sub_matrix (unsigned char **sub)
{
  free(sub);
}

canonical_original_code:
void abm_libertar_sub_matrix(unsigned char **sub)
{
  free(sub);
}

variable_types:
sub
unsigned char **


decompiled_code:
void __fastcall abm_cross_correlation(__int64 a1, unsigned int a2, unsigned int a3, unsigned __int8 **a4, int a5, int a6)
{
int v6; // er15
int v7; // ecx
int v8; // er13
int v9; // er14
unsigned int v10; // ebx
char *v11; // rbp
double v12; // xmm0_8
int v13; // [rsp+8h] [rbp-60h]
int v18; // [rsp+28h] [rbp-40h]
int v19; // [rsp+2Ch] [rbp-3Ch]

v6 = (a6 - 1) / 2;
v7 = (a5 - 1) / 2;
v18 = v7;
if ( v7 < (int)(a2 - v7) )
{
v13 = 2 * v7;
v19 = a2 - v7 - v7;
v8 = 0;
v9 = a3 - v6;
do
{
v10 = v6;
if ( v6 < v9 )
{
do
{
v11 = abm_alocar_sub_matrix(a1, a2, a3, v8, v13, v10 - v6);
v12 = abm_coef_correlacao((unsigned __int8 **)v11, a4, a5, a6);
abm_libertar_sub_matrix(v11);
if ( v12 >= 0.99 )
printf("ENCONTROU: cc = %lf\n H: %d W: %d\n", v12, (unsigned int)(v8 + v18), v10);
++v10;
}
while ( v10 != v9 );
}
++v8;
++v13;
}
while ( v8 != v19 );
}
}

original_code:
void abm_cross_correlation (unsigned char **im, int him, int wim, unsigned char **t, int ht, int wt)
{
  int i, j;
  unsigned char **window;
  int halfw = (wt-1)/2;
  int halfh = (ht-1)/2;
  double cc;
  for(i = halfh; i < him - halfh; i++)
    for(j = halfw; j < wim - halfw; j++)
      {
 window = abm_alocar_sub_matrix (im, him, wim, i-halfh, i+halfh,
     j-halfw, j+halfw);
 cc = abm_coef_correlacao (window, t, ht, wt);
 abm_libertar_sub_matrix(window);
 if (cc >= 0.99)
   printf("ENCONTROU: cc = %lf\n          H: %d   W: %d\n", cc, i, j);
      }
}

canonical_original_code:
void abm_cross_correlation(unsigned char **im, int him, int wim, unsigned char **t, int ht, int wt)
{
  int i; int j;
  unsigned char **window;
  int halfw = (wt-1)/2;
  int halfh = (ht-1)/2;
  double cc;
  for(i = halfh; i < him - halfh; i++)
    for(j = halfw; j < wim - halfw; j++)
      {
 window = abm_alocar_sub_matrix (im, him, wim, i-halfh, i+halfh,
     j-halfw, j+halfw);
 cc = abm_coef_correlacao (window, t, ht, wt);
 abm_libertar_sub_matrix(window);
 if (cc >= 0.99)
   printf("ENCONTROU: cc = %lf\n          H: %d   W: %d\n", cc, i, j);
      }
}

variable_types: him int

variable_types: wim int

variable_types:
t
unsigned char **

variable_types: ht int

variable_types: wt int

variable_types:
window
unsigned char **

variable_types: halfw int

variable_types: halfh int

variable_types: cc double


original_code:
int abm_cross_correlation_epi (unsigned char **im, int him, int wim,
          unsigned char **t, int ht, int wt,
          double *FM, int *fl,
          int ty, int x_min, int x_max,
          double cc_min,
          int coo_final[], double *cc_final)
{
  int i, j;
  int inicio_x, fim_x;
  unsigned char **window;
  int halfw = (wt-1)/2;
  int halfh = (ht-1)/2;
  double cc;
  double cc_max = 0;
  int coo_cc_max[2];
  double y;
  int int_y;
  double epil[3];
  ((x_min >= 0 && x_max <= wim) ? (void) (0) : __assert_fail ("x_min >= 0 && x_max <= wim", "abmatching.c", 215, __extension__ __PRETTY_FUNCTION__));
  ep_lepipolar (FM, fl[1], fl[0], &epil[0], &epil[1], &epil[2]);
  if (x_min-halfw >= 0)
    inicio_x = x_min;
  else
    inicio_x = x_min + halfw;
  if (x_max + halfw <= wim)
    fim_x = x_max;
  else
    fim_x = x_max - halfw;
  for(j = inicio_x; j < fim_x; j++)
    {
      y = (-epil[2]-epil[0]*(double)j)/epil[1];
      int_y = (int)y;
      if((int_y-ty)-halfh < 0 || int_y+ty+halfh > him)
 ;
      else
       for(i = int_y-ty; i <= int_y+ty; i++)
  {
    window = abm_alocar_sub_matrix (im, him, wim, i-halfh, i+halfh,
        j-halfw, j+halfw);
    cc = abm_coef_correlacao (window, t, ht, wt);
    if (cc > cc_max)
      {
        cc_max = cc;
        coo_cc_max[0] = i;
        coo_cc_max[1] = j;
      }
    abm_libertar_sub_matrix(window);
  }
    }
  if (cc_max > cc_min)
    {
      *cc_final = cc_max;
      coo_final[0] = coo_cc_max[0];
      coo_final[1] = coo_cc_max[1];
      return 1;
    }
  return 0;
}

canonical_original_code:
int abm_cross_correlation_epi(unsigned char **im, int him, int wim, unsigned char **t, int ht, int wt, double *FM, int *fl, int ty, int x_min, int x_max, double cc_min, int coo_final[], double *cc_final)
{
  int i; int j;
  int inicio_x; int fim_x;
  unsigned char **window;
  int halfw = (wt-1)/2;
  int halfh = (ht-1)/2;
  double cc;
  double cc_max = 0;
  int coo_cc_max[2];
  double y;
  int int_y;
  double epil[3];
  ((x_min >= 0 && x_max <= wim) ? (void) (0) : __assert_fail ("x_min >= 0 && x_max <= wim", "abmatching.c", 215, __extension__ __PRETTY_FUNCTION__));
  ep_lepipolar (FM, fl[1], fl[0], &epil[0], &epil[1], &epil[2]);
  if (x_min-halfw >= 0)
    inicio_x = x_min;
  else
    inicio_x = x_min + halfw;
  if (x_max + halfw <= wim)
    fim_x = x_max;
  else
    fim_x = x_max - halfw;
  for(j = inicio_x; j < fim_x; j++)
    {
      y = (-epil[2]-epil[0]*(double)j)/epil[1];
      int_y = (int)y;
      if((int_y-ty)-halfh < 0 || int_y+ty+halfh > him)
 ;
      else
       for(i = int_y-ty; i <= int_y+ty; i++)
  {
    window = abm_alocar_sub_matrix (im, him, wim, i-halfh, i+halfh,
        j-halfw, j+halfw);
    cc = abm_coef_correlacao (window, t, ht, wt);
    if (cc > cc_max)
      {
        cc_max = cc;
        coo_cc_max[0] = i;
        coo_cc_max[1] = j;
      }
    abm_libertar_sub_matrix(window);
  }
    }
  if (cc_max > cc_min)
    {
      *cc_final = cc_max;
      coo_final[0] = coo_cc_max[0];
      coo_final[1] = coo_cc_max[1];
      return 1;
    }
  return 0;
}

variable_types:
im
unsigned char **

variable_types:
FM
double *

variable_types:
fl
int *

variable_types: ty int

variable_types: y double

variable_types:
epil
double [3]


original_code:
int abm_cross_correlation_epi_area (unsigned char **iml, int himl, int wiml,
        unsigned char **imr, int himr, int wimr,
        int dim_template,
        double *FM, int ty,
        int x_min_l, int x_max_l,
        int y_min_l, int y_max_l,
        int x_min_r, int x_max_r,
        double cc_min,
        int *n, double *resultado)
{
  int i, j;
  int k = 0;
  int coo_r[2], coo_l[2];
  double cc;
  unsigned char **template;
  for(i = y_min_l; i <= y_max_l; i++)
    for(j = x_min_l; j <= x_max_l; j++)
      {
 coo_l[0] = i; coo_l[1] = j;
 template = abm_alocar_sub_matrix (iml, himl, wiml,
       coo_l[0]-dim_template,
       coo_l[0]+dim_template,
       coo_l[1]-dim_template,
       coo_l[1]+dim_template);
 if (abm_cross_correlation_epi(imr, himr, wimr,
          template,
          2*dim_template+1, 2*dim_template+1,
          FM, coo_l, ty,
          x_min_r, x_max_r, cc_min, coo_r, &cc))
   {
     resultado[(0 +k*5)] = coo_l[0];
     resultado[(1 +k*5)] = coo_l[1];
     resultado[(2 +k*5)] = coo_r[0];
     resultado[(3 +k*5)] = coo_r[1];
     resultado[(4 +k*5)] = cc;
     k++;
   }
 abm_libertar_sub_matrix(template);
      }
  *n = k;
  return k != 0 ? 1 : 0;
}

canonical_original_code:
int abm_cross_correlation_epi_area(unsigned char **iml, int himl, int wiml, unsigned char **imr, int himr, int wimr, int dim_template, double *FM, int ty, int x_min_l, int x_max_l, int y_min_l, int y_max_l, int x_min_r, int x_max_r, double cc_min, int *n, double *resultado)
{
  int i; int j;
  int k = 0;
  int coo_r[2]; int coo_l[2];
  double cc;
  unsigned char **template;
  for(i = y_min_l; i <= y_max_l; i++)
    for(j = x_min_l; j <= x_max_l; j++)
      {
 coo_l[0] = i; coo_l[1] = j;
 template = abm_alocar_sub_matrix (iml, himl, wiml,
       coo_l[0]-dim_template,
       coo_l[0]+dim_template,
       coo_l[1]-dim_template,
       coo_l[1]+dim_template);
 if (abm_cross_correlation_epi(imr, himr, wimr,
          template,
          2*dim_template+1, 2*dim_template+1,
          FM, coo_l, ty,
          x_min_r, x_max_r, cc_min, coo_r, &cc))
   {
     resultado[(0 +k*5)] = coo_l[0];
     resultado[(1 +k*5)] = coo_l[1];
     resultado[(2 +k*5)] = coo_r[0];
     resultado[(3 +k*5)] = coo_r[1];
     resultado[(4 +k*5)] = cc;
     k++;
   }
 abm_libertar_sub_matrix(template);
      }
  *n = k;
  return k != 0 ? 1 : 0;
}

variable_types:
iml
unsigned char **

variable_types: himl int

variable_types: wiml int

variable_types:
imr
unsigned char **

variable_types: himr int

variable_types: wimr int

variable_types:
n
int *

variable_types:
resultado
double *

variable_types: i int

variable_types: j int

variable_types: k int

variable_types:
template
unsigned char **


repo: vascoorey/DistributedTable

decompiled_code:
__int64 rtable_connect()
{
return network_connect();
}

canonical_decompiled_code:
__int64 func0()
{
return network_connect();
}

original_code:
int rtable_connect(struct rtable_t *table) {
 return network_connect(table);
}

variable_types: struct rtable_t { int socket; char *ip; char *porto; } *


decompiled_code:
__int64 __fastcall rtable_disconnect(void *ptr)
{
unsigned int v1; // ebp

if ( ptr )
{
v1 = network_close();
if ( v1 == -1 )
{
fprintf(stderr, "%s : %d : \"remote_table: network_close\"\n", "rtable_disconnect", 113LL);
}
else
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
v1 = 0;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: rtable_disconnect: NULL table\"\n", "rtable_disconnect", 107LL);
v1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
unsigned int v1; // ebp

if ( ptr )
{
v1 = network_close();
if ( v1 == -1 )
{
fprintf(stderr, "%s : %d : \"remote_table: network_close\"\n", "rtable_disconnect", 113LL);
}
else
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
v1 = 0;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: rtable_disconnect: NULL table\"\n", "rtable_disconnect", 107LL);
v1 = -1;
}
return v1;
}

original_code:
int rtable_disconnect(struct rtable_t *table) {
    if(table == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: rtable_disconnect: NULL table\"""\n", __FUNCTION__, 107);
        return -1;
    }
    if((network_close(table)) == -1) {
        fprintf( stderr, "%s : %d : ""\"remote_table: network_close\"""\n", __FUNCTION__, 113);
        return -1;
    }
    free(table->ip);
    free(table->porto);
    free(table);
    return 0;
}

user_defined_types: struct rtable_t { int socket; char *ip; char *porto; }


decompiled_code:
__int64 __fastcall rtable_put(__int64 a1, __int64 a2)
{
_WORD *v2; // rax
_WORD *v3; // rbp
__int64 result; // rax
__int16 v5[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+8h] [rbp-20h]

if ( a1 && a2 )
{
v5[0] = 10;
v5[1] = 10;
v6 = a2;
v2 = (_WORD *)network_send_receive(a1, v5);
v3 = v2;
if ( v2 )
{
if ( *v2 == 11 )
{
free_message(v2);
entry_destroy(a2);
result = 0LL;
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: invalid message\"\n", "rtable_put", 154LL);
entry_destroy(a2);
free_message(v3);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: network_send_receive\"\n", "rtable_put", 147LL);
entry_destroy(a2);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: NULL table or key or data\"\n", "rtable_put", 134LL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
_WORD *v2; // rax
_WORD *v3; // rbp
__int64 result; // rax
__int16 v5[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+8h] [rbp-20h]

if ( a1 && a2 )
{
v5[0] = 10;
v5[1] = 10;
v6 = a2;
v2 = (_WORD *)network_send_receive(a1, v5);
v3 = v2;
if ( v2 )
{
if ( *v2 == 11 )
{
free_message(v2);
entry_destroy(a2);
result = 0LL;
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: invalid message\"\n", "rtable_put", 154LL);
entry_destroy(a2);
free_message(v3);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: network_send_receive\"\n", "rtable_put", 147LL);
entry_destroy(a2);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: NULL table or key or data\"\n", "rtable_put", 134LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int rtable_put(struct rtable_t *table, struct entry_t *entry) {
    if(table == ((void *)0) || entry == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: NULL table or key or data\"""\n", __FUNCTION__, 134);
        return -1;
    }
    struct message_t msg;
    msg.opcode = 10;
    msg.c_type = 10;
    msg.content.entry = entry;
    struct message_t *rsp;
    if((rsp = network_send_receive(table, &msg)) == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: network_send_receive\"""\n", __FUNCTION__, 147);
        entry_destroy(entry);
        return -1;
    }
    if(rsp->opcode != (10 + 1)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: invalid message\"""\n", __FUNCTION__, 154);
        entry_destroy(entry);
        free_message(rsp);
        return -1;
    }
    free_message(rsp);
 entry_destroy(entry);
    return 0;
}

variable_types: struct message_t { short opcode; short c_type; union content_u { struct entry_t { char *key; struct data_t { int datasize; void *data; long timestamp; } *value; } *entry; char *key; char **keys; struct data_t *value; int result; long timestamp; } content; } *

user_defined_types: struct message_t { short opcode; short c_type; union content_u content; }

user_defined_types: struct entry_t { char *key; struct data_t *value; }

user_defined_types: union content_u { struct entry_t *entry; char *key; char **keys; struct data_t *value; int result; long timestamp; }


decompiled_code:
__int64 __fastcall rtable_get(__int64 a1, __int64 a2)
{
_WORD *v2; // rax
_WORD *v3; // rbx
__int16 v4; // ax
__int64 v5; // rbp
__int16 v7[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v8; // [rsp+8h] [rbp-20h]

if ( a1 && a2 )
{
v7[0] = 20;
v7[1] = 20;
v8 = a2;
v2 = (_WORD *)network_send_receive(a1, v7);
v3 = v2;
if ( v2 )
{
v4 = *v2;
if ( v4 == 21 )
{
v5 = *((_QWORD *)v3 + 1);
if ( v5 && (v5 = data_dup(*((_QWORD *)v3 + 1))) == 0 )
{
fprintf(stderr, "%s : %d : \"remote_table: data_dup\"\n", "rtable_get", 204LL);
free_message(v3);
}
else
{
free_message(v3);
}
}
else
{
if ( v4 == 99 && *((_DWORD *)v3 + 2) )
fprintf(stderr, "%s : %d : \"remote_table: invalid message\"\n", "rtable_get", 195LL);
free_message(v3);
v5 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: network_send_receive\"\n", "rtable_get", 188LL);
v5 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: NULL table or key\"\n", "rtable_get", 175LL);
v5 = 0LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
_WORD *v2; // rax
_WORD *v3; // rbx
__int16 v4; // ax
__int64 v5; // rbp
__int16 v7[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v8; // [rsp+8h] [rbp-20h]

if ( a1 && a2 )
{
v7[0] = 20;
v7[1] = 20;
v8 = a2;
v2 = (_WORD *)network_send_receive(a1, v7);
v3 = v2;
if ( v2 )
{
v4 = *v2;
if ( v4 == 21 )
{
v5 = *((_QWORD *)v3 + 1);
if ( v5 && (v5 = data_dup(*((_QWORD *)v3 + 1))) == 0 )
{
fprintf(stderr, "%s : %d : \"remote_table: data_dup\"\n", "rtable_get", 204LL);
free_message(v3);
}
else
{
free_message(v3);
}
}
else
{
if ( v4 == 99 && *((_DWORD *)v3 + 2) )
fprintf(stderr, "%s : %d : \"remote_table: invalid message\"\n", "rtable_get", 195LL);
free_message(v3);
v5 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: network_send_receive\"\n", "rtable_get", 188LL);
v5 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: NULL table or key\"\n", "rtable_get", 175LL);
v5 = 0LL;
}
return v5;
}

original_code:
struct data_t *rtable_get(struct rtable_t *table, char *key) {
    if(table == ((void *)0) || key == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: NULL table or key\"""\n", __FUNCTION__, 175);
        return ((void *)0);
    }
    struct message_t msg;
    msg.opcode = 20;
    msg.c_type = 20;
    msg.content.key = key;
    struct message_t *rsp;
    if((rsp = network_send_receive(table, &msg)) == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: network_send_receive\"""\n", __FUNCTION__, 188);
        return ((void *)0);
    }
    if(rsp->opcode != (20 + 1)) {
  if(rsp->opcode == 99 && rsp->content.result != 0) {
   fprintf( stderr, "%s : %d : ""\"remote_table: invalid message\"""\n", __FUNCTION__, 195);
  }
  free_message(rsp);
        return ((void *)0);
    }
    struct data_t *data = ((void *)0);
 if(rsp->content.value && (data = data_dup(rsp->content.value)) == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: data_dup\"""\n", __FUNCTION__, 204);
        free_message(rsp);
        return ((void *)0);
    }
    free_message(rsp);
    return data;
}

variable_types:
key
char *

variable_types: struct message_t { short opcode; short c_type; union content_u { struct entry_t { char *key; struct data_t { int datasize; void *data; long timestamp; } *value; } *entry; char *key; char **keys; struct data_t *value; int result; long timestamp; } content; }


decompiled_code:
__int64 __fastcall rtable_del(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
unsigned int v4; // ebp
__int16 v6[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+8h] [rbp-20h]

if ( a1 && a2 )
{
v6[0] = 30;
v6[1] = 20;
v7 = a2;
v2 = network_send_receive(a1, v6);
v3 = v2;
if ( v2 )
{
if ( *(_WORD *)v2 == 31 )
{
v4 = *(_DWORD *)(v2 + 8);
free_message(v2);
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: invalid message\"\n", "rtable_del", 245LL);
free_message(v3);
v4 = -1;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: network_send_receive\"\n", "rtable_del", 239LL);
v4 = -1;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: NULL table or key\"\n", "rtable_del", 226LL);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
unsigned int v4; // ebp
__int16 v6[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+8h] [rbp-20h]

if ( a1 && a2 )
{
v6[0] = 30;
v6[1] = 20;
v7 = a2;
v2 = network_send_receive(a1, v6);
v3 = v2;
if ( v2 )
{
if ( *(_WORD *)v2 == 31 )
{
v4 = *(_DWORD *)(v2 + 8);
free_message(v2);
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: invalid message\"\n", "rtable_del", 245LL);
free_message(v3);
v4 = -1;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: network_send_receive\"\n", "rtable_del", 239LL);
v4 = -1;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: NULL table or key\"\n", "rtable_del", 226LL);
v4 = -1;
}
return v4;
}

original_code:
int rtable_del(struct rtable_t *table, char *key) {
    int retVal = 0;
    if(table == ((void *)0) || key == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: NULL table or key\"""\n", __FUNCTION__, 226);
        return -1;
    }
    struct message_t msg;
    msg.opcode = 30;
    msg.c_type = 20;
    msg.content.key = key;
    struct message_t *rsp;
    if((rsp = network_send_receive(table, &msg)) == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: network_send_receive\"""\n", __FUNCTION__, 239);
        return -1;
    }
    if(rsp->opcode != (30 + 1)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: invalid message\"""\n", __FUNCTION__, 245);
        free_message(rsp);
        return -1;
    }
    retVal = rsp->content.result;
    free_message(rsp);
    return retVal;
}

variable_types: retVal int

user_defined_types: struct data_t { int datasize; void *data; long timestamp; }


decompiled_code:
__int64 __fastcall rtable_size(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
unsigned int v3; // ebp
__int16 v5[4]; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+8h] [rbp-20h]

if ( a1 )
{
v5[0] = 40;
v5[1] = 50;
v6 = 0;
v1 = network_send_receive(a1, v5);
v2 = v1;
if ( v1 )
{
if ( *(_WORD *)v1 == 41 )
{
v3 = *(_DWORD *)(v1 + 8);
free_message(v1);
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: invalid message\"\n", "rtable_size", 283LL);
free_message(v2);
v3 = -1;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: network_send_receive\"\n", "rtable_size", 277LL);
v3 = -1;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: NULL table\"\n", "rtable_size", 264LL);
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
unsigned int v3; // ebp
__int16 v5[4]; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+8h] [rbp-20h]

if ( a1 )
{
v5[0] = 40;
v5[1] = 50;
v6 = 0;
v1 = network_send_receive(a1, v5);
v2 = v1;
if ( v1 )
{
if ( *(_WORD *)v1 == 41 )
{
v3 = *(_DWORD *)(v1 + 8);
free_message(v1);
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: invalid message\"\n", "rtable_size", 283LL);
free_message(v2);
v3 = -1;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: network_send_receive\"\n", "rtable_size", 277LL);
v3 = -1;
}
}
else
{
fprintf(stderr, "%s : %d : \"remote_table: NULL table\"\n", "rtable_size", 264LL);
v3 = -1;
}
return v3;
}

original_code:
int rtable_size(struct rtable_t *table) {
    if(table == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: NULL table\"""\n", __FUNCTION__, 264);
        return -1;
    }
    struct message_t msg;
    msg.opcode = 40;
    msg.c_type = 50;
    msg.content.result = 0;
    struct message_t *rsp;
    if((rsp = network_send_receive(table, &msg)) == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: network_send_receive\"""\n", __FUNCTION__, 277);
        return -1;
    }
    if(rsp->opcode != (40 + 1)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: invalid message\"""\n", __FUNCTION__, 283);
        free_message(rsp);
        return -1;
    }
    int size = rsp->content.result;
    free_message(rsp);
    return size;
}

variable_types: size int


decompiled_code:
char *__fastcall rtable_get_keys(char *a1)
{
char *v1; // r12
__int64 v2; // rax
__int64 v3; // r13
const char **v4; // rcx
const char *v5; // rbx
__int64 v6; // rax
int v7; // edx
size_t v8; // r14
__int64 v9; // rbp
char *v10; // rbx
__int16 v12[4]; // [rsp+0h] [rbp-38h] BYREF
int v13; // [rsp+8h] [rbp-30h]

v1 = a1;
if ( !a1 )
{
fprintf(stderr, "%s : %d : \"remote_table: NULL table\"\n", "rtable_get_keys", 303LL);
return v1;
}
v12[0] = 50;
v12[1] = 50;
v13 = 0;
v2 = network_send_receive(a1, v12);
v3 = v2;
if ( !v2 )
{
fprintf(stderr, "%s : %d : \"remote_table: network_send_receive\"\n", "rtable_get_keys", 316LL);
return 0LL;
}
if ( *(_WORD *)v2 != 51 )
{
fprintf(stderr, "%s : %d : \"remote_table: invalid message\"\n", "rtable_get_keys", 322LL);
free_message(v3);
return 0LL;
}
v4 = *(const char ***)(v2 + 8);
v5 = *v4;
v6 = 0LL;
if ( !*v4 )
{
v1 = (char *)malloc(8uLL);
v8 = 8LL;
if ( v1 )
{
LABEL_10:
*(_QWORD *)&v1[v8 - 8] = 0LL;
free_message(v3);
return v1;
}
LABEL_17:
fprintf(stderr, "%s : %d : \"remote_table: malloc keys\"\n", "rtable_get_keys", 339LL);
free_message(v3);
return 0LL;
}
do
v7 = v6++;
while ( v4[v6] );
v8 = 8LL * (v7 + 2);
v1 = (char *)malloc(v8);
if ( !v1 )
goto LABEL_17;
v9 = 0LL;
while ( 1 )
{
v10 = strdup(v5);
*(_QWORD *)&v1[v9] = v10;
if ( !v10 )
break;
v9 += 8LL;
v5 = *(const char **)(*(_QWORD *)(v3 + 8) + v9);
if ( !v5 )
goto LABEL_10;
}
fprintf(stderr, "%s : %d : \"remote_table: strdup keys\"\n", "rtable_get_keys", 348LL);
table_free_keys(v1);
free_message(v3);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func6(char *a1)
{
char *v1; // r12
__int64 v2; // rax
__int64 v3; // r13
const char **v4; // rcx
const char *v5; // rbx
__int64 v6; // rax
int v7; // edx
size_t v8; // r14
__int64 v9; // rbp
char *v10; // rbx
__int16 v12[4]; // [rsp+0h] [rbp-38h] BYREF
int v13; // [rsp+8h] [rbp-30h]

v1 = a1;
if ( !a1 )
{
fprintf(stderr, "%s : %d : \"remote_table: NULL table\"\n", "rtable_get_keys", 303LL);
return v1;
}
v12[0] = 50;
v12[1] = 50;
v13 = 0;
v2 = network_send_receive(a1, v12);
v3 = v2;
if ( !v2 )
{
fprintf(stderr, "%s : %d : \"remote_table: network_send_receive\"\n", "rtable_get_keys", 316LL);
return 0LL;
}
if ( *(_WORD *)v2 != 51 )
{
fprintf(stderr, "%s : %d : \"remote_table: invalid message\"\n", "rtable_get_keys", 322LL);
free_message(v3);
return 0LL;
}
v4 = *(const char ***)(v2 + 8);
v5 = *v4;
v6 = 0LL;
if ( !*v4 )
{
v1 = (char *)malloc(8uLL);
v8 = 8LL;
if ( v1 )
{
LABEL_10:
*(_QWORD *)&v1[v8 - 8] = 0LL;
free_message(v3);
return v1;
}
LABEL_17:
fprintf(stderr, "%s : %d : \"remote_table: malloc keys\"\n", "rtable_get_keys", 339LL);
free_message(v3);
return 0LL;
}
do
v7 = v6++;
while ( v4[v6] );
v8 = 8LL * (v7 + 2);
v1 = (char *)malloc(v8);
if ( !v1 )
goto LABEL_17;
v9 = 0LL;
while ( 1 )
{
v10 = strdup(v5);
*(_QWORD *)&v1[v9] = v10;
if ( !v10 )
break;
v9 += 8LL;
v5 = *(const char **)(*(_QWORD *)(v3 + 8) + v9);
if ( !v5 )
goto LABEL_10;
}
fprintf(stderr, "%s : %d : \"remote_table: strdup keys\"\n", "rtable_get_keys", 348LL);
table_free_keys(v1);
free_message(v3);
return 0LL;
}

original_code:
char **rtable_get_keys(struct rtable_t *table) {
    if(table == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: NULL table\"""\n", __FUNCTION__, 303);
        return ((void *)0);
    }
    struct message_t msg;
    msg.opcode = 50;
    msg.c_type = 50;
    msg.content.result = 0;
    struct message_t *rsp;
    if((rsp = network_send_receive(table, &msg)) == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: network_send_receive\"""\n", __FUNCTION__, 316);
        return ((void *)0);
    }
    if(rsp->opcode != (50 + 1)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: invalid message\"""\n", __FUNCTION__, 322);
        free_message(rsp);
        return ((void *)0);
    }
    int i = 0;
    int nKeys = 0;
    while (rsp->content.keys[i] != ((void *)0)) {
        nKeys++;
        i++;
    }
    nKeys ++;
    char **keys;
    if((keys = (char **) malloc(sizeof(char *) * nKeys)) == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"remote_table: malloc keys\"""\n", __FUNCTION__, 339);
        free_message(rsp);
        return ((void *)0);
    }
    i = 0;
    while (rsp->content.keys[i] != ((void *)0)) {
        if((keys[i] = strdup(rsp->content.keys[i])) == ((void *)0)) {
            fprintf( stderr, "%s : %d : ""\"remote_table: strdup keys\"""\n", __FUNCTION__, 348);
            table_free_keys(keys);
            free_message(rsp);
            return ((void *)0);
        }
        i++;
    }
    keys[nKeys - 1] = ((void *)0);
    free_message(rsp);
    return keys;
}

variable_types: nKeys int

variable_types:
keys
char **

return_type: char **


decompiled_code:
__int64 __fastcall rtable_get_ts(__int64 a1, __int64 a2)
{
_WORD *v2; // rax
_WORD *v3; // rbx
__int16 v4; // ax
__int64 v5; // rbp
__int16 v7[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v8; // [rsp+8h] [rbp-20h]

if ( a1 && a2 )
{
v7[0] = 60;
v7[1] = 20;
v8 = a2;
v2 = (_WORD *)network_send_receive(a1, v7);
v3 = v2;
if ( v2 )
{
v4 = *v2;
if ( v4 == 61 )
{
v5 = *((_QWORD *)v3 + 1);
free_message(v3);
}
else
{
if ( v4 == 99 )
fprintf(stderr, "%s : %d : \"OP_RT_ERROR\"\n", "rtable_get_ts", 391LL);
free_message(v3);
v5 = -1LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"network_send_receive\"\n", "rtable_get_ts", 384LL);
v5 = -1LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"NULL table or key\"\n", "rtable_get_ts", 371LL);
v5 = -1LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
_WORD *v2; // rax
_WORD *v3; // rbx
__int16 v4; // ax
__int64 v5; // rbp
__int16 v7[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v8; // [rsp+8h] [rbp-20h]

if ( a1 && a2 )
{
v7[0] = 60;
v7[1] = 20;
v8 = a2;
v2 = (_WORD *)network_send_receive(a1, v7);
v3 = v2;
if ( v2 )
{
v4 = *v2;
if ( v4 == 61 )
{
v5 = *((_QWORD *)v3 + 1);
free_message(v3);
}
else
{
if ( v4 == 99 )
fprintf(stderr, "%s : %d : \"OP_RT_ERROR\"\n", "rtable_get_ts", 391LL);
free_message(v3);
v5 = -1LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"network_send_receive\"\n", "rtable_get_ts", 384LL);
v5 = -1LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"NULL table or key\"\n", "rtable_get_ts", 371LL);
v5 = -1LL;
}
return v5;
}

original_code:
long rtable_get_ts(struct rtable_t *table, char *key) {
    if(table == ((void *)0) || key == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"NULL table or key\"""\n", __FUNCTION__, 371);
        return -1;
    }
    struct message_t msg;
    msg.opcode = 60;
    msg.c_type = 20;
    msg.content.key = key;
    struct message_t *rsp;
    if((rsp = network_send_receive(table, &msg)) == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"network_send_receive\"""\n", __FUNCTION__, 384);
        return -1;
    }
    if(rsp->opcode != (60 + 1)) {
        if(rsp->opcode == 99) {
            fprintf( stderr, "%s : %d : ""\"OP_RT_ERROR\"""\n", __FUNCTION__, 391);
        }
        free_message(rsp);
        return -1;
    }
    long ts = rsp->content.timestamp;
    free_message(rsp);
    return ts;
}

variable_types: ts long

return_type: long


decompiled_code:
__int64 __fastcall network_connect(__int64 a1)
{
int v2; // eax
unsigned int v3; // er12
struct addrinfo *v4; // rbp
int v5; // edi
const char *v7; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

if ( !a1 )
{
fprintf(stderr, "%s : %d : \"network_client: NULL rtable\"\n", "network_connect", 37LL);
return (unsigned int)-1;
}
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(*(const char **)(a1 + 8), *(const char **)(a1 + 16), &req, &pai);
v3 = v2;
if ( v2 )
{
v7 = gai_strerror(v2);
fprintf(stderr, "network_client: getaddrinfo > %s\n", v7);
return 1;
}
v4 = pai;
if ( !pai )
{
LABEL_12:
freeaddrinfo(pai);
return (unsigned int)-1;
}
while ( 1 )
{
v5 = socket(v4->ai_family, v4->ai_socktype, v4->ai_protocol);
*(_DWORD *)a1 = v5;
if ( v5 != -1 )
break;
fprintf(stderr, "%s : %d : \"network_client: socket\"\n", "network_connect", 57LL);
LABEL_11:
v4 = v4->ai_next;
if ( !v4 )
goto LABEL_12;
}
if ( connect(v5, v4->ai_addr, v4->ai_addrlen) == -1 )
{
close(*(_DWORD *)a1);
goto LABEL_11;
}
freeaddrinfo(pai);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v2; // eax
unsigned int v3; // er12
struct addrinfo *v4; // rbp
int v5; // edi
const char *v7; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

if ( !a1 )
{
fprintf(stderr, "%s : %d : \"network_client: NULL rtable\"\n", "network_connect", 37LL);
return (unsigned int)-1;
}
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(*(const char **)(a1 + 8), *(const char **)(a1 + 16), &req, &pai);
v3 = v2;
if ( v2 )
{
v7 = gai_strerror(v2);
fprintf(stderr, "network_client: getaddrinfo > %s\n", v7);
return 1;
}
v4 = pai;
if ( !pai )
{
LABEL_12:
freeaddrinfo(pai);
return (unsigned int)-1;
}
while ( 1 )
{
v5 = socket(v4->ai_family, v4->ai_socktype, v4->ai_protocol);
*(_DWORD *)a1 = v5;
if ( v5 != -1 )
break;
fprintf(stderr, "%s : %d : \"network_client: socket\"\n", "network_connect", 57LL);
LABEL_11:
v4 = v4->ai_next;
if ( !v4 )
goto LABEL_12;
}
if ( connect(v5, v4->ai_addr, v4->ai_addrlen) == -1 )
{
close(*(_DWORD *)a1);
goto LABEL_11;
}
freeaddrinfo(pai);
return v3;
}

original_code:
int network_connect(struct rtable_t *rtable) {
    if(rtable == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"network_client: NULL rtable\"""\n", __FUNCTION__, 37);
        return -1;
    }
    struct addrinfo hints, *serverInfo, *anAddress;
    int returnValue;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    if((returnValue = getaddrinfo(rtable->ip, rtable->porto, &hints, &serverInfo)) != 0) {
        fprintf(stderr, "network_client: getaddrinfo > %s\n", gai_strerror(returnValue));
        return 1;
    }
    for(anAddress = serverInfo; anAddress; anAddress = anAddress->ai_next) {
        if((rtable->socket = socket(anAddress->ai_family,
                                    anAddress->ai_socktype,
                                    anAddress->ai_protocol)) == -1) {
            fprintf( stderr, "%s : %d : ""\"network_client: socket\"""\n", __FUNCTION__, 57);
            continue;
        }
        if(connect(rtable->socket, anAddress->ai_addr, anAddress->ai_addrlen) == -1) {
            close(rtable->socket);
            continue;
        }
        break;
    }
    if(!anAddress) {
  freeaddrinfo(serverInfo);
        return -1;
    }
    freeaddrinfo(serverInfo);
    return 0;
}

canonical_original_code:
int network_connect(struct rtable_t *rtable) {
    if(rtable == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"network_client: NULL rtable\"""\n", __FUNCTION__, 37);
        return -1;
    }
    struct addrinfo hints; struct addrinfo *serverInfo; struct addrinfo *anAddress;
    int returnValue;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    if((returnValue = getaddrinfo(rtable->ip, rtable->porto, &hints, &serverInfo)) != 0) {
        fprintf(stderr, "network_client: getaddrinfo > %s\n", gai_strerror(returnValue));
        return 1;
    }
    for(anAddress = serverInfo; anAddress; anAddress = anAddress->ai_next) {
        if((rtable->socket = socket(anAddress->ai_family,
                                    anAddress->ai_socktype,
                                    anAddress->ai_protocol)) == -1) {
            fprintf( stderr, "%s : %d : ""\"network_client: socket\"""\n", __FUNCTION__, 57);
            continue;
        }
        if(connect(rtable->socket, anAddress->ai_addr, anAddress->ai_addrlen) == -1) {
            close(rtable->socket);
            continue;
        }
        break;
    }
    if(!anAddress) {
  freeaddrinfo(serverInfo);
        return -1;
    }
    freeaddrinfo(serverInfo);
    return 0;
}

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: returnValue int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


retry

decompiled_code:
__int64 __fastcall retry(int fd, void *buf, signed int a3)
{
int v4; // ebx
void *v5; // rax
void *v6; // r12
__int64 v7; // rbx
unsigned int bufa[11]; // [rsp+Ch] [rbp-2Ch] BYREF

bufa[0] = _bswap_32(a3);
if ( write(fd, bufa, 4uLL) == 4 )
{
if ( write(fd, buf, a3) == a3 )
{
if ( read(fd, bufa, 4uLL) == 4 )
{
v4 = _bswap_32(bufa[0]);
v5 = malloc(v4);
v6 = v5;
if ( v5 )
{
if ( read(fd, v5, v4) == v4 )
{
v7 = string_to_message(v6);
if ( v7 )
free(v6);
else
fprintf(stderr, "%s : %d : \"network_client: string_to_message\"\n", "retry", 228LL);
}
else
{
fprintf(stderr, "%s : %d : \"network_client: rerecv buffer\"\n", "retry", 222LL);
v7 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"network_client: NULL buffer\"\n", "retry", 216LL);
v7 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"network_client: rerecv buffer\"\n", "retry", 208LL);
v7 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"network_client: resend buffer\"\n", "retry", 202LL);
v7 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"network_client: resend bufferSize\"\n", "retry", 196LL);
v7 = 0LL;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf, signed int a3)
{
int v4; // ebx
void *v5; // rax
void *v6; // r12
__int64 v7; // rbx
unsigned int bufa[11]; // [rsp+Ch] [rbp-2Ch] BYREF

bufa[0] = func0(a3);
if ( write(fd, bufa, 4uLL) == 4 )
{
if ( write(fd, buf, a3) == a3 )
{
if ( read(fd, bufa, 4uLL) == 4 )
{
v4 = func0(bufa[0]);
v5 = malloc(v4);
v6 = v5;
if ( v5 )
{
if ( read(fd, v5, v4) == v4 )
{
v7 = string_to_message(v6);
if ( v7 )
free(v6);
else
fprintf(stderr, "%s : %d : \"network_client: string_to_message\"\n", "retry", 228LL);
}
else
{
fprintf(stderr, "%s : %d : \"network_client: rerecv buffer\"\n", "retry", 222LL);
v7 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"network_client: NULL buffer\"\n", "retry", 216LL);
v7 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"network_client: rerecv buffer\"\n", "retry", 208LL);
v7 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"network_client: resend buffer\"\n", "retry", 202LL);
v7 = 0LL;
}
}
else
{
fprintf(stderr, "%s : %d : \"network_client: resend bufferSize\"\n", "retry", 196LL);
v7 = 0LL;
}
return v7;
}

original_code:
struct message_t *retry(int fd, char *buffer, int size) {
    int bufferSize = size;
    uint32_t convertedSize;
    struct message_t *rsp;
 char *bufferReceived;
    convertedSize = htonl(bufferSize);
    if(write(fd, &convertedSize, sizeof(uint32_t)) != sizeof(uint32_t)) {
        fprintf( stderr, "%s : %d : ""\"network_client: resend bufferSize\"""\n", __FUNCTION__, 196);
        return ((void *)0);
    }
    if(write(fd, buffer, bufferSize) != bufferSize) {
        fprintf( stderr, "%s : %d : ""\"network_client: resend buffer\"""\n", __FUNCTION__, 202);
        return ((void *)0);
    }
    if(read(fd, &convertedSize, sizeof(uint32_t)) != sizeof(uint32_t)) {
        fprintf( stderr, "%s : %d : ""\"network_client: rerecv buffer\"""\n", __FUNCTION__, 208);
        return ((void *)0);
    }
    bufferSize = ntohl(convertedSize);
    if((bufferReceived = (char *) malloc(bufferSize)) == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"network_client: NULL buffer\"""\n", __FUNCTION__, 216);
        return ((void *)0);
    }
    if(read(fd, bufferReceived, bufferSize) != bufferSize) {
        fprintf( stderr, "%s : %d : ""\"network_client: rerecv buffer\"""\n", __FUNCTION__, 222);
        return ((void *)0);
    }
    if((rsp = string_to_message(bufferReceived)) == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"network_client: string_to_message\"""\n", __FUNCTION__, 228);
        return ((void *)0);
    }
 free(bufferReceived);
    return rsp;
}

canonical_original_code:
struct message_t *retry(int fd, char *buffer, int size) {
    int bufferSize = size;
    unsigned int convertedSize;
    struct message_t *rsp;
 char *bufferReceived;
    convertedSize = htonl(bufferSize);
    if(write(fd, &convertedSize, sizeof(unsigned int)) != sizeof(unsigned int)) {
        fprintf( stderr, "%s : %d : ""\"network_client: resend bufferSize\"""\n", __FUNCTION__, 196);
        return ((void *)0);
    }
    if(write(fd, buffer, bufferSize) != bufferSize) {
        fprintf( stderr, "%s : %d : ""\"network_client: resend buffer\"""\n", __FUNCTION__, 202);
        return ((void *)0);
    }
    if(read(fd, &convertedSize, sizeof(unsigned int)) != sizeof(unsigned int)) {
        fprintf( stderr, "%s : %d : ""\"network_client: rerecv buffer\"""\n", __FUNCTION__, 208);
        return ((void *)0);
    }
    bufferSize = ntohl(convertedSize);
    if((bufferReceived = (char *) malloc(bufferSize)) == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"network_client: NULL buffer\"""\n", __FUNCTION__, 216);
        return ((void *)0);
    }
    if(read(fd, bufferReceived, bufferSize) != bufferSize) {
        fprintf( stderr, "%s : %d : ""\"network_client: rerecv buffer\"""\n", __FUNCTION__, 222);
        return ((void *)0);
    }
    if((rsp = string_to_message(bufferReceived)) == ((void *)0)) {
        fprintf( stderr, "%s : %d : ""\"network_client: string_to_message\"""\n", __FUNCTION__, 228);
        return ((void *)0);
    }
 free(bufferReceived);
    return rsp;
}

variable_types: fd int

variable_types:
buffer
char *

variable_types: bufferSize int

variable_types:
convertedSize
unsigned int

variable_types:
bufferReceived
char *

return_type: struct message_t { short opcode; short c_type; union content_u { struct entry_t { char *key; struct data_t { int datasize; void *data; long timestamp; } *value; } *entry; char *key; char **keys; struct data_t *value; int result; long timestamp; } content; } *


decompiled_code:
__int64 __fastcall network_send_receive(int *a1, __int64 a2)
{
signed int v2; // eax
signed int v3; // ebp
__int64 v4; // rbx
void *v5; // rdi
_BYTE *v6; // r12
int v8; // er13
_BYTE *v9; // rax
unsigned int buf; // [rsp+4h] [rbp-34h] BYREF
void *ptr; // [rsp+8h] [rbp-30h] BYREF

if ( !a1 || !a2 )
return 0LL;
v2 = message_to_string(a2, &ptr);
v3 = v2;
if ( v2 <= 0 )
{
fprintf(stderr, "%s : %d : \"network_client: message_tostring\"\n", "network_send_receive", 106LL);
return 0LL;
}
buf = _bswap_32(v2);
if ( write(*a1, &buf, 4uLL) != 4 )
{
fprintf(stderr, "%s : %d : \"network_client: send bufferSize > retry...\"\n", "network_send_receive", 118LL);
goto LABEL_6;
}
if ( write(*a1, ptr, v3) != v3 )
{
fprintf(stderr, "%s : %d : \"network_client: send buffer > retry...\"\n", "network_send_receive", 124LL);
goto LABEL_6;
}
if ( read(*a1, &buf, 4uLL) != 4 )
{
fprintf(stderr, "%s : %d : \"network_client: recv buffer > retry...\"\n", "network_send_receive", 130LL);
LABEL_6:
sleep(5u);
v4 = retry(*a1, ptr, v3);
v5 = ptr;
v6 = 0LL;
if ( !ptr )
return v4;
goto LABEL_7;
}
v8 = _bswap_32(buf);
v9 = malloc(v8 + 1);
v6 = v9;
if ( !v9 )
{
free(ptr);
fprintf(stderr, "%s : %d : \"network_client: NULL bufferReceived\"\n", "network_send_receive", 139LL);
return 0LL;
}
if ( read(*a1, v9, v8) == v8 )
{
v6[v8] = 0;
v4 = string_to_message(v6);
if ( !v4 )
fprintf(stderr, "%s : %d : \"network_client: string_to_message\"\n", "network_send_receive", 164LL);
v5 = ptr;
if ( !ptr )
goto LABEL_8;
}
else
{
free(ptr);
free(v6);
perror("network_client: recv bufferReceived > retry...");
v6[v8] = 0;
sleep(5u);
v4 = retry(*a1, ptr, v3);
v5 = ptr;
if ( !ptr )
goto LABEL_8;
}
LABEL_7:
free(v5);
if ( v6 )
LABEL_8:
free(v6);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, __int64 a2)
{
signed int v2; // eax
signed int v3; // ebp
__int64 v4; // rbx
void *v5; // rdi
_BYTE *v6; // r12
int v8; // er13
_BYTE *v9; // rax
unsigned int buf; // [rsp+4h] [rbp-34h] BYREF
void *ptr; // [rsp+8h] [rbp-30h] BYREF

if ( !a1 || !a2 )
return 0LL;
v2 = message_to_string(a2, &ptr);
v3 = v2;
if ( v2 <= 0 )
{
fprintf(stderr, "%s : %d : \"network_client: message_tostring\"\n", "network_send_receive", 106LL);
return 0LL;
}
buf = func0(v2);
if ( write(*a1, &buf, 4uLL) != 4 )
{
fprintf(stderr, "%s : %d : \"network_client: send bufferSize > retry...\"\n", "network_send_receive", 118LL);
goto LABEL_6;
}
if ( write(*a1, ptr, v3) != v3 )
{
fprintf(stderr, "%s : %d : \"network_client: send buffer > retry...\"\n", "network_send_receive", 124LL);
goto LABEL_6;
}
if ( read(*a1, &buf, 4uLL) != 4 )
{
fprintf(stderr, "%s : %d : \"network_client: recv buffer > retry...\"\n", "network_send_receive", 130LL);
LABEL_6:
sleep(5u);
v4 = func2(*a1, ptr, v3);
v5 = ptr;
v6 = 0LL;
if ( !ptr )
return v4;
goto LABEL_7;
}
v8 = func0(buf);
v9 = malloc(v8 + 1);
v6 = v9;
if ( !v9 )
{
free(ptr);
fprintf(stderr, "%s : %d : \"network_client: NULL bufferReceived\"\n", "network_send_receive", 139LL);
return 0LL;
}
if ( read(*a1, v9, v8) == v8 )
{
v6[v8] = 0;
v4 = string_to_message(v6);
if ( !v4 )
fprintf(stderr, "%s : %d : \"network_client: string_to_message\"\n", "network_send_receive", 164LL);
v5 = ptr;
if ( !ptr )
goto LABEL_8;
}
else
{
free(ptr);
free(v6);
perror("network_client: recv bufferReceived > retry...");
v6[v8] = 0;
sleep(5u);
v4 = func2(*a1, ptr, v3);
v5 = ptr;
if ( !ptr )
goto LABEL_8;
}
LABEL_7:
free(v5);
if ( v6 )
LABEL_8:
free(v6);
return v4;
}

original_code:
struct message_t *network_send_receive(struct rtable_t *rtable, struct message_t *msg) {
    if(rtable == ((void *)0) || msg == ((void *)0)) {
        return ((void *)0);
    }
    char *buffer;
    int bufferSize;
    char *bufferReceived = ((void *)0);
    int bufferReceivedSize;
    uint32_t convertedSize;
    struct message_t *rsp;
    if((bufferSize = message_to_string(msg, &buffer)) <= 0) {
        fprintf( stderr, "%s : %d : ""\"network_client: message_tostring\"""\n", __FUNCTION__, 106);
        return ((void *)0);
    }
    convertedSize = htonl(bufferSize);
    _Bool falhou = 0;
    if((write(rtable->socket, &convertedSize, sizeof(uint32_t))) != sizeof(uint32_t)) {
        fprintf( stderr, "%s : %d : ""\"network_client: send bufferSize > retry...\"""\n", __FUNCTION__, 118);
        falhou = 1;
    }
    else {
        if((write(rtable->socket, buffer, bufferSize)) != bufferSize) {
            fprintf( stderr, "%s : %d : ""\"network_client: send buffer > retry...\"""\n", __FUNCTION__, 124);
            falhou = 1;
        }
        else {
            if(read(rtable->socket, &convertedSize, sizeof(uint32_t)) != sizeof(uint32_t)) {
                fprintf( stderr, "%s : %d : ""\"network_client: recv buffer > retry...\"""\n", __FUNCTION__, 130);
                falhou = 1;
            }
            else {
                bufferReceivedSize = ntohl(convertedSize);
                if((bufferReceived = (char *) malloc(bufferReceivedSize + 1)) == ((void *)0)) {
                    free(buffer);
                    fprintf( stderr, "%s : %d : ""\"network_client: NULL bufferReceived\"""\n", __FUNCTION__, 139);
                    return ((void *)0);
                }
                if(read(rtable->socket, bufferReceived, bufferReceivedSize) != bufferReceivedSize) {
                    free(buffer);
                    free(bufferReceived);
                    perror("network_client: recv bufferReceived > retry...");
                    falhou = 1;
                }
                bufferReceived[bufferReceivedSize] = '\0';
            }
        }
    }
    if(falhou) {
        sleep(5);
        rsp = retry(rtable->socket, buffer, bufferSize);
    }
    else {
        if((rsp = string_to_message(bufferReceived)) == ((void *)0)) {
            fprintf( stderr, "%s : %d : ""\"network_client: string_to_message\"""\n", __FUNCTION__, 164);
        }
    }
 if(buffer) {
  free(buffer);
 }
 if(bufferReceived) {
  free(bufferReceived);
 }
    return rsp;
}

canonical_original_code:
struct message_t *network_send_receive(struct rtable_t *rtable, struct message_t *msg) {
    if(rtable == ((void *)0) || msg == ((void *)0)) {
        return ((void *)0);
    }
    char *buffer;
    int bufferSize;
    char *bufferReceived = ((void *)0);
    int bufferReceivedSize;
    unsigned int convertedSize;
    struct message_t *rsp;
    if((bufferSize = message_to_string(msg, &buffer)) <= 0) {
        fprintf( stderr, "%s : %d : ""\"network_client: message_tostring\"""\n", __FUNCTION__, 106);
        return ((void *)0);
    }
    convertedSize = htonl(bufferSize);
    _Bool falhou = 0;
    if((write(rtable->socket, &convertedSize, sizeof(unsigned int))) != sizeof(unsigned int)) {
        fprintf( stderr, "%s : %d : ""\"network_client: send bufferSize > retry...\"""\n", __FUNCTION__, 118);
        falhou = 1;
    }
    else {
        if((write(rtable->socket, buffer, bufferSize)) != bufferSize) {
            fprintf( stderr, "%s : %d : ""\"network_client: send buffer > retry...\"""\n", __FUNCTION__, 124);
            falhou = 1;
        }
        else {
            if(read(rtable->socket, &convertedSize, sizeof(unsigned int)) != sizeof(unsigned int)) {
                fprintf( stderr, "%s : %d : ""\"network_client: recv buffer > retry...\"""\n", __FUNCTION__, 130);
                falhou = 1;
            }
            else {
                bufferReceivedSize = ntohl(convertedSize);
                if((bufferReceived = (char *) malloc(bufferReceivedSize + 1)) == ((void *)0)) {
                    free(buffer);
                    fprintf( stderr, "%s : %d : ""\"network_client: NULL bufferReceived\"""\n", __FUNCTION__, 139);
                    return ((void *)0);
                }
                if(read(rtable->socket, bufferReceived, bufferReceivedSize) != bufferReceivedSize) {
                    free(buffer);
                    free(bufferReceived);
                    perror("network_client: recv bufferReceived > retry...");
                    falhou = 1;
                }
                bufferReceived[bufferReceivedSize] = '\0';
            }
        }
    }
    if(falhou) {
        sleep(5);
        rsp = retry(rtable->socket, buffer, bufferSize);
    }
    else {
        if((rsp = string_to_message(bufferReceived)) == ((void *)0)) {
            fprintf( stderr, "%s : %d : ""\"network_client: string_to_message\"""\n", __FUNCTION__, 164);
        }
    }
 if(buffer) {
  free(buffer);
 }
 if(bufferReceived) {
  free(bufferReceived);
 }
    return rsp;
}

variable_types:
msg
struct message_t *

variable_types: bufferReceivedSize int


decompiled_code:
__int64 __fastcall network_close(int *a1)
{
unsigned int v1; // ebx

if ( !a1 )
return (unsigned int)-1;
v1 = close(*a1);
if ( v1 != -1 )
return 0;
fprintf(stderr, "%s : %d : \"network_client: close\"\n", "network_close", 251LL);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1)
{
unsigned int v1; // ebx

if ( !a1 )
return (unsigned int)-1;
v1 = close(*a1);
if ( v1 != -1 )
return 0;
fprintf(stderr, "%s : %d : \"network_client: close\"\n", "network_close", 251LL);
return v1;
}

original_code:
int network_close(struct rtable_t *rtable) {
    if(rtable == ((void *)0)) {
        return -1;
    }
    if((close(rtable->socket)) == -1) {
        fprintf( stderr, "%s : %d : ""\"network_client: close\"""\n", __FUNCTION__, 251);
        return -1;
    }
    return 0;
}

variable_types: struct rtable_t { int socket; char *ip; char *porto; } *


decompiled_code:
void __fastcall ptable_close(void *ptr)
{
if ( ptr )
{
table_destroy(*(_QWORD *)ptr);
pmanager_destroy(*((_QWORD *)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
table_destroy(*(_QWORD *)ptr);
pmanager_destroy(*((_QWORD *)ptr + 1));
free(ptr);
}
}

original_code:
void ptable_close(struct ptable_t *table) {
    if(table) {
        table_destroy(table->table);
        pmanager_destroy(table->pmanager);
  free(table);
    }
}

variable_types: struct ptable_t { struct table_t { int hashSize; int numElems; int numUpdates; struct list_t { struct node_t { struct node_t *prev; struct node_t *next; struct entry_t { char *key; struct data_t { int datasize; void *data; long timestamp; } *value; } *entry; } *head; struct node_t *tail; int elements; } **table; } *table; struct pmanager_t { char *ckp_name; int ckp_fd; char *stt_name; int stt_fd; char *log_name; int log_fd; int create_flags; int max_log_size; int current_log_size; } *pmanager; } *

user_defined_types: struct ptable_t { struct table_t *table; struct pmanager_t *pmanager; }

user_defined_types: struct table_t { int hashSize; int numElems; int numUpdates; struct list_t **table; }

user_defined_types: struct list_t { struct node_t *head; struct node_t *tail; int elements; }

user_defined_types: struct node_t { struct node_t *prev; struct node_t *next; struct entry_t *entry; }


decompiled_code:
void __fastcall ptable_destroy(void *ptr)
{
if ( ptr )
{
table_destroy(*(_QWORD *)ptr);
pmanager_destroy_clear(*((_QWORD *)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
table_destroy(*(_QWORD *)ptr);
pmanager_destroy_clear(*((_QWORD *)ptr + 1));
free(ptr);
}
}

original_code:
void ptable_destroy(struct ptable_t *table) {
    if(table) {
        table_destroy(table->table);
 pmanager_destroy_clear(table->pmanager);
  free(table);
    }
}

user_defined_types: struct pmanager_t { char *ckp_name; int ckp_fd; char *stt_name; int stt_fd; char *log_name; int log_fd; int create_flags; int max_log_size; int current_log_size; }