updateMoney

decompiled_code:
__int64 __fastcall updateMoney(_DWORD *a1, int a2)
{
__int64 result; // rax

if ( a1 )
{
*a1 -= a2;
result = 1LL;
}
else
{
fwrite("Erreur avec l'interface\n", 1uLL, 0x18uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, int a2)
{
__int64 result; // rax

if ( a1 )
{
*a1 -= a2;
result = 1LL;
}
else
{
fwrite("Erreur avec l'interface\n", 1uLL, 0x18uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int updateMoney(Interface* interface, int price) {
 if(interface != ((void *)0)) {
  interface->money -= price;
 }
 else {
  fprintf(stderr, "Erreur avec l'interface\n");
  return 0;
 }
 return 1;
}

canonical_original_code:
int updateMoney(struct struct_interface *interface, int price) {
 if(interface != ((void *)0)) {
  interface->money -= price;
 }
 else {
  fprintf(stderr, "Erreur avec l'interface\n");
  return 0;
 }
 return 1;
}

variable_types: price int


udapteLife

decompiled_code:
__int64 __fastcall udapteLife(__int64 a1)
{
__int64 result; // rax

if ( a1 )
{
--*(_DWORD *)(a1 + 16);
result = 1LL;
}
else
{
fwrite("Erreur avec l'interface\n", 1uLL, 0x18uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax

if ( a1 )
{
--*(_DWORD *)(a1 + 16);
result = 1LL;
}
else
{
fwrite("Erreur avec l'interface\n", 1uLL, 0x18uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int udapteLife(Interface* interface) {
 if(interface != ((void *)0)) {
  interface->life --;
 }
 else {
  fprintf(stderr, "Erreur avec l'interface\n");
  return 0;
 }
 return 1;
}

canonical_original_code:
int udapteLife(struct struct_interface *interface) {
 if(interface != ((void *)0)) {
  interface->life --;
 }
 else {
  fprintf(stderr, "Erreur avec l'interface\n");
  return 0;
 }
 return 1;
}

variable_types: struct struct_interface { int money; int score; int lvl; int nbMonster; int life; } *

return_type: int


freeInterface

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

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

original_code:
void freeInterface (Interface* interface) {
 if (interface != ((void *)0)) {
  free(interface);
 }
}

canonical_original_code:
void freeInterface(struct struct_interface *interface) {
 if (interface != ((void *)0)) {
  free(interface);
 }
}

return_type: void

user_defined_types: struct struct_interface { int money; int score; int lvl; int nbMonster; int life; }


VectorXY

decompiled_code:
double __fastcall VectorXY(__m128i a1, __m128i a2)
{
double result; // xmm0_8

*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(a2) << 32) | (unsigned int)_mm_cvtsi128_si32(a1);
return result;
}

canonical_decompiled_code:
double __fastcall func0(__m128i a1, __m128i a2)
{
double result; // xmm0_8

*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(a2) << 32) | (unsigned int)_mm_cvtsi128_si32(a1);
return result;
}

original_code:
Vector2D VectorXY(float x, float y) {
 Vector2D new_vector;
 new_vector.x = x;
 new_vector.y = y;
 return new_vector;
}

canonical_original_code:
struct struct_vector VectorXY(float x, float y) {
 struct struct_vector new_vector;
 new_vector.x = x;
 new_vector.y = y;
 return new_vector;
}

variable_types: x float

variable_types: y float

variable_types: struct struct_vector { float x; float y; }


Vector

decompiled_code:
double __fastcall Vector(double a1, __m128i a2)
{
__m128i v2; // xmm2
__m128i v3; // xmm3
double result; // xmm0_8

v2 = a2;
*(float *)v2.m128i_i32 = *(float *)a2.m128i_i32 - *(float *)&a1;
v3 = _mm_cvtsi32_si128(a2.m128i_u32[1]);
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 - *((float *)&a1 + 1);
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v3) << 32) | (unsigned int)_mm_cvtsi128_si32(v2);
return result;
}

canonical_decompiled_code:
double __fastcall func1(double a1, __m128i a2)
{
__m128i v2; // xmm2
__m128i v3; // xmm3
double result; // xmm0_8

v2 = a2;
*(float *)v2.m128i_i32 = *(float *)a2.m128i_i32 - *(float *)&a1;
v3 = _mm_cvtsi32_si128(a2.m128i_u32[1]);
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 - *((float *)&a1 + 1);
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v3) << 32) | (unsigned int)_mm_cvtsi128_si32(v2);
return result;
}

original_code:
Vector2D Vector(Point2D A, Point2D B) {
 Vector2D new_vector;
 new_vector.x = (B.x) - (A.x);
 new_vector.y = (B.y) - (A.y);
 return new_vector;
}

canonical_original_code:
struct struct_vector Vector(struct struct_point A, struct struct_point B) {
 struct struct_vector new_vector;
 new_vector.x = (B.x) - (A.x);
 new_vector.y = (B.y) - (A.y);
 return new_vector;
}

variable_types: struct struct_point { float x; float y; }

variable_types:
B
struct struct_point

return_type: struct struct_vector { float x; float y; }


AddVectors

decompiled_code:
double __fastcall AddVectors(__m128i a1, double a2)
{
__m128i v2; // xmm2
__m128i v3; // xmm3
double result; // xmm0_8

v2 = a1;
*(float *)v2.m128i_i32 = *(float *)a1.m128i_i32 + *(float *)&a2;
v3 = _mm_cvtsi32_si128(a1.m128i_u32[1]);
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 + *((float *)&a2 + 1);
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v3) << 32) | (unsigned int)_mm_cvtsi128_si32(v2);
return result;
}

canonical_decompiled_code:
double __fastcall func2(__m128i a1, double a2)
{
__m128i v2; // xmm2
__m128i v3; // xmm3
double result; // xmm0_8

v2 = a1;
*(float *)v2.m128i_i32 = *(float *)a1.m128i_i32 + *(float *)&a2;
v3 = _mm_cvtsi32_si128(a1.m128i_u32[1]);
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 + *((float *)&a2 + 1);
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v3) << 32) | (unsigned int)_mm_cvtsi128_si32(v2);
return result;
}

original_code:
Vector2D AddVectors(Vector2D V1, Vector2D V2){
 Vector2D new_vector;
 new_vector.x = (V1.x) + (V2.x);
 new_vector.y = (V1.y) + (V2.y);
 return new_vector;
}

canonical_original_code:
struct struct_vector AddVectors(struct struct_vector V1, struct struct_vector V2){
 struct struct_vector new_vector;
 new_vector.x = (V1.x) + (V2.x);
 new_vector.y = (V1.y) + (V2.y);
 return new_vector;
}

user_defined_types: struct struct_vector { float x; float y; }


SubVectors

decompiled_code:
double __fastcall SubVectors(__m128i a1, double a2)
{
__m128i v2; // xmm2
__m128i v3; // xmm3
double result; // xmm0_8

v2 = a1;
*(float *)v2.m128i_i32 = *(float *)a1.m128i_i32 - *(float *)&a2;
v3 = _mm_cvtsi32_si128(a1.m128i_u32[1]);
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 - *((float *)&a2 + 1);
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v3) << 32) | (unsigned int)_mm_cvtsi128_si32(v2);
return result;
}

canonical_decompiled_code:
double __fastcall func3(__m128i a1, double a2)
{
__m128i v2; // xmm2
__m128i v3; // xmm3
double result; // xmm0_8

v2 = a1;
*(float *)v2.m128i_i32 = *(float *)a1.m128i_i32 - *(float *)&a2;
v3 = _mm_cvtsi32_si128(a1.m128i_u32[1]);
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 - *((float *)&a2 + 1);
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v3) << 32) | (unsigned int)_mm_cvtsi128_si32(v2);
return result;
}

original_code:
Vector2D SubVectors(Vector2D V1, Vector2D V2){
 Vector2D new_vector;
 new_vector.x = (V1.x) - (V2.x);
 new_vector.y = (V1.y) - (V2.y);
 return new_vector;
}

canonical_original_code:
struct struct_vector SubVectors(struct struct_vector V1, struct struct_vector V2){
 struct struct_vector new_vector;
 new_vector.x = (V1.x) - (V2.x);
 new_vector.y = (V1.y) - (V2.y);
 return new_vector;
}


MultVector

original_code:
Vector2D MultVector(float lamba, Vector2D V){
 if(lamba == 1)
  return V;
 Vector2D new_vector;
 new_vector.x = lamba * (V.x);
 new_vector.y = lamba * (V.y);
 return new_vector;
}

canonical_original_code:
struct struct_vector MultVector(float lamba, struct struct_vector V){
 if(lamba == 1)
  return V;
 struct struct_vector new_vector;
 new_vector.x = lamba * (V.x);
 new_vector.y = lamba * (V.y);
 return new_vector;
}

variable_types: lamba float

variable_types:
V
struct struct_vector


DivVector

decompiled_code:
double __fastcall DivVector(float a1, double a2)
{
unsigned int v3; // edx
float v4; // xmm0_4
__m128i v5; // xmm1
__m128i v6; // xmm3
double v7; // rax
double result; // xmm0_8

if ( a1 == 0.0 )
{
fwrite("Erreur impossible de faire une division par 0", 1uLL, 0x2DuLL, stderr);
result = 0.0;
}
else
{
v3 = LODWORD(a2);
v4 = *((float *)&a2 + 1);
if ( a1 == 1.0 )
{
*(_QWORD *)&v7 = LODWORD(a2) | (HIDWORD(*(_QWORD *)&a2) << 32);
}
else
{
v5 = (__m128i)(unsigned int)LC0;
v6 = _mm_cvtsi32_si128(v3);
*(float *)v6.m128i_i32 = *(float *)v6.m128i_i32 * (float)(1.0 / a1);
*(float *)v5.m128i_i32 = (float)(1.0 / a1) * v4;
*(_QWORD *)&v7 = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v5) << 32) | (unsigned int)_mm_cvtsi128_si32(v6);
}
result = v7;
}
return result;
}

canonical_decompiled_code:
double __fastcall func5(float a1, double a2)
{
unsigned int v3; // edx
float v4; // xmm0_4
__m128i v5; // xmm1
__m128i v6; // xmm3
double v7; // rax
double result; // xmm0_8

if ( a1 == 0.0 )
{
fwrite("Erreur impossible de faire une division par 0", 1uLL, 0x2DuLL, stderr);
result = 0.0;
}
else
{
v3 = LODWORD(a2);
v4 = *((float *)&a2 + 1);
if ( a1 == 1.0 )
{
*(_QWORD *)&v7 = LODWORD(a2) | (HIDWORD(*(_QWORD *)&a2) << 32);
}
else
{
v5 = (__m128i)(unsigned int)LC0;
v6 = _mm_cvtsi32_si128(v3);
*(float *)v6.m128i_i32 = *(float *)v6.m128i_i32 * (float)(1.0 / a1);
*(float *)v5.m128i_i32 = (float)(1.0 / a1) * v4;
*(_QWORD *)&v7 = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v5) << 32) | (unsigned int)_mm_cvtsi128_si32(v6);
}
result = v7;
}
return result;
}

original_code:
Vector2D DivVector(float lambda, Vector2D V){
 Vector2D new_vector;
 if(lambda == 0) {
  fprintf(stderr, "Erreur impossible de faire une division par 0");
  return new_vector;
 }
 else if(lambda == 1)
  return V;
 lambda = 1/lambda;
 new_vector.x = lambda * (V.x);
 new_vector.y = lambda * (V.y);
 return new_vector;
}

canonical_original_code:
struct struct_vector DivVector(float lambda, struct struct_vector V){
 struct struct_vector new_vector;
 if(lambda == 0) {
  fprintf(stderr, "Erreur impossible de faire une division par 0");
  return new_vector;
 }
 else if(lambda == 1)
  return V;
 lambda = 1/lambda;
 new_vector.x = lambda * (V.x);
 new_vector.y = lambda * (V.y);
 return new_vector;
}

variable_types: lambda float


DotProduct

decompiled_code:
double __fastcall DotProduct(double a1, double a2)
{
return (float)((float)(*((float *)&a1 + 1) * *((float *)&a2 + 1)) + (float)(*(float *)&a2 * *(float *)&a1));
}

canonical_decompiled_code:
double __fastcall func6(double a1, double a2)
{
return (float)((float)(*((float *)&a1 + 1) * *((float *)&a2 + 1)) + (float)(*(float *)&a2 * *(float *)&a1));
}

original_code:
double DotProduct(Vector2D V1, Vector2D V2){
 float result = (V1.x * V2.x) + (V1.y * V2.y);
 return result;
}

canonical_original_code:
double DotProduct(struct struct_vector V1, struct struct_vector V2){
 float result = (V1.x * V2.x) + (V1.y * V2.y);
 return result;
}

variable_types: result float

return_type: double


Norm

decompiled_code:
float __fastcall Norm(double a1)
{
float v1; // xmm0_4
float result; // xmm0_4

v1 = (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)) + (float)(*(float *)&a1 * *(float *)&a1);
if ( v1 < 0.0 )
result = sqrtf(v1);
else
result = fsqrt(v1);
return result;
}

canonical_decompiled_code:
float __fastcall func7(double a1)
{
float v1; // xmm0_4
float result; // xmm0_4

v1 = (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)) + (float)(*(float *)&a1 * *(float *)&a1);
if ( v1 < 0.0 )
result = sqrtf(v1);
else
result = fsqrt(v1);
return result;
}

original_code:
float Norm(Vector2D V) {
 float norme;
 norme = ((V.x) * (V.x)) + ((V.y) * (V.y));
 norme = sqrt(norme);
 return norme;
}

