decompiled_code:
int __fastcall msr_pretty_printer_hex(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
char *v7; // r12
unsigned int i; // er13
unsigned __int8 v9; // al
__int64 v10; // rbp
unsigned __int8 *v11; // rbx
int result; // eax

v7 = &a7;
for ( i = 0; i != 3; ++i )
{
printf("Track %d: \n", i);
v9 = v7[255];
if ( v9 )
{
v10 = (__int64)&v7[v9];
v11 = (unsigned __int8 *)v7;
do
printf("%02x ", *v11++);
while ( v11 != (unsigned __int8 *)v10 );
}
result = putchar(10);
v7 += 256;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
char *v7; // r12
unsigned int i; // er13
unsigned __int8 v9; // al
__int64 v10; // rbp
unsigned __int8 *v11; // rbx
int result; // eax

v7 = &a7;
for ( i = 0; i != 3; ++i )
{
printf("Track %d: \n", i);
v9 = v7[255];
if ( v9 )
{
v10 = (__int64)&v7[v9];
v11 = (unsigned __int8 *)v7;
do
printf("%02x ", *v11++);
while ( v11 != (unsigned __int8 *)v10 );
}
result = putchar(10);
v7 += 256;
}
return result;
}

original_code:
void
msr_pretty_printer_hex (msr_tracks_t tracks)
{
 int track_number;
 for (track_number = 0; track_number < 3; track_number++) {
  int x;
  printf("Track %d: \n", track_number);
  for (x = 0; x < tracks.msr_tracks[track_number].msr_tk_len; x++)
   printf("%02x ", tracks.msr_tracks[track_number].msr_tk_data[x]);
  printf("\n");
 }
}

canonical_original_code:
void msr_pretty_printer_hex(struct msr_tracks tracks)
{
 int track_number;
 for (track_number = 0; track_number < 3; track_number++) {
  int x;
  printf("Track %d: \n", track_number);
  for (x = 0; x < tracks.msr_tracks[track_number].msr_tk_len; x++)
   printf("%02x ", tracks.msr_tracks[track_number].msr_tk_data[x]);
  printf("\n");
 }
}

variable_types: struct msr_tracks { struct msr_track { unsigned char msr_tk_data[255]; unsigned char msr_tk_len; } msr_tracks[3]; }

user_defined_types: struct msr_tracks { struct msr_track msr_tracks[3]; }


repo: ioerror/libmsr

decompiled_code:
int __fastcall msr_pretty_printer_string(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
char *v7; // rbp
unsigned int i; // ebx
int result; // eax

v7 = &a7;
for ( i = 0; i != 3; ++i )
{
if ( v7[255] )
result = printf("Track %d: \n[%s]\n", i, v7);
v7 += 256;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
char *v7; // rbp
unsigned int i; // ebx
int result; // eax

v7 = &a7;
for ( i = 0; i != 3; ++i )
{
if ( v7[255] )
result = printf("Track %d: \n[%s]\n", i, v7);
v7 += 256;
}
return result;
}

original_code:
void
msr_pretty_printer_string (msr_tracks_t tracks)
{
 int track_number;
 for (track_number = 0; track_number < 3; track_number++) {
  if (tracks.msr_tracks[track_number].msr_tk_len)
   printf ("Track %d: \n[%s]\n", track_number,
   tracks.msr_tracks[track_number].msr_tk_data);
 }
}

canonical_original_code:
void msr_pretty_printer_string(struct msr_tracks tracks)
{
 int track_number;
 for (track_number = 0; track_number < 3; track_number++) {
  if (tracks.msr_tracks[track_number].msr_tk_len)
   printf ("Track %d: \n[%s]\n", track_number,
   tracks.msr_tracks[track_number].msr_tk_data);
 }
}

return_type: void

user_defined_types: struct msr_track { unsigned char msr_tk_data[255]; unsigned char msr_tk_len; }


decompiled_code:
__int64 __fastcall msr_reverse_byte(unsigned int a1)
{
unsigned int v1; // eax

v1 = a1;
LOBYTE(v1) = (unsigned __int8)a1 >> 7;
return (32 * (_BYTE)a1) & 0x40 | (8 * (_BYTE)a1) & 0x20 | (2 * (_BYTE)a1) & 0x10 | ((int)(unsigned __int8)a1 >> 1) & 8 | ((int)(unsigned __int8)a1 >> 3) & 4 | ((int)(unsigned __int8)a1 >> 5) & 2 | ((unsigned __int8)a1 << 7) | v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
unsigned int v1; // eax

v1 = a1;
LOBYTE(v1) = (unsigned __int8)a1 >> 7;
return (32 * (_BYTE)a1) & 0x40 | (8 * (_BYTE)a1) & 0x20 | (2 * (_BYTE)a1) & 0x10 | ((int)(unsigned __int8)a1 >> 1) & 8 | ((int)(unsigned __int8)a1 >> 3) & 4 | ((int)(unsigned __int8)a1 >> 5) & 2 | ((unsigned __int8)a1 << 7) | v1;
}

variable_types:
byte
unsigned char

return_type: unsigned char


original_code:
int
msr_reverse_track (int track_number, msr_tracks_t * tracks)
{
 int i;
 int status = 0;
 int bytes_to_shuffle;
 char first_byte;
 char last_byte;
 unsigned char * head;
 unsigned char * tail;
 bytes_to_shuffle = tracks->msr_tracks[track_number].msr_tk_len;
 for (i=0; i <= bytes_to_shuffle / 2; i++) {
  head = &tracks->msr_tracks[track_number].msr_tk_data[i];
  tail = &tracks->msr_tracks[track_number].msr_tk_data[(bytes_to_shuffle -1) -i];
  first_byte = msr_reverse_byte(*head);
  last_byte = msr_reverse_byte(*tail);
  *head = last_byte;
  *tail = first_byte;
 }
 return status;
}

canonical_original_code:
int msr_reverse_track(int track_number, struct msr_tracks *tracks)
{
 int i;
 int status = 0;
 int bytes_to_shuffle;
 char first_byte;
 char last_byte;
 unsigned char *head;
 unsigned char *tail;
 bytes_to_shuffle = tracks->msr_tracks[track_number].msr_tk_len;
 for (i=0; i <= bytes_to_shuffle / 2; i++) {
  head = &tracks->msr_tracks[track_number].msr_tk_data[i];
  tail = &tracks->msr_tracks[track_number].msr_tk_data[(bytes_to_shuffle -1) -i];
  first_byte = msr_reverse_byte(*head);
  last_byte = msr_reverse_byte(*tail);
  *head = last_byte;
  *tail = first_byte;
 }
 return status;
}

variable_types: struct msr_tracks { struct msr_track { unsigned char msr_tk_data[255]; unsigned char msr_tk_len; } msr_tracks[3]; } *

variable_types: i int

variable_types: status int

variable_types:
head
unsigned char *

variable_types:
tail
unsigned char *

return_type: int


decompiled_code:
__int64 __fastcall msr_reverse_tracks(__int64 a1)
{
unsigned int v1; // ebx
__int64 result; // rax

v1 = 0;
while ( 1 )
{
result = msr_reverse_track(v1, a1);
if ( (_DWORD)result )
break;
if ( ++v1 == 3 )
return result;
}
printf("Unable to reverse track: %i\n", v1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
unsigned int v1; // ebx
__int64 result; // rax

v1 = 0;
while ( 1 )
{
result = func7(v1, a1);
if ( (_DWORD)result )
break;
if ( ++v1 == 3 )
return result;
}
printf("Unable to reverse track: %i\n", v1);
return 0xFFFFFFFFLL;
}

original_code:
int
msr_reverse_tracks (msr_tracks_t * tracks)
{
 int i, status;
 for (i = 0; i < 3; i++) {
  status = msr_reverse_track(i, tracks);
  if (status != 0) {
   printf("Unable to reverse track: %i\n", i);
   status = -1;
   break;
  }
 }
 return status;
}

canonical_original_code:
int msr_reverse_tracks(struct msr_tracks *tracks)
{
 int i; int status;
 for (i = 0; i < 3; i++) {
  status = msr_reverse_track(i, tracks);
  if (status != 0) {
   printf("Unable to reverse track: %i\n", i);
   status = -1;
   break;
  }
 }
 return status;
}


decompiled_code:
void *card_list_create()
{
return calloc(1uLL, 0x138uLL);
}

canonical_decompiled_code:
void *func7()
{
return calloc(1uLL, 0x138uLL);
}

original_code:
CARD_LIST *card_list_create()
{
 return (CARD_LIST *)calloc(1, sizeof(CARD_LIST));
}

canonical_original_code:
struct card_list *card_list_create()
{
 return (struct card_list *)calloc(1, sizeof(CARD_LIST));
}

return_type: struct card_list { char filename[32]; unsigned char raw_card[128]; unsigned char mod_card[128]; int offset; struct card_list *next; struct card_list *prev; } *


original_code:
void card_list_remove(CARD_LIST *item)
{
 item->next->prev = item->prev;
 item->prev->next = item->next;
 memset(item, 0, sizeof(CARD_LIST));
 free(item);
}

canonical_original_code:
void card_list_remove(struct card_list *item)
{
 item->next->prev = item->prev;
 item->prev->next = item->next;
 memset(item, 0, sizeof(CARD_LIST));
 free(item);
}

variable_types: struct card_list { char filename[32]; unsigned char raw_card[128]; unsigned char mod_card[128]; int offset; struct card_list *next; struct card_list *prev; } *


decompiled_code:
void __fastcall card_list_destroy(_QWORD *a1)
{
_QWORD *v2; // rbp

do
{
v2 = a1;
a1 = (_QWORD *)a1[37];
card_list_remove(v2);
}
while ( v2 != a1 );
}

canonical_decompiled_code:
void __fastcall func9(_QWORD *a1)
{
_QWORD *v2; // rbp

do
{
v2 = a1;
a1 = (_QWORD *)a1[37];
func8(v2);
}
while ( v2 != a1 );
}

original_code:
void card_list_destroy(CARD_LIST *item)
{
 CARD_LIST *next;
 next = item;
 do
 {
  item = next;
  next = item->next;
  card_list_remove(item);
 }
 while (next != item);
}

canonical_original_code:
void card_list_destroy(struct card_list *item)
{
 struct card_list *next;
 next = item;
 do
 {
  item = next;
  next = item->next;
  card_list_remove(item);
 }
 while (next != item);
}

user_defined_types: struct card_list { char filename[32]; unsigned char raw_card[128]; unsigned char mod_card[128]; int offset; struct card_list *next; struct card_list *prev; }


decompiled_code:
__int64 __fastcall remove_card(__int64 a1)
{
__int64 v1; // rbp

v1 = *(_QWORD *)(a1 + 296);
if ( a1 == v1 )
{
printw("You cannot remove the only remaining card!\n");
}
else
{
printw("Removed \"%s\".\n\n", (const char *)a1);
card_list_remove((_QWORD *)a1);
}
wrefresh(_bss_start);
sleep(1u);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rbp

v1 = *(_QWORD *)(a1 + 296);
if ( a1 == v1 )
{
printw("You cannot remove the only remaining card!\n");
}
else
{
printw("Removed \"%s\".\n\n", (const char *)a1);
func8((_QWORD *)a1);
}
wrefresh(_bss_start);
sleep(1u);
return v1;
}

original_code:
CARD_LIST *remove_card(CARD_LIST *item)
{
 CARD_LIST *next;
 next = item->next;
 if (item == next)
 {
  printw("You cannot remove the only remaining card!\n");
 }
 else
 {
  printw ("Removed \"%s\".\n\n", item->filename);
  card_list_remove(item);
 }
 wrefresh(stdscr);
 sleep(1);
 return next;
}

canonical_original_code:
struct card_list *remove_card(struct card_list *item)
{
 struct card_list *next;
 next = item->next;
 if (item == next)
 {
  printw("You cannot remove the only remaining card!\n");
 }
 else
 {
  printw ("Removed \"%s\".\n\n", item->filename);
  card_list_remove(item);
 }
 wrefresh(stdscr);
 sleep(1);
 return next;
}

variable_types:
item
struct card_list *


original_code:
void shift_card(CARD_LIST *item, int shift)
{
 unsigned char a, b;
 unsigned char *src, *dst;
 int bit_offset, byte_offset;
 unsigned char rel_shift;
 int i;
 src = item->raw_card;
 dst = item->mod_card;
 memset(dst, 0, 128);
 item->offset += shift;
 byte_offset = abs(item->offset) / 8;
 bit_offset = abs(item->offset) % 8;
 if (item->offset >= 0)
 {
  dst += byte_offset;
  rel_shift = bit_offset;
  a = 0;
 }
 else
 {
  byte_offset += 1;
  src += byte_offset;
  rel_shift = 8 - bit_offset;
  a = *(src - 1);
 }
 for (i=0; i<128 - byte_offset; i++)
 {
  b = *(src + i);
  *(dst + i) = (((a<<8 | b) >> rel_shift ) & 0xff);
  a = b;
 }
}

canonical_original_code:
void shift_card(struct card_list *item, int shift)
{
 unsigned char a; unsigned char b;
 unsigned char *src; unsigned char *dst;
 int bit_offset; int byte_offset;
 unsigned char rel_shift;
 int i;
 src = item->raw_card;
 dst = item->mod_card;
 memset(dst, 0, 128);
 item->offset += shift;
 byte_offset = abs(item->offset) / 8;
 bit_offset = abs(item->offset) % 8;
 if (item->offset >= 0)
 {
  dst += byte_offset;
  rel_shift = bit_offset;
  a = 0;
 }
 else
 {
  byte_offset += 1;
  src += byte_offset;
  rel_shift = 8 - bit_offset;
  a = *(src - 1);
 }
 for (i=0; i<128 - byte_offset; i++)
 {
  b = *(src + i);
  *(dst + i) = (((a<<8 | b) >> rel_shift ) & 0xff);
  a = b;
 }
}

variable_types: shift int

variable_types:
a
unsigned char

variable_types:
b
unsigned char

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *


decompiled_code:
__int64 __fastcall read_file(const char *a1, char *a2)
{
unsigned int v3; // er12
ssize_t v4; // rax
unsigned int v5; // ebx
int *v7; // rax
char *v8; // rax

v3 = open(a1, 0);
if ( v3 == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
printw("open: %s.\n", v8);
wrefresh(_bss_start);
sleep(1u);
}
else
{
do
{
v4 = read(v3, a2, 8uLL);
v5 = v4;
a2 += 8;
}
while ( v4 > 0 );
close(v3);
v3 = v5;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1, char *a2)
{
unsigned int v3; // er12
ssize_t v4; // rax
unsigned int v5; // ebx
int *v7; // rax
char *v8; // rax

v3 = open(a1, 0);
if ( v3 == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
printw("open: %s.\n", v8);
wrefresh(_bss_start);
sleep(1u);
}
else
{
do
{
v4 = read(v3, a2, 8uLL);
v5 = v4;
a2 += 8;
}
while ( v4 > 0 );
close(v3);
v3 = v5;
}
return v3;
}

original_code:
int read_file (const char *filename, unsigned char *buffer)
{
 int fd;
 ssize_t bytes_read;
 fd = open(filename, 00);
 if (fd == -1)
 {
  printw("open: %s.\n", strerror((*__errno_location ())));
  wrefresh(stdscr);
  sleep(1);
  return -1;
 }
 do
 {
  bytes_read = read(fd, buffer, 8);
  buffer += 8;
 }
 while (bytes_read > 0);
 buffer = ((void *)0);
 close(fd);
 return bytes_read;
}

canonical_original_code:
int read_file(char *filename, unsigned char *buffer)
{
 int fd;
 long bytes_read;
 fd = open(filename, 00);
 if (fd == -1)
 {
  printw("open: %s.\n", strerror((*__errno_location ())));
  wrefresh(stdscr);
  sleep(1);
  return -1;
 }
 do
 {
  bytes_read = read(fd, buffer, 8);
  buffer += 8;
 }
 while (bytes_read > 0);
 buffer = ((void *)0);
 close(fd);
 return bytes_read;
}

variable_types:
filename
char *

variable_types:
buffer
unsigned char *

variable_types: fd int


decompiled_code:
int __fastcall print_bits(int a1)
{
int v2; // ebp
int result; // eax

v2 = 8;
do
{
result = printw("%c", ((unsigned int)(char)a1 >> 31) + 48);
a1 *= 2;
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
int __fastcall func13(int a1)
{
int v2; // ebp
int result; // eax

v2 = 8;
do
{
result = printw("%c", ((unsigned int)(char)a1 >> 31) + 48);
a1 *= 2;
--v2;
}
while ( v2 );
return result;
}

original_code:
void print_bits(unsigned char c)
{
    int i;
    for (i = 0; i<8; i++)
    {
        printw("%c", (c&0x80)?'1':'0');
        c <<= 1;
    }
}

variable_types:
c
unsigned char


decompiled_code:
int __fastcall dump_buffer(__int64 a1)
{
__int64 i; // rbx
int result; // eax

for ( i = 1LL; i != 129; ++i )
{
print_bits(*(unsigned __int8 *)(a1 + i - 1));
result = printw(" ");
if ( (i & 7) != 0 )
{
if ( (i & 3) == 0 )
result = printw(" ");
}
else
{
result = printw("\n");
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
__int64 i; // rbx
int result; // eax

for ( i = 1LL; i != 129; ++i )
{
func13(*(unsigned __int8 *)(a1 + i - 1));
result = printw(" ");
if ( (i & 7) != 0 )
{
if ( (i & 3) == 0 )
result = printw(" ");
}
else
{
result = printw("\n");
}
}
return result;
}

original_code:
void dump_buffer(const unsigned char *buffer)
{
 int i;
 for (i=0; i<128; i++)
 {
  print_bits(*(buffer +i));
  printw(" ");
  if ((i + 1) % 8 == 0)
  {
   printw("\n");
  }
  else if ((i + 1) % 4 == 0)
  {
   printw(" ");
  }
 }
}

canonical_original_code:
void dump_buffer(unsigned char *buffer)
{
 int i;
 for (i=0; i<128; i++)
 {
  print_bits(*(buffer +i));
  printw(" ");
  if ((i + 1) % 8 == 0)
  {
   printw("\n");
  }
  else if ((i + 1) % 4 == 0)
  {
   printw(" ");
  }
 }
}


decompiled_code:
int __fastcall display_card(__int64 a1)
{
printw("File: %s (Offset: %+d bits)\n\n", (const char *)a1, *(unsigned int *)(a1 + 288));
dump_buffer(a1 + 160);
return wrefresh(_bss_start);
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1)
{
printw("File: %s (Offset: %+d bits)\n\n", (const char *)a1, *(unsigned int *)(a1 + 288));
func14(a1 + 160);
return wrefresh(_bss_start);
}

original_code:
void display_card(CARD_LIST *item)
{
 printw("File: %s  (Offset: %+d bits)\n\n", item->filename, item->offset);
 dump_buffer(item->mod_card);
 wrefresh(stdscr);
}

canonical_original_code:
void display_card(struct card_list *item)
{
 printw("File: %s  (Offset: %+d bits)\n\n", item->filename, item->offset);
 dump_buffer(item->mod_card);
 wrefresh(stdscr);
}


decompiled_code:
int display_header()
{
size_t v0; // rax
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

strcpy(v2, "File Field Visualizer 0.1");
v0 = strlen(v2);
mvprintw(0, (72 - v0) >> 1, "%s\n", v2);
printw("\n");
return wrefresh(_bss_start);
}

canonical_decompiled_code:
int func16()
{
size_t v0; // rax
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

strcpy(v2, "File Field Visualizer 0.1");
v0 = strlen(v2);
mvprintw(0, (72 - v0) >> 1, "%s\n", v2);
printw("\n");
return wrefresh(_bss_start);
}

original_code:
void display_header()
{
 int y, x;
 char title[] = "File Field Visualizer 0.1";
 y = 0;
 x = (72 - strlen(title)) / 2;
 mvprintw(y, x, "%s\n", title);
 printw("\n");
 wrefresh(stdscr);
}

canonical_original_code:
void display_header()
{
 int y; int x;
 char title[] = "File Field Visualizer 0.1";
 y = 0;
 x = (72 - strlen(title)) / 2;
 mvprintw(y, x, "%s\n", title);
 printw("\n");
 wrefresh(stdscr);
}

variable_types: y int

variable_types: x int

variable_types:
title
char []


decompiled_code:
int display_footer()
{
char v1[56]; // [rsp+0h] [rbp-38h] BYREF

strcpy(v1, "Commands: <L>, <R>, <U>, <D>, a, r, ?, q.");
printw("\n");
printw("%s\n", v1);
return wrefresh(_bss_start);
}

canonical_decompiled_code:
int func17()
{
char v1[56]; // [rsp+0h] [rbp-38h] BYREF

strcpy(v1, "Commands: <L>, <R>, <U>, <D>, a, r, ?, q.");
printw("\n");
printw("%s\n", v1);
return wrefresh(_bss_start);
}

original_code:
void display_footer()
{
 char commands[] = "Commands: <L>, <R>, <U>, <D>, a, r, ?, q.";
 printw("\n");
 printw("%s\n", commands);
 wrefresh(stdscr);
}

variable_types:
commands
char []


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbp
__int64 *v4; // rbx
__m128i *v5; // rax
__int64 v6; // rbp
char v7; // r12
int v8; // eax

if ( argc <= 1 )
{
printf("Usage: %s [file1] ... [fileN]\n", *argv);
exit(1);
}
initscr();
keypad(_bss_start, 1);
noecho();
display_header();
v3 = (char **)(argv + 1);
v4 = 0LL;
do
{
v5 = add_card(*v3, (__int64)v4);
v4 = (__int64 *)v5;
++v3;
}
while ( v3 != (char **)&argv[(unsigned int)(argc - 2) + 2] );
v6 = v5[18].m128i_i64[1];
sleep(1u);
v7 = 1;
while ( v7 )
{
wclear(_bss_start);
display_header();
display_card(v6);
display_footer();
printw("\n");
wrefresh(_bss_start);
v8 = wgetch(_bss_start);
if ( v8 == 114 )
{
v6 = remove_card(v6);
goto LABEL_10;
}
if ( v8 > 114 )
{
if ( v8 == 260 )
{
shift_card(v6, -1);
goto LABEL_10;
}
if ( v8 <= 260 )
{
if ( v8 == 258 )
{
v6 = *(_QWORD *)(v6 + 296);
goto LABEL_10;
}
if ( v8 == 259 )
{
v6 = *(_QWORD *)(v6 + 304);
goto LABEL_10;
}
}
else if ( v8 == 261 )
{
shift_card(v6, 1);
goto LABEL_10;
}
goto LABEL_28;
}
if ( v8 == 97 )
{
v6 = (__int64)add_card(0LL, v6);
goto LABEL_10;
}
if ( v8 <= 97 )
{
if ( v8 != 10 )
{
if ( v8 == 63 )
{
printw("<DOWN> - next card\n");
printw("<UP> - previous card\n");
printw("<LEFT> - bit shift left\n");
printw("<RIGHT> - bit shift right\n");
printw("a - add card\n");
printw("r - remove card\n");
printw("? - this help screen\n");
printw("q - exit program\n");
printw("\n");
printw("Press any key to continue ...\n");
wrefresh(_bss_start);
wgetch(_bss_start);
goto LABEL_10;
}
goto LABEL_28;
}
}
else
{
if ( v8 == 113 )
{
v7 = 0;
goto LABEL_10;
}
LABEL_28:
printw("Unrecognized command: %c.\n", (unsigned int)v8);
wrefresh(_bss_start);
sleep(1u);
LABEL_10:
wrefresh(_bss_start);
}
}
card_list_destroy(v4);
endwin();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbp
__int64 *v4; // rbx
__m128i *v5; // rax
__int64 v6; // rbp
char v7; // r12
int v8; // eax

if ( argc <= 1 )
{
printf("Usage: %s [file1] ... [fileN]\n", *argv);
exit(1);
}
initscr();
keypad(_bss_start, 1);
noecho();
func16();
v3 = (char **)(argv + 1);
v4 = 0LL;
do
{
v5 = add_card(*v3, (__int64)v4);
v4 = (__int64 *)v5;
++v3;
}
while ( v3 != (char **)&argv[(unsigned int)(argc - 2) + 2] );
v6 = v5[18].m128i_i64[1];
sleep(1u);
v7 = 1;
while ( v7 )
{
wclear(_bss_start);
func16();
func15(v6);
func17();
printw("\n");
wrefresh(_bss_start);
v8 = wgetch(_bss_start);
if ( v8 == 114 )
{
v6 = func10(v6);
goto LABEL_10;
}
if ( v8 > 114 )
{
if ( v8 == 260 )
{
func11(v6, -1);
goto LABEL_10;
}
if ( v8 <= 260 )
{
if ( v8 == 258 )
{
v6 = *(_QWORD *)(v6 + 296);
goto LABEL_10;
}
if ( v8 == 259 )
{
v6 = *(_QWORD *)(v6 + 304);
goto LABEL_10;
}
}
else if ( v8 == 261 )
{
func11(v6, 1);
goto LABEL_10;
}
goto LABEL_28;
}
if ( v8 == 97 )
{
v6 = (__int64)add_card(0LL, v6);
goto LABEL_10;
}
if ( v8 <= 97 )
{
if ( v8 != 10 )
{
if ( v8 == 63 )
{
printw("<DOWN> - next card\n");
printw("<UP> - previous card\n");
printw("<LEFT> - bit shift left\n");
printw("<RIGHT> - bit shift right\n");
printw("a - add card\n");
printw("r - remove card\n");
printw("? - this help screen\n");
printw("q - exit program\n");
printw("\n");
printw("Press any key to continue ...\n");
wrefresh(_bss_start);
wgetch(_bss_start);
goto LABEL_10;
}
goto LABEL_28;
}
}
else
{
if ( v8 == 113 )
{
v7 = 0;
goto LABEL_10;
}
LABEL_28:
printw("Unrecognized command: %c.\n", (unsigned int)v8);
wrefresh(_bss_start);
sleep(1u);
LABEL_10:
wrefresh(_bss_start);
}
}
func9(v4);
endwin();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 CARD_LIST *cards;
 CARD_LIST *cur_card;
 unsigned char loop;
 int command;
 int i;
 if (argc <2)
 {
  printf("Usage: %s [file1] ... [fileN]\n", argv[0]);
  exit(1);
 }
 initscr();
 keypad(stdscr, 1);
 noecho();
 display_header();
 cards = ((void *)0);
 for (i=1; i<argc; i++)
 {
  cards = add_card(argv[i], cards);
 }
 cur_card = cards->next;
 sleep(1);
 loop = 1;
 while (loop)
 {
  wclear(stdscr);
  display_header();
  display_card(cur_card);
  display_footer();
  printw("\n");
  wrefresh(stdscr);
  command = wgetch(stdscr);
  switch (command)
  {
  case 0404:
   shift_card(cur_card, -1);
   break;
  case 0405:
   shift_card(cur_card, 1);
   break;
  case 0402:
   cur_card = cur_card->next;
   break;
  case 0403:
   cur_card = cur_card->prev;
   break;
  case 'a':
   cur_card = add_card(((void *)0), cur_card);
   break;
  case 'r':
   cur_card = remove_card(cur_card);
   break;
  case '?':
   printw("<DOWN> - next card\n");
   printw("<UP> - previous card\n");
   printw("<LEFT> - bit shift left\n");
   printw("<RIGHT> - bit shift right\n");
   printw("a - add card\n");
   printw("r - remove card\n");
   printw("? - this help screen\n");
   printw("q - exit program\n");
   printw("\n");
   printw("Press any key to continue ...\n");
   wrefresh(stdscr);
   wgetch(stdscr);
   break;
  case 'q':
   loop = 0;
   break;
  case '\n':
   continue;
  default:
   printw("Unrecognized command: %c.\n", command);
   wrefresh(stdscr);
   sleep(1);
   break;
  }
  wrefresh(stdscr);
 }
 card_list_destroy(cards);
 endwin();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct card_list *cards;
 struct card_list *cur_card;
 unsigned char loop;
 int command;
 int i;
 if (argc <2)
 {
  printf("Usage: %s [file1] ... [fileN]\n", argv[0]);
  exit(1);
 }
 initscr();
 keypad(stdscr, 1);
 noecho();
 display_header();
 cards = ((void *)0);
 for (i=1; i<argc; i++)
 {
  cards = add_card(argv[i], cards);
 }
 cur_card = cards->next;
 sleep(1);
 loop = 1;
 while (loop)
 {
  wclear(stdscr);
  display_header();
  display_card(cur_card);
  display_footer();
  printw("\n");
  wrefresh(stdscr);
  command = wgetch(stdscr);
  switch (command)
  {
  case 0404:
   shift_card(cur_card, -1);
   break;
  case 0405:
   shift_card(cur_card, 1);
   break;
  case 0402:
   cur_card = cur_card->next;
   break;
  case 0403:
   cur_card = cur_card->prev;
   break;
  case 'a':
   cur_card = add_card(((void *)0), cur_card);
   break;
  case 'r':
   cur_card = remove_card(cur_card);
   break;
  case '?':
   printw("<DOWN> - next card\n");
   printw("<UP> - previous card\n");
   printw("<LEFT> - bit shift left\n");
   printw("<RIGHT> - bit shift right\n");
   printw("a - add card\n");
   printw("r - remove card\n");
   printw("? - this help screen\n");
   printw("q - exit program\n");
   printw("\n");
   printw("Press any key to continue ...\n");
   wrefresh(stdscr);
   wgetch(stdscr);
   break;
  case 'q':
   loop = 0;
   break;
  case '\n':
   continue;
  default:
   printw("Unrecognized command: %c.\n", command);
   wrefresh(stdscr);
   sleep(1);
   break;
  }
  wrefresh(stdscr);
 }
 card_list_destroy(cards);
 endwin();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
loop
unsigned char

variable_types: command int

variable_types: i int


getend

decompiled_code:
__int64 __fastcall getend(__int64 a1)
{
char v2[3]; // [rsp+Ch] [rbp-Ch] BYREF
unsigned __int8 v3; // [rsp+Fh] [rbp-9h]

serial_read(a1, v2, 4LL);
if ( v3 == 48 )
return 0LL;
printf("read returned error status: 0x%x\n", v3);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char v2[3]; // [rsp+Ch] [rbp-Ch] BYREF
unsigned __int8 v3; // [rsp+Fh] [rbp-9h]

serial_read(a1, v2, 4LL);
if ( v3 == 48 )
return 0LL;
printf("read returned error status: 0x%x\n", v3);
return 0xFFFFFFFFLL;
}

original_code:
static int
getend (int fd)
{
 msr_end_t m;
 serial_read (fd, &m, sizeof(m));
 if (m.msr_sts != 0x30) {
  printf ("read returned error status: 0x%x\n", m.msr_sts);
  return (-1);
 }
 return (0);
}

canonical_original_code:
static int getend(int fd)
{
 struct msr_end m;
 serial_read (fd, &m, sizeof(m));
 if (m.msr_sts != 0x30) {
  printf ("read returned error status: 0x%x\n", m.msr_sts);
  return (-1);
 }
 return (0);
}

variable_types: struct msr_end { unsigned char msr_enddelim; unsigned char msr_fs; unsigned char msr_esc; unsigned char msr_sts; }


getstart

decompiled_code:
__int64 __fastcall getstart(unsigned int a1)
{
int i; // ebx
char v3[25]; // [rsp+Fh] [rbp-19h] BYREF

for ( i = 0; i != 3; ++i )
{
serial_readchar(a1, v3);
if ( v3[0] == 115 )
break;
}
return (unsigned int)-(i == 3);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
int i; // ebx
char v3[25]; // [rsp+Fh] [rbp-19h] BYREF

for ( i = 0; i != 3; ++i )
{
serial_readchar(a1, v3);
if ( v3[0] == 115 )
break;
}
return (unsigned int)-(i == 3);
}

original_code:
static int
getstart (int fd)
{
 uint8_t b;
 int i, r;
 for (i = 0; i < 3; i++) {
  r = serial_readchar(fd, &b);
  if (b == 0x73)
   break;
 }
 if (i == 3)
  return (-1);
 return (0);
}

canonical_original_code:
static int getstart(int fd)
{
 unsigned char b;
 int i; int r;
 for (i = 0; i < 3; i++) {
  r = serial_readchar(fd, &b);
  if (b == 0x73)
   break;
 }
 if (i == 3)
  return (-1);
 return (0);
}

variable_types:
b
unsigned char

variable_types: r int


decompiled_code:
__int64 __fastcall msr_cmd(__int64 a1, char a2)
{
char v3[10]; // [rsp+Eh] [rbp-Ah] BYREF

v3[0] = 27;
v3[1] = a2;
return serial_write(a1, v3, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char a2)
{
char v3[10]; // [rsp+Eh] [rbp-Ah] BYREF

v3[0] = 27;
v3[1] = a2;
return serial_write(a1, v3, 2LL);
}

original_code:
int
msr_cmd (int fd, uint8_t c)
{
 msr_cmd_t cmd;
 cmd.msr_esc = 0x1B;
 cmd.msr_cmd = c;
 return (serial_write (fd, &cmd, sizeof(cmd)));
}

canonical_original_code:
int msr_cmd(int fd, unsigned char c)
{
 struct msr_cmd cmd;
 cmd.msr_esc = 0x1B;
 cmd.msr_cmd = c;
 return (serial_write (fd, &cmd, sizeof(cmd)));
}

variable_types: struct msr_cmd { unsigned char msr_esc; unsigned char msr_cmd; }


decompiled_code:
__int64 __fastcall msr_zeros(__int64 a1)
{
char v2[11]; // [rsp+Dh] [rbp-Bh] BYREF

msr_cmd(a1, 108);
serial_read((unsigned int)a1, v2, 3LL);
printf("zero13: %d zero: %d\n", (unsigned __int8)v2[1], (unsigned __int8)v2[2]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
char v2[11]; // [rsp+Dh] [rbp-Bh] BYREF

func4(a1, 108);
serial_read((unsigned int)a1, v2, 3LL);
printf("zero13: %d zero: %d\n", (unsigned __int8)v2[1], (unsigned __int8)v2[2]);
return 0LL;
}

original_code:
int msr_zeros (int fd)
{
 msr_lz_t lz;
 msr_cmd (fd, 0x6C);
 serial_read (fd, &lz, sizeof(lz));
 printf("zero13: %d zero: %d\n", lz.msr_lz_tk1_3, lz.msr_lz_tk2);
 return (0);
}

canonical_original_code:
int msr_zeros(int fd)
{
 struct msr_lz lz;
 msr_cmd (fd, 0x6C);
 serial_read (fd, &lz, sizeof(lz));
 printf("zero13: %d zero: %d\n", lz.msr_lz_tk1_3, lz.msr_lz_tk2);
 return (0);
}

variable_types: struct msr_lz { unsigned char msr_esc; unsigned char msr_lz_tk1_3; unsigned char msr_lz_tk2; }


decompiled_code:
__int64 __fastcall msr_commtest(__int64 a1)
{
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

if ( (unsigned int)msr_cmd(a1, 101) == -1 )
err(1, "Commtest write failed");
do
serial_readchar((unsigned int)a1, v2);
while ( v2[0] != 121 );
puts("Communications test passed.");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

if ( (unsigned int)func4(a1, 101) == -1 )
err(1, "Commtest write failed");
do
serial_readchar((unsigned int)a1, v2);
while ( v2[0] != 121 );
puts("Communications test passed.");
return 0LL;
}

original_code:
int
msr_commtest (int fd)
{
 int r;
 uint8_t buf[2];
 r = msr_cmd (fd, 0x65);
 if (r == -1)
     err(1, "Commtest write failed");
 while (1) {
  serial_readchar (fd, &buf[0]);
  if (buf[0] == 0x79)
   break;
 }
 if (buf[0] != 0x79) {
  printf("Communications test failure\n");
  return (-1);
 } else
  printf("Communications test passed.\n");
 return (0);
}

canonical_original_code:
int msr_commtest(int fd)
{
 int r;
 unsigned char buf[2];
 r = msr_cmd (fd, 0x65);
 if (r == -1)
     err(1, "Commtest write failed");
 while (1) {
  serial_readchar (fd, &buf[0]);
  if (buf[0] == 0x79)
   break;
 }
 if (buf[0] != 0x79) {
  printf("Communications test failure\n");
  return (-1);
 } else
  printf("Communications test passed.\n");
 return (0);
}

variable_types:
buf
unsigned char [2]


decompiled_code:
__int64 __fastcall msr_fwrev(unsigned int a1)
{
unsigned int v1; // ebp
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

bzero(v3, 0x40uLL);
if ( (unsigned int)msr_cmd(a1, 118) )
return (unsigned int)-1;
v1 = 0;
serial_readchar(a1, v3);
serial_read(a1, v3, 8LL);
v3[8] = 0;
printf("Firmware Version: %s\n", v3);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
unsigned int v1; // ebp
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

bzero(v3, 0x40uLL);
if ( (unsigned int)func4(a1, 118) )
return (unsigned int)-1;
v1 = 0;
serial_readchar(a1, v3);
serial_read(a1, v3, 8LL);
v3[8] = 0;
printf("Firmware Version: %s\n", v3);
return v1;
}

original_code:
int
msr_fwrev (int fd)
{
 uint8_t buf[64];
 bzero (buf, sizeof(buf));
 if (msr_cmd (fd, 0x76) != 0)
            return (-1);
 serial_readchar (fd, &buf[0]);
 serial_read (fd, buf, 8);
 buf[8] = '\0';
 printf ("Firmware Version: %s\n", buf);
 return (0);
}

canonical_original_code:
int msr_fwrev(int fd)
{
 unsigned char buf[64];
 bzero (buf, sizeof(buf));
 if (msr_cmd (fd, 0x76) != 0)
            return (-1);
 serial_readchar (fd, &buf[0]);
 serial_read (fd, buf, 8);
 buf[8] = '\0';
 printf ("Firmware Version: %s\n", buf);
 return (0);
}

variable_types: fd int

variable_types:
buf
unsigned char [64]


decompiled_code:
__int64 __fastcall msr_model(__int64 a1)
{
__int64 result; // rax
char v2[11]; // [rsp+Dh] [rbp-Bh] BYREF

msr_cmd(a1, 116);
serial_read((unsigned int)a1, v2, 3LL);
result = 1LL;
if ( v2[2] == 83 )
{
printf("Device Model: MSR-206-%c\n", (unsigned __int8)v2[1]);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
char v2[11]; // [rsp+Dh] [rbp-Bh] BYREF

func4(a1, 116);
serial_read((unsigned int)a1, v2, 3LL);
result = 1LL;
if ( v2[2] == 83 )
{
printf("Device Model: MSR-206-%c\n", (unsigned __int8)v2[1]);
result = 0LL;
}
return result;
}

original_code:
int
msr_model (int fd)
{
 msr_model_t m;
 msr_cmd (fd, 0x74);
 serial_read (fd, &m, sizeof(m));
 if (m.msr_s != 0x53)
  return (1);
 printf("Device Model: MSR-206-%c\n", m.msr_model);
 return (0);
}

canonical_original_code:
int msr_model(int fd)
{
 struct msr_model m;
 msr_cmd (fd, 0x74);
 serial_read (fd, &m, sizeof(m));
 if (m.msr_s != 0x53)
  return (1);
 printf("Device Model: MSR-206-%c\n", m.msr_model);
 return (0);
}

variable_types: struct msr_model { unsigned char msr_esc; unsigned char msr_model; unsigned char msr_s; }


decompiled_code:
__int64 __fastcall msr_flash_led(__int64 a1, char a2)
{
if ( (unsigned int)msr_cmd(a1, a2) == -1 )
err(1, "LED failure");
usleep(0x186A0u);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char a2)
{
if ( (unsigned int)func4(a1, a2) == -1 )
err(1, "LED failure");
usleep(0x186A0u);
return 0LL;
}

original_code:
int
msr_flash_led (int fd, uint8_t led)
{
 int r;
 r = msr_cmd (fd, led);
 if (r == -1)
  err(1, "LED failure");
 usleep (100000);
 return (0);
}

canonical_original_code:
int msr_flash_led(int fd, unsigned char led)
{
 int r;
 r = msr_cmd (fd, led);
 if (r == -1)
  err(1, "LED failure");
 usleep (100000);
 return (0);
}

variable_types:
led
unsigned char


decompiled_code:
__int64 __fastcall msr_sensor_test(__int64 a1)
{
__int64 result; // rax
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

msr_cmd(a1, 134);
puts("Attempting sensor test -- please slide a card...");
serial_read((unsigned int)a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("Sensor test successfull");
result = 0LL;
}
else
{
puts("It appears that the sensor did not sense a magnetic card.");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 result; // rax
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

func4(a1, 134);
puts("Attempting sensor test -- please slide a card...");
serial_read((unsigned int)a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("Sensor test successfull");
result = 0LL;
}
else
{
puts("It appears that the sensor did not sense a magnetic card.");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
msr_sensor_test (int fd)
{
 uint8_t b[4];
 msr_cmd (fd, 0x86);
 printf("Attempting sensor test -- please slide a card...\n");
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("Sensor test successfull\n");
  return 0;
 }
 printf("It appears that the sensor did not sense a magnetic card.\n");
 return (-1);
}

canonical_original_code:
int msr_sensor_test(int fd)
{
 unsigned char b[4];
 msr_cmd (fd, 0x86);
 printf("Attempting sensor test -- please slide a card...\n");
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("Sensor test successfull\n");
  return 0;
 }
 printf("It appears that the sensor did not sense a magnetic card.\n");
 return (-1);
}

variable_types:
b
unsigned char [4]


decompiled_code:
__int64 __fastcall msr_ram_test(unsigned int a1)
{
__int64 result; // rax
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

puts("Running ram test...");
msr_cmd(a1, 135);
serial_read(a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("RAM test successfull.");
result = 0LL;
}
else
{
puts("It appears that the RAM test failed");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
__int64 result; // rax
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

puts("Running ram test...");
func4(a1, 135);
serial_read(a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("RAM test successfull.");
result = 0LL;
}
else
{
puts("It appears that the RAM test failed");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
msr_ram_test (int fd)
{
 uint8_t b[2];
 printf("Running ram test...\n");
 msr_cmd (fd, 0x87);
 serial_read(fd, b, sizeof(b));
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("RAM test successfull.\n");
   return (0);
 }
 printf("It appears that the RAM test failed\n");
 return (-1);
}

canonical_original_code:
int msr_ram_test(int fd)
{
 unsigned char b[2];
 printf("Running ram test...\n");
 msr_cmd (fd, 0x87);
 serial_read(fd, b, sizeof(b));
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("RAM test successfull.\n");
   return (0);
 }
 printf("It appears that the RAM test failed\n");
 return (-1);
}

variable_types:
b
unsigned char [2]


decompiled_code:
__int64 __fastcall msr_set_hi_co(unsigned int a1)
{
__int64 result; // rax
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

puts("Putting the writer to Hi-Co mode...");
msr_cmd(a1, 120);
serial_read(a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("We were able to put the writer into Hi-Co mode.");
result = 0LL;
}
else
{
printf("It appears that the reader did not switch to Hi-Co mode.");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
__int64 result; // rax
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

puts("Putting the writer to Hi-Co mode...");
func4(a1, 120);
serial_read(a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("We were able to put the writer into Hi-Co mode.");
result = 0LL;
}
else
{
printf("It appears that the reader did not switch to Hi-Co mode.");
result = 1LL;
}
return result;
}

original_code:
int
msr_set_hi_co (int fd)
{
 char b[2];
 printf("Putting the writer to Hi-Co mode...\n");
 msr_cmd (fd, 0x78);
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("We were able to put the writer into Hi-Co mode.\n");
  return (0);
 }
 printf("It appears that the reader did not switch to Hi-Co mode.");
 return (1);
}

canonical_original_code:
int msr_set_hi_co(int fd)
{
 char b[2];
 printf("Putting the writer to Hi-Co mode...\n");
 msr_cmd (fd, 0x78);
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("We were able to put the writer into Hi-Co mode.\n");
  return (0);
 }
 printf("It appears that the reader did not switch to Hi-Co mode.");
 return (1);
}

variable_types:
b
char [2]


decompiled_code:
__int64 __fastcall msr_set_lo_co(unsigned int a1)
{
__int64 result; // rax
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

puts("Putting the writer to Lo-Co mode...");
msr_cmd(a1, 121);
serial_read(a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("We were able to put the writer into Lo-Co mode.");
result = 0LL;
}
else
{
printf("It appears that the reader did not switch to Lo-Co mode.");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1)
{
__int64 result; // rax
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

puts("Putting the writer to Lo-Co mode...");
func4(a1, 121);
serial_read(a1, v2, 2LL);
if ( v2[0] == 27 && v2[1] == 48 )
{
puts("We were able to put the writer into Lo-Co mode.");
result = 0LL;
}
else
{
printf("It appears that the reader did not switch to Lo-Co mode.");
result = 1LL;
}
return result;
}

original_code:
int
msr_set_lo_co (int fd)
{
 char b[2];
 printf("Putting the writer to Lo-Co mode...\n");
 msr_cmd (fd, 0x79);
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("We were able to put the writer into Lo-Co mode.\n");
  return (0);
 }
 printf("It appears that the reader did not switch to Lo-Co mode.");
 return (1);
}

canonical_original_code:
int msr_set_lo_co(int fd)
{
 char b[2];
 printf("Putting the writer to Lo-Co mode...\n");
 msr_cmd (fd, 0x79);
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("We were able to put the writer into Lo-Co mode.\n");
  return (0);
 }
 printf("It appears that the reader did not switch to Lo-Co mode.");
 return (1);
}


decompiled_code:
__int64 __fastcall msr_reset(__int64 a1)
{
msr_cmd(a1, 97);
usleep(0x186A0u);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
func4(a1, 97);
usleep(0x186A0u);
return 0LL;
}

original_code:
int
msr_reset (int fd)
{
 msr_cmd (fd, 0x61);
 usleep (100000);
 return (0);
}

canonical_original_code:
int msr_reset(int fd)
{
 msr_cmd (fd, 0x61);
 usleep (100000);
 return (0);
}


decompiled_code:
__int64 __fastcall msr_iso_read(__int64 a1, _BYTE *a2)
{
unsigned int v2; // ebx

if ( (unsigned int)msr_cmd(a1, 114) == -1 )
err(1, "Command write failed");
if ( (unsigned int)getstart(a1) == -1 )
err(1, "get start delimiter failed");
gettrack_iso((unsigned int)a1, 1, (__int64)a2, a2 + 255);
gettrack_iso((unsigned int)a1, 2, (__int64)(a2 + 256), a2 + 511);
gettrack_iso((unsigned int)a1, 3, (__int64)(a2 + 512), a2 + 767);
v2 = getend((unsigned int)a1);
if ( v2 != -1 )
return 0;
warnx("read failed");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, _BYTE *a2)
{
unsigned int v2; // ebx

if ( (unsigned int)func4(a1, 114) == -1 )
err(1, "Command write failed");
if ( (unsigned int)func1(a1) == -1 )
err(1, "get start delimiter failed");
func2((unsigned int)a1, 1, (__int64)a2, a2 + 255);
func2((unsigned int)a1, 2, (__int64)(a2 + 256), a2 + 511);
func2((unsigned int)a1, 3, (__int64)(a2 + 512), a2 + 767);
v2 = func0((unsigned int)a1);
if ( v2 != -1 )
return 0;
warnx("read failed");
return v2;
}

original_code:
int
msr_iso_read(int fd, msr_tracks_t * tracks)
{
 int r;
 int i;
 r = msr_cmd (fd, 0x72);
 if (r == -1)
  err(1, "Command write failed");
 if (getstart (fd) == -1)
  err(1, "get start delimiter failed");
 for (i = 0; i < 3; i++)
  gettrack_iso (fd, i + 1, tracks->msr_tracks[i].msr_tk_data,
      &tracks->msr_tracks[i].msr_tk_len);
 if (getend (fd) == -1) {
  warnx("read failed");
  return (-1);
 }
 return (0);
}

canonical_original_code:
int msr_iso_read(int fd, struct msr_tracks *tracks)
{
 int r;
 int i;
 r = msr_cmd (fd, 0x72);
 if (r == -1)
  err(1, "Command write failed");
 if (getstart (fd) == -1)
  err(1, "get start delimiter failed");
 for (i = 0; i < 3; i++)
  gettrack_iso (fd, i + 1, tracks->msr_tracks[i].msr_tk_data,
      &tracks->msr_tracks[i].msr_tk_len);
 if (getend (fd) == -1) {
  warnx("read failed");
  return (-1);
 }
 return (0);
}

variable_types: struct msr_tracks { struct msr_track { unsigned char msr_tk_data[255]; unsigned char msr_tk_len; } msr_tracks[3]; } *


decompiled_code:
__int64 __fastcall msr_erase(__int64 a1, char a2)
{
__int64 result; // rax
char v3[18]; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned __int8 v4; // [rsp+1Eh] [rbp-Ah] BYREF
unsigned __int8 v5; // [rsp+1Fh] [rbp-9h]

v3[0] = a2;
msr_cmd(a1, 99);
serial_write((unsigned int)a1, v3, 1LL);
if ( (unsigned int)serial_read((unsigned int)a1, &v4, 2LL) == -1 )
err(1, "read erase response failed");
if ( v4 == 27 && v5 == 48 )
{
puts("Erase successfull");
result = 0LL;
}
else
{
printf("%x %x\n", v4, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, char a2)
{
__int64 result; // rax
char v3[18]; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned __int8 v4; // [rsp+1Eh] [rbp-Ah] BYREF
unsigned __int8 v5; // [rsp+1Fh] [rbp-9h]

v3[0] = a2;
func4(a1, 99);
serial_write((unsigned int)a1, v3, 1LL);
if ( (unsigned int)serial_read((unsigned int)a1, &v4, 2LL) == -1 )
err(1, "read erase response failed");
if ( v4 == 27 && v5 == 48 )
{
puts("Erase successfull");
result = 0LL;
}
else
{
printf("%x %x\n", v4, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
msr_erase (int fd, uint8_t tracks)
{
 uint8_t b[2];
 msr_cmd (fd, 0x63);
 serial_write (fd, &tracks, 1);
 if (serial_read (fd, b, 2) == -1)
  err(1, "read erase response failed");
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("Erase successfull\n");
  return (0);
 } else
  printf ("%x %x\n", b[0], b[1]);
 return (-1);
}

canonical_original_code:
int msr_erase(int fd, unsigned char tracks)
{
 unsigned char b[2];
 msr_cmd (fd, 0x63);
 serial_write (fd, &tracks, 1);
 if (serial_read (fd, b, 2) == -1)
  err(1, "read erase response failed");
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("Erase successfull\n");
  return (0);
 } else
  printf ("%x %x\n", b[0], b[1]);
 return (-1);
}

variable_types:
tracks
unsigned char


decompiled_code:
__int64 __fastcall msr_iso_write(__int64 a1, __int64 a2)
{
__int64 i; // r12
char v5; // [rsp+Ch] [rbp-1Ch] BYREF
char v6; // [rsp+Dh] [rbp-1Bh]

msr_cmd(a1, 119);
v5 = 27;
v6 = 115;
serial_write((unsigned int)a1, &v5, 2LL);
for ( i = 1LL; i != 4; ++i )
{
v5 = 27;
v6 = i;
serial_write((unsigned int)a1, &v5, 2LL);
serial_write((unsigned int)a1, a2, *(unsigned __int8 *)(a2 + 255));
a2 += 256LL;
}
v5 = 63;
v6 = 28;
serial_write((unsigned int)a1, &v5, 2LL);
serial_readchar((unsigned int)a1, &v5);
serial_readchar((unsigned int)a1, &v5);
if ( v5 != 48 )
warnx("write failed");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2)
{
__int64 i; // r12
char v5; // [rsp+Ch] [rbp-1Ch] BYREF
char v6; // [rsp+Dh] [rbp-1Bh]

func4(a1, 119);
v5 = 27;
v6 = 115;
serial_write((unsigned int)a1, &v5, 2LL);
for ( i = 1LL; i != 4; ++i )
{
v5 = 27;
v6 = i;
serial_write((unsigned int)a1, &v5, 2LL);
serial_write((unsigned int)a1, a2, *(unsigned __int8 *)(a2 + 255));
a2 += 256LL;
}
v5 = 63;
v6 = 28;
serial_write((unsigned int)a1, &v5, 2LL);
serial_readchar((unsigned int)a1, &v5);
serial_readchar((unsigned int)a1, &v5);
if ( v5 != 48 )
warnx("write failed");
return 0LL;
}

original_code:
int
msr_iso_write(int fd, msr_tracks_t * tracks)
{
 int i;
 uint8_t buf[4];
 msr_cmd (fd, 0x77);
 buf[0] = 0x1B;
 buf[1] = 0x73;
 serial_write (fd, buf, 2);
 for (i = 0; i < 3; i++) {
  buf[0] = 0x1B;
  buf[1] = i + 1;
  serial_write (fd, buf, 2);
  serial_write (fd, tracks->msr_tracks[i].msr_tk_data,
   tracks->msr_tracks[i].msr_tk_len);
 }
 buf[0] = 0x3F;
 buf[1] = 0x1C;
 serial_write (fd, buf, 2);
 serial_readchar (fd, &buf[0]);
 serial_readchar (fd, &buf[0]);
 if (buf[0] != 0x30)
  warnx("write failed");
 return (0);
}

canonical_original_code:
int msr_iso_write(int fd, struct msr_tracks *tracks)
{
 int i;
 unsigned char buf[4];
 msr_cmd (fd, 0x77);
 buf[0] = 0x1B;
 buf[1] = 0x73;
 serial_write (fd, buf, 2);
 for (i = 0; i < 3; i++) {
  buf[0] = 0x1B;
  buf[1] = i + 1;
  serial_write (fd, buf, 2);
  serial_write (fd, tracks->msr_tracks[i].msr_tk_data,
   tracks->msr_tracks[i].msr_tk_len);
 }
 buf[0] = 0x3F;
 buf[1] = 0x1C;
 serial_write (fd, buf, 2);
 serial_readchar (fd, &buf[0]);
 serial_readchar (fd, &buf[0]);
 if (buf[0] != 0x30)
  warnx("write failed");
 return (0);
}

variable_types:
buf
unsigned char [4]


decompiled_code:
__int64 __fastcall msr_raw_read(__int64 a1, _BYTE *a2)
{
if ( (unsigned int)msr_cmd(a1, 109) == -1 )
err(1, "Command write failed");
if ( (unsigned int)getstart(a1) == -1 )
err(1, "get start delimiter failed");
gettrack_raw((unsigned int)a1, 1, (__int64)a2, a2 + 255);
gettrack_raw((unsigned int)a1, 2, (__int64)(a2 + 256), a2 + 511);
gettrack_raw((unsigned int)a1, 3, (__int64)(a2 + 512), a2 + 767);
if ( (unsigned int)getend((unsigned int)a1) == -1 )
err(1, "read failed");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, _BYTE *a2)
{
if ( (unsigned int)func4(a1, 109) == -1 )
err(1, "Command write failed");
if ( (unsigned int)func1(a1) == -1 )
err(1, "get start delimiter failed");
func3((unsigned int)a1, 1, (__int64)a2, a2 + 255);
func3((unsigned int)a1, 2, (__int64)(a2 + 256), a2 + 511);
func3((unsigned int)a1, 3, (__int64)(a2 + 512), a2 + 767);
if ( (unsigned int)func0((unsigned int)a1) == -1 )
err(1, "read failed");
return 0LL;
}

original_code:
int
msr_raw_read(int fd, msr_tracks_t * tracks)
{
 int r;
 int i;
 r = msr_cmd (fd, 0x6D);
 if (r == -1)
  err(1, "Command write failed");
 if (getstart (fd) == -1)
  err(1, "get start delimiter failed");
 for (i = 0; i < 3; i++)
  gettrack_raw (fd, i + 1, tracks->msr_tracks[i].msr_tk_data,
      &tracks->msr_tracks[i].msr_tk_len);
 if (getend (fd) == -1)
  err(1, "read failed");
 return (0);
}

canonical_original_code:
int msr_raw_read(int fd, struct msr_tracks *tracks)
{
 int r;
 int i;
 r = msr_cmd (fd, 0x6D);
 if (r == -1)
  err(1, "Command write failed");
 if (getstart (fd) == -1)
  err(1, "get start delimiter failed");
 for (i = 0; i < 3; i++)
  gettrack_raw (fd, i + 1, tracks->msr_tracks[i].msr_tk_data,
      &tracks->msr_tracks[i].msr_tk_len);
 if (getend (fd) == -1)
  err(1, "read failed");
 return (0);
}

variable_types: i int


decompiled_code:
__int64 __fastcall msr_raw_write(__int64 a1, __int64 a2)
{
__int64 i; // r12
char v5; // [rsp+Ch] [rbp-1Ch] BYREF
char v6; // [rsp+Dh] [rbp-1Bh]
char v7; // [rsp+Eh] [rbp-1Ah]

msr_cmd(a1, 110);
v5 = 27;
v6 = 115;
serial_write((unsigned int)a1, &v5, 2LL);
for ( i = 1LL; i != 4; ++i )
{
v5 = 27;
v6 = i;
v7 = *(_BYTE *)(a2 + 255);
serial_write((unsigned int)a1, &v5, 3LL);
serial_write((unsigned int)a1, a2, *(unsigned __int8 *)(a2 + 255));
a2 += 256LL;
}
v5 = 63;
v6 = 28;
serial_write((unsigned int)a1, &v5, 2LL);
serial_readchar((unsigned int)a1, &v5);
serial_readchar((unsigned int)a1, &v5);
if ( v5 != 48 )
warnx("raw write failed");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, __int64 a2)
{
__int64 i; // r12
char v5; // [rsp+Ch] [rbp-1Ch] BYREF
char v6; // [rsp+Dh] [rbp-1Bh]
char v7; // [rsp+Eh] [rbp-1Ah]

func4(a1, 110);
v5 = 27;
v6 = 115;
serial_write((unsigned int)a1, &v5, 2LL);
for ( i = 1LL; i != 4; ++i )
{
v5 = 27;
v6 = i;
v7 = *(_BYTE *)(a2 + 255);
serial_write((unsigned int)a1, &v5, 3LL);
serial_write((unsigned int)a1, a2, *(unsigned __int8 *)(a2 + 255));
a2 += 256LL;
}
v5 = 63;
v6 = 28;
serial_write((unsigned int)a1, &v5, 2LL);
serial_readchar((unsigned int)a1, &v5);
serial_readchar((unsigned int)a1, &v5);
if ( v5 != 48 )
warnx("raw write failed");
return 0LL;
}

original_code:
int
msr_raw_write(int fd, msr_tracks_t * tracks)
{
 int i;
 uint8_t buf[4];
 msr_cmd (fd, 0x6E);
 buf[0] = 0x1B;
 buf[1] = 0x73;
 serial_write (fd, buf, 2);
 for (i = 0; i < 3; i++) {
  buf[0] = 0x1B;
  buf[1] = i + 1;
  buf[2] = tracks->msr_tracks[i].msr_tk_len;
  serial_write (fd, buf, 3);
  serial_write (fd, tracks->msr_tracks[i].msr_tk_data,
   tracks->msr_tracks[i].msr_tk_len);
 }
 buf[0] = 0x3F;
 buf[1] = 0x1C;
 serial_write (fd, buf, 2);
 serial_readchar (fd, &buf[0]);
 serial_readchar (fd, &buf[0]);
 if (buf[0] != 0x30)
  warnx("raw write failed");
 return (0);
}

canonical_original_code:
int msr_raw_write(int fd, struct msr_tracks *tracks)
{
 int i;
 unsigned char buf[4];
 msr_cmd (fd, 0x6E);
 buf[0] = 0x1B;
 buf[1] = 0x73;
 serial_write (fd, buf, 2);
 for (i = 0; i < 3; i++) {
  buf[0] = 0x1B;
  buf[1] = i + 1;
  buf[2] = tracks->msr_tracks[i].msr_tk_len;
  serial_write (fd, buf, 3);
  serial_write (fd, tracks->msr_tracks[i].msr_tk_data,
   tracks->msr_tracks[i].msr_tk_len);
 }
 buf[0] = 0x3F;
 buf[1] = 0x1C;
 serial_write (fd, buf, 2);
 serial_readchar (fd, &buf[0]);
 serial_readchar (fd, &buf[0]);
 if (buf[0] != 0x30)
  warnx("raw write failed");
 return (0);
}


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

msr_reset(a1);
result = msr_commtest((unsigned int)a1);
if ( (_DWORD)result != -1 )
{
msr_reset((unsigned int)a1);
result = 0LL;
}
return result;
}

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

func14(a1);
result = func6((unsigned int)a1);
if ( (_DWORD)result != -1 )
{
func14((unsigned int)a1);
result = 0LL;
}
return result;
}

original_code:
int
msr_init(int fd)
{
 msr_reset (fd);
 if (msr_commtest (fd) == -1)
  return (-1);
 msr_reset (fd);
 return (0);
}


decompiled_code:
__int64 __fastcall msr_set_bpi(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax
char v3[18]; // [rsp+Ch] [rbp-1Ch] BYREF
char v4[10]; // [rsp+1Eh] [rbp-Ah] BYREF

v3[0] = a2;
msr_cmd(a1, 98);
serial_write((unsigned int)a1, v3, 1LL);
serial_read((unsigned int)a1, v4, 2LL);
if ( v4[0] == 27 && v4[1] == 48 )
{
printf("Set bits per inch to: %d\n", (unsigned __int8)v3[0]);
result = 0LL;
}
else
{
warnx("Set bpi failed\n");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax
char v3[18]; // [rsp+Ch] [rbp-1Ch] BYREF
char v4[10]; // [rsp+1Eh] [rbp-Ah] BYREF

v3[0] = a2;
func4(a1, 98);
serial_write((unsigned int)a1, v3, 1LL);
serial_read((unsigned int)a1, v4, 2LL);
if ( v4[0] == 27 && v4[1] == 48 )
{
printf("Set bits per inch to: %d\n", (unsigned __int8)v3[0]);
result = 0LL;
}
else
{
warnx("Set bpi failed\n");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
msr_set_bpi (int fd, uint8_t bpi)
{
 uint8_t b[2];
 msr_cmd (fd, 0x62);
 serial_write (fd, &bpi, 1);
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("Set bits per inch to: %d\n", bpi);
  return (0);
 }
 warnx ("Set bpi failed\n");
 return (-1);
}

canonical_original_code:
int msr_set_bpi(int fd, unsigned char bpi)
{
 unsigned char b[2];
 msr_cmd (fd, 0x62);
 serial_write (fd, &bpi, 1);
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  printf("Set bits per inch to: %d\n", bpi);
  return (0);
 }
 warnx ("Set bpi failed\n");
 return (-1);
}

variable_types:
bpi
unsigned char


decompiled_code:
__int64 __fastcall msr_set_bpc(__int64 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
__int64 result; // rax
unsigned __int8 v5; // [rsp+Bh] [rbp-Dh] BYREF
unsigned __int8 v6; // [rsp+Ch] [rbp-Ch]
unsigned __int8 v7; // [rsp+Dh] [rbp-Bh]
char v8[10]; // [rsp+Eh] [rbp-Ah] BYREF

v5 = a2;
v6 = a3;
v7 = a4;
msr_cmd(a1, 111);
serial_write((unsigned int)a1, &v5, 3LL);
serial_read((unsigned int)a1, v8, 2LL);
if ( v8[0] == 27 && v8[1] == 48 )
{
serial_read((unsigned int)a1, &v5, 3LL);
printf("Set bpc... %d %d %d\n", v5, v6, v7);
result = 0LL;
}
else
{
warnx("failed to set bpc");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
__int64 result; // rax
unsigned __int8 v5; // [rsp+Bh] [rbp-Dh] BYREF
unsigned __int8 v6; // [rsp+Ch] [rbp-Ch]
unsigned __int8 v7; // [rsp+Dh] [rbp-Bh]
char v8[10]; // [rsp+Eh] [rbp-Ah] BYREF

v5 = a2;
v6 = a3;
v7 = a4;
func4(a1, 111);
serial_write((unsigned int)a1, &v5, 3LL);
serial_read((unsigned int)a1, v8, 2LL);
if ( v8[0] == 27 && v8[1] == 48 )
{
serial_read((unsigned int)a1, &v5, 3LL);
printf("Set bpc... %d %d %d\n", v5, v6, v7);
result = 0LL;
}
else
{
warnx("failed to set bpc");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
msr_set_bpc (int fd, uint8_t bpc1, uint8_t bpc2, uint8_t bpc3)
{
 uint8_t b[2];
 msr_bpc_t bpc;
 bpc.msr_bpctk1 = bpc1;
 bpc.msr_bpctk2 = bpc2;
 bpc.msr_bpctk3 = bpc3;
 msr_cmd (fd, 0x6F);
 serial_write (fd, &bpc, sizeof(bpc));
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  serial_read (fd, &bpc, sizeof(bpc));
  printf ("Set bpc... %d %d %d\n", bpc.msr_bpctk1,
      bpc.msr_bpctk2, bpc.msr_bpctk3);
  return (0);
 }
 warnx("failed to set bpc");
 return (-1);
}

canonical_original_code:
int msr_set_bpc(int fd, unsigned char bpc1, unsigned char bpc2, unsigned char bpc3)
{
 unsigned char b[2];
 struct msr_bpc bpc;
 bpc.msr_bpctk1 = bpc1;
 bpc.msr_bpctk2 = bpc2;
 bpc.msr_bpctk3 = bpc3;
 msr_cmd (fd, 0x6F);
 serial_write (fd, &bpc, sizeof(bpc));
 serial_read (fd, &b, 2);
 if (b[0] == 0x1B && b[1] == 0x30) {
  serial_read (fd, &bpc, sizeof(bpc));
  printf ("Set bpc... %d %d %d\n", bpc.msr_bpctk1,
      bpc.msr_bpctk2, bpc.msr_bpctk3);
  return (0);
 }
 warnx("failed to set bpc");
 return (-1);
}

variable_types: struct msr_bpc { unsigned char msr_bpctk1; unsigned char msr_bpctk2; unsigned char msr_bpctk3; }


decompiled_code:
int __fastcall serial_setup(int fd, speed_t speed)
{
int result; // eax
tcflag_t v3; // eax
struct termios v4; // [rsp+0h] [rbp-58h] BYREF

result = tcgetattr(fd, &v4);
if ( result != -1 )
{
cfsetispeed(&v4, speed);
cfsetospeed(&v4, speed);
v4.c_cflag = v4.c_cflag & 0xFFFFFE8F | 0x8B0;
v4.c_lflag &= 0xFFFF7FB4;
v3 = v4.c_iflag;
BYTE1(v3) = BYTE1(v4.c_iflag) & 0xE2;
v4.c_iflag = v3 | 5;
v4.c_oflag &= 0xFFFFFFFE;
result = -(tcsetattr(fd, 0, &v4) == -1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int fd, speed_t speed)
{
int result; // eax
tcflag_t v3; // eax
struct termios v4; // [rsp+0h] [rbp-58h] BYREF

result = tcgetattr(fd, &v4);
if ( result != -1 )
{
cfsetispeed(&v4, speed);
cfsetospeed(&v4, speed);
v4.c_cflag = v4.c_cflag & 0xFFFFFE8F | 0x8B0;
v4.c_lflag &= 0xFFFF7FB4;
v3 = v4.c_iflag;
BYTE1(v3) = BYTE1(v4.c_iflag) & 0xE2;
v4.c_iflag = v3 | 5;
v4.c_oflag &= 0xFFFFFFFE;
result = -(tcsetattr(fd, 0, &v4) == -1);
}
return result;
}

original_code:
static int
serial_setup (int fd, speed_t baud)
{
        struct termios options;
 if (tcgetattr(fd, &options) == -1)
  return (-1);
 cfsetispeed(&options, baud);
 cfsetospeed(&options, baud);
 options.c_cflag |= (0004000 | 0000200);
 options.c_cflag &= ~0000400;
 options.c_cflag &= ~0000100;
 options.c_cflag &= ~0000060;
 options.c_cflag |= 0000060;
 options.c_lflag &= ~0000002;
 options.c_lflag &= ~0000010;
 options.c_lflag &= ~0000100;
 options.c_lflag &= ~0000001;
 options.c_lflag &= ~0100000;
 options.c_iflag &= ~0000400;
 options.c_iflag &= ~0002000;
 options.c_iflag &= ~0010000;
 options.c_iflag &= ~0004000;
 options.c_iflag |= 0000001;
 options.c_iflag |= 0000004;
 options.c_oflag &= ~0000001;
 if (tcsetattr(fd, 0, &options) == -1)
  return (-1);
 return (0);
}

canonical_original_code:
static int serial_setup(int fd, unsigned int baud)
{
        struct termios options;
 if (tcgetattr(fd, &options) == -1)
  return (-1);
 cfsetispeed(&options, baud);
 cfsetospeed(&options, baud);
 options.c_cflag |= (0004000 | 0000200);
 options.c_cflag &= ~0000400;
 options.c_cflag &= ~0000100;
 options.c_cflag &= ~0000060;
 options.c_cflag |= 0000060;
 options.c_lflag &= ~0000002;
 options.c_lflag &= ~0000010;
 options.c_lflag &= ~0000100;
 options.c_lflag &= ~0000001;
 options.c_lflag &= ~0100000;
 options.c_iflag &= ~0000400;
 options.c_iflag &= ~0002000;
 options.c_iflag &= ~0010000;
 options.c_iflag &= ~0004000;
 options.c_iflag |= 0000001;
 options.c_iflag |= 0000004;
 options.c_oflag &= ~0000001;
 if (tcsetattr(fd, 0, &options) == -1)
  return (-1);
 return (0);
}

variable_types:
baud
unsigned int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
__int64 __fastcall serial_readchar(int fd, _BYTE *a2)
{
unsigned int v2; // edx
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

do
v2 = read(fd, buf, 1uLL);
while ( v2 == -1 );
*a2 = buf[0];
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, _BYTE *a2)
{
unsigned int v2; // edx
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

do
v2 = read(fd, buf, 1uLL);
while ( v2 == -1 );
*a2 = buf[0];
return v2;
}

original_code:
int
serial_readchar (int fd, uint8_t * c)
{
 char b;
 int r;
 while ((r = read (fd, &b, 1)) == -1)
  ;
 if (r != -1) {
  *c = b;
 }
 return (r);
}

canonical_original_code:
int serial_readchar(int fd, unsigned char *c)
{
 char b;
 int r;
 while ((r = read (fd, &b, 1)) == -1)
  ;
 if (r != -1) {
  *c = b;
 }
 return (r);
}

variable_types:
c
unsigned char *

variable_types: b char

variable_types: r int


decompiled_code:
__int64 __fastcall serial_read(int fd, _BYTE *a2, __int64 a3)
{
_BYTE *v3; // rbx
_BYTE *v4; // rbp
char v6[25]; // [rsp+1h] [rbp-19h] BYREF

if ( !a3 )
return 0LL;
v3 = a2;
v4 = &a2[a3];
do
{
serial_readchar(fd, v6);
*v3++ = v6[0];
}
while ( v3 != v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, _BYTE *a2, __int64 a3)
{
_BYTE *v3; // rbx
_BYTE *v4; // rbp
char v6[25]; // [rsp+1h] [rbp-19h] BYREF

if ( !a3 )
return 0LL;
v3 = a2;
v4 = &a2[a3];
do
{
func8(fd, v6);
*v3++ = v6[0];
}
while ( v3 != v4 );
return 0LL;
}

original_code:
int
serial_read (int fd, void * buf, size_t len)
{
 size_t i;
 uint8_t b, *p;
 p = buf;
 for (i = 0; i < len; i++) {
  serial_readchar (fd, &b);
  p[i] = b;
 }
 return (0);
}

canonical_original_code:
int serial_read(int fd, void *buf, unsigned long len)
{
 unsigned long i;
 unsigned char b; unsigned char *p;
 p = buf;
 for (i = 0; i < len; i++) {
  serial_readchar (fd, &b);
  p[i] = b;
 }
 return (0);
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
len
unsigned long

variable_types:
i
unsigned long

variable_types:
b
unsigned char

variable_types:
p
unsigned char *


decompiled_code:
ssize_t __fastcall serial_write(int a1, const void *a2, size_t a3)
{
return write(a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func10(int a1, const void *a2, size_t a3)
{
return write(a1, a2, a3);
}

original_code:
int
serial_write (int fd, void * buf, size_t len)
{
 return (write (fd, buf, len));
}

canonical_original_code:
int serial_write(int fd, void *buf, unsigned long len)
{
 return (write (fd, buf, len));
}


decompiled_code:
int __fastcall serial_open(const char *a1, int *a2, int a3, speed_t a4)
{
int result; // eax
int v6; // ebx

result = open(a1, a3 | 0x101002);
v6 = result;
if ( result != -1 )
{
result = serial_setup(result, a4);
if ( result )
{
close(v6);
result = -1;
}
else
{
*a2 = v6;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(const char *a1, int *a2, int a3, speed_t a4)
{
int result; // eax
int v6; // ebx

result = open(a1, a3 | 0x101002);
v6 = result;
if ( result != -1 )
{
result = func7(result, a4);
if ( result )
{
close(v6);
result = -1;
}
else
{
*a2 = v6;
}
}
return result;
}

original_code:
int
serial_open(char *path, int * fd, int blocking, speed_t baud)
{
 int f;
 f = open(path, blocking | 02 | 04010000);
 if (f == -1)
  return (-1);
 if (serial_setup (f, baud) != 0) {
  close (f);
  return (-1);
 }
 *fd = f;
 return (0);
}

canonical_original_code:
int serial_open(char *path, int *fd, int blocking, unsigned int baud)
{
 int f;
 f = open(path, blocking | 02 | 04010000);
 if (f == -1)
  return (-1);
 if (serial_setup (f, baud) != 0) {
  close (f);
  return (-1);
 }
 *fd = f;
 return (0);
}

variable_types:
path
char *

variable_types:
fd
int *

variable_types: blocking int

variable_types: f int


decompiled_code:
__int64 __fastcall serial_close(int a1)
{
close(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
close(a1);
return 0LL;
}

original_code:
int
serial_close(int fd)
{
 close (fd);
 return (0);
}


decompiled_code:
ssize_t __fastcall mak_cmd(int a1, unsigned __int8 a2, char a3)
{
char v4[10]; // [rsp+Eh] [rbp-Ah] BYREF

v4[0] = a2;
v4[1] = a3;
printf("Attempting to send command: %c\n", a2);
return serial_write(a1, v4, 2uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func14(int a1, unsigned __int8 a2, char a3)
{
char v4[10]; // [rsp+Eh] [rbp-Ah] BYREF

v4[0] = a2;
v4[1] = a3;
printf("Attempting to send command: %c\n", a2);
return func10(a1, v4, 2uLL);
}

original_code:
int
mak_cmd(int fd, uint8_t c, uint8_t tracks)
{
 mak_generic_cmd_t cmd;
 cmd.mak_cmd = c;
 cmd.mak_track_mask = tracks;
 printf("Attempting to send command: %c\n", cmd.mak_cmd);
 return (serial_write(fd,&cmd, sizeof(cmd)));
}

canonical_original_code:
int mak_cmd(int fd, unsigned char c, unsigned char tracks)
{
 struct mak_cmd cmd;
 cmd.mak_cmd = c;
 cmd.mak_track_mask = tracks;
 printf("Attempting to send command: %c\n", cmd.mak_cmd);
 return (serial_write(fd,&cmd, sizeof(cmd)));
}

variable_types:
c
unsigned char

variable_types:
tracks
unsigned char

variable_types: struct mak_cmd { unsigned char mak_cmd; unsigned char mak_track_mask; }


decompiled_code:
__int64 __fastcall mak_reset(int fd)
{
unsigned int v1; // ebx
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
int v4; // [rsp+8h] [rbp-10h]
__int16 v5; // [rsp+Ch] [rbp-Ch]
char v6; // [rsp+Eh] [rbp-Ah]
char v7; // [rsp+Fh] [rbp-9h]

v3 = 63LL;
v4 = 0;
v5 = 0;
v6 = 0;
printf("Sending reset command: %c\n", 63LL);
serial_write(fd, &v3, 4uLL);
printf("We expect: %s\n", "MSUSB CI.270209");
printf("We got ");
v1 = serial_read(fd, &v3, 15LL);
v7 = 0;
printf("buf: %s\n", (const char *)&v3);
printf("Reset status: %d\n", v1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func15(int fd)
{
unsigned int v1; // ebx
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
int v4; // [rsp+8h] [rbp-10h]
__int16 v5; // [rsp+Ch] [rbp-Ch]
char v6; // [rsp+Eh] [rbp-Ah]
char v7; // [rsp+Fh] [rbp-9h]

v3 = 63LL;
v4 = 0;
v5 = 0;
v6 = 0;
printf("Sending reset command: %c\n", 63LL);
func10(fd, &v3, 4uLL);
printf("We expect: %s\n", "MSUSB CI.270209");
printf("We got ");
v1 = func9(fd, &v3, 15LL);
v7 = 0;
printf("buf: %s\n", (const char *)&v3);
printf("Reset status: %d\n", v1);
return v1;
}

original_code:
int mak_reset(int fd)
{
 int r;
 int i;
 char buf[strlen("MSUSB CI.270209") + 1];
 memset(buf, 0, strlen("MSUSB CI.270209"));
 buf[0] = '?';
 printf("Sending reset command: %c\n", '?');
 serial_write(fd, buf, sizeof('?'));
 printf("We expect: %s\n", "MSUSB CI.270209");
 printf("We got ");
 r = serial_read(fd, buf, strlen("MSUSB CI.270209"));
 buf[strlen("MSUSB CI.270209")] = '\0';
 printf("buf: %s\n", buf);
 printf("Reset status: %d\n", r);
 return r;
}

canonical_original_code:
int mak_reset(int fd)
{
 int r;
 int i;
 char buf[-1];
 memset(buf, 0, strlen("MSUSB CI.270209"));
 buf[0] = '?';
 printf("Sending reset command: %c\n", '?');
 serial_write(fd, buf, sizeof('?'));
 printf("We expect: %s\n", "MSUSB CI.270209");
 printf("We got ");
 r = serial_read(fd, buf, strlen("MSUSB CI.270209"));
 buf[strlen("MSUSB CI.270209")] = '\0';
 printf("buf: %s\n", buf);
 printf("Reset status: %d\n", r);
 return r;
}

variable_types: i int

variable_types:
buf
char [-1]


decompiled_code:
__int64 __fastcall mak_read(int fd, char a2)
{
unsigned int v2; // ebx
__int64 v3; // r12
__int64 result; // rax
unsigned __int16 v5; // [rsp+6h] [rbp-22h] BYREF
char v6[2]; // [rsp+9h] [rbp-1Fh] BYREF
__int16 s1; // [rsp+Bh] [rbp-1Dh] BYREF
char v8; // [rsp+Dh] [rbp-1Bh]

puts("Attempting to perform a read...");
mak_cmd(fd, 0x52u, a2);
puts("Command sent!");
serial_read(fd, &s1, 5LL);
printf("We got: %s\n", (const char *)&s1);
printf("We expected: %s\n", "Ready ");
if ( !memcmp(&s1, "Ready ", 6uLL) )
{
puts("Doh!");
result = 0xFFFFFFFFLL;
}
else
{
puts("Please swipe a card for read...");
s1 = 0;
v8 = 0;
serial_read(fd, &s1, 3LL);
printf("We expect: %s\n", "RD ");
printf("We expect it to be of len: %d\n", 3LL);
printf("We got: %s\n", (const char *)&s1);
v2 = memcmp(&s1, "RD ", 3uLL);
if ( v2 )
{
result = 0xFFFFFFFFLL;
}
else
{
serial_read(fd, &v5, 2LL);
printf("Sample count appears to be: %d\n", v5);
v3 = (unsigned __int16)_bswap_16(v5);
printf("Sample count appears to be: %d\n", v3);
if ( (int)v3 > 0 )
{
do
{
serial_read(fd, v6, 2LL);
printf("%d %02x %02x\n", v2++, (unsigned __int8)v6[0], (unsigned __int8)v6[1]);
}
while ( (_DWORD)v3 != v2 );
}
puts("In theory, we have dumped the full sample data now...");
serial_read(fd, &s1, 5LL);
printf("Sample read returned status: %s\n", (const char *)&s1);
result = (unsigned int)-(memcmp(&s1, "RD=OK", 5uLL) != 0);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(int fd, char a2)
{
unsigned int v2; // ebx
__int64 v3; // r12
__int64 result; // rax
unsigned __int16 v5; // [rsp+6h] [rbp-22h] BYREF
char v6[2]; // [rsp+9h] [rbp-1Fh] BYREF
__int16 s1; // [rsp+Bh] [rbp-1Dh] BYREF
char v8; // [rsp+Dh] [rbp-1Bh]

puts("Attempting to perform a read...");
func14(fd, 0x52u, a2);
puts("Command sent!");
func9(fd, &s1, 5LL);
printf("We got: %s\n", (const char *)&s1);
printf("We expected: %s\n", "Ready ");
if ( !memcmp(&s1, "Ready ", 6uLL) )
{
puts("Doh!");
result = 0xFFFFFFFFLL;
}
else
{
puts("Please swipe a card for read...");
s1 = 0;
v8 = 0;
func9(fd, &s1, 3LL);
printf("We expect: %s\n", "RD ");
printf("We expect it to be of len: %d\n", 3LL);
printf("We got: %s\n", (const char *)&s1);
v2 = memcmp(&s1, "RD ", 3uLL);
if ( v2 )
{
result = 0xFFFFFFFFLL;
}
else
{
func9(fd, &v5, 2LL);
printf("Sample count appears to be: %d\n", v5);
v3 = (unsigned __int16)func13(v5);
printf("Sample count appears to be: %d\n", v3);
if ( (int)v3 > 0 )
{
do
{
func9(fd, v6, 2LL);
printf("%d %02x %02x\n", v2++, (unsigned __int8)v6[0], (unsigned __int8)v6[1]);
}
while ( (_DWORD)v3 != v2 );
}
puts("In theory, we have dumped the full sample data now...");
func9(fd, &s1, 5LL);
printf("Sample read returned status: %s\n", (const char *)&s1);
result = (unsigned int)-(memcmp(&s1, "RD=OK", 5uLL) != 0);
}
}
return result;
}

original_code:
int
mak_read(int fd, uint8_t tracks)
{
 int r;
 int i;
 char buf[5];
 unsigned char sample_tmp[2];
 uint16_t sample_count;
 int sample_count_guessing;
 printf("Attempting to perform a read...\n");
 r = mak_cmd(fd, 'R', tracks);
 printf("Command sent!\n");
 serial_read(fd, buf, strlen("Ready ") -1);
 printf("We got: %s\n", buf);
 printf("We expected: %s\n", "Ready ");
 if (!memcmp(buf, "Ready ", strlen("Ready "))) {
  printf("Doh!\n");
  return -1;
 }
 printf("Please swipe a card for read...\n");
 memset(buf, 0, 3);
 serial_read(fd, buf, 3);
 printf("We expect: %s\n", "RD ");
 printf("We expect it to be of len: %d\n", strlen("RD "));
 printf("We got: %s\n", buf);
 r = memcmp(buf, "RD ", strlen("RD "));
 if (r != 0) {
  return -1;
 }
 serial_read(fd, &sample_count, 2);
 printf("Sample count appears to be: %d\n", sample_count);
 sample_count_guessing = ntohs(sample_count);
 printf("Sample count appears to be: %d\n", sample_count_guessing);
 for (i = 0; i < sample_count_guessing ; i++) {
  serial_read(fd, sample_tmp, 2);
  printf("%d %02x %02x\n", i, sample_tmp[0], sample_tmp[1]);
 }
 printf("In theory, we have dumped the full sample data now...\n");
 serial_read(fd, buf, 5);
 printf("Sample read returned status: %s\n", buf);
 r = memcmp(buf, "RD=OK", 5);
 if (r != 0)
  return -1;
 return r;
}

canonical_original_code:
int mak_read(int fd, unsigned char tracks)
{
 int r;
 int i;
 char buf[5];
 unsigned char sample_tmp[2];
 unsigned short sample_count;
 int sample_count_guessing;
 printf("Attempting to perform a read...\n");
 r = mak_cmd(fd, 'R', tracks);
 printf("Command sent!\n");
 serial_read(fd, buf, strlen("Ready ") -1);
 printf("We got: %s\n", buf);
 printf("We expected: %s\n", "Ready ");
 if (!memcmp(buf, "Ready ", strlen("Ready "))) {
  printf("Doh!\n");
  return -1;
 }
 printf("Please swipe a card for read...\n");
 memset(buf, 0, 3);
 serial_read(fd, buf, 3);
 printf("We expect: %s\n", "RD ");
 printf("We expect it to be of len: %d\n", strlen("RD "));
 printf("We got: %s\n", buf);
 r = memcmp(buf, "RD ", strlen("RD "));
 if (r != 0) {
  return -1;
 }
 serial_read(fd, &sample_count, 2);
 printf("Sample count appears to be: %d\n", sample_count);
 sample_count_guessing = ntohs(sample_count);
 printf("Sample count appears to be: %d\n", sample_count_guessing);
 for (i = 0; i < sample_count_guessing ; i++) {
  serial_read(fd, sample_tmp, 2);
  printf("%d %02x %02x\n", i, sample_tmp[0], sample_tmp[1]);
 }
 printf("In theory, we have dumped the full sample data now...\n");
 serial_read(fd, buf, 5);
 printf("Sample read returned status: %s\n", buf);
 r = memcmp(buf, "RD=OK", 5);
 if (r != 0)
  return -1;
 return r;
}

variable_types:
buf
char [5]


decompiled_code:
__int64 __fastcall mak_successful_read(int fd, char a2)
{
__int64 result; // rax

do
{
mak_reset(fd);
result = mak_read(fd, a2);
}
while ( (_DWORD)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(int fd, char a2)
{
__int64 result; // rax

do
{
func15(fd);
result = func17(fd, a2);
}
while ( (_DWORD)result );
return result;
}

original_code:
int
mak_successful_read(int fd, uint8_t tracks)
{
 int r;
 do {
  mak_reset(fd);
  r = mak_read(fd, tracks);
 } while (r != 0);
 return r;
}

canonical_original_code:
int mak_successful_read(int fd, unsigned char tracks)
{
 int r;
 do {
  mak_reset(fd);
  r = mak_read(fd, tracks);
 } while (r != 0);
 return r;
}

variable_types: r int


decompiled_code:
__int64 __fastcall mak_clone(int fd)
{
unsigned int v1; // eax
unsigned int v2; // ebx
char s1; // [rsp+Bh] [rbp-Dh] BYREF
char v5; // [rsp+Ch] [rbp-Ch]
char v6; // [rsp+Dh] [rbp-Bh]
char v7; // [rsp+Eh] [rbp-Ah]
char v8; // [rsp+Fh] [rbp-9h]

s1 = 67;
v5 = 7;
v1 = serial_write(fd, &s1, 2uLL);
printf("Serial write status: %i\n", v1);
serial_read(fd, &s1, 3LL);
if ( !memcmp(&s1, "CP ", 3uLL) )
{
puts("Ready to clone from Makstripe buffer to card.");
puts("Please swipe blank card");
v2 = serial_read(fd, &s1, 5LL);
if ( !memcmp(&s1, "CP=OK", 5uLL) )
{
printf("Clone succesfull: %i\n", v2);
}
else
{
printf("We expect a string of length: %i\n", 5LL);
printf("buf was unequal to MAKSTRIPE_CLONE_STS_OK: %s\n", "CP=OK");
printf("%c%c%c%c%c\n", (unsigned int)s1, (unsigned int)v5, (unsigned int)v6, (unsigned int)v7, (unsigned int)v8);
v2 = -1;
}
}
else
{
printf("buf should be: %s\n", "CP ");
printf("%c%c%c%c%c\n", (unsigned int)s1, (unsigned int)v5, (unsigned int)v6, (unsigned int)v7, (unsigned int)v8);
puts("buf was unequal to MAKSTRIPE_CLONE_RESP.");
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func19(int fd)
{
unsigned int v1; // eax
unsigned int v2; // ebx
char s1; // [rsp+Bh] [rbp-Dh] BYREF
char v5; // [rsp+Ch] [rbp-Ch]
char v6; // [rsp+Dh] [rbp-Bh]
char v7; // [rsp+Eh] [rbp-Ah]
char v8; // [rsp+Fh] [rbp-9h]

s1 = 67;
v5 = 7;
v1 = func10(fd, &s1, 2uLL);
printf("Serial write status: %i\n", v1);
func9(fd, &s1, 3LL);
if ( !memcmp(&s1, "CP ", 3uLL) )
{
puts("Ready to clone from Makstripe buffer to card.");
puts("Please swipe blank card");
v2 = func9(fd, &s1, 5LL);
if ( !memcmp(&s1, "CP=OK", 5uLL) )
{
printf("Clone succesfull: %i\n", v2);
}
else
{
printf("We expect a string of length: %i\n", 5LL);
printf("buf was unequal to MAKSTRIPE_CLONE_STS_OK: %s\n", "CP=OK");
printf("%c%c%c%c%c\n", (unsigned int)s1, (unsigned int)v5, (unsigned int)v6, (unsigned int)v7, (unsigned int)v8);
v2 = -1;
}
}
else
{
printf("buf should be: %s\n", "CP ");
printf("%c%c%c%c%c\n", (unsigned int)s1, (unsigned int)v5, (unsigned int)v6, (unsigned int)v7, (unsigned int)v8);
puts("buf was unequal to MAKSTRIPE_CLONE_RESP.");
v2 = -1;
}
return v2;
}

original_code:
int
mak_clone(int fd)
{
 int c;
 char buf[strlen("CP=OK")];
 buf[0] = 'C';
 buf[1] = 0x7;
 c = serial_write(fd, buf, 2);
 printf("Serial write status: %i\n", c);
 c = serial_read(fd, buf, strlen("CP "));
 if (memcmp(buf, "CP ", strlen("CP ")) != 0) {
  printf("buf should be: %s\n", "CP ");
  printf("%c%c%c%c%c\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
  printf("buf was unequal to MAKSTRIPE_CLONE_RESP.\n");
  return -1;
 }
 printf("Ready to clone from Makstripe buffer to card.\n");
 printf("Please swipe blank card\n");
 c = serial_read(fd, buf, strlen("CP=OK"));
 if (memcmp(buf, "CP=OK", strlen("CP=OK")) != 0) {
  printf("We expect a string of length: %i\n", strlen("CP=OK"));
  printf("buf was unequal to MAKSTRIPE_CLONE_STS_OK: %s\n", "CP=OK");
  printf("%c%c%c%c%c\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
  return -1;
 }
 printf("Clone succesfull: %i\n", c);
 return c;
}

canonical_original_code:
int mak_clone(int fd)
{
 int c;
 char buf[-1];
 buf[0] = 'C';
 buf[1] = 0x7;
 c = serial_write(fd, buf, 2);
 printf("Serial write status: %i\n", c);
 c = serial_read(fd, buf, strlen("CP "));
 if (memcmp(buf, "CP ", strlen("CP ")) != 0) {
  printf("buf should be: %s\n", "CP ");
  printf("%c%c%c%c%c\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
  printf("buf was unequal to MAKSTRIPE_CLONE_RESP.\n");
  return -1;
 }
 printf("Ready to clone from Makstripe buffer to card.\n");
 printf("Please swipe blank card\n");
 c = serial_read(fd, buf, strlen("CP=OK"));
 if (memcmp(buf, "CP=OK", strlen("CP=OK")) != 0) {
  printf("We expect a string of length: %i\n", strlen("CP=OK"));
  printf("buf was unequal to MAKSTRIPE_CLONE_STS_OK: %s\n", "CP=OK");
  printf("%c%c%c%c%c\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
  return -1;
 }
 printf("Clone succesfull: %i\n", c);
 return c;
}

variable_types: fd int

variable_types: c int


decompiled_code:
__int64 __fastcall mak_successful_clone(int fd)
{
__int64 result; // rax

do
result = mak_clone(fd);
while ( (_DWORD)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(int fd)
{
__int64 result; // rax

do
result = func19(fd);
while ( (_DWORD)result );
return result;
}

original_code:
int
mak_successful_clone(int fd)
{
 int r;
 do {
  r = mak_clone(fd);
 } while (r != 0);
 return r;
}


decompiled_code:
__int64 __fastcall reverse_byte(unsigned int a1)
{
unsigned int v1; // eax

v1 = a1;
LOBYTE(v1) = (unsigned __int8)a1 >> 7;
return (32 * (_BYTE)a1) & 0x40 | (8 * (_BYTE)a1) & 0x20 | (2 * (_BYTE)a1) & 0x10 | ((int)(unsigned __int8)a1 >> 1) & 8 | ((int)(unsigned __int8)a1 >> 3) & 4 | ((int)(unsigned __int8)a1 >> 5) & 2 | ((unsigned __int8)a1 << 7) | v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
unsigned int v1; // eax

v1 = a1;
LOBYTE(v1) = (unsigned __int8)a1 >> 7;
return (32 * (_BYTE)a1) & 0x40 | (8 * (_BYTE)a1) & 0x20 | (2 * (_BYTE)a1) & 0x10 | ((int)(unsigned __int8)a1 >> 1) & 8 | ((int)(unsigned __int8)a1 >> 3) & 4 | ((int)(unsigned __int8)a1 >> 5) & 2 | ((unsigned __int8)a1 << 7) | v1;
}

variable_types:
byte
unsigned char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__off_t v4; // rbx
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( argc <= 1 )
{
printf("Usage: %s [file]\n", *argv);
exit(1);
}
v3 = open(argv[1], 0, envp);
v4 = lseek(v3, 0LL, 2);
while ( v4 > 0 )
{
v4 = lseek(v3, v4 - 1, 0);
read(v3, buf, 1uLL);
buf[0] = reverse_byte((unsigned __int8)buf[0]);
write(2, buf, 1uLL);
}
close(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__off_t v4; // rbx
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( argc <= 1 )
{
printf("Usage: %s [file]\n", *argv);
exit(1);
}
v3 = open(argv[1], 0, envp);
v4 = lseek(v3, 0LL, 2);
while ( v4 > 0 )
{
v4 = lseek(v3, v4 - 1, 0);
read(v3, buf, 1uLL);
buf[0] = func7((unsigned __int8)buf[0]);
write(2, buf, 1uLL);
}
close(v3);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int fd = -1;
 off_t filepos;
 unsigned char byte;
 if (argc < 2)
 {
  printf("Usage: %s [file]\n", argv[0]);
  exit(1);
 }
 fd = open(argv[1], 00);
 filepos = lseek(fd, 0, 2);
 while (filepos > 0)
 {
  filepos = lseek(fd, filepos - 1, 0);
  read(fd, &byte, 1);
  byte = reverse_byte(byte);
  write(2, &byte, 1);
 }
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int fd = -1;
 long filepos;
 unsigned char byte;
 if (argc < 2)
 {
  printf("Usage: %s [file]\n", argv[0]);
  exit(1);
 }
 fd = open(argv[1], 00);
 filepos = lseek(fd, 0, 2);
 while (filepos > 0)
 {
  filepos = lseek(fd, filepos - 1, 0);
  read(fd, &byte, 1);
  byte = reverse_byte(byte);
  write(2, &byte, 1);
 }
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: filepos long


rshift

decompiled_code:
__int64 __fastcall rshift(__int16 a1, unsigned __int8 a2, char a3)
{
return (int)(unsigned __int16)(a2 | (unsigned __int16)(a1 << 8)) >> (8 - a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int16 a1, unsigned __int8 a2, char a3)
{
return (int)(unsigned __int16)(a2 | (unsigned __int16)(a1 << 8)) >> (8 - a3);
}

original_code:
unsigned char rshift(unsigned char a, unsigned char b, int shift)
{
    return (((unsigned short)(a<<8 | b) >> (8 - shift)) & 0x00ff);
}

variable_types:
a
unsigned char

variable_types:
b
unsigned char

variable_types: shift int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
ssize_t v4; // rbx
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
char v7; // [rsp+Dh] [rbp-1Bh] BYREF
unsigned __int8 v8; // [rsp+Eh] [rbp-1Ah] BYREF
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( argc <= 2 )
{
printf("Usage: %s [file] [offset]\n", *argv);
exit(1);
}
sscanf(argv[2], "%d", &v6);
if ( v6 > 7 )
{
puts("Error: Offset must be between 0 and 7 (inclusive).");
exit(1);
}
printf("Offset: %d bits.\n", v6);
v3 = open(argv[1], 0);
read(v3, buf, 1uLL);
do
{
v4 = read(v3, &v8, 1uLL);
v7 = rshift((unsigned __int8)buf[0], v8, v6);
write(2, &v7, 1uLL);
buf[0] = v8;
}
while ( v4 );
close(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
ssize_t v4; // rbx
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
char v7; // [rsp+Dh] [rbp-1Bh] BYREF
unsigned __int8 v8; // [rsp+Eh] [rbp-1Ah] BYREF
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( argc <= 2 )
{
printf("Usage: %s [file] [offset]\n", *argv);
exit(1);
}
sscanf(argv[2], "%d", &v6);
if ( v6 > 7 )
{
puts("Error: Offset must be between 0 and 7 (inclusive).");
exit(1);
}
printf("Offset: %d bits.\n", v6);
v3 = open(argv[1], 0);
read(v3, buf, 1uLL);
do
{
v4 = read(v3, &v8, 1uLL);
v7 = func7((unsigned __int8)buf[0], v8, v6);
write(2, &v7, 1uLL);
buf[0] = v8;
}
while ( v4 );
close(v3);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int fd = -1;
 ssize_t bytes_read = 0;
 unsigned char a, b, byte;
 int offset;
 if (argc < 3)
 {
  printf("Usage: %s [file] [offset]\n", argv[0]);
  exit(1);
 }
 sscanf(argv[2], "%d", &offset);
 if (offset < 0 || offset > 7)
 {
  printf("Error: Offset must be between 0 and 7 (inclusive).\n");
  exit(1);
 }
 printf("Offset: %d bits.\n", offset);
 fd = open(argv[1], 00);
 read(fd, &a, 1);
 do
 {
  bytes_read = read(fd, &b, 1);
  byte = rshift(a, b, offset);
  write(2, &byte, 1);
  a = b;
 }
 while (bytes_read != 0);
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int fd = -1;
 long bytes_read = 0;
 unsigned char a; unsigned char b; unsigned char byte;
 int offset;
 if (argc < 3)
 {
  printf("Usage: %s [file] [offset]\n", argv[0]);
  exit(1);
 }
 sscanf(argv[2], "%d", &offset);
 if (offset < 0 || offset > 7)
 {
  printf("Error: Offset must be between 0 and 7 (inclusive).\n");
  exit(1);
 }
 printf("Offset: %d bits.\n", offset);
 fd = open(argv[1], 00);
 read(fd, &a, 1);
 do
 {
  bytes_read = read(fd, &b, 1);
  byte = rshift(a, b, offset);
  write(2, &byte, 1);
  a = b;
 }
 while (bytes_read != 0);
 close(fd);
 return 0;
}

variable_types: offset int


decompiled_code:
__int64 __fastcall do_leet_led_dance(unsigned int a1)
{
int v1; // ebp

v1 = 3;
do
{
msr_flash_led(a1, 129LL);
msr_flash_led(a1, 131LL);
msr_flash_led(a1, 132LL);
msr_flash_led(a1, 133LL);
usleep(0x186A0u);
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
int v1; // ebp

v1 = 3;
do
{
msr_flash_led(a1, 129LL);
msr_flash_led(a1, 131LL);
msr_flash_led(a1, 132LL);
msr_flash_led(a1, 133LL);
usleep(0x186A0u);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
int
do_leet_led_dance (int fd)
{
 int z = 0;
 while (z < 3) {
 msr_flash_led(fd, 0x81);
 msr_flash_led(fd, 0x83);
 msr_flash_led(fd, 0x84);
 msr_flash_led(fd, 0x85);
 usleep (100000);
 z++;
 }
 return(0);
}

canonical_original_code:
int do_leet_led_dance(int fd)
{
 int z = 0;
 while (z < 3) {
 msr_flash_led(fd, 0x81);
 msr_flash_led(fd, 0x83);
 msr_flash_led(fd, 0x84);
 msr_flash_led(fd, 0x85);
 usleep (100000);
 z++;
 }
 return(0);
}

variable_types: z int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
_BYTE *v4; // rbx
unsigned int v5; // ebp
_BYTE v6[780]; // [rsp+0h] [rbp-328h] BYREF
unsigned int v7[7]; // [rsp+30Ch] [rbp-1Ch] BYREF

v7[0] = -1;
v3 = argv[1];
if ( !v3 )
{
printf("no device specified, defaulting to %s\n", "/dev/ttyS0");
v3 = "/dev/ttyS0";
}
if ( (unsigned int)serial_open(v3, v7, 2048LL, 13LL) != -1 )
{
msr_init(v7[0]);
msr_model(v7[0]);
msr_fwrev(v7[0]);
msr_set_lo_co(v7[0]);
msr_sensor_test(v7[0]);
msr_ram_test(v7[0]);
puts("Preparing reader for reading...");
do_leet_led_dance(v7[0]);
puts("Ready to read an ISO formatted card. Please slide a card.");
bzero(v6, 0x300uLL);
v6[255] = -1;
v6[511] = -1;
v6[767] = -1;
msr_iso_read(v7[0], v6);
v4 = v6;
v5 = 0;
while ( 1 )
{
if ( v4[255] )
printf("track%d: [%s]\n", v5, v4);
++v5;
v4 += 256;
if ( v5 == 3 )
{
msr_init(v7[0]);
puts("Attempting erase, please swipe card...");
msr_erase(v7[0], 7LL);
msr_init(v7[0]);
puts("Attempting ISO write, please swipe card...");
msr_iso_write(v7[0], v6);
puts("write complete");
msr_init(v7[0]);
serial_close(v7[0]);
exit(0);
}
}
}
err(1, "Serial open of %s failed", v3);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
_BYTE *v4; // rbx
unsigned int v5; // ebp
_BYTE v6[780]; // [rsp+0h] [rbp-328h] BYREF
unsigned int v7[7]; // [rsp+30Ch] [rbp-1Ch] BYREF

v7[0] = -1;
v3 = argv[1];
if ( !v3 )
{
printf("no device specified, defaulting to %s\n", "/dev/ttyS0");
v3 = "/dev/ttyS0";
}
if ( (unsigned int)serial_open(v3, v7, 2048LL, 13LL) != -1 )
{
msr_init(v7[0]);
msr_model(v7[0]);
msr_fwrev(v7[0]);
msr_set_lo_co(v7[0]);
msr_sensor_test(v7[0]);
msr_ram_test(v7[0]);
puts("Preparing reader for reading...");
func0(v7[0]);
puts("Ready to read an ISO formatted card. Please slide a card.");
bzero(v6, 0x300uLL);
v6[255] = -1;
v6[511] = -1;
v6[767] = -1;
msr_iso_read(v7[0], v6);
v4 = v6;
v5 = 0;
while ( 1 )
{
if ( v4[255] )
printf("track%d: [%s]\n", v5, v4);
++v5;
v4 += 256;
if ( v5 == 3 )
{
msr_init(v7[0]);
puts("Attempting erase, please swipe card...");
msr_erase(v7[0], 7LL);
msr_init(v7[0]);
puts("Attempting ISO write, please swipe card...");
msr_iso_write(v7[0], v6);
puts("write complete");
msr_init(v7[0]);
serial_close(v7[0]);
exit(0);
}
}
}
err(1, "Serial open of %s failed", v3);
}

original_code:
int main(int argc, char * argv[])
{
 int fd = -1;
 int serial;
 msr_tracks_t tracks;
 int i;
 char *device = "/dev/ttyS0";
 if (argv[1] != ((void *)0))
  device = argv[1];
 else
  printf ("no device specified, defaulting to %s\n", device);
 serial = serial_open (device, &fd, 04000, 0000015);
 if (serial == -1) {
  err(1, "Serial open of %s failed", device);
  exit(1);
 }
 msr_init (fd);
 msr_model (fd);
 msr_fwrev (fd);
 msr_set_lo_co (fd);
 msr_sensor_test (fd);
 msr_ram_test (fd);
 printf("Preparing reader for reading...\n");
 do_leet_led_dance (fd);
 printf("Ready to read an ISO formatted card. Please slide a card.\n");
 bzero ((char *)&tracks, sizeof(tracks));
 for (i = 0; i < 3; i++)
  tracks.msr_tracks[i].msr_tk_len = 255;
 msr_iso_read (fd, &tracks);
 for (i = 0; i < 3; i++) {
  if (tracks.msr_tracks[i].msr_tk_len)
   printf ("track%d: [%s]\n", i,
    tracks.msr_tracks[i].msr_tk_data);
 }
 msr_init (fd);
 printf ("Attempting erase, please swipe card...\n");
 msr_erase (fd, 0x07);
 msr_init (fd);
 printf ("Attempting ISO write, please swipe card...\n");
 msr_iso_write (fd, &tracks);
 printf ("write complete\n");
 msr_init (fd);
 serial_close (fd);
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd = -1;
 int serial;
 struct msr_tracks tracks;
 int i;
 char *device = "/dev/ttyS0";
 if (argv[1] != ((void *)0))
  device = argv[1];
 else
  printf ("no device specified, defaulting to %s\n", device);
 serial = serial_open (device, &fd, 04000, 0000015);
 if (serial == -1) {
  err(1, "Serial open of %s failed", device);
  exit(1);
 }
 msr_init (fd);
 msr_model (fd);
 msr_fwrev (fd);
 msr_set_lo_co (fd);
 msr_sensor_test (fd);
 msr_ram_test (fd);
 printf("Preparing reader for reading...\n");
 do_leet_led_dance (fd);
 printf("Ready to read an ISO formatted card. Please slide a card.\n");
 bzero ((char *)&tracks, sizeof(tracks));
 for (i = 0; i < 3; i++)
  tracks.msr_tracks[i].msr_tk_len = 255;
 msr_iso_read (fd, &tracks);
 for (i = 0; i < 3; i++) {
  if (tracks.msr_tracks[i].msr_tk_len)
   printf ("track%d: [%s]\n", i,
    tracks.msr_tracks[i].msr_tk_data);
 }
 msr_init (fd);
 printf ("Attempting erase, please swipe card...\n");
 msr_erase (fd, 0x07);
 msr_init (fd);
 printf ("Attempting ISO write, please swipe card...\n");
 msr_iso_write (fd, &tracks);
 printf ("write complete\n");
 msr_init (fd);
 serial_close (fd);
 exit(0);
}

variable_types:
argv
char *[]

variable_types: serial int

variable_types: struct msr_tracks { struct msr_track { unsigned char msr_tk_data[255]; unsigned char msr_tk_len; } msr_tracks[3]; }

variable_types:
device
char *


repo: iomz/DARSH

decompiled_code:
__int64 __fastcall permute_str(const char *a1, const char *a2, const char *a3)
{
int v3; // er13
int v4; // eax
int v5; // er15
int v6; // ebx
size_t v7; // r14
char dest[312]; // [rsp+10h] [rbp-138h] BYREF

dest[0] = (unsigned __int8)&unk_71F;
v3 = strlen(a1);
v4 = strlen(a2);
if ( v3 >= 0 )
{
v5 = v4;
v6 = 0;
v7 = v4;
do
{
if ( !strncmp(&a1[v6], a2, v7) )
{
strcat(dest, a3);
v6 = v6 + v5 - 1;
}
else
{
strncat(dest, &a1[v6], 1uLL);
}
++v6;
}
while ( v3 >= v6 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2, const char *a3)
{
int v3; // er13
int v4; // eax
int v5; // er15
int v6; // ebx
size_t v7; // r14
char dest[312]; // [rsp+10h] [rbp-138h] BYREF

dest[0] = (unsigned __int8)&unk_71F;
v3 = strlen(a1);
v4 = strlen(a2);
if ( v3 >= 0 )
{
v5 = v4;
v6 = 0;
v7 = v4;
do
{
if ( !strncmp(&a1[v6], a2, v7) )
{
strcat(dest, a3);
v6 = v6 + v5 - 1;
}
else
{
strncat(dest, &a1[v6], 1uLL);
}
++v6;
}
while ( v3 >= v6 );
}
return 0LL;
}

original_code:
char *permute_str(const char *a, const char *b, const char *c)
{
 int i = 0, max_a, max_b;
 char result[256];
 result[0] = "\0";
 max_a = strlen(a);
 max_b = strlen(b);
 for (i = 0; i <= max_a; i++) {
  if (0 == strncmp(&a[i], b, max_b)) {
   strcat(result, c);
   i += max_b - 1;
  } else {
   strncat(result, &a[i], 1);
  }
 }
 return result;
}

canonical_original_code:
char *permute_str(char *a, char *b, char *c)
{
 int i = 0; int max_a; int max_b;
 char result[256];
 result[0] = "\0";
 max_a = strlen(a);
 max_b = strlen(b);
 for (i = 0; i <= max_a; i++) {
  if (0 == strncmp(&a[i], b, max_b)) {
   strcat(result, c);
   i += max_b - 1;
  } else {
   strncat(result, &a[i], 1);
  }
 }
 return result;
}

variable_types:
a
char *

variable_types:
b
char *

variable_types:
c
char *

variable_types: i int

variable_types:
result
char [256]

return_type: char *


decompiled_code:
__int64 __fastcall read_line(int fd, void *buf)
{
unsigned int i; // ebp
int v4; // eax

for ( i = 0; ; ++i )
{
v4 = read(fd, buf, 1uLL);
if ( v4 == -1 )
{
perror("read");
return (unsigned int)-1;
}
if ( !v4 )
break;
if ( *(_BYTE *)buf == 10 )
{
buf = (char *)buf + 1;
++i;
break;
}
if ( !*(_BYTE *)buf )
{
++i;
break;
}
buf = (char *)buf + 1;
}
*(_BYTE *)buf = 0;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf)
{
unsigned int i; // ebp
int v4; // eax

for ( i = 0; ; ++i )
{
v4 = read(fd, buf, 1uLL);
if ( v4 == -1 )
{
perror("read");
return (unsigned int)-1;
}
if ( !v4 )
break;
if ( *(_BYTE *)buf == 10 )
{
buf = (char *)buf + 1;
++i;
break;
}
if ( !*(_BYTE *)buf )
{
++i;
break;
}
buf = (char *)buf + 1;
}
*(_BYTE *)buf = 0;
return i;
}

original_code:
int read_line(int socket, char *p)
{
 int len = 0;
 while (1) {
  int ret;
  ret = read(socket, p, 1);
  if (ret == -1) {
   perror("read");
   return -1;
  } else if (ret == 0) {
   break;
  }
  if (*p == '\n') {
   p++;
   len++;
   break;
  }
  if (*p == '\0') {
   len++;
   break;
  }
  p++;
  len++;
 }
 *p = '\0';
 return len;
}

variable_types: socket int

variable_types:
p
char *

variable_types: len int

variable_types: ret int


decompiled_code:
char *get_host()
{
struct utsname *v0; // rbx

v0 = (struct utsname *)malloc(0x186uLL);
if ( uname(v0) < 0 )
fwrite("failed to uname()", 1uLL, 0x11uLL, stderr);
return v0->nodename;
}

canonical_decompiled_code:
char *func3()
{
struct utsname *v0; // rbx

v0 = (struct utsname *)malloc(0x186uLL);
if ( uname(v0) < 0 )
fwrite("failed to uname()", 1uLL, 0x11uLL, stderr);
return v0->nodename;
}

original_code:
char *get_host(void)
{
 struct utsname *uname_info;
 uname_info = (struct utsname *)malloc(sizeof(struct utsname));
 if (uname(uname_info) < 0) {
  fprintf(stderr, "failed to uname()");
 }
 return uname_info->nodename;
}

canonical_original_code:
char *get_host()
{
 struct utsname *uname_info;
 uname_info = (struct utsname *)malloc(sizeof(struct utsname));
 if (uname(uname_info) < 0) {
  fprintf(stderr, "failed to uname()");
 }
 return uname_info->nodename;
}

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; } *


decompiled_code:
char *__fastcall get_ip(char *src)
{
int v1; // ebx
char v3[16]; // [rsp+0h] [rbp-48h] BYREF
__int16 v4; // [rsp+10h] [rbp-38h]
struct in_addr in; // [rsp+14h] [rbp-34h]

v1 = socket(2, 2, 0);
v4 = 2;
strncpy(v3, src, 0xFuLL);
ioctl(v1, 0x8915uLL, v3);
close(v1);
return inet_ntoa(in);
}

canonical_decompiled_code:
char *__fastcall func4(char *src)
{
int v1; // ebx
char v3[16]; // [rsp+0h] [rbp-48h] BYREF
__int16 v4; // [rsp+10h] [rbp-38h]
struct in_addr in; // [rsp+14h] [rbp-34h]

v1 = socket(2, 2, 0);
v4 = 2;
strncpy(v3, src, 0xFuLL);
ioctl(v1, 0x8915uLL, v3);
close(v1);
return inet_ntoa(in);
}

original_code:
char *get_ip(char *interface_name) {
 int fd;
 struct ifreq ifr;
 fd = socket(2, SOCK_DGRAM, 0);
 ifr.ifr_ifru.ifru_addr.sa_family = 2;
 strncpy(ifr.ifr_ifrn.ifrn_name, interface_name, 16 -1);
 ioctl(fd, 0x8915, &ifr);
 close(fd);
 return inet_ntoa(((struct sockaddr_in *)&ifr.ifr_ifru.ifru_addr)->sin_addr);
}

variable_types: fd int

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
__int64 __fastcall get_client_info(char *src, char *a2)
{
char *v2; // rbx
char v4[3]; // [rsp+0h] [rbp-108h] BYREF

strcpy(v4, src);
v2 = get_ip(a2);
strcat(v4, ", ");
strcat(v4, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *src, char *a2)
{
char *v2; // rbx
char v4[3]; // [rsp+0h] [rbp-108h] BYREF

strcpy(v4, src);
v2 = func4(a2);
strcat(v4, ", ");
strcat(v4, v2);
return 0LL;
}

original_code:
char *get_client_info(char *host_id, char *interface_name)
{
 char client_info[256];
 strcpy(client_info, host_id);
 char *client_ip = get_ip(interface_name);
 strcat(client_info, ", ");
 strcat(client_info, client_ip);
 strcat(client_info, "\n");
 return client_info;
}


decompiled_code:
__int64 __fastcall get_client_info_FQDN(char *src)
{
char *v1; // rax
size_t v2; // rax
char v4[256]; // [rsp+0h] [rbp-208h] BYREF
char dest[264]; // [rsp+100h] [rbp-108h] BYREF

strcpy(dest, src);
v1 = get_host();
strcpy(v4, v1);
strcat(dest, ", ");
v2 = strlen(v4);
strncat(dest, v4, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *src)
{
char *v1; // rax
size_t v2; // rax
char v4[256]; // [rsp+0h] [rbp-208h] BYREF
char dest[264]; // [rsp+100h] [rbp-108h] BYREF

strcpy(dest, src);
v1 = func3();
strcpy(v4, v1);
strcat(dest, ", ");
v2 = strlen(v4);
strncat(dest, v4, v2);
return 0LL;
}

original_code:
char *get_client_info_FQDN(char *host_id)
{
 char client_info[256];
 char host_name[256];
 strcpy(client_info, host_id);
 strcpy(host_name, get_host());
 strcat(client_info, ", ");
 strncat(client_info, host_name, strlen(host_name));
 strcat(client_info, "\n");
 return client_info;
}