canonical_original_code:
float Norm(struct struct_vector V) {
 float norme;
 norme = ((V.x) * (V.x)) + ((V.y) * (V.y));
 norme = sqrt(norme);
 return norme;
}

variable_types: norme float

return_type: float


Normalize

decompiled_code:
double __fastcall Normalize(double a1)
{
float v2; // xmm0_4
__m128i v3; // xmm2
__m128i v4; // xmm3
double result; // xmm0_8

v2 = Norm(a1);
v3 = _mm_cvtsi32_si128(LODWORD(a1));
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 / v2;
v4 = _mm_cvtsi32_si128(HIDWORD(a1));
*(float *)v4.m128i_i32 = *(float *)v4.m128i_i32 / v2;
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v4) << 32) | (unsigned int)_mm_cvtsi128_si32(v3);
return result;
}

canonical_decompiled_code:
double __fastcall func8(double a1)
{
float v2; // xmm0_4
__m128i v3; // xmm2
__m128i v4; // xmm3
double result; // xmm0_8

v2 = func7(a1);
v3 = _mm_cvtsi32_si128(LODWORD(a1));
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 / v2;
v4 = _mm_cvtsi32_si128(HIDWORD(a1));
*(float *)v4.m128i_i32 = *(float *)v4.m128i_i32 / v2;
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v4) << 32) | (unsigned int)_mm_cvtsi128_si32(v3);
return result;
}

original_code:
Vector2D Normalize(Vector2D V){
 Vector2D new_vector;
 float norme = Norm(V);
 new_vector.x = (V.x) / norme;
 new_vector.y = (V.y) / norme;
 return new_vector;
}

canonical_original_code:
struct struct_vector Normalize(struct struct_vector V){
 struct struct_vector new_vector;
 float norme = Norm(V);
 new_vector.x = (V.x) / norme;
 new_vector.y = (V.y) / norme;
 return new_vector;
}


PointPlusVector

decompiled_code:
double __fastcall PointPlusVector(__m128i a1, double a2)
{
__m128i v2; // xmm2
__m128i v3; // xmm3
double result; // xmm0_8

v2 = a1;
*(float *)v2.m128i_i32 = *(float *)a1.m128i_i32 + *(float *)&a2;
v3 = _mm_cvtsi32_si128(a1.m128i_u32[1]);
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 + *((float *)&a2 + 1);
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v3) << 32) | (unsigned int)_mm_cvtsi128_si32(v2);
return result;
}

canonical_decompiled_code:
double __fastcall func9(__m128i a1, double a2)
{
__m128i v2; // xmm2
__m128i v3; // xmm3
double result; // xmm0_8

v2 = a1;
*(float *)v2.m128i_i32 = *(float *)a1.m128i_i32 + *(float *)&a2;
v3 = _mm_cvtsi32_si128(a1.m128i_u32[1]);
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 + *((float *)&a2 + 1);
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v3) << 32) | (unsigned int)_mm_cvtsi128_si32(v2);
return result;
}

original_code:
Point2D PointPlusVector(Point2D P, Vector2D V) {
 Point2D new_point;
 new_point.x = (P.x) + (V.x);
 new_point.y = (P.y) + (V.y);
 return new_point;
}

canonical_original_code:
struct struct_point PointPlusVector(struct struct_point P, struct struct_vector V) {
 struct struct_point new_point;
 new_point.x = (P.x) + (V.x);
 new_point.y = (P.y) + (V.y);
 return new_point;
}

variable_types:
P
struct struct_point

return_type: struct struct_point { float x; float y; }


decompiled_code:
_QWORD *new_LNode()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
}
return result;
}

original_code:
LNode* new_LNode(void) {
 LNode* p_lnode = malloc(sizeof(LNode));
 if (p_lnode != ((void *)0)) {
  p_lnode->length = 0;
  p_lnode->p_head = ((void *)0);
  p_lnode->p_tail = ((void *)0);
 }
 return p_lnode;
}

canonical_original_code:
struct struct_lnode *new_LNode() {
 struct struct_lnode *p_lnode = malloc(sizeof(LNode));
 if (p_lnode != ((void *)0)) {
  p_lnode->length = 0;
  p_lnode->p_head = ((void *)0);
  p_lnode->p_tail = ((void *)0);
 }
 return p_lnode;
}

variable_types: struct struct_lnode { unsigned long length; struct struct_node { float x; float y; struct struct_node *p_next; } *p_head; struct struct_node *p_tail; } *

user_defined_types: struct struct_lnode { unsigned long length; struct struct_node *p_head; struct struct_node *p_tail; }


addNode

decompiled_code:
__int64 __fastcall addNode(_QWORD *a1, __m128i a2, __m128i a3)
{
int v3; // er12
int v4; // ebp
_DWORD *v5; // rax
__int64 v6; // rdx
__int64 result; // rax

if ( a1 )
{
v3 = _mm_cvtsi128_si32(a2);
v4 = _mm_cvtsi128_si32(a3);
v5 = malloc(0x10uLL);
if ( v5 )
{
*v5 = v3;
v5[1] = v4;
*((_QWORD *)v5 + 1) = 0LL;
v6 = a1[2];
if ( v6 )
*(_QWORD *)(v6 + 8) = v5;
else
a1[1] = v5;
a1[2] = v5;
++*a1;
result = 1LL;
}
else
{
puts("Probleme au moment de l'allocation du nouveau noeud");
result = 0LL;
}
}
else
{
puts("Cette liste de noeuds n'existe pas");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __m128i a2, __m128i a3)
{
int v3; // er12
int v4; // ebp
_DWORD *v5; // rax
__int64 v6; // rdx
__int64 result; // rax

if ( a1 )
{
v3 = _mm_cvtsi128_si32(a2);
v4 = _mm_cvtsi128_si32(a3);
v5 = malloc(0x10uLL);
if ( v5 )
{
*v5 = v3;
v5[1] = v4;
*((_QWORD *)v5 + 1) = 0LL;
v6 = a1[2];
if ( v6 )
*(_QWORD *)(v6 + 8) = v5;
else
a1[1] = v5;
a1[2] = v5;
++*a1;
result = 1LL;
}
else
{
puts("Probleme au moment de l'allocation du nouveau noeud");
result = 0LL;
}
}
else
{
puts("Cette liste de noeuds n'existe pas");
result = 0LL;
}
return result;
}

original_code:
int addNode(LNode* p_lnode, float x, float y) {
 if (p_lnode != ((void *)0)) {
  Node* new_node = malloc(sizeof(Node));
  if (new_node != ((void *)0)) {
   new_node->x = x;
   new_node->y = y;
   new_node->p_next = ((void *)0);
   if (p_lnode->p_tail == ((void *)0))
    p_lnode->p_head = new_node;
   else
    p_lnode->p_tail->p_next = new_node;
   p_lnode->p_tail = new_node;
   p_lnode->length++;
  }
  else {
   printf("Probleme au moment de l'allocation du nouveau noeud\n");
   return 0;
  }
 }
 else {
  printf("Cette liste de noeuds n'existe pas\n");
  return 0;
 }
 return 1;
}

canonical_original_code:
int addNode(struct struct_lnode *p_lnode, float x, float y) {
 if (p_lnode != ((void *)0)) {
  struct struct_node *new_node = malloc(sizeof(Node));
  if (new_node != ((void *)0)) {
   new_node->x = x;
   new_node->y = y;
   new_node->p_next = ((void *)0);
   if (p_lnode->p_tail == ((void *)0))
    p_lnode->p_head = new_node;
   else
    p_lnode->p_tail->p_next = new_node;
   p_lnode->p_tail = new_node;
   p_lnode->length++;
  }
  else {
   printf("Probleme au moment de l'allocation du nouveau noeud\n");
   return 0;
  }
 }
 else {
  printf("Cette liste de noeuds n'existe pas\n");
  return 0;
 }
 return 1;
}

variable_types: struct struct_node { float x; float y; struct struct_node *p_next; } *


freeAllNode

decompiled_code:
void __fastcall freeAllNode(_QWORD *a1)
{
_QWORD *i; // rsi

if ( *a1 )
{
for ( i = (_QWORD *)a1[1]; i; i = (_QWORD *)a1[1] )
a1 = removeNode(a1, i);
}
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1)
{
_QWORD *i; // rsi

if ( *a1 )
{
for ( i = (_QWORD *)a1[1]; i; i = (_QWORD *)a1[1] )
a1 = removeNode(a1, i);
}
free(a1);
}

original_code:
void freeAllNode (LNode* p_lnode) {
 if (p_lnode->length != 0) {
  while (p_lnode->p_head != ((void *)0)) {
   p_lnode = removeNode(p_lnode, p_lnode->p_head);
  }
 }
 free(p_lnode);
}

canonical_original_code:
void freeAllNode(struct struct_lnode *p_lnode) {
 if (p_lnode->length != 0) {
  while (p_lnode->p_head != ((void *)0)) {
   p_lnode = removeNode(p_lnode, p_lnode->p_head);
  }
 }
 free(p_lnode);
}

user_defined_types: struct struct_node { float x; float y; struct struct_node *p_next; }


freeImage

decompiled_code:
void __fastcall freeImage(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void freeImage (Image* image) {
 if (image != ((void *)0)) {
  free(image->path);
  free(image);
 }
}

canonical_original_code:
void freeImage(struct struct_image *image) {
 if (image != ((void *)0)) {
  free(image->path);
  free(image);
 }
}

variable_types: struct struct_image { char *path; char magicNumber[2]; unsigned int heightImg; unsigned int widthImg; int maxValue; } *


PointXY

decompiled_code:
double __fastcall PointXY(__m128i a1, __m128i a2)
{
double result; // xmm0_8

*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(a2) << 32) | (unsigned int)_mm_cvtsi128_si32(a1);
return result;
}

original_code:
Point2D PointXY(float x, float y) {
 Point2D new_point;
 new_point.x = x;
 new_point.y = y;
 return new_point;
}

canonical_original_code:
struct struct_point PointXY(float x, float y) {
 struct struct_point new_point;
 new_point.x = x;
 new_point.y = y;
 return new_point;
}

user_defined_types: struct struct_point { float x; float y; }


repo: LapoFrati/BattleShip

decompiled_code:
int init_keyboard()
{
tcgetattr(0, &initial_settings);
*(__m128i *)&new_settings.c_iflag = _mm_load_si128((const __m128i *)&initial_settings);
*(__m128i *)&new_settings.c_line = _mm_load_si128((const __m128i *)&initial_settings.c_line);
*(__m128i *)&new_settings.c_cc[15] = _mm_load_si128((const __m128i *)&initial_settings.c_cc[15]);
*(_QWORD *)&new_settings.c_cc[31] = *(_QWORD *)&initial_settings.c_cc[31];
new_settings.c_ospeed = initial_settings.c_ospeed;
new_settings.c_lflag &= 0xFFFFFFF4;
new_settings.c_cc[6] = 1;
new_settings.c_cc[5] = 0;
return tcsetattr(0, 0, &new_settings);
}

canonical_decompiled_code:
int func0()
{
tcgetattr(0, &initial_settings);
*(__m128i *)&new_settings.c_iflag = _mm_load_si128((const __m128i *)&initial_settings);
*(__m128i *)&new_settings.c_line = _mm_load_si128((const __m128i *)&initial_settings.c_line);
*(__m128i *)&new_settings.c_cc[15] = _mm_load_si128((const __m128i *)&initial_settings.c_cc[15]);
*(_QWORD *)&new_settings.c_cc[31] = *(_QWORD *)&initial_settings.c_cc[31];
new_settings.c_ospeed = initial_settings.c_ospeed;
new_settings.c_lflag &= 0xFFFFFFF4;
new_settings.c_cc[6] = 1;
new_settings.c_cc[5] = 0;
return tcsetattr(0, 0, &new_settings);
}

original_code:
void init_keyboard()
{
    tcgetattr(0,&initial_settings);
    new_settings = initial_settings;
    new_settings.c_lflag &= ~0000002;
    new_settings.c_lflag &= ~0000010;
    new_settings.c_lflag &= ~0000001;
    new_settings.c_cc[6] = 1;
    new_settings.c_cc[5] = 0;
    tcsetattr(0, 0, &new_settings);
}


decompiled_code:
int close_keyboard()
{
return tcsetattr(0, 0, &initial_settings);
}

canonical_decompiled_code:
int func1()
{
return tcsetattr(0, 0, &initial_settings);
}

original_code:
void close_keyboard()
{
    tcsetattr(0, 0, &initial_settings);
}


kbhit

decompiled_code:
ssize_t kbhit()
{
ssize_t result; // rax
char buf[9]; // [rsp+1h] [rbp-9h] BYREF

result = 1LL;
if ( peek_character == -1 )
{
result = read(0, buf, 1uLL);
if ( (_DWORD)result == 1 )
peek_character = buf[0];
else
result = 0LL;
}
return result;
}

canonical_decompiled_code:
ssize_t func2()
{
ssize_t result; // rax
char buf[9]; // [rsp+1h] [rbp-9h] BYREF

result = 1LL;
if ( peek_character == -1 )
{
result = read(0, buf, 1uLL);
if ( (_DWORD)result == 1 )
peek_character = buf[0];
else
result = 0LL;
}
return result;
}

original_code:
int kbhit()
{
    char ch;
    int nread;
    if(peek_character != -1)
        return 1;
    nread = read(0,&ch,1);
    if(nread == 1) {
        peek_character = ch;
        return 1;
    }
    return 0;
}

variable_types: ch char

variable_types: nread int


readch

decompiled_code:
__int64 readch()
{
__int64 result; // rax
char buf[9]; // [rsp+1h] [rbp-9h] BYREF

result = (unsigned int)peek_character;
if ( peek_character == -1 )
{
read(0, buf, 1uLL);
result = (unsigned __int8)buf[0];
}
else
{
peek_character = -1;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
char buf[9]; // [rsp+1h] [rbp-9h] BYREF

result = (unsigned int)peek_character;
if ( peek_character == -1 )
{
read(0, buf, 1uLL);
result = (unsigned __int8)buf[0];
}
else
{
peek_character = -1;
}
return result;
}

original_code:
char readch()
{
    char ch;
    if(peek_character != -1) {
        ch = peek_character;
        peek_character = -1;
        return ch;
    }
    read(0,&ch,1);
    return ch;
}

return_type: char


premios

repo: Lazyapply/loteria

decompiled_code:
__int64 __fastcall premios(int a1)
{
__int64 result; // rax

if ( a1 == 5 )
return 500LL;
if ( a1 > 5 )
{
result = 0LL;
if ( a1 == 6 )
result = 10000LL;
}
else
{
result = 10LL;
if ( a1 != 3 )
{
result = 0LL;
if ( a1 == 4 )
result = 50LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax

if ( a1 == 5 )
return 500LL;
if ( a1 > 5 )
{
result = 0LL;
if ( a1 == 6 )
result = 10000LL;
}
else
{
result = 10LL;
if ( a1 != 3 )
{
result = 0LL;
if ( a1 == 4 )
result = 50LL;
}
}
return result;
}

original_code:
int premios(int aciertos){
 int a;
 switch(aciertos){
   case 3:
    a=10;
   break;
   case 4:
    a=50;
   break;
   case 5:
    a=500;
   break;
   case 6:
    a=10000;
   break;
   default:
    a=0;
   break;
  }
  return a;
}

variable_types: aciertos int

variable_types: a int


strrev

decompiled_code:
const char *__fastcall strrev(const char *a1)
{
char *v1; // rcx
char *v2; // rdx
char v3; // al
char v4; // al

if ( a1 )
{
if ( *a1 )
{
v1 = (char *)&a1[strlen(a1) - 1];
if ( a1 < v1 )
{
v2 = (char *)a1;
do
{
v3 = *v1 ^ *v2;
*v2 = v3;
v4 = *v1 ^ v3;
*v1 = v4;
*v2++ ^= v4;
--v1;
}
while ( v2 < v1 );
}
}
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
char *v1; // rcx
char *v2; // rdx
char v3; // al
char v4; // al

if ( a1 )
{
if ( *a1 )
{
v1 = (char *)&a1[strlen(a1) - 1];
if ( a1 < v1 )
{
v2 = (char *)a1;
do
{
v3 = *v1 ^ *v2;
*v2 = v3;
v4 = *v1 ^ v3;
*v1 = v4;
*v2++ ^= v4;
--v1;
}
while ( v2 < v1 );
}
}
}
return a1;
}

original_code:
char* strrev(char *str){
      char *p1, *p2;
      if (! str || ! *str)
            return str;
      for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
      {
            *p1 ^= *p2;
            *p2 ^= *p1;
            *p1 ^= *p2;
      }
      return str;
}

canonical_original_code:
char *strrev(char *str){
      char *p1; char *p2;
      if (! str || ! *str)
            return str;
      for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
      {
            *p1 ^= *p2;
            *p2 ^= *p1;
            *p1 ^= *p2;
      }
      return str;
}

variable_types:
str
char *

return_type: char *


decompiled_code:
const char *__fastcall int2Char2(int a1)
{
int v1; // ebx
int v2; // edx
int v3; // ebp
char *v4; // rdi
__int64 v5; // rdx

v1 = a1;
if ( (unsigned int)(a1 + 9) <= 0x12 )
{
v4 = (char *)malloc(1uLL);
*v4 = v1 % 10 + 48;
}
else
{
v2 = a1;
v3 = 1;
do
{
v2 /= 10;
++v3;
}
while ( (unsigned int)(v2 + 9) > 0x12 );
v4 = (char *)malloc(v3);
if ( v3 > 0 )
{
v5 = 0LL;
do
{
v4[v5] = v1 % 10 + 48;
v1 /= 10;
++v5;
}
while ( v3 > (int)v5 );
}
}
return strrev(v4);
}

canonical_decompiled_code:
const char *__fastcall func2(int a1)
{
int v1; // ebx
int v2; // edx
int v3; // ebp
char *v4; // rdi
__int64 v5; // rdx

v1 = a1;
if ( (unsigned int)(a1 + 9) <= 0x12 )
{
v4 = (char *)malloc(1uLL);
*v4 = v1 % 10 + 48;
}
else
{
v2 = a1;
v3 = 1;
do
{
v2 /= 10;
++v3;
}
while ( (unsigned int)(v2 + 9) > 0x12 );
v4 = (char *)malloc(v3);
if ( v3 > 0 )
{
v5 = 0LL;
do
{
v4[v5] = v1 % 10 + 48;
v1 /= 10;
++v5;
}
while ( v3 > (int)v5 );
}
}
return func1(v4);
}

original_code:
char* int2Char2(int num){
 char *cad;
 int nDigitos=1, aux=num, i;
 while(aux/10!=0){
  aux=aux/10;
  nDigitos++;
 }
 cad=(char*)malloc(nDigitos*sizeof(char));
 for(i=0;i<nDigitos;i++){
  cad[i]=(num%10)+'0';
  num=num/10;
 }
 return strrev(cad);
}

canonical_original_code:
char *int2Char2(int num){
 char *cad;
 int nDigitos = 1; int aux = num; int i;
 while(aux/10!=0){
  aux=aux/10;
  nDigitos++;
 }
 cad=(char *)malloc(nDigitos*sizeof(char));
 for(i=0;i<nDigitos;i++){
  cad[i]=(num%10)+'0';
  num=num/10;
 }
 return strrev(cad);
}

variable_types: num int

variable_types:
cad
char *

variable_types: nDigitos int

variable_types: aux int

variable_types: i int


decompiled_code:
__int64 __fastcall check_bet(char *a1, __int64 a2)
{
char *v2; // rdi
unsigned int i; // ebp
int j; // eax
int v6; // ecx

v2 = strtok(a1, ",");
for ( i = 0; v2; v2 = strtok(0LL, ",") )
{
v6 = atoi(v2);
for ( j = 0; j <= 5; ++j )
{
if ( *(_DWORD *)(a2 + 4LL * j) == v6 )
{
++i;
++j;
}
}
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, __int64 a2)
{
char *v2; // rdi
unsigned int i; // ebp
int j; // eax
int v6; // ecx

v2 = strtok(a1, ",");
for ( i = 0; v2; v2 = strtok(0LL, ",") )
{
v6 = atoi(v2);
for ( j = 0; j <= 5; ++j )
{
if ( *(_DWORD *)(a2 + 4LL * j) == v6 )
{
++i;
++j;
}
}
}
return i;
}

original_code:
int check_bet(char *combinacionStrCVS, int *combinacionGanadora){
 int i=0, aciertos=0;
 char *aux;
 aux= strtok(combinacionStrCVS, ",");
 while(aux !=((void *)0)){
  for(i=0;i<6;i++){
   if(combinacionGanadora[i] == atoi(aux)){
    aciertos++;
    i++;
   }
  }
  aux=strtok(((void *)0), ",");
 }
 return aciertos;
}

canonical_original_code:
int check_bet(char *combinacionStrCVS, int *combinacionGanadora){
 int i = 0; int aciertos = 0;
 char *aux;
 aux= strtok(combinacionStrCVS, ",");
 while(aux !=((void *)0)){
  for(i=0;i<6;i++){
   if(combinacionGanadora[i] == atoi(aux)){
    aciertos++;
    i++;
   }
  }
  aux=strtok(((void *)0), ",");
 }
 return aciertos;
}

variable_types:
combinacionStrCVS
char *

variable_types:
combinacionGanadora
int *

variable_types:
aux
char *


signalHandler

decompiled_code:
void __fastcall signalHandler(int a1, __int64 a2)
{
if ( *(_DWORD *)(a2 + 8) == -1 && _libc_current_sigrtmin() == a1 )
++signalCounter;
}

canonical_decompiled_code:
void __fastcall func5(int a1, __int64 a2)
{
if ( *(_DWORD *)(a2 + 8) == -1 && _libc_current_sigrtmin() == a1 )
++signalCounter;
}

original_code:
void signalHandler(int mySignal, siginfo_t *info, void *other){
 char *src;
 switch(info->si_code){
  case SI_QUEUE:
   src = "sigqueue";
   if(mySignal==(__libc_current_sigrtmin ()))
    signalCounter++;
  break;
  case SI_TIMER:
   src = "timer";
  break;
  case SI_ASYNCIO:
   src = "asyncio";
  break;
  case SI_MESGQ:
   src = "msg queue";
  break;
  default:
   src = "unknown!";
  break;
 }
}

canonical_original_code:
void signalHandler(int mySignal, struct siginfo_t *info, void *other){
 char *src;
 switch(info->si_code){
  case SI_QUEUE:
   src = "sigqueue";
   if(mySignal==(__libc_current_sigrtmin ()))
    signalCounter++;
  break;
  case SI_TIMER:
   src = "timer";
  break;
  case SI_ASYNCIO:
   src = "asyncio";
  break;
  case SI_MESGQ:
   src = "msg queue";
  break;
  default:
   src = "unknown!";
  break;
 }
}

variable_types: mySignal int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
other
void *

variable_types:
src
char *

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


memoryAllocation

decompiled_code:
void *__fastcall memoryAllocation(int a1)
{
return malloc(4LL * a1);
}

canonical_decompiled_code:
void *__fastcall func6(int a1)
{
return malloc(4LL * a1);
}

original_code:
int* memoryAllocation(int jugadores){
 int *A;
 A= (int*)malloc(jugadores * sizeof(int));
 return A;
}

canonical_original_code:
int *memoryAllocation(int jugadores){
 int *A;
 A= (int *)malloc(jugadores * sizeof(int));
 return A;
}

variable_types: jugadores int

variable_types:
A
int *

return_type: int *


decompiled_code:
void *__fastcall read_from_pipe(int *a1)
{
void *v1; // rbp

v1 = malloc(0x11uLL);
close(a1[1]);
read(*a1, v1, 0x11uLL);
close(*a1);
return v1;
}

canonical_decompiled_code:
void *__fastcall func7(int *a1)
{
void *v1; // rbp

v1 = malloc(0x11uLL);
close(a1[1]);
read(*a1, v1, 0x11uLL);
close(*a1);
return v1;
}

original_code:
char* read_from_pipe(int *pipe){
 char *cad=(char*)malloc(17*sizeof(char));
 close(pipe[1]);
 read(pipe[0], cad, 17);
 close(pipe[0]);
 return cad;
}

canonical_original_code:
char *read_from_pipe(int *pipe){
 char *cad = (char*)malloc(17*sizeof(char));
 close(pipe[1]);
 read(pipe[0], cad, 17);
 close(pipe[0]);
 return cad;
}

variable_types:
pipe
int *


decompiled_code:
void __fastcall write_to_pipe(int **a1, const char *a2, int a3)
{
int **v3; // rbx
__int64 v4; // r12
size_t v5; // rax

if ( a3 > 0 )
{
v3 = a1;
v4 = (__int64)&a1[(unsigned int)(a3 - 1) + 1];
do
{
close(**v3);
v5 = strlen(a2);
write((*v3)[1], a2, v5);
close((*v3++)[1]);
}
while ( v3 != (int **)v4 );
}
}

original_code:
void write_to_pipe(int **pipe, char *string, int jugadores){
 int i;
 for(i=0;i<jugadores;i++){
  close(pipe[i][0]);
  write(pipe[i][1], string, strlen(string));
  close(pipe[i][1]);
 }
}

variable_types:
pipe
int **

variable_types:
string
char *


decompiled_code:
int *rand_bet()
{
__pid_t v0; // eax
int *v1; // rbp
int i; // ebx
int v3; // edx
__int64 v4; // rax

v0 = getpid();
srand(v0 + 12345678);
v1 = (int *)memoryAllocation(5);
for ( i = 0; i <= 5; ++i )
{
v3 = random() % 15 + 1;
if ( i < 0 )
{
LABEL_3:
v1[i] = v3;
}
else
{
v4 = 0LL;
while ( v1[v4] != v3 )
{
if ( i < (int)++v4 )
goto LABEL_3;
}
--i;
}
}
return sortV(v1);
}

original_code:
int* rand_bet(){
 srand(getpid()+12345678);
 int *bet = memoryAllocation(5);
 int num, i, j, d=0;
 for(i=0; i<6; i++){
  num = random()%(1-16) +1;
  for(j=0;j<=i;j++){
   if(num == bet[j]){
    d=1;
    break;
   }
  }
  if(d == 1){
   i--;
   d=0;
  }
  else
   bet[i]=num;
 }
 bet=sortV(bet);
 return bet;
}

canonical_original_code:
int *rand_bet(){
 srand(getpid()+12345678);
 int *bet = memoryAllocation(5);
 int num; int i; int j; int d = 0;
 for(i=0; i<6; i++){
  num = random()%(1-16) +1;
  for(j=0;j<=i;j++){
   if(num == bet[j]){
    d=1;
    break;
   }
  }
  if(d == 1){
   i--;
   d=0;
  }
  else
   bet[i]=num;
 }
 bet=sortV(bet);
 return bet;
}

variable_types:
bet
int *

variable_types: num int

variable_types: j int

variable_types: d int


decompiled_code:
int __fastcall show_bet(unsigned int *a1)
{
unsigned int *v1; // rbx

v1 = a1;
do
printf("%d ", *v1++);
while ( v1 != a1 + 6 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func11(unsigned int *a1)
{
unsigned int *v1; // rbx

v1 = a1;
do
printf("%d ", *v1++);
while ( v1 != a1 + 6 );
return putchar(10);
}

original_code:
void show_bet(int* bet){
 int i=0;
 for(i=0;i<6;i++){
  printf("%d ", bet[i]);
 }
 printf("\n");
}

canonical_original_code:
void show_bet(int *bet){
 int i = 0;
 for(i=0;i<6;i++){
  printf("%d ", bet[i]);
 }
 printf("\n");
}

variable_types: i int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // r15
int v5; // eax
__pid_t *v6; // r14
int v7; // eax
_QWORD *v8; // r13
__int64 i; // rbx
__int64 j; // rbx
__pid_t *v11; // rbp
int k; // ebx
_QWORD *v13; // r13
__int64 v14; // rbx
union sigval v15; // r12
int v16; // ebp
__pid_t v17; // eax
__int64 v18; // rax
int v19; // eax
__pid_t v20; // eax
__int64 v21; // rbp
unsigned int v22; // ebx
__int64 v23; // rax
__int64 v24; // r13
int l; // ebx
_DWORD *v26; // rbp
unsigned int v27; // ebx
unsigned int v28; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-3Ch] BYREF

LODWORD(stat_loc.__uptr) = 0;
sa.sa_handler = (__sighandler_t)&signalHandler;
sa.sa_flags = 4;
v3 = _libc_current_sigrtmin();
sigaction(v3, &sa, 0LL);
v4 = argv[2];
v5 = atoi(v4);
v6 = (__pid_t *)malloc(16LL * v5);
v7 = atoi(v4);
v8 = malloc(8LL * v7);
for ( i = 0LL; atoi(v4) > (int)i; ++i )
v8[i] = malloc(8uLL);
for ( j = 0LL; atoi(argv[2]) > (int)j; ++j )
pipe((int *)v8[j]);
if ( argc == 3 )
{
v11 = v6;
for ( k = 0; atoi(argv[2]) > k; ++k )
{
v20 = fork();
if ( !v20 )
{
v13 = &v8[k];
close(*(_DWORD *)(*v13 + 4LL));
v14 = rand_bet();
v15.sival_ptr = (void *)(unsigned int)getpid();
v16 = _libc_current_sigrtmin();
v17 = getppid();
sigqueue(v17, v16, v15);
v18 = read_from_pipe(*v13);
v19 = check_bet(v18, v14);
exit(v19);
}
if ( v20 < 0 )
{
puts("Error en el fork");
}
else
{
*v11 = v20;
v11[1] = k;
}
v11 += 4;
}
}
else
{
puts(aN);
}
while ( atoi(argv[2]) > signalCounter )
pause();
v21 = rand_bet();
v22 = atoi(argv[2]);
v23 = int2Char(v21);
write_to_pipe(v8, v23, v22);
v24 = 0LL;
while ( wait((__WAIT_STATUS)&stat_loc) >= 0 )
{
v26 = v6 + 1;
for ( l = 0; atoi(argv[2]) > l; ++l )
{
if ( *v26 == (_DWORD)v24 )
{
*(_QWORD *)&v6[4 * v24 + 2] = (int)premios((unsigned int)(SLODWORD(stat_loc.__uptr) / 256));
LODWORD(stat_loc.__uptr) = 0;
}
v26 += 4;
}
++v24;
}
v27 = atoi(argv[2]);
v28 = atoi(argv[1]);
gen_Snr(v28, v6, v27);
return 0;
}

original_code:
int main(int argc, char const *argv[])
{
 pid_t pid, wpid;
 int *apuestaHijo;
 int *combinacionGanadora;
 int **myPipe;
 HIJO *hijos;
 int buffer;
 int i=1, j;
 int cont=0;
 int fatherOn=0;
 union sigval v;
 sa.__sigaction_handler.sa_sigaction = signalHandler;
 sa.sa_flags = 4;
 sigaction((__libc_current_sigrtmin ()), &sa, ((void *)0));
 hijos=(HIJO*)malloc(atoi(argv[2])*sizeof(HIJO));
 myPipe=(int**)malloc(atoi(argv[2])*sizeof(int*));
 for(i=0;i<atoi(argv[2]);i++)
  myPipe[i]=(int*)malloc(2*sizeof(int));
 for(i=0;i<atoi(argv[2]);i++)
  pipe(myPipe[i]);
 if (argc == 3)
 {
  for(i=0;i<atoi(argv[2]);i++){
   pid =fork();
   if(pid == 0){
    int betCounter, j;
    close(myPipe[i][1]);
    apuestaHijo=rand_bet();
    v.sival_int=getpid();
    sigqueue(getppid(), (__libc_current_sigrtmin ()), v);
    betCounter=check_bet(read_from_pipe(myPipe[i]), apuestaHijo);
    exit(betCounter);
   }
   else if(pid < 0){
    printf("Error en el fork\n");
   }
   else{
    hijos[i].pid=pid;
    hijos[i].num=i;
   }
  }
 }
 else{
  printf("Número de parámetros inválido\n");
 }
    while(signalCounter < atoi(argv[2])){
     pause();
    }
    combinacionGanadora=rand_bet();
    write_to_pipe(myPipe, int2Char(combinacionGanadora), atoi(argv[2]));
    int *resultados, h=0, g=0;
    resultados=(int*)malloc(atoi(argv[2])*sizeof(int));
    while((wpid = wait(&cont)) >=0){
     for(h=0;h<atoi(argv[2]);h++){
      if(hijos[h].num == g){
       hijos[g].premio=(long)premios(cont/256);
       cont=0;
      }
     }
     g++;
    }
    gen_Snr(atoi(argv[1]), hijos, atoi(argv[2]));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int pid; int wpid;
 int *apuestaHijo;
 int *combinacionGanadora;
 int **myPipe;
 struct HIJO *hijos;
 int buffer;
 int i = 1; int j;
 int cont = 0;
 int fatherOn = 0;
 union sigval v;
 sa.__sigaction_handler.sa_sigaction = signalHandler;
 sa.sa_flags = 4;
 sigaction((__libc_current_sigrtmin ()), &sa, ((void *)0));
 hijos=(struct HIJO *)malloc(atoi(argv[2])*sizeof(HIJO));
 myPipe=(int **)malloc(atoi(argv[2])*sizeof(int *));
 for(i=0;i<atoi(argv[2]);i++)
  myPipe[i]=(int *)malloc(2*sizeof(int));
 for(i=0;i<atoi(argv[2]);i++)
  pipe(myPipe[i]);
 if (argc == 3)
 {
  for(i=0;i<atoi(argv[2]);i++){
   pid =fork();
   if(pid == 0){
    int betCounter; int j;
    close(myPipe[i][1]);
    apuestaHijo=rand_bet();
    v.sival_int=getpid();
    sigqueue(getppid(), (__libc_current_sigrtmin ()), v);
    betCounter=check_bet(read_from_pipe(myPipe[i]), apuestaHijo);
    exit(betCounter);
   }
   else if(pid < 0){
    printf("Error en el fork\n");
   }
   else{
    hijos[i].pid=pid;
    hijos[i].num=i;
   }
  }
 }
 else{
  printf("Número de parámetros inválido\n");
 }
    while(signalCounter < atoi(argv[2])){
     pause();
    }
    combinacionGanadora=rand_bet();
    write_to_pipe(myPipe, int2Char(combinacionGanadora), atoi(argv[2]));
    int *resultados; int h = 0; int g = 0;
    resultados=(int *)malloc(atoi(argv[2])*sizeof(int));
    while((wpid = wait(&cont)) >=0){
     for(h=0;h<atoi(argv[2]);h++){
      if(hijos[h].num == g){
       hijos[g].premio=(long)premios(cont/256);
       cont=0;
      }
     }
     g++;
    }
    gen_Snr(atoi(argv[1]), hijos, atoi(argv[2]));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: pid int

variable_types: wpid int

variable_types:
apuestaHijo
int *

variable_types:
myPipe
int **

variable_types: struct HIJO { int pid; int num; long premio; } *

variable_types: buffer int

variable_types: cont int

variable_types: fatherOn int

variable_types: union sigval { int sival_int; void *sival_ptr; }

variable_types: betCounter int

variable_types:
resultados
int *

variable_types: h int

variable_types: g int


decompiled_code:
_BOOL8 __fastcall my_isnalpha(char a1)
{
_BOOL4 v1; // edx

v1 = 0;
if ( (unsigned __int8)((a1 & 0xDF) - 65) > 0x19u )
v1 = (unsigned __int8)(a1 - 48) > 9u;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1)
{
_BOOL4 v1; // edx

v1 = 0;
if ( (unsigned __int8)((a1 & 0xDF) - 65) > 0x19u )
v1 = (unsigned __int8)(a1 - 48) > 9u;
return v1;
}

variable_types: c char


decompiled_code:
__int64 __fastcall my_count_nalpha(char *a1)
{
char v2; // di
char *v3; // rbx
unsigned int v4; // ebp

v2 = *a1;
if ( !v2 )
return 0;
v3 = a1 + 1;
v4 = 0;
do
{
v4 -= !my_isnalpha(v2) - 1;
v2 = *v3++;
}
while ( v2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char v2; // di
char *v3; // rbx
unsigned int v4; // ebp

v2 = *a1;
if ( !v2 )
return 0;
v3 = a1 + 1;
v4 = 0;
do
{
v4 -= !func0(v2) - 1;
v2 = *v3++;
}
while ( v2 );
return v4;
}

original_code:
int my_count_nalpha(char *str)
{
  int i;
  int count;
  i = 0;
  count = 0;
  while (str[i] != '\0')
    {
      if (my_isnalpha(str[i]))
     count = count + 1;
      i = i + 1;
    }
  return (count);
}

variable_types:
str
char *

variable_types: i int

variable_types: count int


Init

repo: Learn-Algorithm/Learn-Algorithm

decompiled_code:
char *Init()
{
return Create(32);
}

canonical_decompiled_code:
char *func8()
{
return func7(32);
}

original_code:
Trie* Init(void)
{
   return Create(' ');
}

canonical_original_code:
struct Trie *Init()
{
   return Create(' ');
}

return_type: struct Trie { int count; char value; struct Trie *children[26]; } *


Query

decompiled_code:
__int64 __fastcall Query(unsigned int *a1, const char *a2)
{
unsigned int *v2; // rbx
int v3; // eax
const char *v4; // rdx
__int64 v5; // rsi
unsigned int *v6; // rcx

v2 = a1;
v3 = strlen(a2);
if ( v3 <= 0 )
{
v6 = a1;
}
else
{
v4 = a2;
v5 = (__int64)&a2[v3 - 1 + 1];
while ( 1 )
{
v6 = v2;
v2 = *(unsigned int **)&v2[2 * *v4 - 192];
if ( !v2 )
break;
if ( ++v4 == (const char *)v5 )
{
v6 = v2;
return *v6;
}
}
}
return *v6;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1, const char *a2)
{
unsigned int *v2; // rbx
int v3; // eax
const char *v4; // rdx
__int64 v5; // rsi
unsigned int *v6; // rcx

v2 = a1;
v3 = strlen(a2);
if ( v3 <= 0 )
{
v6 = a1;
}
else
{
v4 = a2;
v5 = (__int64)&a2[v3 - 1 + 1];
while ( 1 )
{
v6 = v2;
v2 = *(unsigned int **)&v2[2 * *v4 - 192];
if ( !v2 )
break;
if ( ++v4 == (const char *)v5 )
{
v6 = v2;
return *v6;
}
}
}
return *v6;
}

original_code:
int Query(Trie* t, char* word)
{
    Trie* cur = t;
    int len = (int)strlen(word);
    for (int i = 0; i < len; i++) {
        int index = ((int)word[i] - (int)'a');
        if (cur->children[index] == ((void *)0)) {
            break;
        }
        cur = cur->children[index];
    }
    return cur->count;
}

canonical_original_code:
int Query(struct Trie *t, char *word)
{
    struct Trie *cur = t;
    int len = (int)strlen(word);
    for (int i = 0; i < len; i++) {
        int index = ((int)word[i] - (int)'a');
        if (cur->children[index] == ((void *)0)) {
            break;
        }
        cur = cur->children[index];
    }
    return cur->count;
}

variable_types: struct Trie { int count; char value; struct Trie *children[26]; } *

variable_types:
word
char *

variable_types: len int

variable_types: index int


Exists

decompiled_code:
bool __fastcall Exists(unsigned int *a1, const char *a2)
{
return (int)Query(a1, a2) > 0;
}

canonical_decompiled_code:
bool __fastcall func10(unsigned int *a1, const char *a2)
{
return (int)func9(a1, a2) > 0;
}

original_code:
_Bool Exists(Trie* t, char* word)
{
    return Query(t, word) > 0 ? 1 : 0;
}

canonical_original_code:
_Bool Exists(struct Trie *t, char *word)
{
    return Query(t, word) > 0 ? 1 : 0;
}

user_defined_types: struct Trie { int count; char value; struct Trie *children[26]; }


Minimum

decompiled_code:
__int64 __fastcall Minimum(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
AVL* Minimum(AVL* node)
{
    if (!node) return ((void *)0);
    while (node->lchild) {
        node = node->lchild;
    }
    return node;
}

canonical_original_code:
struct AVL *Minimum(struct AVL *node)
{
    if (!node) return ((void *)0);
    while (node->lchild) {
        node = node->lchild;
    }
    return node;
}

variable_types:
node
struct AVL *

return_type: struct AVL { int key; int height; struct AVL *lchild; struct AVL *rchild; } *


Maximum

decompiled_code:
__int64 __fastcall Maximum(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

original_code:
AVL* Maximum(AVL* node)
{
    if (!node) return ((void *)0);
    while (node->rchild) {
        node = node->rchild;
    }
    return node;
}

canonical_original_code:
struct AVL *Maximum(struct AVL *node)
{
    if (!node) return ((void *)0);
    while (node->rchild) {
        node = node->rchild;
    }
    return node;
}

user_defined_types: struct AVL { int key; int height; struct AVL *lchild; struct AVL *rchild; }


Visit

decompiled_code:
int __fastcall Visit(unsigned int *a1)
{
int result; // eax

if ( a1 )
result = printf("%d ", *a1);
return result;
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
int result; // eax

if ( a1 )
result = printf("%d ", *a1);
return result;
}

original_code:
void Visit(AVL* node)
{
    if(node != ((void *)0)) printf("%d ", node->key);
}

canonical_original_code:
void Visit(struct AVL *node)
{
    if(node != ((void *)0)) printf("%d ", node->key);
}

variable_types: struct AVL { int key; int height; struct AVL *lchild; struct AVL *rchild; } *


InOrder

decompiled_code:
__int64 __fastcall InOrder(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
InOrder(*a1);
Visit((__int64)a1);
result = InOrder(a1[1]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
func9(*a1);
func7((__int64)a1);
result = func9(a1[1]);
}
return result;
}

original_code:
void InOrder(AVL* root)
{
    if (!root) return;
    InOrder(root->lchild);
    Visit(root);
    InOrder(root->rchild);
}

canonical_original_code:
void InOrder(struct AVL *root)
{
    if (!root) return;
    InOrder(root->lchild);
    Visit(root);
    InOrder(root->rchild);
}


copylink

repo: Leask/VCP

decompiled_code:
__int64 __fastcall copylink(char *path, char *to)
{
int v2; // er12
int v3; // eax
__int64 result; // rax
struct stat v5; // [rsp+0h] [rbp-10A8h] BYREF
char buf[4120]; // [rsp+90h] [rbp-1018h] BYREF

v2 = stat(to, &v5);
v3 = readlink(path, buf, 0xFFFuLL);
if ( v3 < 0 )
{
logadds(0xFFFFFFFFLL, "%s: Bad link", path);
result = 1LL;
}
else
{
buf[v3] = 0;
if ( use_curses )
{
scrn_upd_file(path, to);
}
else if ( vflag )
{
fprintf(stderr, "\r%lu/%lu - %s -> %s\n", curfile, totalfiles, path, to);
}
if ( v2 != -1 && unlink(to) == -1 )
{
logadds(0xFFFFFFFFLL, "%s: Can not overwrite link", to);
result = 1LL;
}
else if ( symlink(buf, to) == -1 )
{
logadds(0xFFFFFFFFLL, "%s: Can not create link", to);
result = 1LL;
}
else
{
if ( use_curses )
logadds(1LL, "%s: Created", to);
++goodcp;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *path, char *to)
{
int v2; // er12
int v3; // eax
__int64 result; // rax
struct stat v5; // [rsp+0h] [rbp-10A8h] BYREF
char buf[4120]; // [rsp+90h] [rbp-1018h] BYREF

v2 = stat(to, &v5);
v3 = readlink(path, buf, 0xFFFuLL);
if ( v3 < 0 )
{
logadds(0xFFFFFFFFLL, "%s: Bad link", path);
result = 1LL;
}
else
{
buf[v3] = 0;
if ( use_curses )
{
scrn_upd_file(path, to);
}
else if ( vflag )
{
fprintf(stderr, "\r%lu/%lu - %s -> %s\n", curfile, totalfiles, path, to);
}
if ( v2 != -1 && unlink(to) == -1 )
{
logadds(0xFFFFFFFFLL, "%s: Can not overwrite link", to);
result = 1LL;
}
else if ( symlink(buf, to) == -1 )
{
logadds(0xFFFFFFFFLL, "%s: Can not create link", to);
result = 1LL;
}
else
{
if ( use_curses )
logadds(1LL, "%s: Created", to);
++goodcp;
result = 0LL;
}
}
return result;
}

original_code:
int copylink(char *src, char *dest) {
 char buf[4096];
 int exists = 0;
 int i;
 struct stat st2;
 if(stat(dest,&st2) != -1)
  exists=1;
 i = readlink(src,buf,sizeof(buf)-1);
 if(i < 0) {
  logadds(-1,"%s: Bad link",src,((void *)0));
  return 1;
 }
 buf[i] = '\0';
 if(use_curses) {
  scrn_upd_file(src,dest);
 } else if(vflag) {
  fprintf(stderr,"\r%lu/%lu - %s -> %s\n",curfile,totalfiles,src,dest);
 }
 if(exists) {
  if(unlink(dest) == -1){
   logadds(-1,"%s: Can not overwrite link",dest,((void *)0));
   return 1;
  }
 }
 if(symlink(buf,dest) == -1){
  logadds(-1,"%s: Can not create link",dest,((void *)0));
  return 1;
 }
 if(use_curses)
  logadds(1,"%s: Created",dest,((void *)0));
 goodcp++;
 return 0;
}

variable_types:
src
char *

variable_types:
dest
char *

variable_types:
buf
char [4096]

variable_types: exists int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


copyfifo

decompiled_code:
__int64 __fastcall copyfifo(char *path, __int64 a2)
{
int v2; // edx
__int64 result; // rax
struct stat v4; // [rsp+0h] [rbp-A8h] BYREF

if ( use_curses )
{
scrn_upd_file(path, 0LL);
}
else if ( vflag )
{
fprintf(stderr, "\r%lu/%lu - %s\n", curfile, totalfiles, path);
}
if ( stat(path, &v4) == -1 || (v2 = unlink(path), result = 1LL, !v2) )
{
if ( mkfifo(path, *(_DWORD *)(a2 + 24)) == -1 )
{
logadds(0xFFFFFFFFLL, "%s: Can not create fifo file", path);
result = 1LL;
}
else
{
setperm(path, a2);
if ( use_curses )
logadds(1LL, "%s: Created", path);
++goodcp;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *path, __int64 a2)
{
int v2; // edx
__int64 result; // rax
struct stat v4; // [rsp+0h] [rbp-A8h] BYREF

if ( use_curses )
{
scrn_upd_file(path, 0LL);
}
else if ( vflag )
{
fprintf(stderr, "\r%lu/%lu - %s\n", curfile, totalfiles, path);
}
if ( stat(path, &v4) == -1 || (v2 = unlink(path), result = 1LL, !v2) )
{
if ( mkfifo(path, *(_DWORD *)(a2 + 24)) == -1 )
{
logadds(0xFFFFFFFFLL, "%s: Can not create fifo file", path);
result = 1LL;
}
else
{
setperm(path, a2);
if ( use_curses )
logadds(1LL, "%s: Created", path);
++goodcp;
result = 0LL;
}
}
return result;
}

original_code:
int copyfifo(char *destfile, struct stat *st) {
 struct stat tmp;
 if(use_curses) {
  scrn_upd_file(destfile,((void *)0));
 } else if(vflag) {
  fprintf(stderr,"\r%lu/%lu - %s\n",curfile,totalfiles,destfile);
 }
 if(stat(destfile,&tmp) != -1) {
  if(unlink(destfile))
   return 1;
 }
 if(mkfifo(destfile,st->st_mode) == -1) {
  logadds(-1,"%s: Can not create fifo file",destfile,((void *)0));
  return 1;
 }
 setperm(destfile,st);
 if(use_curses)
  logadds(1,"%s: Created",destfile,((void *)0));
 goodcp++;
 return 0;
}

variable_types:
destfile
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *


copyspecial

decompiled_code:
__int64 __fastcall copyspecial(char *path, __int64 a2)
{
unsigned int v2; // er12
struct stat v4; // [rsp+0h] [rbp-A8h] BYREF

if ( use_curses )
{
scrn_upd_file(path, 0LL);
}
else if ( vflag )
{
fprintf(stderr, "\r%lu/%lu - %s\n", curfile, totalfiles, path);
}
if ( stat(path, &v4) == -1 || (v2 = 1, !unlink(path)) )
{
v2 = mknod(path, *(_DWORD *)(a2 + 24), *(_QWORD *)(a2 + 40));
if ( v2 )
{
logadds(0xFFFFFFFFLL, "%s: Can not create file", path);
v2 = 1;
}
else
{
setperm(path, a2);
if ( use_curses )
logadds(1LL, "%s: Created", path);
++goodcp;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *path, __int64 a2)
{
unsigned int v2; // er12
struct stat v4; // [rsp+0h] [rbp-A8h] BYREF

if ( use_curses )
{
scrn_upd_file(path, 0LL);
}
else if ( vflag )
{
fprintf(stderr, "\r%lu/%lu - %s\n", curfile, totalfiles, path);
}
if ( stat(path, &v4) == -1 || (v2 = 1, !unlink(path)) )
{
v2 = mknod(path, *(_DWORD *)(a2 + 24), *(_QWORD *)(a2 + 40));
if ( v2 )
{
logadds(0xFFFFFFFFLL, "%s: Can not create file", path);
v2 = 1;
}
else
{
setperm(path, a2);
if ( use_curses )
logadds(1LL, "%s: Created", path);
++goodcp;
}
}
return v2;
}

original_code:
int copyspecial(char *destfile, struct stat *st) {
 struct stat tmp;
 if(use_curses) {
  scrn_upd_file(destfile,((void *)0));
 } else if(vflag) {
  fprintf(stderr,"\r%lu/%lu - %s\n",curfile,totalfiles,destfile);
 }
 if(stat(destfile,&tmp) != -1) {
  if(unlink(destfile))
   return 1;
 }
 if(mknod(destfile,st->st_mode,st->st_rdev)) {
  logadds(-1,"%s: Can not create file",destfile,((void *)0));
  return 1;
 }
 setperm(destfile,st);
 if(use_curses)
  logadds(1,"%s: Created",destfile,((void *)0));
 goodcp++;
 return 0;
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


copyfile

decompiled_code:
__int64 __fastcall copyfile(const char *a1, const char *a2, __int64 a3)
{
int v3; // er15
__int64 v4; // rdx
int v5; // er12
__int64 v6; // r14
int *v7; // rax
__int64 result; // rax
__int64 v9; // rdx
int *v10; // rax
const char *v11; // rax
int v12; // eax
int v13; // er13
int v14; // ebx
char *v15; // rbp
int v16; // ebx
int v17; // edx
int v18; // eax
unsigned int v19; // [rsp+0h] [rbp-F8h]
__int64 v20; // [rsp+0h] [rbp-F8h]
unsigned int v21; // [rsp+0h] [rbp-F8h]
struct timeval timeout; // [rsp+20h] [rbp-D8h] BYREF
struct stat v24; // [rsp+30h] [rbp-C8h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 100LL;
if ( use_curses )
{
scrn_upd_file(a1, a2);
}
else if ( vflag )
{
fprintf(stderr, "\r%lu/%lu - %s\n", curfile, totalfiles, a1);
}
v3 = open(a1, 0);
if ( v3 == -1 )
{
v7 = _errno_location();
print_error(a1, (unsigned int)*v7);
result = 1LL;
}
else
{
if ( stat(a2, &v24) == -1 )
{
v21 = *(_DWORD *)(a3 + 24);
v9 = v21;
BYTE1(v9) = BYTE1(v21) & 0xF3;
v5 = open(a2, 577, v9);
}
else
{
if ( Iflag | iflag && (unsigned int)logget(a2) )
return 1LL;
if ( nflag )
{
logadds(1LL, "%s: file has not been overwritten", a2);
return 0LL;
}
if ( fflag )
{
unlink(a2);
v19 = *(_DWORD *)(a3 + 24);
v4 = v19;
BYTE1(v4) = BYTE1(v19) & 0xF3;
v5 = open(a2, 577, v4);
}
else
{
v5 = open(a2, 513, 0LL);
}
}
if ( v5 == -1 )
{
v10 = _errno_location();
print_error(a2, (unsigned int)*v10);
return 1LL;
}
v20 = *(_QWORD *)(a3 + 48);
if ( v20 )
{
if ( buf_size <= 0 )
buf_size = 204800;
if ( !databuf )
{
databuf = malloc(buf_size);
if ( !databuf )
{
exit_pre();
fprintf(stderr, "Can not allocate %d bytes of memory\n", buf_size);
exit(1);
}
}
v6 = 0LL;
while ( 1 )
{
v12 = read(v3, databuf, buf_size);
v13 = v12;
v14 = v12;
if ( v12 <= 0 )
break;
v15 = (char *)databuf;
v16 = v12;
v17 = 0;
do
{
v15 += v17;
v16 -= v17;
v18 = write(v5, v15, v16);
v17 = v18;
}
while ( v16 > v18 && v18 > 0 );
if ( v16 != v18 )
{
logadds(0xFFFFFFFFLL, "%s: Error writing file", a2);
return 1LL;
}
v6 += v13;
if ( use_curses )
scrn_upd_part(v6, v20);
else
scrn_updtxt(v6, v20, 0LL);
if ( dflag )
select(0, 0LL, 0LL, 0LL, &timeout);
}
if ( use_curses )
scrn_upd_part(v6, v20);
else
scrn_updtxt(v6, v20, 1LL);
close(v3);
close(v5);
if ( v14 < 0 )
{
logadds(0xFFFFFFFFLL, "%s: Error reading file", a1);
return 1LL;
}
}
else
{
logadds(1LL, "%s: file size is 0", a1);
close(v3);
close(v5);
}
setperm(a2, a3);
++goodcp;
result = use_curses;
if ( use_curses )
{
v11 = (const char *)pathname(a1);
logadds(1LL, "%s: File copied", v11);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, const char *a2, __int64 a3)
{
int v3; // er15
__int64 v4; // rdx
int v5; // er12
__int64 v6; // r14
int *v7; // rax
__int64 result; // rax
__int64 v9; // rdx
int *v10; // rax
const char *v11; // rax
int v12; // eax
int v13; // er13
int v14; // ebx
char *v15; // rbp
int v16; // ebx
int v17; // edx
int v18; // eax
unsigned int v19; // [rsp+0h] [rbp-F8h]
__int64 v20; // [rsp+0h] [rbp-F8h]
unsigned int v21; // [rsp+0h] [rbp-F8h]
struct timeval timeout; // [rsp+20h] [rbp-D8h] BYREF
struct stat v24; // [rsp+30h] [rbp-C8h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 100LL;
if ( use_curses )
{
scrn_upd_file(a1, a2);
}
else if ( vflag )
{
fprintf(stderr, "\r%lu/%lu - %s\n", curfile, totalfiles, a1);
}
v3 = open(a1, 0);
if ( v3 == -1 )
{
v7 = _errno_location();
print_error(a1, (unsigned int)*v7);
result = 1LL;
}
else
{
if ( stat(a2, &v24) == -1 )
{
v21 = *(_DWORD *)(a3 + 24);
v9 = v21;
BYTE1(v9) = BYTE1(v21) & 0xF3;
v5 = open(a2, 577, v9);
}
else
{
if ( Iflag | iflag && (unsigned int)logget(a2) )
return 1LL;
if ( nflag )
{
logadds(1LL, "%s: file has not been overwritten", a2);
return 0LL;
}
if ( fflag )
{
unlink(a2);
v19 = *(_DWORD *)(a3 + 24);
v4 = v19;
BYTE1(v4) = BYTE1(v19) & 0xF3;
v5 = open(a2, 577, v4);
}
else
{
v5 = open(a2, 513, 0LL);
}
}
if ( v5 == -1 )
{
v10 = _errno_location();
print_error(a2, (unsigned int)*v10);
return 1LL;
}
v20 = *(_QWORD *)(a3 + 48);
if ( v20 )
{
if ( buf_size <= 0 )
buf_size = 204800;
if ( !databuf )
{
databuf = malloc(buf_size);
if ( !databuf )
{
exit_pre();
fprintf(stderr, "Can not allocate %d bytes of memory\n", buf_size);
exit(1);
}
}
v6 = 0LL;
while ( 1 )
{
v12 = read(v3, databuf, buf_size);
v13 = v12;
v14 = v12;
if ( v12 <= 0 )
break;
v15 = (char *)databuf;
v16 = v12;
v17 = 0;
do
{
v15 += v17;
v16 -= v17;
v18 = write(v5, v15, v16);
v17 = v18;
}
while ( v16 > v18 && v18 > 0 );
if ( v16 != v18 )
{
logadds(0xFFFFFFFFLL, "%s: Error writing file", a2);
return 1LL;
}
v6 += v13;
if ( use_curses )
scrn_upd_part(v6, v20);
else
scrn_updtxt(v6, v20, 0LL);
if ( dflag )
select(0, 0LL, 0LL, 0LL, &timeout);
}
if ( use_curses )
scrn_upd_part(v6, v20);
else
scrn_updtxt(v6, v20, 1LL);
close(v3);
close(v5);
if ( v14 < 0 )
{
logadds(0xFFFFFFFFLL, "%s: Error reading file", a1);
return 1LL;
}
}
else
{
logadds(1LL, "%s: file size is 0", a1);
close(v3);
close(v5);
}
setperm(a2, a3);
++goodcp;
result = use_curses;
if ( use_curses )
{
v11 = (const char *)pathname(a1);
logadds(1LL, "%s: File copied", v11);
result = 0LL;
}
}
return result;
}

original_code:
int copyfile(char *srcfile, char *destfile, struct stat *st) {
 int f, f2;
 struct stat st2;
 int rcnt = 0;
 int rest = 0;
 int wcnt = 0;
 char *p = ((void *)0);
 unsigned long sizecpd, size;
 struct timeval timea;
 timea.tv_sec = 0;
 timea.tv_usec = 100;
 if(use_curses) {
  scrn_upd_file(srcfile,destfile);
 } else if(vflag) {
  fprintf(stderr,"\r%lu/%lu - %s\n",curfile,totalfiles,srcfile);
 }
 if((f = open(srcfile, 00)) == -1) {
  print_error(srcfile,(*__errno_location ()));
  return 1;
 }
 if(stat(destfile,&st2) != -1) {
  if(iflag || Iflag) {
   if(logget(destfile))
    return 1;
  }
  if(nflag) {
   logadds(1,"%s: file has not been overwritten",destfile,((void *)0));
   return 0;
  }
  if(fflag) {
   unlink(destfile);
   f2 = open(destfile, 01 | 0100 | 01000, st->st_mode & ~(04000 | 02000));
  } else
   f2 = open(destfile, 01 | 01000,0);
 } else {
  f2 = open(destfile, 01 | 0100 | 01000, st->st_mode & ~(04000 | 02000));
 }
 if(f2 == -1) {
  print_error(destfile,(*__errno_location ()));
  return 1;
 }
 size = st->st_size;
 sizecpd = 0;
 if(size < 1) {
  logadds(1,"%s: file size is 0",srcfile,((void *)0));
 } else {
  if(buf_size < 1)
   buf_size = 204800;
  if(databuf == ((void *)0)) {
   if((databuf = (char *)malloc(buf_size)) == ((void *)0)) {
    exit_pre();
    fprintf(stderr,"Can not allocate %d bytes of memory\n",buf_size);
    exit(1);
   }
  }
  while ((rcnt = read(f,databuf,buf_size)) > 0) {
   rest = rcnt;
   p = databuf;
   wcnt = 0;
   for(;;) {
    p += wcnt;
    rest -= wcnt;
    wcnt = write(f2,p,rest);
    if(rest <= wcnt || wcnt <= 0)
     break;
   }
   if(rest != wcnt) {
    logadds(-1,"%s: Error writing file",destfile,((void *)0));
    return 1;
   }
   sizecpd += rcnt;
   if(use_curses)
    scrn_upd_part(sizecpd,size);
   else
    scrn_updtxt(sizecpd,size,0);
   if(dflag)
    select(0,((void *)0),((void *)0),((void *)0),&timea);
  }
  if(use_curses) {
   scrn_upd_part(sizecpd,size);
  } else {
   scrn_updtxt(sizecpd,size,1);
  }
 }
 close(f);
 close(f2);
 if(rcnt < 0) {
  logadds(-1,"%s: Error reading file",srcfile,((void *)0));
  return 1;
 }
 setperm(destfile,st);
 goodcp++;
 if(use_curses)
  logadds(1,"%s: File copied",pathname(srcfile),((void *)0));
 return 0;
}

canonical_original_code:
int copyfile(char *srcfile, char *destfile, struct stat *st) {
 int f; int f2;
 struct stat st2;
 int rcnt = 0;
 int rest = 0;
 int wcnt = 0;
 char *p = ((void *)0);
 unsigned long sizecpd; unsigned long size;
 struct timeval timea;
 timea.tv_sec = 0;
 timea.tv_usec = 100;
 if(use_curses) {
  scrn_upd_file(srcfile,destfile);
 } else if(vflag) {
  fprintf(stderr,"\r%lu/%lu - %s\n",curfile,totalfiles,srcfile);
 }
 if((f = open(srcfile, 00)) == -1) {
  print_error(srcfile,(*__errno_location ()));
  return 1;
 }
 if(stat(destfile,&st2) != -1) {
  if(iflag || Iflag) {
   if(logget(destfile))
    return 1;
  }
  if(nflag) {
   logadds(1,"%s: file has not been overwritten",destfile,((void *)0));
   return 0;
  }
  if(fflag) {
   unlink(destfile);
   f2 = open(destfile, 01 | 0100 | 01000, st->st_mode & ~(04000 | 02000));
  } else
   f2 = open(destfile, 01 | 01000,0);
 } else {
  f2 = open(destfile, 01 | 0100 | 01000, st->st_mode & ~(04000 | 02000));
 }
 if(f2 == -1) {
  print_error(destfile,(*__errno_location ()));
  return 1;
 }
 size = st->st_size;
 sizecpd = 0;
 if(size < 1) {
  logadds(1,"%s: file size is 0",srcfile,((void *)0));
 } else {
  if(buf_size < 1)
   buf_size = 204800;
  if(databuf == ((void *)0)) {
   if((databuf = (char *)malloc(buf_size)) == ((void *)0)) {
    exit_pre();
    fprintf(stderr,"Can not allocate %d bytes of memory\n",buf_size);
    exit(1);
   }
  }
  while ((rcnt = read(f,databuf,buf_size)) > 0) {
   rest = rcnt;
   p = databuf;
   wcnt = 0;
   for(;;) {
    p += wcnt;
    rest -= wcnt;
    wcnt = write(f2,p,rest);
    if(rest <= wcnt || wcnt <= 0)
     break;
   }
   if(rest != wcnt) {
    logadds(-1,"%s: Error writing file",destfile,((void *)0));
    return 1;
   }
   sizecpd += rcnt;
   if(use_curses)
    scrn_upd_part(sizecpd,size);
   else
    scrn_updtxt(sizecpd,size,0);
   if(dflag)
    select(0,((void *)0),((void *)0),((void *)0),&timea);
  }
  if(use_curses) {
   scrn_upd_part(sizecpd,size);
  } else {
   scrn_updtxt(sizecpd,size,1);
  }
 }
 close(f);
 close(f2);
 if(rcnt < 0) {
  logadds(-1,"%s: Error reading file",srcfile,((void *)0));
  return 1;
 }
 setperm(destfile,st);
 goodcp++;
 if(use_curses)
  logadds(1,"%s: File copied",pathname(srcfile),((void *)0));
 return 0;
}

variable_types:
srcfile
char *

variable_types: f int

variable_types: rcnt int

variable_types: rest int

variable_types: wcnt int

variable_types:
p
char *

variable_types:
sizecpd
unsigned long

variable_types:
size
unsigned long

variable_types: struct timeval { long tv_sec; long tv_usec; }


pathlong

decompiled_code:
__int64 __fastcall pathlong(char *src, char *a2)
{
int v2; // er13
int v3; // er12
__int64 i; // rax
int v5; // edx
__int64 v6; // rax
char v8[20]; // [rsp+0h] [rbp-68h] BYREF
char v9; // [rsp+14h] [rbp-54h]
char v10; // [rsp+1Fh] [rbp-49h]
char dest[72]; // [rsp+20h] [rbp-48h] BYREF

if ( !src )
{
v2 = 0;
if ( !a2 )
goto LABEL_18;
goto LABEL_4;
}
if ( src == a2 )
{
v2 = strlen(src);
goto LABEL_4;
}
v2 = strlen(src);
v3 = 0;
if ( a2 )
LABEL_4:
v3 = strlen(a2);
if ( (unsigned int)(v2 - 1) <= 0x13 )
{
strcpy(dest, src);
}
else if ( v2 > 0 )
{
for ( i = 1LL; i != 21; ++i )
*(&v10 + i) = src[i];
dest[20] = 0;
}
if ( (unsigned int)(v3 - 1) <= 0x13 )
{
strcpy(v8, a2);
}
else if ( v3 > 0 )
{
v5 = strlen(a2) - 20;
v6 = 0LL;
if ( src == a2 )
{
do
{
v8[v6] = a2[v5 + v6];
++v6;
}
while ( v6 != 20 );
v9 = 0;
}
else
{
do
{
v8[v6] = src[v5 + v6];
++v6;
}
while ( v6 != 20 );
v9 = 0;
}
}
LABEL_18:
logadds(0xFFFFFFFFLL, "%s ... %s: Path too long, not copied", dest, v8);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src, char *a2)
{
int v2; // er13
int v3; // er12
__int64 i; // rax
int v5; // edx
__int64 v6; // rax
char v8[20]; // [rsp+0h] [rbp-68h] BYREF
char v9; // [rsp+14h] [rbp-54h]
char v10; // [rsp+1Fh] [rbp-49h]
char dest[72]; // [rsp+20h] [rbp-48h] BYREF

if ( !src )
{
v2 = 0;
if ( !a2 )
goto LABEL_18;
goto LABEL_4;
}
if ( src == a2 )
{
v2 = strlen(src);
goto LABEL_4;
}
v2 = strlen(src);
v3 = 0;
if ( a2 )
LABEL_4:
v3 = strlen(a2);
if ( (unsigned int)(v2 - 1) <= 0x13 )
{
strcpy(dest, src);
}
else if ( v2 > 0 )
{
for ( i = 1LL; i != 21; ++i )
*(&v10 + i) = src[i];
dest[20] = 0;
}
if ( (unsigned int)(v3 - 1) <= 0x13 )
{
strcpy(v8, a2);
}
else if ( v3 > 0 )
{
v5 = strlen(a2) - 20;
v6 = 0LL;
if ( src == a2 )
{
do
{
v8[v6] = a2[v5 + v6];
++v6;
}
while ( v6 != 20 );
v9 = 0;
}
else
{
do
{
v8[v6] = src[v5 + v6];
++v6;
}
while ( v6 != 20 );
v9 = 0;
}
}
LABEL_18:
logadds(0xFFFFFFFFLL, "%s ... %s: Path too long, not copied", dest, v8);
return 1LL;
}

original_code:
int pathlong(char *path,char *path2) {
 char buf[21],buf2[21];
 int x, l;
 int i = 0;
 int d = 0;
 if(path != ((void *)0)) {
  if(path == path2)
   i = d = strlen(path);
  else
   i = strlen(path);
 }
 if(path2 != ((void *)0))
  d = strlen(path2);
 if(i<21 && i>0)
  strcpy(buf,path);
 else if(i>0){
  for(x=0;x<20;x++)
   buf[x] = path[x+1];
  buf[20] = '\0';
 }
 if(d<21 && d>0)
  strcpy(buf2,path2);
 else if(d>0){
  l = strlen(path2) - 20;
  if(path == path2) {
   for(x=0;x<20;x++)
    buf2[x] = path2[x+l];
   buf2[20] = '\0';
  } else {
   for(x=0;x<20;x++)
    buf2[x] = path[x+l];
   buf2[20] = '\0';
  }
 }
 logadds(-1,"%s ... %s: Path too long, not copied",buf,buf2);
 return 1;
}

canonical_original_code:
int pathlong(char *path, char *path2) {
 char buf[21]; char buf2[21];
 int x; int l;
 int i = 0;
 int d = 0;
 if(path != ((void *)0)) {
  if(path == path2)
   i = d = strlen(path);
  else
   i = strlen(path);
 }
 if(path2 != ((void *)0))
  d = strlen(path2);
 if(i<21 && i>0)
  strcpy(buf,path);
 else if(i>0){
  for(x=0;x<20;x++)
   buf[x] = path[x+1];
  buf[20] = '\0';
 }
 if(d<21 && d>0)
  strcpy(buf2,path2);
 else if(d>0){
  l = strlen(path2) - 20;
  if(path == path2) {
   for(x=0;x<20;x++)
    buf2[x] = path2[x+l];
   buf2[20] = '\0';
  } else {
   for(x=0;x<20;x++)
    buf2[x] = path[x+l];
   buf2[20] = '\0';
  }
 }
 logadds(-1,"%s ... %s: Path too long, not copied",buf,buf2);
 return 1;
}

variable_types:
path
char *

variable_types:
buf
char [21]

variable_types: x int

variable_types: l int

variable_types: i int

variable_types: d int


pathchsize

decompiled_code:
__int64 __fastcall pathchsize(char *src, char *a2)
{
int v2; // er12
int v3; // eax
unsigned int v4; // edx
int v6; // eax

if ( src == a2 )
{
v6 = strlen(src);
v4 = 0;
if ( v6 <= 4094 )
return v4;
goto LABEL_6;
}
if ( src )
{
v2 = strlen(src);
v3 = 0;
if ( !a2 )
goto LABEL_5;
}
else
{
v2 = 0;
if ( !a2 )
return 0;
}
v3 = strlen(a2);
LABEL_5:
v4 = 0;
if ( v2 + v3 > 4094 )
{
LABEL_6:
pathlong(src, a2);
v4 = 1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, char *a2)
{
int v2; // er12
int v3; // eax
unsigned int v4; // edx
int v6; // eax

if ( src == a2 )
{
v6 = strlen(src);
v4 = 0;
if ( v6 <= 4094 )
return v4;
goto LABEL_6;
}
if ( src )
{
v2 = strlen(src);
v3 = 0;
if ( !a2 )
goto LABEL_5;
}
else
{
v2 = 0;
if ( !a2 )
return 0;
}
v3 = strlen(a2);
LABEL_5:
v4 = 0;
if ( v2 + v3 > 4094 )
{
LABEL_6:
func0(src, a2);
v4 = 1;
}
return v4;
}

original_code:
int pathchsize(char *path, char *path2) {
 int i = 0;
 int d = 0;
 if(path == path2) {
  i = strlen(path);
  if(i<(4096 - 1))
   return 0;
 } else {
  if(path != ((void *)0))
   i = strlen(path);
  if(path2 != ((void *)0))
   d = strlen(path2);
  if((i+d)<(4096 - 1))
   return 0;
 }
 pathlong(path,path2);
 return 1;
}


pathdadd

decompiled_code:
__int64 __fastcall pathdadd(char *src, char *a2)
{
unsigned int v2; // er12
char *v3; // rbp
int v4; // er13
char *v5; // rax

v2 = 0;
if ( a2 )
{
v3 = a2;
v4 = strlen(src);
v2 = pathchsize(src, a2);
if ( v2 )
{
v2 = 1;
}
else
{
if ( src[v4 - 1] == 47 )
{
v3 = &a2[*a2 == 47];
}
else if ( *a2 != 47 )
{
*(_WORD *)&src[strlen(src)] = 47;
}
strcat(src, v3);
v5 = &src[strlen(src) - 1];
if ( *v5 == 47 )
*v5 = 0;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, char *a2)
{
unsigned int v2; // er12
char *v3; // rbp
int v4; // er13
char *v5; // rax

v2 = 0;
if ( a2 )
{
v3 = a2;
v4 = strlen(src);
v2 = func1(src, a2);
if ( v2 )
{
v2 = 1;
}
else
{
if ( src[v4 - 1] == 47 )
{
v3 = &a2[*a2 == 47];
}
else if ( *a2 != 47 )
{
*(_WORD *)&src[strlen(src)] = 47;
}
strcat(src, v3);
v5 = &src[strlen(src) - 1];
if ( *v5 == 47 )
*v5 = 0;
}
}
return v2;
}

original_code:
int pathdadd(char *master,char *dir) {
 int end = strlen(master)-1;
 if(dir == ((void *)0))
  return 0;
 if(pathchsize(master,dir))
  return 1;
 if(master[end] == '/' && *dir == '/')
  dir++;
 else if(master[end] != '/' && *dir != '/') {
  if(master != ((void *)0))
   strcat(master,"/");
 }
 strcat(master,dir);
 if(master[strlen(master)-1] == '/')
  master[strlen(master)-1] = '\0';
 return 0;
}

canonical_original_code:
int pathdadd(char *master, char *dir) {
 int end = strlen(master)-1;
 if(dir == ((void *)0))
  return 0;
 if(pathchsize(master,dir))
  return 1;
 if(master[end] == '/' && *dir == '/')
  dir++;
 else if(master[end] != '/' && *dir != '/') {
  if(master != ((void *)0))
   strcat(master,"/");
 }
 strcat(master,dir);
 if(master[strlen(master)-1] == '/')
  master[strlen(master)-1] = '\0';
 return 0;
}

variable_types:
master
char *

variable_types:
dir
char *

variable_types: end int


pathnamed

decompiled_code:
__int64 __fastcall pathnamed(const char *a1)
{
char *v1; // rax
unsigned int v2; // edx
bool v3; // zf
__int64 result; // rax

v1 = strrchr(a1, 47);
v2 = (_DWORD)v1 - (_DWORD)a1;
v3 = v1 == 0LL;
result = 0LL;
if ( !v3 )
result = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
char *v1; // rax
unsigned int v2; // edx
bool v3; // zf
__int64 result; // rax

v1 = strrchr(a1, 47);
v2 = (_DWORD)v1 - (_DWORD)a1;
v3 = v1 == 0LL;
result = 0LL;
if ( !v3 )
result = v2;
return result;
}

original_code:
int pathnamed(char *path) {
 char *p;
 p = strrchr(path,'/');
 if(path[strlen(path)-1] == '/') {
  p--;
  p = strrchr(path,'/');
 }
 if(p == ((void *)0))
  return 0;
 return p - path;
}


pathname

decompiled_code:
const char *__fastcall pathname(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

if ( !a1 )
return 0LL;
v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

if ( !a1 )
return 0LL;
v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

original_code:
char *pathname(char *path) {
 char *p;
 if(path == ((void *)0))
  return path;
 p = strrchr(path,'/');
 if(p == ((void *)0))
  return path;
 p++;
 return p;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
int v4; // eax
int v5; // er12
int v6; // er15
int v7; // er12
int v8; // ebx
unsigned int v9; // er13
const char **v10; // rbp
char **v11; // rax
const char *v12; // r14
char **v13; // r12
unsigned int v15; // [rsp+Ch] [rbp-15Ch]
char v16[24]; // [rsp+10h] [rbp-158h] BYREF
int v17; // [rsp+28h] [rbp-140h]
struct stat v18; // [rsp+A0h] [rbp-C8h] BYREF

conf_read(1LL, argv, envp);
conf_read(0LL, argv, v3);
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "HLPRfinpvtdIVmhb:u");
if ( v4 == -1 )
break;
if ( v4 == 98 )
{
buf_size = atoi(optarg);
}
else if ( (unsigned int)flag_setc((unsigned int)(char)v4, 1LL) == -1 )
{
usage();
}
}
v5 = Vflag;
if ( Vflag )
{
printf("VCP %d.%d\n", 2LL, 2LL);
v5 = 0;
}
else
{
v6 = hflag;
if ( !hflag )
{
v7 = optind;
v8 = argc - optind;
if ( argc - optind <= 1 )
usage();
if ( nflag )
{
if ( !iflag )
{
if ( !fflag )
goto LABEL_84;
goto LABEL_14;
}
puts("-i and -n conflict");
usage();
if ( !fflag )
goto LABEL_84;
if ( nflag )
{
LABEL_14:
puts("-f and -n conflict");
usage();
if ( !fflag )
goto LABEL_84;
goto LABEL_82;
}
}
else if ( !fflag )
{
goto LABEL_84;
}
LABEL_82:
if ( iflag )
{
puts("-f and -i conflict");
usage();
}
LABEL_84:
scrn_init();
if ( Rflag )
{
if ( !(Lflag | Hflag | Pflag) )
Pflag = 1;
}
else
{
if ( !Hflag )
{
if ( !Pflag )
goto LABEL_23;
goto LABEL_48;
}
Hflag = 0;
logadds(1LL, "-H ignored", 0LL, 0LL);
}
if ( !Pflag )
goto LABEL_23;
if ( Rflag )
{
if ( !Lflag )
{
LABEL_32:
if ( !Pflag )
goto LABEL_34;
goto LABEL_33;
}
goto LABEL_25;
}
LABEL_48:
Pflag = 0;
logadds(1LL, "-P ignored", 0LL, 0LL);
LABEL_23:
if ( !Lflag )
goto LABEL_32;
if ( !Rflag )
{
Lflag = 0;
logadds(1LL, "-L ignored", 0LL, 0LL);
if ( !Pflag )
goto LABEL_53;
if ( !Lflag )
{
LABEL_33:
if ( !Hflag )
goto LABEL_34;
Hflag = 0;
logadds(1LL, "-H ignored", 0LL, 0LL);
LABEL_53:
if ( Hflag && Lflag )
goto LABEL_27;
goto LABEL_34;
}
LABEL_51:
Lflag = 0;
logadds(1LL, "-L ignored", 0LL, 0LL);
goto LABEL_33;
}
LABEL_25:
if ( !Pflag )
{
if ( Hflag )
{
LABEL_27:
Lflag = 0;
logadds(1LL, "-L ignored", 0LL, 0LL);
}
LABEL_34:
if ( Iflag )
{
if ( !iflag || (Iflag = 0, logadds(1LL, "-I ignored", 0LL, 0LL), Iflag) )
iflag = 1;
}
v9 = 6;
if ( Rflag )
{
v9 = 21 - (Hflag == 0);
if ( Lflag )
v9 = v9 & 0xFFFFFFEF | 2;
}
scrn_upd_file(0LL, 0LL);
scrn_upd_part(0LL, 0LL);
if ( vflag )
flags_print();
v10 = &argv[v7];
if ( mflag )
{
if ( stat(*v10, &v18) == -1 )
{
endwin();
use_curses = 0;
logadds(0xFFFFFFFFLL, "%s: Not a vaild source", *v10);
usage();
}
v12 = v10[1];
v10[1] = 0LL;
v15 = v8 - 1;
totalfiles = (int)((v8 - 1) * cntfiles(v10, v9));
v10[1] = v12;
if ( (v18.st_mode & 0xF000) == 0x4000 && !Rflag )
{
endwin();
use_curses = 0;
logadds(0xFFFFFFFFLL, "%s is a directory, not copied", *v10);
ret = 1;
done(v15);
}
if ( v8 > 1 )
{
v13 = (char **)(v10 + 1);
do
{
dest = *v13;
v10[1] = 0LL;
if ( (v18.st_mode & 0xF000) == 0x4000 )
copyall(v10, v9, 1LL);
else
copyall(v10, v9, 0LL);
v10[1] = v12;
++v13;
}
while ( &v10[(unsigned int)(v8 - 2) + 2] != (const char **)v13 );
}
done(v15);
}
v11 = (char **)&v10[v8 - 1];
dest = *v11;
*v11 = 0LL;
totalfiles = (int)cntfiles(v10, v9);
if ( stat(dest, &v18) == -1 )
{
if ( v8 == 2 )
{
statit(*v10, v16, 1LL);
LABEL_75:
if ( (v17 & 0xF000) == 0x4000 )
{
copyall(v10, v9, 2LL);
goto LABEL_77;
}
LABEL_76:
copyall(v10, v9, 0LL);
LABEL_77:
done(0LL);
return 1;
}
endwin();
use_curses = 0;
logadds(0xFFFFFFFFLL, "%s: Not a vaild destination", dest);
usage();
}
else
{
if ( (v18.st_mode & 0xF000) == 0x4000 )
{
check_iloop(v10, dest);
copyall(v10, v9, 1LL);
done(0LL);
endwin();
use_curses = 0;
logadds(0xFFFFFFFFLL, "%s: Not a valid destination", dest);
usage();
return 1;
}
if ( v8 == 2 )
{
statit(*v10, v16, 1LL);
goto LABEL_76;
}
v6 = 1;
}
endwin();
use_curses = 0;
logadds(0xFFFFFFFFLL, "%s: Not a vaild destination", dest);
usage();
statit(*v10, v16, 1LL);
if ( v6 )
goto LABEL_76;
goto LABEL_75;
}
goto LABEL_51;
}
printf("VCP %d.%d\n", 2LL, 2LL);
puts("usage:");
puts("vcp [options] src dest");
puts("vcp [options] src1 src2 .. destdir");
puts("vcp [options -m] src dest1 dest2 ..");
putchar(10);
puts("options:");
puts("-R\tcopies directories, re-creates special files");
puts("-v\tverbose output");
puts("-H\tfollows symlinks on cmd line (needs -R)");
puts("-L\tall symlinks are followed (needs -R)");
puts("-P\tno symlinks are followed (needs -R, default)");
puts("-f\tforces existing files to be overwritten");
puts("-i\tprompts when existing file found (Y/[N])");
puts("-I\tprompts when existing file found ([Y]/N)");
puts("-n\tno existing files are overwritten");
puts("-p\tattempts to keep all permissions");
puts("-t\toutput to console, use with -v for status");
puts("-d\tdelayed copy");
puts("-V\tprint version and exit");
puts("-m\tmulti-output file copy");
puts("-b BUF\tset read buffer size (bytes)");
puts("-u\tfiles present with newer time stamp and same size are not copied");
puts("-h\tprint this");
}
return v5;
}

original_code:
int main(int argc, char *argv[]) {
 struct stat st,st2;
 int fts_opt;
 int ch;
 int exist = 0;
 char *targv = ((void *)0);
 int i = 0;
 fts_opt = 0x0004 | 0x0010;
 conf_read(1);
 conf_read(0);
 while ((ch = getopt(argc, argv, "HLPRfinpvtdIVmhb:u")) != -1) {
  if(ch == 'b') {
   buf_size = atoi(optarg);
  }
  else if(flag_setc(ch,1) == -1) {
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if(Vflag) {
  printf("VCP %d.%d\n",2,2);
  return 0;
 }
 if(hflag) {
  printf("VCP %d.%d\n",2,2);
  printf("usage:\n");
  printf("vcp [options] src dest\n");
  printf("vcp [options] src1 src2 .. destdir\n");
  printf("vcp [options -m] src dest1 dest2 ..\n");
  printf("\n");
  printf("options:\n");
  printf("-R\tcopies directories, re-creates special files\n");
  printf("-v\tverbose output\n");
  printf("-H\tfollows symlinks on cmd line (needs -R)\n");
  printf("-L\tall symlinks are followed (needs -R)\n");
  printf("-P\tno symlinks are followed (needs -R, default)\n");
  printf("-f\tforces existing files to be overwritten\n");
  printf("-i\tprompts when existing file found (Y/[N])\n");
  printf("-I\tprompts when existing file found ([Y]/N)\n");
  printf("-n\tno existing files are overwritten\n");
  printf("-p\tattempts to keep all permissions\n");
  printf("-t\toutput to console, use with -v for status\n");
  printf("-d\tdelayed copy\n");
  printf("-V\tprint version and exit\n");
  printf("-m\tmulti-output file copy\n");
  printf("-b BUF\tset read buffer size (bytes)\n");
  printf("-u\tfiles present with newer time stamp and same size are not copied\n");
  printf("-h\tprint this\n");
  return 0;
 }
 if(argc < 2)
  usage();
 if(nflag && iflag) {
  printf("-i and -n conflict\n");
  usage();
 }
 if(fflag && nflag) {
  printf("-f and -n conflict\n");
  usage();
 }
 if(fflag && iflag) {
  printf("-f and -i conflict\n");
  usage();
 }
 scrn_init();
 if(Rflag && !Pflag && !Hflag && !Lflag)
  Pflag = 1;
 if(Hflag && !Rflag) {
  Hflag = 0;
  logadds(1,"-H ignored",((void *)0),((void *)0));
 }
 if(Pflag && !Rflag) {
  Pflag = 0;
  logadds(1,"-P ignored",((void *)0),((void *)0));
 }
 if(Lflag && !Rflag) {
  Lflag = 0;
  logadds(1,"-L ignored",((void *)0),((void *)0));
 }
 if(Pflag) {
  if(Lflag) {
   Lflag = 0;
   logadds(1,"-L ignored",((void *)0),((void *)0));
  }
  if(Hflag) {
   Hflag = 0;
   logadds(1,"-H ignored",((void *)0),((void *)0));
  }
 }
 if(Hflag && Lflag) {
  Lflag = 0;
  logadds(1,"-L ignored",((void *)0),((void *)0));
 }
 if(Iflag && iflag) {
  Iflag = 0;
  logadds(1,"-I ignored",((void *)0),((void *)0));
 }
 if(Iflag)
  iflag = 1;
 if(Rflag) {
  if(Hflag)
   fts_opt |= 0x0001;
  if(Lflag) {
   fts_opt &= ~0x0010;
   fts_opt |= 0x0002;
  }
 } else {
  fts_opt &= ~0x0010;
  fts_opt |= 0x0002;
 }
 scrn_upd_file(((void *)0),((void *)0));
 scrn_upd_part(0,0);
 if(vflag)
  flags_print();
 if(mflag) {
  if(stat(argv[0],&st) == -1) {
   endwin();
   use_curses = 0;
   logadds(-1,"%s: Not a vaild source",argv[0],((void *)0));
   usage();
  }
  targv = argv[1];
  argv[1] = ((void *)0);
  totalfiles = cntfiles(argv,fts_opt) * (argc - 1);
  argv[1] = targv;
  if(((((st.st_mode)) & 0170000) == (0040000)) && !Rflag) {
   endwin();
   use_curses = 0;
   logadds(-1,"%s is a directory, not copied",argv[0],((void *)0));
   ret = 1;
   done(argc-1);
  }
  for (i=1;i<argc;i++){
   dest.opath = argv[i];
   argv[1] = ((void *)0);
   if(((((st.st_mode)) & 0170000) == (0040000)))
    copyall(argv,fts_opt,1);
   else
    copyall(argv,fts_opt,0);
   argv[1] = targv;
  }
  done(argc-1);
 }
 dest.opath = argv[argc-1];
 argv[argc-1] = ((void *)0);
 totalfiles = cntfiles(argv,fts_opt);
 if(stat(dest.opath,&st) == -1) {
  if(argc != 2) {
   endwin();
   use_curses = 0;
   logadds(-1,"%s: Not a vaild destination",dest.opath,((void *)0));
   usage();
  }
  exist = 0;
 } else
  exist = 1;
 if(!exist || !((((st.st_mode)) & 0170000) == (0040000))) {
  if(argc != 2) {
   endwin();
   use_curses = 0;
   logadds(-1,"%s: Not a vaild destination",dest.opath,((void *)0));
   usage();
  }
  statit(argv[0],&st2,1);
  if(!exist) {
   if(((((st2.st_mode)) & 0170000) == (0040000))) {
    copyall(argv,fts_opt,2);
   } else {
    copyall(argv,fts_opt,0);
   }
  } else {
   copyall(argv,fts_opt,0);
  }
  done(0);
 } else {
  if(((((st.st_mode)) & 0170000) == (0040000))) {
   check_iloop(argv,dest.opath);
   copyall(argv,fts_opt,1);
   done(0);
  }
  endwin();
  use_curses = 0;
  logadds(-1,"%s: Not a valid destination",dest.opath,((void *)0));
  usage();
 }
 return 1;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 struct stat st; struct stat st2;
 int fts_opt;
 int ch;
 int exist = 0;
 char *targv = ((void *)0);
 int i = 0;
 fts_opt = 0x0004 | 0x0010;
 conf_read(1);
 conf_read(0);
 while ((ch = getopt(argc, argv, "HLPRfinpvtdIVmhb:u")) != -1) {
  if(ch == 'b') {
   buf_size = atoi(optarg);
  }
  else if(flag_setc(ch,1) == -1) {
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if(Vflag) {
  printf("VCP %d.%d\n",2,2);
  return 0;
 }
 if(hflag) {
  printf("VCP %d.%d\n",2,2);
  printf("usage:\n");
  printf("vcp [options] src dest\n");
  printf("vcp [options] src1 src2 .. destdir\n");
  printf("vcp [options -m] src dest1 dest2 ..\n");
  printf("\n");
  printf("options:\n");
  printf("-R\tcopies directories, re-creates special files\n");
  printf("-v\tverbose output\n");
  printf("-H\tfollows symlinks on cmd line (needs -R)\n");
  printf("-L\tall symlinks are followed (needs -R)\n");
  printf("-P\tno symlinks are followed (needs -R, default)\n");
  printf("-f\tforces existing files to be overwritten\n");
  printf("-i\tprompts when existing file found (Y/[N])\n");
  printf("-I\tprompts when existing file found ([Y]/N)\n");
  printf("-n\tno existing files are overwritten\n");
  printf("-p\tattempts to keep all permissions\n");
  printf("-t\toutput to console, use with -v for status\n");
  printf("-d\tdelayed copy\n");
  printf("-V\tprint version and exit\n");
  printf("-m\tmulti-output file copy\n");
  printf("-b BUF\tset read buffer size (bytes)\n");
  printf("-u\tfiles present with newer time stamp and same size are not copied\n");
  printf("-h\tprint this\n");
  return 0;
 }
 if(argc < 2)
  usage();
 if(nflag && iflag) {
  printf("-i and -n conflict\n");
  usage();
 }
 if(fflag && nflag) {
  printf("-f and -n conflict\n");
  usage();
 }
 if(fflag && iflag) {
  printf("-f and -i conflict\n");
  usage();
 }
 scrn_init();
 if(Rflag && !Pflag && !Hflag && !Lflag)
  Pflag = 1;
 if(Hflag && !Rflag) {
  Hflag = 0;
  logadds(1,"-H ignored",((void *)0),((void *)0));
 }
 if(Pflag && !Rflag) {
  Pflag = 0;
  logadds(1,"-P ignored",((void *)0),((void *)0));
 }
 if(Lflag && !Rflag) {
  Lflag = 0;
  logadds(1,"-L ignored",((void *)0),((void *)0));
 }
 if(Pflag) {
  if(Lflag) {
   Lflag = 0;
   logadds(1,"-L ignored",((void *)0),((void *)0));
  }
  if(Hflag) {
   Hflag = 0;
   logadds(1,"-H ignored",((void *)0),((void *)0));
  }
 }
 if(Hflag && Lflag) {
  Lflag = 0;
  logadds(1,"-L ignored",((void *)0),((void *)0));
 }
 if(Iflag && iflag) {
  Iflag = 0;
  logadds(1,"-I ignored",((void *)0),((void *)0));
 }
 if(Iflag)
  iflag = 1;
 if(Rflag) {
  if(Hflag)
   fts_opt |= 0x0001;
  if(Lflag) {
   fts_opt &= ~0x0010;
   fts_opt |= 0x0002;
  }
 } else {
  fts_opt &= ~0x0010;
  fts_opt |= 0x0002;
 }
 scrn_upd_file(((void *)0),((void *)0));
 scrn_upd_part(0,0);
 if(vflag)
  flags_print();
 if(mflag) {
  if(stat(argv[0],&st) == -1) {
   endwin();
   use_curses = 0;
   logadds(-1,"%s: Not a vaild source",argv[0],((void *)0));
   usage();
  }
  targv = argv[1];
  argv[1] = ((void *)0);
  totalfiles = cntfiles(argv,fts_opt) * (argc - 1);
  argv[1] = targv;
  if(((((st.st_mode)) & 0170000) == (0040000)) && !Rflag) {
   endwin();
   use_curses = 0;
   logadds(-1,"%s is a directory, not copied",argv[0],((void *)0));
   ret = 1;
   done(argc-1);
  }
  for (i=1;i<argc;i++){
   dest.opath = argv[i];
   argv[1] = ((void *)0);
   if(((((st.st_mode)) & 0170000) == (0040000)))
    copyall(argv,fts_opt,1);
   else
    copyall(argv,fts_opt,0);
   argv[1] = targv;
  }
  done(argc-1);
 }
 dest.opath = argv[argc-1];
 argv[argc-1] = ((void *)0);
 totalfiles = cntfiles(argv,fts_opt);
 if(stat(dest.opath,&st) == -1) {
  if(argc != 2) {
   endwin();
   use_curses = 0;
   logadds(-1,"%s: Not a vaild destination",dest.opath,((void *)0));
   usage();
  }
  exist = 0;
 } else
  exist = 1;
 if(!exist || !((((st.st_mode)) & 0170000) == (0040000))) {
  if(argc != 2) {
   endwin();
   use_curses = 0;
   logadds(-1,"%s: Not a vaild destination",dest.opath,((void *)0));
   usage();
  }
  statit(argv[0],&st2,1);
  if(!exist) {
   if(((((st2.st_mode)) & 0170000) == (0040000))) {
    copyall(argv,fts_opt,2);
   } else {
    copyall(argv,fts_opt,0);
   }
  } else {
   copyall(argv,fts_opt,0);
  }
  done(0);
 } else {
  if(((((st.st_mode)) & 0170000) == (0040000))) {
   check_iloop(argv,dest.opath);
   copyall(argv,fts_opt,1);
   done(0);
  }
  endwin();
  use_curses = 0;
  logadds(-1,"%s: Not a valid destination",dest.opath,((void *)0));
  usage();
 }
 return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: ch int

variable_types: exist int

variable_types:
targv
char *