deleteTree

decompiled_code:
__int64 __fastcall deleteTree(__int64 a1)
{
return postorderTraverse(a1, (__int64 (__fastcall *)(__int64))deleteNode);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return func7(a1, (__int64 (__fastcall *)(__int64))deleteNode);
}

original_code:
void deleteTree(Tree tree)
{
  postorderTraverse(tree, deleteNode);
}

canonical_original_code:
void deleteTree(struct TreeNode *tree)
{
  postorderTraverse(tree, deleteNode);
}


inorderTraverse

repo: Karlinha/CompiladoresI

decompiled_code:
__int64 __fastcall inorderTraverse(__int64 a1, __int64 (__fastcall *a2)(__int64))
{
unsigned int v2; // ebx
__int64 result; // rax

if ( a1 && *(_DWORD *)(a1 + 36) )
{
v2 = 0;
do
{
postorderTraverse(*(_QWORD *)(*(_QWORD *)(a1 + 40) + 8LL * v2), a2);
result = a2(a1);
++v2;
}
while ( *(_DWORD *)(a1 + 36) > v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 (__fastcall *a2)(__int64))
{
unsigned int v2; // ebx
__int64 result; // rax

if ( a1 && *(_DWORD *)(a1 + 36) )
{
v2 = 0;
do
{
func7(*(_QWORD *)(*(_QWORD *)(a1 + 40) + 8LL * v2), a2);
result = a2(a1);
++v2;
}
while ( *(_DWORD *)(a1 + 36) > v2 );
}
return result;
}

original_code:
void inorderTraverse(Tree tree,
                     NodeFunction *nodeFunction)
{
  unsigned i;
  if ((Tree)((void *)0) != tree) {
    for(i = 0; i < tree->nrBranches; i++) {
      postorderTraverse(tree->branches[i], nodeFunction);
      nodeFunction(tree);
    }
  }
}

canonical_original_code:
void inorderTraverse(struct TreeNode *tree, void (*nodeFunction)(struct TreeNode *node))
{
  unsigned int i;
  if ((Tree)((void *)0) != tree) {
    for(i = 0; i < tree->nrBranches; i++) {
      postorderTraverse(tree->branches[i], nodeFunction);
      nodeFunction(tree);
    }
  }
}

variable_types: struct TreeNode { char *name; char *parent; unsigned int height; unsigned int width; unsigned int depth; int x; int y; unsigned int nrBranches; struct TreeNode **branches; } *

variable_types:
nodeFunction
void (*)(struct TreeNode *node)

variable_types:
i
unsigned int

return_type: void


preorderTraverse

decompiled_code:
__int64 __fastcall preorderTraverse(__int64 a1, __int64 (*a2)(void))
{
__int64 result; // rax
unsigned int v3; // ebx

if ( a1 )
{
result = a2();
if ( *(_DWORD *)(a1 + 36) )
{
v3 = 0;
do
result = preorderTraverse(*(_QWORD *)(*(_QWORD *)(a1 + 40) + 8LL * v3++), a2);
while ( *(_DWORD *)(a1 + 36) > v3 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 (*a2)(void))
{
__int64 result; // rax
unsigned int v3; // ebx

if ( a1 )
{
result = a2();
if ( *(_DWORD *)(a1 + 36) )
{
v3 = 0;
do
result = func10(*(_QWORD *)(*(_QWORD *)(a1 + 40) + 8LL * v3++), a2);
while ( *(_DWORD *)(a1 + 36) > v3 );
}
}
return result;
}

original_code:
void preorderTraverse(Tree tree,
                      NodeFunction *nodeFunction)
{
  unsigned i;
  if(tree != (Tree)((void *)0)) {
    nodeFunction(tree);
    for(i = 0; i < tree->nrBranches; i++)
      preorderTraverse(tree->branches[i], nodeFunction);
  }
}

canonical_original_code:
void preorderTraverse(struct TreeNode *tree, void (*nodeFunction)(struct TreeNode *node))
{
  unsigned int i;
  if(tree != (Tree)((void *)0)) {
    nodeFunction(tree);
    for(i = 0; i < tree->nrBranches; i++)
      preorderTraverse(tree->branches[i], nodeFunction);
  }
}

user_defined_types: struct TreeNode { char *name; char *parent; unsigned int height; unsigned int width; unsigned int depth; int x; int y; unsigned int nrBranches; struct TreeNode **branches; }


shapeTree

decompiled_code:
void __fastcall shapeTree(__int64 a1, unsigned int *a2, unsigned int *a3, unsigned int *a4, int a5, unsigned int a6)
{
unsigned int v10; // eax
_DWORD *v11; // r15
unsigned int v12; // ebx
_DWORD *v13; // [rsp+8h] [rbp-50h]
void *v14; // [rsp+10h] [rbp-48h] BYREF
void *ptr; // [rsp+18h] [rbp-40h] BYREF

v10 = treeHeight(a1, a6);
*a2 = v10;
doShapeTree(a1, v10, a6, (unsigned int **)&ptr, (unsigned int **)&v14, a5, a6);
*a3 = 0;
*a4 = 0;
if ( *a2 )
{
v11 = ptr;
v13 = v14;
v12 = 0;
do
{
*a3 = intMax(*a3, v11[v12 + 1]);
*a4 = intMax(*a4, v13[++v12]);
}
while ( *a2 > v12 );
}
free(ptr);
free(v14);
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, unsigned int *a2, unsigned int *a3, unsigned int *a4, int a5, unsigned int a6)
{
unsigned int v10; // eax
_DWORD *v11; // r15
unsigned int v12; // ebx
_DWORD *v13; // [rsp+8h] [rbp-50h]
void *v14; // [rsp+10h] [rbp-48h] BYREF
void *ptr; // [rsp+18h] [rbp-40h] BYREF

v10 = func3(a1, a6);
*a2 = v10;
func5(a1, v10, a6, (unsigned int **)&ptr, (unsigned int **)&v14, a5, a6);
*a3 = 0;
*a4 = 0;
if ( *a2 )
{
v11 = ptr;
v13 = v14;
v12 = 0;
do
{
*a3 = func0(*a3, v11[v12 + 1]);
*a4 = func0(*a4, v13[++v12]);
}
while ( *a2 > v12 );
}
free(ptr);
free(v14);
}

original_code:
void shapeTree(Tree tree,
               unsigned *height,
               unsigned *leftWidth,
               unsigned *rightWidth,
               unsigned xSeparation,
               unsigned ySeparation)
{
  unsigned i;
  edge *left;
  edge *right;
  *height = treeHeight(tree, ySeparation);
  doShapeTree(tree, *height, ySeparation, &left, &right,
              xSeparation, ySeparation);
  *leftWidth = 0;
  *rightWidth = 0;
  for (i = 0; i < *height; i++) {
    *leftWidth = (unsigned)intMax((int)*leftWidth, left->offset[i]);
    *rightWidth = (unsigned)intMax((int)*rightWidth, right->offset[i]);
  }
  (void)free((char *)left);
  (void)free((char *)right);
}

canonical_original_code:
void shapeTree(struct TreeNode *tree, unsigned int *height, unsigned int *leftWidth, unsigned int *rightWidth, unsigned int xSeparation, unsigned int ySeparation)
{
  unsigned int i;
  struct edge *left;
  struct edge *right;
  *height = treeHeight(tree, ySeparation);
  doShapeTree(tree, *height, ySeparation, &left, &right,
              xSeparation, ySeparation);
  *leftWidth = 0;
  *rightWidth = 0;
  for (i = 0; i < *height; i++) {
    *leftWidth = (unsigned int)intMax((int)*leftWidth, left->offset[i]);
    *rightWidth = (unsigned int)intMax((int)*rightWidth, right->offset[i]);
  }
  (void)free((char *)left);
  (void)free((char *)right);
}

variable_types:
height
unsigned int *

variable_types:
leftWidth
unsigned int *

variable_types:
rightWidth
unsigned int *

variable_types:
xSeparation
unsigned int

variable_types:
ySeparation
unsigned int

variable_types: struct edge { unsigned int yPosition; int offset[1]; } *


inserir

decompiled_code:
__int64 __fastcall inserir(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(_QWORD *)(a2 + 16);
*(_QWORD *)(a1 + 24) = result;
*(_QWORD *)(a2 + 16) = a1;
return result;
}

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

result = *(_QWORD *)(a2 + 16);
*(_QWORD *)(a1 + 24) = result;
*(_QWORD *)(a2 + 16) = a1;
return result;
}

original_code:
void inserir(ArvoreGen* filho, ArvoreGen* pai)
{
    filho->prox = pai->prim;
    pai->prim = filho;
}

canonical_original_code:
void inserir(struct arvgen *filho, struct arvgen *pai)
{
    filho->prox = pai->prim;
    pai->prim = filho;
}

variable_types: struct arvgen { char *info; char *pai_nome; struct arvgen *prim; struct arvgen *prox; } *

variable_types:
pai
struct arvgen *


imprime

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

if ( a1 )
{
imprime(*(_QWORD *)(a1 + 24));
printf("%s %s\n", *(const char **)(a1 + 8), *(const char **)a1);
result = imprime(*(_QWORD *)(a1 + 16));
}
return result;
}

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

if ( a1 )
{
func1(*(_QWORD *)(a1 + 24));
printf("%s %s\n", *(const char **)(a1 + 8), *(const char **)a1);
result = func1(*(_QWORD *)(a1 + 16));
}
return result;
}

original_code:
void imprime (ArvoreGen* a)
{
    if(a != ((void *)0)) {
        ArvoreGen* p = a;
  imprime(p->prox);
  printf("%s %s\n",p->pai_nome, p->info);
  imprime(p->prim);
    }
}

canonical_original_code:
void imprime(struct arvgen *a)
{
    if(a != ((void *)0)) {
        struct arvgen *p = a;
  imprime(p->prox);
  printf("%s %s\n",p->pai_nome, p->info);
  imprime(p->prim);
    }
}

user_defined_types: struct arvgen { char *info; char *pai_nome; struct arvgen *prim; struct arvgen *prox; }


decompiled_code:
void __fastcall __noreturn my_handler(unsigned int a1)
{
printf("Caught SIGINT %d\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(unsigned int a1)
{
printf("Caught SIGINT %d\n", a1);
exit(1);
}

original_code:
void my_handler(int s)
{
    printf("Caught SIGINT %d\n", s);
    exit(1);
}

variable_types: s int


philosophe

decompiled_code:
void __fastcall __noreturn philosophe(unsigned int a1, __int64 a2)
{
unsigned int v2; // er13
unsigned int v3; // ebx
int *v4; // r15
int *v5; // r14
unsigned int j; // ebp
int v7; // eax
int v8; // eax
unsigned int i; // ebp
int v10; // eax
struct sigaction v11; // [rsp+0h] [rbp-D8h] BYREF

v11.sa_handler = (__sighandler_t)my_handler;
sigemptyset(&v11.sa_mask);
v11.sa_flags = 0;
sigaction(2, &v11, 0LL);
v2 = a1 + 1;
if ( a1 == 4 )
v2 = 0;
v3 = a1 + 1;
v4 = (int *)(a2 + 4LL * (int)a1);
v5 = (int *)(a2 + 4LL * (int)v2);
while ( 1 )
{
printf("Process : %i Etat : %i.\n", v3, 0LL);
v8 = rand();
sleep(v8 % 10);
printf("Process : %i et j'ai fini de dormir.\n", v3);
printf("Process : %i Etat : %i.\n", v3, 1LL);
for ( i = 1; ; ++i )
{
printf("Process : %i et je demande ma fourchette gauche (%i).\n", v3, a1);
if ( semop(*v4, &Reserver, 1uLL) != -1 )
break;
printf("Process : %i et je n'ai pas obtenu ma fourchette gauche (%i)(%i essais).\n", v3, a1, i);
v10 = rand();
sleep(v10 % 2);
}
printf("Process : %i et j'ai obtenu ma fourchette gauche (%i).\n", v3, a1);
for ( j = 1; ; ++j )
{
printf("Process : %i et je demande ma fourchette droite (%i).\n", v3, v2);
if ( semop(*v5, &Reserver, 1uLL) != -1 )
break;
printf("Process : %i et je n'ai pas obtenu ma fourchette droite (%i)(%i essais).\n", v3, v2, j);
sleep(1u);
}
printf("Process : %i et j'ai obtenu ma fourchette droite (%i).\n", v3, v2);
printf("Process : %i Etat : %i.\n", v3, 2LL);
printf("Process : %i Etat : %i.\n", v3, 2LL);
v7 = rand();
sleep(v7 % 15);
semop(*v4, &Liberer, 1uLL);
semop(*v5, &Liberer, 1uLL);
printf(aProcessIEtJeVi, v3);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(unsigned int a1, __int64 a2)
{
unsigned int v2; // er13
unsigned int v3; // ebx
int *v4; // r15
int *v5; // r14
unsigned int j; // ebp
int v7; // eax
int v8; // eax
unsigned int i; // ebp
int v10; // eax
struct sigaction v11; // [rsp+0h] [rbp-D8h] BYREF

v11.sa_handler = (__sighandler_t)my_handler;
sigemptyset(&v11.sa_mask);
v11.sa_flags = 0;
sigaction(2, &v11, 0LL);
v2 = a1 + 1;
if ( a1 == 4 )
v2 = 0;
v3 = a1 + 1;
v4 = (int *)(a2 + 4LL * (int)a1);
v5 = (int *)(a2 + 4LL * (int)v2);
while ( 1 )
{
printf("Process : %i Etat : %i.\n", v3, 0LL);
v8 = rand();
sleep(v8 % 10);
printf("Process : %i et j'ai fini de dormir.\n", v3);
printf("Process : %i Etat : %i.\n", v3, 1LL);
for ( i = 1; ; ++i )
{
printf("Process : %i et je demande ma fourchette gauche (%i).\n", v3, a1);
if ( semop(*v4, &Reserver, 1uLL) != -1 )
break;
printf("Process : %i et je n'ai pas obtenu ma fourchette gauche (%i)(%i essais).\n", v3, a1, i);
v10 = rand();
sleep(v10 % 2);
}
printf("Process : %i et j'ai obtenu ma fourchette gauche (%i).\n", v3, a1);
for ( j = 1; ; ++j )
{
printf("Process : %i et je demande ma fourchette droite (%i).\n", v3, v2);
if ( semop(*v5, &Reserver, 1uLL) != -1 )
break;
printf("Process : %i et je n'ai pas obtenu ma fourchette droite (%i)(%i essais).\n", v3, v2, j);
sleep(1u);
}
printf("Process : %i et j'ai obtenu ma fourchette droite (%i).\n", v3, v2);
printf("Process : %i Etat : %i.\n", v3, 2LL);
printf("Process : %i Etat : %i.\n", v3, 2LL);
v7 = rand();
sleep(v7 % 15);
semop(*v4, &Liberer, 1uLL);
semop(*v5, &Liberer, 1uLL);
printf(aProcessIEtJeVi, v3);
}
}

original_code:
void philosophe(int pPosition, int mtx_fork[])
{
    struct sigaction sigIntHandler;
    sigIntHandler.__sigaction_handler.sa_handler = my_handler;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(2, &sigIntHandler, ((void *)0));
    int gauche = pPosition;
    int droite = pPosition + 1 == 5 ? 0 : pPosition + 1;
    pPosition++;
    state myState;
    int i;
    while (1)
    {
        myState = THINK;
        printf("Process : %i Etat : %i.\n", pPosition, myState);
        sleep((int)rand() % 10);
        printf("Process : %i et j'ai fini de dormir.\n", pPosition);
        myState = STARVE;
        printf("Process : %i Etat : %i.\n", pPosition, myState);
        for (i = 1; ; ++i)
        {
            printf("Process : %i et je demande ma fourchette gauche (%i).\n", pPosition, gauche);
            if (semop(mtx_fork[gauche], &Reserver, 1) != -1 )
            {
                printf("Process : %i et j'ai obtenu ma fourchette gauche (%i).\n", pPosition, gauche);
                int j;
                for (j = 1; ; ++j)
                {
                    printf("Process : %i et je demande ma fourchette droite (%i).\n", pPosition, droite);
                    if (semop(mtx_fork[droite], &Reserver, 1) != -1 )
                    {
                        printf("Process : %i et j'ai obtenu ma fourchette droite (%i).\n", pPosition, droite);
                        break;
                    }
                    else
                    {
                        printf("Process : %i et je n'ai pas obtenu ma fourchette droite (%i)(%i essais).\n", pPosition, droite, j);
                        sleep(1);
                    }
                }
                break;
            }
            else
            {
                printf("Process : %i et je n'ai pas obtenu ma fourchette gauche (%i)(%i essais).\n", pPosition, gauche, i);
                sleep((int)rand() % 2);
            }
        }
        myState = EAT;
        printf("Process : %i Etat : %i.\n", pPosition, myState);
        printf("Process : %i Etat : %i.\n", pPosition, myState);
        sleep((int)rand() % 15);
        semop(mtx_fork[gauche], &Liberer, 1);
        semop(mtx_fork[droite], &Liberer, 1);
        printf("Process : %i et je viens de libérer mes fourchettes.\n", pPosition);
    }
}

canonical_original_code:
void philosophe(int pPosition, int mtx_fork[])
{
    struct sigaction sigIntHandler;
    sigIntHandler.__sigaction_handler.sa_handler = my_handler;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(2, &sigIntHandler, ((void *)0));
    int gauche = pPosition;
    int droite = pPosition + 1 == 5 ? 0 : pPosition + 1;
    pPosition++;
    enum state myState;
    int i;
    while (1)
    {
        myState = THINK;
        printf("Process : %i Etat : %i.\n", pPosition, myState);
        sleep((int)rand() % 10);
        printf("Process : %i et j'ai fini de dormir.\n", pPosition);
        myState = STARVE;
        printf("Process : %i Etat : %i.\n", pPosition, myState);
        for (i = 1; ; ++i)
        {
            printf("Process : %i et je demande ma fourchette gauche (%i).\n", pPosition, gauche);
            if (semop(mtx_fork[gauche], &Reserver, 1) != -1 )
            {
                printf("Process : %i et j'ai obtenu ma fourchette gauche (%i).\n", pPosition, gauche);
                int j;
                for (j = 1; ; ++j)
                {
                    printf("Process : %i et je demande ma fourchette droite (%i).\n", pPosition, droite);
                    if (semop(mtx_fork[droite], &Reserver, 1) != -1 )
                    {
                        printf("Process : %i et j'ai obtenu ma fourchette droite (%i).\n", pPosition, droite);
                        break;
                    }
                    else
                    {
                        printf("Process : %i et je n'ai pas obtenu ma fourchette droite (%i)(%i essais).\n", pPosition, droite, j);
                        sleep(1);
                    }
                }
                break;
            }
            else
            {
                printf("Process : %i et je n'ai pas obtenu ma fourchette gauche (%i)(%i essais).\n", pPosition, gauche, i);
                sleep((int)rand() % 2);
            }
        }
        myState = EAT;
        printf("Process : %i Etat : %i.\n", pPosition, myState);
        printf("Process : %i Etat : %i.\n", pPosition, myState);
        sleep((int)rand() % 15);
        semop(mtx_fork[gauche], &Liberer, 1);
        semop(mtx_fork[droite], &Liberer, 1);
        printf("Process : %i et je viens de libérer mes fourchettes.\n", pPosition);
    }
}

variable_types: pPosition int

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

variable_types: gauche int

variable_types: droite int

variable_types:
myState
enum state { THINK=0, STARVE=1, EAT=2 }

variable_types: i int

variable_types: j int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

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


decompiled_code:
int __fastcall my_handler_1(unsigned int a1)
{
return printf("Caught signal %d, going to kill myself\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
return printf("Caught signal %d, going to kill myself\n", a1);
}

original_code:
void my_handler_1(int s)
{
    printf("Caught signal %d, going to kill myself\n", s);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx
key_t v4; // eax
int v5; // eax
__pid_t v6; // eax
int *v7; // rbx
__pid_t v9; // eax
__pid_t v10; // eax
__pid_t v11; // eax
__pid_t v12; // eax
__pid_t *v13; // rbx
int v14[5]; // [rsp+0h] [rbp-F8h] BYREF
char v15; // [rsp+14h] [rbp-E4h] BYREF
int v16[5]; // [rsp+20h] [rbp-D8h] BYREF
char v17; // [rsp+34h] [rbp-C4h] BYREF
struct sigaction v18; // [rsp+40h] [rbp-B8h] BYREF

v18.sa_handler = (__sighandler_t)my_handler_1;
sigemptyset(&v18.sa_mask);
v18.sa_flags = 0;
sigaction(2, &v18, 0LL);
for ( i = 0LL; i != 5; ++i )
{
v4 = ftok("./", i);
v5 = semget(v4, 1, 944);
v16[i] = v5;
semctl(v5, 0, 16, 1LL);
}
v6 = fork();
v14[0] = v6 == 0;
if ( v6 )
{
v9 = fork();
v14[1] = v9 == 0;
if ( v9 )
{
v10 = fork();
v14[2] = v10 == 0;
if ( v10 )
{
v11 = fork();
v14[3] = v11 == 0;
if ( v11 )
{
v12 = fork();
v14[4] = v12 == 0;
if ( v12 )
{
v13 = v14;
do
waitpid(*v13++, 0LL, 0);
while ( v13 != (__pid_t *)&v15 );
}
else
{
sleep(0);
philosophe(4LL, v16);
}
}
else
{
sleep(0);
philosophe(3LL, v16);
}
}
else
{
sleep(0);
philosophe(2LL, v16);
}
}
else
{
sleep(0);
philosophe(1LL, v16);
}
}
else
{
sleep(0);
philosophe(0LL, v16);
}
v7 = v16;
do
semctl(*v7++, 0, 0, 0LL);
while ( v7 != (int *)&v17 );
return 0;
}

original_code:
int main(int argc, char const *argv[])
{
    struct sigaction sigIntHandler;
    sigIntHandler.__sigaction_handler.sa_handler = my_handler_1;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(2, &sigIntHandler, ((void *)0));
    int mtx_fork[5];
    int i;
    for (i = 0; i < 5; ++i)
    {
        mtx_fork[i] = semget ( ftok ( "./", i ), 1, 01000 | 0660 );
        semctl ( mtx_fork[i], 0, 16, 1);
    }
    int time = 0;
    int step = 8;
    pid_t lol[5];
    i = 0;
    if (lol[i++] = fork() == 0)
    {
        sleep(time);
        philosophe(i - 1, mtx_fork);
    }
    else if (lol[i++] = fork() == 0)
    {
        step = 8 - step;
        time += step;
        sleep(time);
        philosophe(i - 1, mtx_fork);
    }
    else if (lol[i++] = fork() == 0)
    {
        step = 8 - step;
        time += step;
        sleep(time);
        philosophe(i - 1, mtx_fork);
    }
    else if (lol[i++] = fork() == 0)
    {
        step = 8 - step;
        time += step;
        sleep(time);
        philosophe(i - 1, mtx_fork);
    }
    else if (lol[i++] = fork() == 0)
    {
        step = 8 - step;
        time += step;
        sleep(time);
        philosophe(i - 1, mtx_fork);
    }
    else
    {
        for (i = 0; i < 5; ++i)
        {
            waitpid(lol[i], ((void *)0), 0);
        }
    }
    for (i = 0; i < 5; ++i)
    {
        semctl ( mtx_fork[i], 0, 0, 0 );
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct sigaction sigIntHandler;
    sigIntHandler.__sigaction_handler.sa_handler = my_handler_1;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(2, &sigIntHandler, ((void *)0));
    int mtx_fork[5];
    int i;
    for (i = 0; i < 5; ++i)
    {
        mtx_fork[i] = semget ( ftok ( "./", i ), 1, 01000 | 0660 );
        semctl ( mtx_fork[i], 0, 16, 1);
    }
    int time = 0;
    int step = 8;
    int lol[5];
    i = 0;
    if (lol[i++] = fork() == 0)
    {
        sleep(time);
        philosophe(i - 1, mtx_fork);
    }
    else if (lol[i++] = fork() == 0)
    {
        step = 8 - step;
        time += step;
        sleep(time);
        philosophe(i - 1, mtx_fork);
    }
    else if (lol[i++] = fork() == 0)
    {
        step = 8 - step;
        time += step;
        sleep(time);
        philosophe(i - 1, mtx_fork);
    }
    else if (lol[i++] = fork() == 0)
    {
        step = 8 - step;
        time += step;
        sleep(time);
        philosophe(i - 1, mtx_fork);
    }
    else if (lol[i++] = fork() == 0)
    {
        step = 8 - step;
        time += step;
        sleep(time);
        philosophe(i - 1, mtx_fork);
    }
    else
    {
        for (i = 0; i < 5; ++i)
        {
            waitpid(lol[i], ((void *)0), 0);
        }
    }
    for (i = 0; i < 5; ++i)
    {
        semctl ( mtx_fork[i], 0, 0, 0 );
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: time int

variable_types: step int

variable_types:
lol
int [5]

return_type: int

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

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


decompiled_code:
void __noreturn my_handler_pong()
{
puts("Pong : Caught SIGINT");
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
puts("Pong : Caught SIGINT");
exit(1);
}

original_code:
void my_handler_pong(int s)
{
    printf("Pong : Caught SIGINT\n");
    exit(1);
}


decompiled_code:
void __noreturn my_handler_alrm_pong()
{
puts("Pong : Caught ALARM");
exit(1);
}

canonical_decompiled_code:
void __noreturn func8()
{
puts("Pong : Caught ALARM");
exit(1);
}

original_code:
void my_handler_alrm_pong(int s)
{
    printf("Pong : Caught ALARM\n");
    exit(1);
}


decompiled_code:
unsigned int my_handler_usr_pong()
{
unsigned int v0; // eax
int v1; // eax

v0 = a_read();
printf("Pong : I just got pinged, cpt is %i\n", v0);
v1 = a_read();
a_write((unsigned int)(v1 + 1));
sleep(1u);
kill(friendPidPong, 10);
return alarm(3u);
}

canonical_decompiled_code:
unsigned int func9()
{
unsigned int v0; // eax
int v1; // eax

v0 = func14();
printf("Pong : I just got pinged, cpt is %i\n", v0);
v1 = func14();
func13((unsigned int)(v1 + 1));
sleep(1u);
kill(friendPidPong, 10);
return alarm(3u);
}

original_code:
void my_handler_usr_pong(int s)
{
    printf("Pong : I just got pinged, cpt is %i\n", a_read());
    a_write((a_read()) + 1);
    sleep(1);
    kill(friendPidPong, 10);
    alarm(3);
}


pong

decompiled_code:
void __fastcall __noreturn pong(__pid_t a1)
{
struct sigaction v1; // [rsp+0h] [rbp-1E8h] BYREF
struct sigaction v2; // [rsp+A0h] [rbp-148h] BYREF
struct sigaction v3; // [rsp+140h] [rbp-A8h] BYREF

friendPidPong = a1;
v3.sa_handler = (__sighandler_t)my_handler_pong;
sigemptyset(&v3.sa_mask);
v3.sa_flags = 0;
sigaction(2, &v3, 0LL);
v2.sa_handler = (__sighandler_t)my_handler_usr_pong;
sigemptyset(&v2.sa_mask);
v2.sa_flags = 0;
sigaction(10, &v2, 0LL);
v1.sa_handler = (__sighandler_t)my_handler_alrm_pong;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
sigaction(14, &v1, 0LL);
while ( 1 )
;
}

canonical_decompiled_code:
void __fastcall __noreturn func10(__pid_t a1)
{
struct sigaction v1; // [rsp+0h] [rbp-1E8h] BYREF
struct sigaction v2; // [rsp+A0h] [rbp-148h] BYREF
struct sigaction v3; // [rsp+140h] [rbp-A8h] BYREF

friendPidPong = a1;
v3.sa_handler = (__sighandler_t)my_handler_pong;
sigemptyset(&v3.sa_mask);
v3.sa_flags = 0;
sigaction(2, &v3, 0LL);
v2.sa_handler = (__sighandler_t)my_handler_usr_pong;
sigemptyset(&v2.sa_mask);
v2.sa_flags = 0;
sigaction(10, &v2, 0LL);
v1.sa_handler = (__sighandler_t)my_handler_alrm_pong;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
sigaction(14, &v1, 0LL);
while ( 1 )
;
}

original_code:
void pong(pid_t pid)
{
    friendPidPong = pid;
    struct sigaction sigIntHandler;
    sigIntHandler.__sigaction_handler.sa_handler = my_handler_pong;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(2, &sigIntHandler, ((void *)0));
    struct sigaction sigUsrHandler;
    sigUsrHandler.__sigaction_handler.sa_handler = my_handler_usr_pong;
    sigemptyset(&sigUsrHandler.sa_mask);
    sigUsrHandler.sa_flags = 0;
    sigaction(10, &sigUsrHandler, ((void *)0));
    struct sigaction sigAlrmHandler;
    sigAlrmHandler.__sigaction_handler.sa_handler = my_handler_alrm_pong;
    sigemptyset(&sigAlrmHandler.sa_mask);
    sigAlrmHandler.sa_flags = 0;
    sigaction(14, &sigAlrmHandler, ((void *)0));
    for (;;)
    {
    }
}

canonical_original_code:
void pong(int pid)
{
    friendPidPong = pid;
    struct sigaction sigIntHandler;
    sigIntHandler.__sigaction_handler.sa_handler = my_handler_pong;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(2, &sigIntHandler, ((void *)0));
    struct sigaction sigUsrHandler;
    sigUsrHandler.__sigaction_handler.sa_handler = my_handler_usr_pong;
    sigemptyset(&sigUsrHandler.sa_mask);
    sigUsrHandler.sa_flags = 0;
    sigaction(10, &sigUsrHandler, ((void *)0));
    struct sigaction sigAlrmHandler;
    sigAlrmHandler.__sigaction_handler.sa_handler = my_handler_alrm_pong;
    sigemptyset(&sigAlrmHandler.sa_mask);
    sigAlrmHandler.sa_flags = 0;
    sigaction(14, &sigAlrmHandler, ((void *)0));
    for (;;)
    {
    }
}

variable_types: pid int


decompiled_code:
int my_handler_1()
{
return puts("Main : caught SIGINT, going to kill myself");
}

canonical_decompiled_code:
int func11()
{
return puts("Main : caught SIGINT, going to kill myself");
}

original_code:
void my_handler_1(int s)
{
    printf("Main : caught SIGINT, going to kill myself\n");
}


decompiled_code:
int my_handler_usr_main()
{
return printf("I just received SIGUSR1");
}

canonical_decompiled_code:
int func12()
{
return printf("I just received SIGUSR1");
}

original_code:
void my_handler_usr_main(int s)
{
    printf("I just received SIGUSR1");
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
unsigned int v4; // eax
struct sigaction v5; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-A8h] BYREF

v6.sa_handler = (__sighandler_t)my_handler_usr_main;
sigemptyset(&v6.sa_mask);
v6.sa_flags = 0;
sigaction(10, &v6, 0LL);
v5.sa_handler = (__sighandler_t)my_handler_1;
sigemptyset(&v5.sa_mask);
v5.sa_flags = 0;
sigaction(2, &v5, 0LL);
v3 = fork();
if ( !v3 )
{
v4 = getppid();
ping(v4);
}
pong(v3);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
unsigned int v4; // eax
struct sigaction v5; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-A8h] BYREF

v6.sa_handler = (__sighandler_t)my_handler_usr_main;
sigemptyset(&v6.sa_mask);
v6.sa_flags = 0;
sigaction(10, &v6, 0LL);
v5.sa_handler = (__sighandler_t)my_handler_1;
sigemptyset(&v5.sa_mask);
v5.sa_flags = 0;
sigaction(2, &v5, 0LL);
v3 = fork();
if ( !v3 )
{
v4 = getppid();
func18(v4);
}
func10(v3);
}

original_code:
int main(int argc, char const *argv[])
{
    struct sigaction sigUsrHandler;
    sigUsrHandler.__sigaction_handler.sa_handler = my_handler_usr_main;
    sigemptyset(&sigUsrHandler.sa_mask);
    sigUsrHandler.sa_flags = 0;
    sigaction(10, &sigUsrHandler, ((void *)0));
    struct sigaction sigIntHandler;
    sigIntHandler.__sigaction_handler.sa_handler = my_handler_1;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(2, &sigIntHandler, ((void *)0));
    pid_t pid_ping;
    pid_t pid_pong;
    if ((pid_ping = fork()) == 0)
    {
        ping(getppid());
    }
    else
    {
        pong(pid_ping);
        waitpid(pid_pong, ((void *)0), 0);
        waitpid(pid_ping, ((void *)0), 0);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct sigaction sigUsrHandler;
    sigUsrHandler.__sigaction_handler.sa_handler = my_handler_usr_main;
    sigemptyset(&sigUsrHandler.sa_mask);
    sigUsrHandler.sa_flags = 0;
    sigaction(10, &sigUsrHandler, ((void *)0));
    struct sigaction sigIntHandler;
    sigIntHandler.__sigaction_handler.sa_handler = my_handler_1;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(2, &sigIntHandler, ((void *)0));
    int pid_ping;
    int pid_pong;
    if ((pid_ping = fork()) == 0)
    {
        ping(getppid());
    }
    else
    {
        pong(pid_ping);
        waitpid(pid_pong, ((void *)0), 0);
        waitpid(pid_ping, ((void *)0), 0);
    }
    return 0;
}


decompiled_code:
void __noreturn my_handler_int_ping()
{
puts("Ping : Caught SIGINT");
exit(1);
}

canonical_decompiled_code:
void __noreturn func15()
{
puts("Ping : Caught SIGINT");
exit(1);
}

original_code:
void my_handler_int_ping(int s)
{
    printf("Ping : Caught SIGINT\n");
    exit(1);
}


decompiled_code:
void __noreturn my_handler_alrm_ping()
{
puts("Ping : Caught ALARM");
exit(1);
}

canonical_decompiled_code:
void __noreturn func16()
{
puts("Ping : Caught ALARM");
exit(1);
}

original_code:
void my_handler_alrm_ping(int s)
{
    printf("Ping : Caught ALARM\n");
    exit(1);
}


decompiled_code:
unsigned int my_handler_usr_ping()
{
unsigned int v0; // eax
int v1; // eax

v0 = a_read();
printf("Ping : I just got ponged, cpt is %i\n", v0);
v1 = a_read();
a_write(v1 + 1);
sleep(1u);
kill(friendPid, 10);
return alarm(3u);
}

canonical_decompiled_code:
unsigned int func17()
{
unsigned int v0; // eax
int v1; // eax

v0 = func14();
printf("Ping : I just got ponged, cpt is %i\n", v0);
v1 = func14();
func13(v1 + 1);
sleep(1u);
kill(friendPid, 10);
return alarm(3u);
}

original_code:
void my_handler_usr_ping(int s)
{
    printf("Ping : I just got ponged, cpt is %i\n", a_read());
    a_write((a_read()) + 1);
    sleep(1);
    kill(friendPid, 10);
    alarm(3);
}


ping

decompiled_code:
void __fastcall __noreturn ping(__pid_t a1)
{
struct sigaction v1; // [rsp+0h] [rbp-1E8h] BYREF
struct sigaction v2; // [rsp+A0h] [rbp-148h] BYREF
struct sigaction v3; // [rsp+140h] [rbp-A8h] BYREF

friendPid = a1;
v3.sa_handler = (__sighandler_t)my_handler_int_ping;
sigemptyset(&v3.sa_mask);
v3.sa_flags = 0;
sigaction(2, &v3, 0LL);
v2.sa_handler = (__sighandler_t)my_handler_usr_ping;
sigemptyset(&v2.sa_mask);
v2.sa_flags = 0;
sigaction(10, &v2, 0LL);
v1.sa_handler = (__sighandler_t)my_handler_alrm_ping;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
sigaction(14, &v1, 0LL);
a_write(1u);
kill(friendPid, 10);
while ( 1 )
;
}

canonical_decompiled_code:
void __fastcall __noreturn func18(__pid_t a1)
{
struct sigaction v1; // [rsp+0h] [rbp-1E8h] BYREF
struct sigaction v2; // [rsp+A0h] [rbp-148h] BYREF
struct sigaction v3; // [rsp+140h] [rbp-A8h] BYREF

friendPid = a1;
v3.sa_handler = (__sighandler_t)my_handler_int_ping;
sigemptyset(&v3.sa_mask);
v3.sa_flags = 0;
sigaction(2, &v3, 0LL);
v2.sa_handler = (__sighandler_t)my_handler_usr_ping;
sigemptyset(&v2.sa_mask);
v2.sa_flags = 0;
sigaction(10, &v2, 0LL);
v1.sa_handler = (__sighandler_t)my_handler_alrm_ping;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
sigaction(14, &v1, 0LL);
func13(1u);
kill(friendPid, 10);
while ( 1 )
;
}

original_code:
void ping(pid_t pid)
{
    friendPid = pid;
    struct sigaction sigIntHandler;
    sigIntHandler.__sigaction_handler.sa_handler = my_handler_int_ping;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(2, &sigIntHandler, ((void *)0));
    struct sigaction sigUsrHandler;
    sigUsrHandler.__sigaction_handler.sa_handler = my_handler_usr_ping;
    sigemptyset(&sigUsrHandler.sa_mask);
    sigUsrHandler.sa_flags = 0;
    sigaction(10, &sigUsrHandler, ((void *)0));
    struct sigaction sigAlrmHandler;
    sigAlrmHandler.__sigaction_handler.sa_handler = my_handler_alrm_ping;
    sigemptyset(&sigAlrmHandler.sa_mask);
    sigAlrmHandler.sa_flags = 0;
    sigaction(14, &sigAlrmHandler, ((void *)0));
    a_write(1);
    kill(friendPid, 10);
    for(;;){}
}

canonical_original_code:
void ping(int pid)
{
    friendPid = pid;
    struct sigaction sigIntHandler;
    sigIntHandler.__sigaction_handler.sa_handler = my_handler_int_ping;
    sigemptyset(&sigIntHandler.sa_mask);
    sigIntHandler.sa_flags = 0;
    sigaction(2, &sigIntHandler, ((void *)0));
    struct sigaction sigUsrHandler;
    sigUsrHandler.__sigaction_handler.sa_handler = my_handler_usr_ping;
    sigemptyset(&sigUsrHandler.sa_mask);
    sigUsrHandler.sa_flags = 0;
    sigaction(10, &sigUsrHandler, ((void *)0));
    struct sigaction sigAlrmHandler;
    sigAlrmHandler.__sigaction_handler.sa_handler = my_handler_alrm_ping;
    sigemptyset(&sigAlrmHandler.sa_mask);
    sigAlrmHandler.sa_flags = 0;
    sigaction(14, &sigAlrmHandler, ((void *)0));
    a_write(1);
    kill(friendPid, 10);
    for(;;){}
}


repo: KathleenLabrie/KLlibc

decompiled_code:
__int64 __fastcall write_key(__int64 a1, __int64 a2, const char *a3, __int64 a4, __int64 a5)
{
int v7; // ebx
float v8; // xmm0_4
double v10; // [rsp+0h] [rbp-48h] BYREF
float v11; // [rsp+Ch] [rbp-3Ch] BYREF
int v12; // [rsp+10h] [rbp-38h] BYREF
unsigned int v13; // [rsp+14h] [rbp-34h] BYREF
__int64 v14[6]; // [rsp+18h] [rbp-30h] BYREF

v13 = 0;
v7 = get_type(a4);
if ( (unsigned int)ffopentest(7LL, v14, a1, 1LL, &v13) )
printerror(v13);
if ( v7 == 42 )
{
v8 = atof(a3);
v11 = v8;
if ( (unsigned int)ffuky(v14[0], 42LL, a2, &v11, a5, &v13) )
printerror(v13);
}
else if ( v7 > 42 )
{
if ( v7 != 82 )
goto LABEL_16;
v10 = atof(a3);
if ( (unsigned int)ffuky(v14[0], 82LL, a2, &v10, a5, &v13) )
printerror(v13);
}
else
{
if ( v7 != 16 )
{
if ( v7 == 31 )
{
v12 = atoi(a3);
if ( (unsigned int)ffuky(v14[0], 31LL, a2, &v12, a5, &v13) )
printerror(v13);
goto LABEL_17;
}
LABEL_16:
printerror(410LL);
goto LABEL_17;
}
if ( (unsigned int)ffuky(v14[0], 16LL, a2, a3, a5, &v13) )
printerror(v13);
}
LABEL_17:
if ( (unsigned int)ffclos(v14[0], &v13) )
printerror(v13);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, const char *a3, __int64 a4, __int64 a5)
{
int v7; // ebx
float v8; // xmm0_4
double v10; // [rsp+0h] [rbp-48h] BYREF
float v11; // [rsp+Ch] [rbp-3Ch] BYREF
int v12; // [rsp+10h] [rbp-38h] BYREF
unsigned int v13; // [rsp+14h] [rbp-34h] BYREF
__int64 v14[6]; // [rsp+18h] [rbp-30h] BYREF

v13 = 0;
v7 = get_type(a4);
if ( (unsigned int)ffopentest(7LL, v14, a1, 1LL, &v13) )
printerror(v13);
if ( v7 == 42 )
{
v8 = atof(a3);
v11 = v8;
if ( (unsigned int)ffuky(v14[0], 42LL, a2, &v11, a5, &v13) )
printerror(v13);
}
else if ( v7 > 42 )
{
if ( v7 != 82 )
goto LABEL_16;
v10 = atof(a3);
if ( (unsigned int)ffuky(v14[0], 82LL, a2, &v10, a5, &v13) )
printerror(v13);
}
else
{
if ( v7 != 16 )
{
if ( v7 == 31 )
{
v12 = atoi(a3);
if ( (unsigned int)ffuky(v14[0], 31LL, a2, &v12, a5, &v13) )
printerror(v13);
goto LABEL_17;
}
LABEL_16:
printerror(410LL);
goto LABEL_17;
}
if ( (unsigned int)ffuky(v14[0], 16LL, a2, a3, a5, &v13) )
printerror(v13);
}
LABEL_17:
if ( (unsigned int)ffclos(v14[0], &v13) )
printerror(v13);
return 0LL;
}

original_code:
int write_key(char filename[], char keyword[], char value[], char type[],
   char comment[])
{
 fitsfile *fptr;
 int status=0;
 int datatype;
 int ivalue;
 float fvalue;
 double dvalue;
 datatype = get_type(type);
 if ( ffopentest( 7, &fptr, filename, 1, &status) )
  printerror( status );
 switch (datatype) {
   case 16:
    if ( ffuky(fptr, datatype, keyword, value, comment, &status) )
   printerror( status );
 break;
   case 31:
       ivalue = atoi(value);
       if ( ffuky(fptr, datatype, keyword, &ivalue, comment, &status) )
  printerror( status );
    break;
   case 42:
       fvalue = (float)atof(value);
    if ( ffuky(fptr, datatype, keyword, &fvalue, comment, &status) )
  printerror( status );
    break;
   case 82:
    dvalue = atof(value);
       if ( ffuky(fptr, datatype, keyword, &dvalue, comment, &status) )
  printerror( status );
    break;
   default:
    printerror( 410 );
 break;
 }
 if ( ffclos(fptr, &status) )
  printerror( status );
 return(0);
}

canonical_original_code:
int write_key(char filename[], char keyword[], char value[], char type[], char comment[])
{
 struct fitsfile *fptr;
 int status = 0;
 int datatype;
 int ivalue;
 float fvalue;
 double dvalue;
 datatype = get_type(type);
 if ( ffopentest( 7, &fptr, filename, 1, &status) )
  printerror( status );
 switch (datatype) {
   case 16:
    if ( ffuky(fptr, datatype, keyword, value, comment, &status) )
   printerror( status );
 break;
   case 31:
       ivalue = atoi(value);
       if ( ffuky(fptr, datatype, keyword, &ivalue, comment, &status) )
  printerror( status );
    break;
   case 42:
       fvalue = (float)atof(value);
    if ( ffuky(fptr, datatype, keyword, &fvalue, comment, &status) )
  printerror( status );
    break;
   case 82:
    dvalue = atof(value);
       if ( ffuky(fptr, datatype, keyword, &dvalue, comment, &status) )
  printerror( status );
    break;
   default:
    printerror( 410 );
 break;
 }
 if ( ffclos(fptr, &status) )
  printerror( status );
 return(0);
}

variable_types:
filename
char []

variable_types:
keyword
char []

variable_types:
value
char []

variable_types:
type
char []

variable_types:
comment
char []

variable_types: struct fitsfile { int HDUposition; struct FITSfile { int filehandle; int driver; int open_count; char *filename; int validcode; int only_one; long long filesize; long long logfilesize; int lasthdu; long long bytepos; long long io_pos; int curbuf; int curhdu; int hdutype; int writemode; int maxhdu; int MAXHDU; long long *headstart; long long headend; long long ENDpos; long long nextkey; long long datastart; int imgdim; long long imgnaxis[99]; int tfield; int startcol; long long origrows; long long numrows; long long rowlength; struct tcolumn { char ttype[70]; long long tbcol; int tdatatype; long long trepeat; double tscale; double tzero; long long tnull; char strnull[20]; char tform[10]; long twidth; } *tableptr; long long heapstart; long long heapsize; int request_compress_type; long request_tilesize[6]; float request_quantize_level; int request_quantize_method; int request_dither_seed; int request_lossy_int_compress; int request_huge_hdu; float request_hcomp_scale; int request_hcomp_smooth; int compress_type; long tilesize[6]; float quantize_level; int quantize_method; int dither_seed; int compressimg; char zcmptype[12]; int zbitpix; int zndim; long znaxis[6]; long maxtilelen; long maxelem; int cn_compressed; int cn_uncompressed; int cn_gzip_data; int cn_zscale; int cn_zzero; int cn_zblank; double zscale; double zzero; double cn_bscale; double cn_bzero; double cn_actual_bzero; int zblank; int rice_blocksize; int rice_bytepix; float hcomp_scale; int hcomp_smooth; int *tilerow; long *tiledatasize; int *tiletype; void **tiledata; void **tilenullarray; int *tileanynull; char *iobuffer; long bufrecnum[40]; int dirty[40]; int ageindex[40]; } *Fptr; } *

variable_types: status int

variable_types: datatype int

variable_types: ivalue int

variable_types: fvalue float

variable_types: dvalue double

user_defined_types: struct fitsfile { int HDUposition; struct FITSfile *Fptr; }

user_defined_types: struct FITSfile { int filehandle; int driver; int open_count; char *filename; int validcode; int only_one; long long filesize; long long logfilesize; int lasthdu; long long bytepos; long long io_pos; int curbuf; int curhdu; int hdutype; int writemode; int maxhdu; int MAXHDU; long long *headstart; long long headend; long long ENDpos; long long nextkey; long long datastart; int imgdim; long long imgnaxis[99]; int tfield; int startcol; long long origrows; long long numrows; long long rowlength; struct tcolumn *tableptr; long long heapstart; long long heapsize; int request_compress_type; long request_tilesize[6]; float request_quantize_level; int request_quantize_method; int request_dither_seed; int request_lossy_int_compress; int request_huge_hdu; float request_hcomp_scale; int request_hcomp_smooth; int compress_type; long tilesize[6]; float quantize_level; int quantize_method; int dither_seed; int compressimg; char zcmptype[12]; int zbitpix; int zndim; long znaxis[6]; long maxtilelen; long maxelem; int cn_compressed; int cn_uncompressed; int cn_gzip_data; int cn_zscale; int cn_zzero; int cn_zblank; double zscale; double zzero; double cn_bscale; double cn_bzero; double cn_actual_bzero; int zblank; int rice_blocksize; int rice_bytepix; float hcomp_scale; int hcomp_smooth; int *tilerow; long *tiledatasize; int *tiletype; void **tiledata; void **tilenullarray; int *tileanynull; char *iobuffer; long bufrecnum[40]; int dirty[40]; int ageindex[40]; }


decompiled_code:
__int64 __fastcall modify_key(const char *a1, __int64 a2, __int64 a3)
{
unsigned int v5; // [rsp+4h] [rbp-24h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v5 = 0;
if ( (unsigned int)ffopentest(7LL, v6, a1, 1LL, &v5) )
printerror(v5);
if ( (unsigned int)ffmnam(v6[0], a2, a3, &v5) )
{
if ( v5 == 202 )
{
printf("\n%s:\t", a1);
fflush(stdout);
printwarning(v5);
}
else
{
printerror(v5);
}
}
if ( (unsigned int)ffclos(v6[0], &v5) )
printerror(v5);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, __int64 a2, __int64 a3)
{
unsigned int v5; // [rsp+4h] [rbp-24h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v5 = 0;
if ( (unsigned int)ffopentest(7LL, v6, a1, 1LL, &v5) )
printerror(v5);
if ( (unsigned int)ffmnam(v6[0], a2, a3, &v5) )
{
if ( v5 == 202 )
{
printf("\n%s:\t", a1);
fflush(stdout);
printwarning(v5);
}
else
{
printerror(v5);
}
}
if ( (unsigned int)ffclos(v6[0], &v5) )
printerror(v5);
return v5;
}

original_code:
int modify_key(char filename[], char old_keyword[], char new_keyword[])
{
 fitsfile *fptr;
 int status=0;
 if ( ffopentest( 7, &fptr, filename, 1, &status) )
  printerror( status );
 if ( ffmnam(fptr, old_keyword, new_keyword, &status) ) {
  if (status == 202) {
  printf("\n%s:\t", filename);
  fflush(stdout);
  printwarning( status );
 }
 else {
  printerror( status );
 }
 }
 if ( ffclos(fptr, &status) )
  printerror( status );
 return(status);
}

canonical_original_code:
int modify_key(char filename[], char old_keyword[], char new_keyword[])
{
 struct fitsfile *fptr;
 int status = 0;
 if ( ffopentest( 7, &fptr, filename, 1, &status) )
  printerror( status );
 if ( ffmnam(fptr, old_keyword, new_keyword, &status) ) {
  if (status == 202) {
  printf("\n%s:\t", filename);
  fflush(stdout);
  printwarning( status );
 }
 else {
  printerror( status );
 }
 }
 if ( ffclos(fptr, &status) )
  printerror( status );
 return(status);
}

user_defined_types: struct tcolumn { char ttype[70]; long long tbcol; int tdatatype; long long trepeat; double tscale; double tzero; long long tnull; char strnull[20]; char tform[10]; long twidth; }


printwarning

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

if ( a1 )
result = ffrprt(stderr, a1);
return result;
}

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

if ( a1 )
result = ffrprt(stderr, a1);
return result;
}

original_code:
void printwarning( int status)
{
 if (status)
 {
   ffrprt(stderr, status);
 }
 return;
}

canonical_original_code:
void printwarning(int status)
{
 if (status)
 {
   ffrprt(stderr, status);
 }
 return;
}


fpolynome

decompiled_code:
void __fastcall fpolynome(_QWORD *a1, int a2, double a3)
{
__int64 i; // rbx

*a1 = LC0;
if ( a2 > 1 )
{
for ( i = 1LL; i != a2; ++i )
*(double *)&a1[i] = pow(a3, (double)(int)i);
}
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1, int a2, double a3)
{
__int64 i; // rbx

*a1 = LC0;
if ( a2 > 1 )
{
for ( i = 1LL; i != a2; ++i )
*(double *)&a1[i] = pow(a3, (double)(int)i);
}
}

original_code:
void fpolynome(double x, double afunc[], int na)
{
 int i;
 afunc[0]=1.;
 for (i=1;i<na;i++) afunc[i]=(double)pow((double)x,(double)i);
 return;
}

variable_types: x double

variable_types:
afunc
double []

variable_types: i int


decompiled_code:
__int64 __fastcall parse_imname(__int64 a1, char *a2, __int64 a3)
{
const char **v4; // rbx
int v5; // ebp
char v7[80]; // [rsp+0h] [rbp-C8h] BYREF
char dest[120]; // [rsp+50h] [rbp-78h] BYREF

v4 = (const char **)svector(2LL, 80LL);
v5 = splitstr(a1, v4, &unk_165);
strcpy(a2, *v4);
if ( v5 == 2 )
{
*(_QWORD *)a3 = lvector(4LL);
strcpy(dest, v4[1]);
splitstr(dest, v4, &unk_167);
strcpy(dest, *v4);
splitstr(dest, v4, &unk_169);
strcpy(dest, *v4);
strcpy(v7, v4[1]);
splitstr(dest, v4, &unk_16B);
**(_QWORD **)a3 = atoi(*v4);
*(_QWORD *)(*(_QWORD *)a3 + 8LL) = atoi(v4[1]);
splitstr(v7, v4, &unk_16B);
*(_QWORD *)(*(_QWORD *)a3 + 16LL) = atoi(*v4);
*(_QWORD *)(*(_QWORD *)a3 + 24LL) = atoi(v4[1]);
}
return free_svector(v4);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2, __int64 a3)
{
const char **v4; // rbx
int v5; // ebp
char v7[80]; // [rsp+0h] [rbp-C8h] BYREF
char dest[120]; // [rsp+50h] [rbp-78h] BYREF

v4 = (const char **)svector(2LL, 80LL);
v5 = splitstr(a1, v4, &unk_165);
strcpy(a2, *v4);
if ( v5 == 2 )
{
*(_QWORD *)a3 = lvector(4LL);
strcpy(dest, v4[1]);
splitstr(dest, v4, &unk_167);
strcpy(dest, *v4);
splitstr(dest, v4, &unk_169);
strcpy(dest, *v4);
strcpy(v7, v4[1]);
splitstr(dest, v4, &unk_16B);
**(_QWORD **)a3 = atoi(*v4);
*(_QWORD *)(*(_QWORD *)a3 + 8LL) = atoi(v4[1]);
splitstr(v7, v4, &unk_16B);
*(_QWORD *)(*(_QWORD *)a3 + 16LL) = atoi(*v4);
*(_QWORD *)(*(_QWORD *)a3 + 24LL) = atoi(v4[1]);
}
return free_svector(v4);
}

original_code:
void parse_imname(char imstring[], char imname[], unsigned long **section)
{
 int n;
 char **p_parse, tmp1[80], tmp2[80];
 p_parse = svector(2,80);
 n=splitstr(imstring, p_parse, "[");
 strcpy(imname, p_parse[0]);
 if (n == 2) {
   *section = lvector(4);
   strcpy(tmp1, p_parse[1]);
   splitstr(tmp1, p_parse, "]");
   strcpy(tmp1, p_parse[0]);
   splitstr(tmp1, p_parse, ",");
   strcpy(tmp1, p_parse[0]);
   strcpy(tmp2, p_parse[1]);
   splitstr(tmp1, p_parse, ":");
   *(*section+0) = atoi(p_parse[0]);
   *(*section+1) = atoi(p_parse[1]);
   splitstr(tmp2, p_parse, ":");
   *(*section+2) = atoi(p_parse[0]);
   *(*section+3) = atoi(p_parse[1]);
 }
 free_svector(p_parse);
 return;
}

canonical_original_code:
void parse_imname(char imstring[], char imname[], unsigned long **section)
{
 int n;
 char **p_parse; char tmp1[80]; char tmp2[80];
 p_parse = svector(2,80);
 n=splitstr(imstring, p_parse, "[");
 strcpy(imname, p_parse[0]);
 if (n == 2) {
   *section = lvector(4);
   strcpy(tmp1, p_parse[1]);
   splitstr(tmp1, p_parse, "]");
   strcpy(tmp1, p_parse[0]);
   splitstr(tmp1, p_parse, ",");
   strcpy(tmp1, p_parse[0]);
   strcpy(tmp2, p_parse[1]);
   splitstr(tmp1, p_parse, ":");
   *(*section+0) = atoi(p_parse[0]);
   *(*section+1) = atoi(p_parse[1]);
   splitstr(tmp2, p_parse, ":");
   *(*section+2) = atoi(p_parse[0]);
   *(*section+3) = atoi(p_parse[1]);
 }
 free_svector(p_parse);
 return;
}

variable_types:
imstring
char []

variable_types:
imname
char []

variable_types:
section
unsigned long **

variable_types: n int


splitstr

original_code:
int splitstr(char line[], char *p_line[], char delimiter[])
{
  int n=0,i=0,j;
  char *token,tmpstr[strlen(line)+1];
  strcpy(tmpstr,line);
  if (!strcmp(delimiter,"\40|\11")) {
    j=0;
    while (i < strlen(line)) {
      if ( ((int)line[i] != 32) && ((int)line[i] != 9) && ((int)line[i] != 10) ) {
        tmpstr[j++] = line[i];
      }
      else if (j != 0) {
        tmpstr[j] = '\0';
  strcpy(p_line[n++], tmpstr);
  j=0;
      }
      i++;
    }
    if (j != 0) {
      tmpstr[j] = '\0';
      strcpy(p_line[n++], tmpstr);
    }
    if (n == 0) {
      tmpstr[0]='\0';
      strcpy(p_line[0],tmpstr);
    }
  }
  else {
    token=strtok(tmpstr,delimiter);
    while (token!=((void *)0)) {
      strcpy(p_line[n++],token);
      token=strtok(((void *)0),delimiter);
    }
  }
  if (n > 0) {
    strcpy(tmpstr,p_line[n-1]);
    token=strtok(tmpstr,"\n");
    strcpy(p_line[n-1],token);
  }
  return(n);
}

canonical_original_code:
int splitstr(char line[], char *p_line[], char delimiter[])
{
  int n = 0; int i = 0; int j;
  char *token; char tmpstr[-1];
  strcpy(tmpstr,line);
  if (!strcmp(delimiter,"\40|\11")) {
    j=0;
    while (i < strlen(line)) {
      if ( ((int)line[i] != 32) && ((int)line[i] != 9) && ((int)line[i] != 10) ) {
        tmpstr[j++] = line[i];
      }
      else if (j != 0) {
        tmpstr[j] = '\0';
  strcpy(p_line[n++], tmpstr);
  j=0;
      }
      i++;
    }
    if (j != 0) {
      tmpstr[j] = '\0';
      strcpy(p_line[n++], tmpstr);
    }
    if (n == 0) {
      tmpstr[0]='\0';
      strcpy(p_line[0],tmpstr);
    }
  }
  else {
    token=strtok(tmpstr,delimiter);
    while (token!=((void *)0)) {
      strcpy(p_line[n++],token);
      token=strtok(((void *)0),delimiter);
    }
  }
  if (n > 0) {
    strcpy(tmpstr,p_line[n-1]);
    token=strtok(tmpstr,"\n");
    strcpy(p_line[n-1],token);
  }
  return(n);
}

variable_types:
line
char []

variable_types:
delimiter
char []

variable_types: j int

variable_types:
token
char *

variable_types:
tmpstr
char [-1]


decompiled_code:
__int64 __fastcall get_type(const void *a1)
{
unsigned int v2; // edx

v2 = 16;
if ( !memcmp("string", a1, 6uLL) )
return v2;
v2 = 11;
if ( !memcmp("byte", a1, 4uLL) )
return v2;
v2 = 21;
if ( !memcmp("short", a1, 5uLL) )
return v2;
v2 = 20;
if ( !memcmp("ushort", a1, 6uLL) )
return v2;
v2 = 14;
if ( !memcmp("log", a1, 3uLL) )
return v2;
v2 = 31;
if ( !memcmp("int", a1, 3uLL) )
return v2;
v2 = 30;
if ( !memcmp("uint", a1, 4uLL) )
return v2;
v2 = 41;
if ( !memcmp("long", a1, 4uLL) )
return v2;
v2 = 40;
if ( !memcmp("ulong", a1, 5uLL) )
return v2;
v2 = 42;
if ( !memcmp("float", a1, 5uLL) )
return v2;
if ( !memcmp("double", a1, 6uLL) )
return 82;
printf("ERROR: Unrecognized data type (%s)\n", (const char *)a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1)
{
unsigned int v2; // edx

v2 = 16;
if ( !memcmp("string", a1, 6uLL) )
return v2;
v2 = 11;
if ( !memcmp("byte", a1, 4uLL) )
return v2;
v2 = 21;
if ( !memcmp("short", a1, 5uLL) )
return v2;
v2 = 20;
if ( !memcmp("ushort", a1, 6uLL) )
return v2;
v2 = 14;
if ( !memcmp("log", a1, 3uLL) )
return v2;
v2 = 31;
if ( !memcmp("int", a1, 3uLL) )
return v2;
v2 = 30;
if ( !memcmp("uint", a1, 4uLL) )
return v2;
v2 = 41;
if ( !memcmp("long", a1, 4uLL) )
return v2;
v2 = 40;
if ( !memcmp("ulong", a1, 5uLL) )
return v2;
v2 = 42;
if ( !memcmp("float", a1, 5uLL) )
return v2;
if ( !memcmp("double", a1, 6uLL) )
return 82;
printf("ERROR: Unrecognized data type (%s)\n", (const char *)a1);
return 0xFFFFFFFFLL;
}

original_code:
int get_type(char type[])
{
 if (!strncmp("string",type,6)) { return(16); }
 else if (!strncmp("byte",type,4)) { return(11); }
 else if (!strncmp("short",type,5)) { return(21); }
 else if (!strncmp("ushort",type,6)) { return(20); }
 else if (!strncmp("log",type,3)) { return(14); }
 else if (!strncmp("int",type,3)) { return(31); }
 else if (!strncmp("uint",type,4)) { return(30); }
 else if (!strncmp("long",type,4)) { return(41); }
 else if (!strncmp("ulong",type,5)) { return(40); }
 else if (!strncmp("float",type,5)) { return(42); }
 else if (!strncmp("double",type,6)) { return(82); }
 else {
   printf("ERROR: Unrecognized data type (%s)\n",type);
   return(-1);
 }
}

variable_types:
type
char []


decompiled_code:
__int64 __fastcall read_keyword(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v7; // [rsp+4h] [rbp-24h] BYREF
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v7 = 0;
if ( (unsigned int)ffopentest(7LL, v8, a1, 0LL, &v7) )
printerror(v7);
if ( (unsigned int)ffgkey(v8[0], a2, a3, a4, &v7) && v7 != 202 )
printerror(v7);
if ( (unsigned int)ffclos(v8[0], &v7) && v7 != 202 )
printerror(v7);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v7; // [rsp+4h] [rbp-24h] BYREF
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v7 = 0;
if ( (unsigned int)ffopentest(7LL, v8, a1, 0LL, &v7) )
printerror(v7);
if ( (unsigned int)ffgkey(v8[0], a2, a3, a4, &v7) && v7 != 202 )
printerror(v7);
if ( (unsigned int)ffclos(v8[0], &v7) && v7 != 202 )
printerror(v7);
return v7;
}

original_code:
int read_keyword(char filename[], char keyword[], char value[], char comment[])
{
 fitsfile *fptr;
 int status = 0;
 if ( ffopentest( 7, &fptr, filename, 0, &status) )
  printerror( status );
 if ( ffgkey(fptr, keyword, value, comment, &status) )
  if (status != 202) printerror( status );
 if ( ffclos(fptr, &status) )
  if (status != 202) printerror( status );
 return(status);
}

canonical_original_code:
int read_keyword(char filename[], char keyword[], char value[], char comment[])
{
 struct fitsfile *fptr;
 int status = 0;
 if ( ffopentest( 7, &fptr, filename, 0, &status) )
  printerror( status );
 if ( ffgkey(fptr, keyword, value, comment, &status) )
  if (status != 202) printerror( status );
 if ( ffclos(fptr, &status) )
  if (status != 202) printerror( status );
 return(status);
}

variable_types:
filename
char []

variable_types:
keyword
char []

variable_types:
value
char []

variable_types:
comment
char []

variable_types: struct fitsfile { int HDUposition; struct FITSfile { int filehandle; int driver; int open_count; char *filename; int validcode; int only_one; long long filesize; long long logfilesize; int lasthdu; long long bytepos; long long io_pos; int curbuf; int curhdu; int hdutype; int writemode; int maxhdu; int MAXHDU; long long *headstart; long long headend; long long ENDpos; long long nextkey; long long datastart; int imgdim; long long imgnaxis[99]; int tfield; int startcol; long long origrows; long long numrows; long long rowlength; struct tcolumn { char ttype[70]; long long tbcol; int tdatatype; long long trepeat; double tscale; double tzero; long long tnull; char strnull[20]; char tform[10]; long twidth; } *tableptr; long long heapstart; long long heapsize; int request_compress_type; long request_tilesize[6]; float request_quantize_level; int request_quantize_method; int request_dither_seed; int request_lossy_int_compress; int request_huge_hdu; float request_hcomp_scale; int request_hcomp_smooth; int compress_type; long tilesize[6]; float quantize_level; int quantize_method; int dither_seed; int compressimg; char zcmptype[12]; int zbitpix; int zndim; long znaxis[6]; long maxtilelen; long maxelem; int cn_compressed; int cn_uncompressed; int cn_gzip_data; int cn_zscale; int cn_zzero; int cn_zblank; double zscale; double zzero; double cn_bscale; double cn_bzero; double cn_actual_bzero; int zblank; int rice_blocksize; int rice_bytepix; float hcomp_scale; int hcomp_smooth; int *tilerow; long *tiledatasize; int *tiletype; void **tiledata; void **tilenullarray; int *tileanynull; char *iobuffer; long bufrecnum[40]; int dirty[40]; int ageindex[40]; } *Fptr; } *

variable_types: status int


decompiled_code:
__int64 __fastcall read_key(__int64 a1, __int64 a2, char *a3, __int64 a4, __int64 a5)
{
int v7; // ebx
double v9; // [rsp+0h] [rbp-48h] BYREF
float v10; // [rsp+8h] [rbp-40h] BYREF
unsigned int v11; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned __int16 v12; // [rsp+12h] [rbp-36h] BYREF
unsigned int v13; // [rsp+14h] [rbp-34h] BYREF
__int64 v14[6]; // [rsp+18h] [rbp-30h] BYREF

v13 = 0;
v7 = get_type(a4);
if ( (unsigned int)ffopentest(7LL, v14, a1, 0LL, &v13) )
printerror(v13);
if ( v7 == 31 )
{
if ( (unsigned int)ffgky(v14[0], 31LL, a2, &v11, a5, &v13) )
printerror(v13);
sprintf(a3, "%d", v11);
}
else if ( v7 <= 31 )
{
if ( v7 == 16 )
{
if ( (unsigned int)ffgky(v14[0], 16LL, a2, a3, a5, &v13) )
printerror(v13);
}
else
{
if ( v7 != 20 )
goto LABEL_26;
if ( (unsigned int)ffgky(v14[0], 20LL, a2, &v12, a5, &v13) )
printerror(v13);
sprintf(a3, "%d", v12);
}
}
else
{
if ( v7 != 42 )
{
if ( v7 == 82 )
{
if ( (unsigned int)ffgky(v14[0], 82LL, a2, &v9, a5, &v13) )
printerror(v13);
sprintf(a3, "%lf", v9);
goto LABEL_15;
}
LABEL_26:
printerror(410LL);
goto LABEL_15;
}
if ( (unsigned int)ffgky(v14[0], 42LL, a2, &v10, a5, &v13) )
printerror(v13);
sprintf(a3, "%f", v10);
}
LABEL_15:
if ( (unsigned int)ffclos(v14[0], &v13) )
printerror(v13);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, char *a3, __int64 a4, __int64 a5)
{
int v7; // ebx
double v9; // [rsp+0h] [rbp-48h] BYREF
float v10; // [rsp+8h] [rbp-40h] BYREF
unsigned int v11; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned __int16 v12; // [rsp+12h] [rbp-36h] BYREF
unsigned int v13; // [rsp+14h] [rbp-34h] BYREF
__int64 v14[6]; // [rsp+18h] [rbp-30h] BYREF

v13 = 0;
v7 = get_type(a4);
if ( (unsigned int)ffopentest(7LL, v14, a1, 0LL, &v13) )
printerror(v13);
if ( v7 == 31 )
{
if ( (unsigned int)ffgky(v14[0], 31LL, a2, &v11, a5, &v13) )
printerror(v13);
sprintf(a3, "%d", v11);
}
else if ( v7 <= 31 )
{
if ( v7 == 16 )
{
if ( (unsigned int)ffgky(v14[0], 16LL, a2, a3, a5, &v13) )
printerror(v13);
}
else
{
if ( v7 != 20 )
goto LABEL_26;
if ( (unsigned int)ffgky(v14[0], 20LL, a2, &v12, a5, &v13) )
printerror(v13);
sprintf(a3, "%d", v12);
}
}
else
{
if ( v7 != 42 )
{
if ( v7 == 82 )
{
if ( (unsigned int)ffgky(v14[0], 82LL, a2, &v9, a5, &v13) )
printerror(v13);
sprintf(a3, "%lf", v9);
goto LABEL_15;
}
LABEL_26:
printerror(410LL);
goto LABEL_15;
}
if ( (unsigned int)ffgky(v14[0], 42LL, a2, &v10, a5, &v13) )
printerror(v13);
sprintf(a3, "%f", v10);
}
LABEL_15:
if ( (unsigned int)ffclos(v14[0], &v13) )
printerror(v13);
return 0LL;
}

original_code:
int read_key(char filename[], char keyword[], char value[], char type[],
  char comment[])
{
 fitsfile *fptr;
 int status=0;
 int datatype;
 unsigned short usvalue;
 int ivalue;
 float fvalue;
 double dvalue;
 datatype = get_type(type);
 if ( ffopentest( 7, &fptr, filename, 0, &status) )
  printerror( status );
 switch (datatype) {
   case 16:
    if ( ffgky(fptr, datatype, keyword, value, comment, &status) )
  printerror( status );
 break;
   case 20:
    if ( ffgky(fptr, datatype, keyword, &usvalue, comment, &status) )
  printerror( status );
 sprintf(value,"%d",usvalue);
 break;
   case 31:
    if ( ffgky(fptr, datatype, keyword, &ivalue, comment, &status) )
  printerror( status );
 sprintf(value,"%d",ivalue);
 break;
   case 42:
    if ( ffgky(fptr, datatype, keyword, &fvalue, comment, &status) )
  printerror( status );
 sprintf(value,"%f",fvalue);
 break;
   case 82:
    if ( ffgky(fptr, datatype, keyword, &dvalue, comment, &status) )
  printerror( status );
 sprintf(value,"%lf",dvalue);
 break;
   default:
    printerror( 410 );
 break;
 }
 if ( ffclos(fptr, &status) )
  printerror( status );
 return(0);
}

canonical_original_code:
int read_key(char filename[], char keyword[], char value[], char type[], char comment[])
{
 struct fitsfile *fptr;
 int status = 0;
 int datatype;
 unsigned short usvalue;
 int ivalue;
 float fvalue;
 double dvalue;
 datatype = get_type(type);
 if ( ffopentest( 7, &fptr, filename, 0, &status) )
  printerror( status );
 switch (datatype) {
   case 16:
    if ( ffgky(fptr, datatype, keyword, value, comment, &status) )
  printerror( status );
 break;
   case 20:
    if ( ffgky(fptr, datatype, keyword, &usvalue, comment, &status) )
  printerror( status );
 sprintf(value,"%d",usvalue);
 break;
   case 31:
    if ( ffgky(fptr, datatype, keyword, &ivalue, comment, &status) )
  printerror( status );
 sprintf(value,"%d",ivalue);
 break;
   case 42:
    if ( ffgky(fptr, datatype, keyword, &fvalue, comment, &status) )
  printerror( status );
 sprintf(value,"%f",fvalue);
 break;
   case 82:
    if ( ffgky(fptr, datatype, keyword, &dvalue, comment, &status) )
  printerror( status );
 sprintf(value,"%lf",dvalue);
 break;
   default:
    printerror( 410 );
 break;
 }
 if ( ffclos(fptr, &status) )
  printerror( status );
 return(0);
}

variable_types: datatype int

variable_types:
usvalue
unsigned short

variable_types: ivalue int

variable_types: fvalue float

variable_types: dvalue double


fgaussS

variable_types:
x
double []

variable_types:
a
double []

variable_types:
y
double *

variable_types:
dyda
double []

variable_types: ndim int

variable_types: ex double


findbin

decompiled_code:
__int64 __fastcall findbin(float *a1, int a2, float a3)
{
double v3; // xmm0_8
double v4; // xmm2_8
double v5; // xmm1_8

v3 = a3;
v4 = (float)(a1[1] - *a1);
v5 = *a1 - v4 * 0.5;
if ( v5 > v3 )
return 0xFFFFFFFFLL;
if ( v3 >= a1[a2 - 1] + v4 * 0.5 )
return 4294967294LL;
return (unsigned int)(int)((v3 - v5) / v4);
}

canonical_decompiled_code:
__int64 __fastcall func0(float *a1, int a2, float a3)
{
double v3; // xmm0_8
double v4; // xmm2_8
double v5; // xmm1_8

v3 = a3;
v4 = (float)(a1[1] - *a1);
v5 = *a1 - v4 * 0.5;
if ( v5 > v3 )
return 0xFFFFFFFFLL;
if ( v3 >= a1[a2 - 1] + v4 * 0.5 )
return 4294967294LL;
return (unsigned int)(int)((v3 - v5) / v4);
}

original_code:
int findbin(float x, float *xbin, unsigned int nbin)
{
 int bin;
 float inter;
 inter = xbin[1]-xbin[0];
 if (x < xbin[0]-inter/2.) return -1;
 if (x >= xbin[nbin-1]+inter/2.) return -2;
 bin = (int)( (x - (xbin[0]-inter/2.))/ inter );
 return bin;
}

variable_types: x float

variable_types:
xbin
float *

variable_types:
nbin
unsigned int

variable_types: bin int

variable_types: inter float


findpeak

decompiled_code:
__int64 __fastcall findpeak(__int64 a1, int a2)
{
__int64 v2; // rax
unsigned int v3; // edx

if ( !a2 )
return 0;
v2 = 0LL;
v3 = 0;
do
{
if ( *(float *)(a1 + 4 * v2) > *(float *)(a1 + 4LL * (int)v3) )
v3 = v2;
++v2;
}
while ( v2 != a2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 v2; // rax
unsigned int v3; // edx

if ( !a2 )
return 0;
v2 = 0LL;
v3 = 0;
do
{
if ( *(float *)(a1 + 4 * v2) > *(float *)(a1 + 4LL * (int)v3) )
v3 = v2;
++v2;
}
while ( v2 != a2 );
return v3;
}

original_code:
int findpeak(float *ybin, unsigned int nbin)
{
 int bin,maxbin=0;
 for (bin=0;bin<nbin;bin++) {
   if ( *(ybin+bin) > *(ybin+maxbin) ) { maxbin = bin; }
 }
 return maxbin;
}

canonical_original_code:
int findpeak(float *ybin, unsigned int nbin)
{
 int bin; int maxbin = 0;
 for (bin=0;bin<nbin;bin++) {
   if ( *(ybin+bin) > *(ybin+maxbin) ) { maxbin = bin; }
 }
 return maxbin;
}

variable_types:
ybin
float *

variable_types: maxbin int


bingdev

original_code:
float bingdev(float *xbin, float *ybin, unsigned int nbin, long *idnum)
{
 int i;
 int bin,peak,wing;
 float firstdev,seconddev,fx,x;
 float stddev,F;
 int findbin(float x, float *xbin, unsigned int nbin);
 int findpeak(float *ybin, unsigned int nbin);
 peak=findpeak(ybin,nbin);
 wing = ( (peak < nbin/2) ? nbin-1: 0 );
 stddev = sqrt( 0.5*pow((xbin[wing]-xbin[peak]),2)/log(ybin[peak]/ybin[wing]) );
 F = 1.25*ybin[peak]*stddev*(sqrt(2*3.1415926535));
 do {
   firstdev = gasdev(idnum);
   x = firstdev *stddev + xbin[peak];
   fx = 1./(stddev*(sqrt(2*3.1415926535))) * exp( -0.5*pow(firstdev,2) );
   fx *= F;
   if ( (bin = findbin(x,xbin,nbin)) > 0 ) {
     seconddev = fx * ran1(idnum);
   }
 } while ((seconddev > ybin[bin]) || (bin<0));
 return x;
}

canonical_original_code:
float bingdev(float *xbin, float *ybin, unsigned int nbin, long *idnum)
{
 int i;
 int bin; int peak; int wing;
 float firstdev; float seconddev; float fx; float x;
 float stddev; float F;
 int findbin(float x, float *xbin, unsigned int nbin);
 int findpeak(float *ybin, unsigned int nbin);
 peak=findpeak(ybin,nbin);
 wing = ( (peak < nbin/2) ? nbin-1: 0 );
 stddev = sqrt( 0.5*pow((xbin[wing]-xbin[peak]),2)/log(ybin[peak]/ybin[wing]) );
 F = 1.25*ybin[peak]*stddev*(sqrt(2*3.1415926535));
 do {
   firstdev = gasdev(idnum);
   x = firstdev *stddev + xbin[peak];
   fx = 1./(stddev*(sqrt(2*3.1415926535))) * exp( -0.5*pow(firstdev,2) );
   fx *= F;
   if ( (bin = findbin(x,xbin,nbin)) > 0 ) {
     seconddev = fx * ran1(idnum);
   }
 } while ((seconddev > ybin[bin]) || (bin<0));
 return x;
}

variable_types:
idnum
long *

variable_types: i int

variable_types: peak int

variable_types: wing int

variable_types: firstdev float

variable_types: seconddev float

variable_types: fx float

variable_types: stddev float

variable_types: F float

variable_types: int (float x, float *xbin, unsigned int nbin)

variable_types:
findpeak
int (float *ybin, unsigned int nbin)

return_type: float


canonical_original_code:
void nr_rlft3(float ***data, float **speq, unsigned long nn1, unsigned long nn2, unsigned long nn3, int isign)
{
  void nr_fourn(float data[], unsigned long nn[], int ndim, int isign);
  void nrerror(char error_text[]);
  unsigned long i1; unsigned long i2; unsigned long i3; unsigned long j1; unsigned long j2; unsigned long j3; unsigned long nn[4]; unsigned long ii3;
  double theta; double wi; double wpi; double wpr; double wr; double wtemp;
  float c1; float c2; float h1r; float h1i; float h2r; float h2i;
  if (1+&data[nn1][nn2][nn3]-&data[1][1][1] != nn1*nn2*nn3)
    nrerror("rlft3: problem wiht dimensions or contiguity of data arrya\n");
  c1=0.5;
  c2 = -0.5*isign;
  theta=isign*(6.28318530717959/nn3);
  wtemp=sin(0.5*theta);
  wpr = -2.0*wtemp*wtemp;
  wpi=sin(theta);
  nn[1]=nn1;
  nn[2]=nn2;
  nn[3]=nn3 >> 1;
  if (isign == 1) {
    nr_fourn(&data[1][1][1]-1,nn,3,isign);
    for (i1=1;i1<=nn1;i1++) {
      for (i2=1,j2=0;i2<=nn2;i2++) {
        speq[i1][++j2]=data[i1][i2][1];
 speq[i1][++j2]=data[i1][i2][2];
      }
    }
  }
  for (i1=1;i1<=nn1;i1++) {
    j1=(i1 != 1 ? nn1-i1+2 : 1);
    wr=1.0;
    wi=0.0;
    for (ii3=1,i3=1;i3<=(nn3>>2)+1;i3++,ii3+=2) {
      for (i2=1;i2<=nn2;i2++) {
        if (i3 == 1) {
    j2=(i2 != 1 ? ((nn2-i2)<<1)+3 : 1);
    h1r=c1*(data[i1][i2][1]+speq[j1][j2]);
    h1i=c1*(data[i1][i2][2]-speq[j1][j2+1]);
    h2i=c2*(data[i1][i2][1]-speq[j1][j2]);
    h2r=-c2*(data[i1][i2][2]+speq[j1][j2+1]);
    data[i1][i2][1]=h1r+h2r;
    data[i1][i2][2]=h1i+h2i;
    speq[j1][j2]=h1r-h2r;
    speq[j1][j2+1]=h2i-h1i;
 } else {
    j2=(i2 != 1 ? nn2-i2+2 : 1);
    j3=nn3+3-(i3<<1);
    h1r=c1*(data[i1][i2][ii3]+data[j1][j2][j3]);
    h1i=c1*(data[i1][i2][ii3+1]-data[j1][j2][j3+1]);
    h2i=c2*(data[i1][i2][ii3]-data[j1][j2][j3]);
    h2r=-c2*(data[i1][i2][ii3+1]+data[j1][j2][j3+1]);
    data[i1][i2][ii3]=h1r+wr*h2r-wi*h2i;
    data[i1][i2][ii3+1]=h1i+wr*h2i+wi*h2r;
    data[j1][j2][j3]=h1r-wr*h2r+wi*h2i;
    data[j1][j2][j3+1]=-h1i+wr*h2i+wi*h2r;
 }
      }
      wr=(wtemp=wr)*wpr-wi*wpi+wr;
      wi=wi*wpr+wtemp*wpi+wi;
    }
  }
  if (isign == -1)
    nr_fourn(&data[1][1][1]-1,nn,3,isign);
}

variable_types:
data
float ***

variable_types:
speq
float **

variable_types: isign int

variable_types: void (float data[], unsigned long nn[], int ndim, int isign)

variable_types:
nrerror
void (char error_text[])

variable_types:
nn
unsigned long [4]

variable_types: theta double

variable_types: wi double

variable_types: wpi double

variable_types: wpr double

variable_types: wr double

variable_types: wtemp double


original_code:
void nr_fourn(float data[], unsigned long nn[], int ndim, int isign)
{
 int idim;
 unsigned long i1,i2,i3,i2rev,i3rev,ip1,ip2,ip3,ifp1,ifp2;
 unsigned long ibit,k1,k2,n,nprev,nrem,ntot;
 float tempi,tempr;
 double theta,wi,wpi,wpr,wr,wtemp;
 for (ntot=1,idim=1;idim<=ndim;idim++)
   ntot *= nn[idim];
 nprev=1;
 for (idim=ndim;idim>=1;idim--) {
   n=nn[idim];
   nrem=ntot/(n*nprev);
   ip1=nprev << 1;
   ip2=ip1*n;
   ip3=ip2*nrem;
   i2rev=1;
   for (i2=1;i2<=ip2;i2+=ip1) {
     if (i2 < i2rev) {
       for (i1=i2;i1<=i2+ip1-2;i1+=2) {
         for (i3=i1;i3<=ip3;i3+=ip2) {
    i3rev = i2rev+i3-i2;
    tempr=(data[i3]);(data[i3])=(data[i3rev]);(data[i3rev])=tempr;
    tempr=(data[i3+1]);(data[i3+1])=(data[i3rev+1]);(data[i3rev+1])=tempr;
  }
       }
     }
     ibit = ip2 >> 1;
     while (ibit >= ip1 && i2rev > ibit) {
       i2rev -= ibit;
       ibit >>= 1;
     }
     i2rev += ibit;
   }
   ifp1 = ip1;
   while (ifp1<ip2) {
     ifp2=ifp1 << 1;
     theta=isign*6.28318530717959/(ifp2/ip1);
     wtemp=sin(0.5*theta);
     wpr = -2.0*wtemp*wtemp;
     wpi=sin(theta);
     wr=1.0;
     wi=0.0;
     for (i3=1;i3<=ifp1;i3+=ip1) {
       for (i1=i3;i1<=i3+ip1-2;i1+=2) {
         for (i2=i1;i2<=ip3;i2+=ifp2) {
    k1=i2;
    k2=k1+ifp1;
    tempr=(float)wr*data[k2]-(float)wi*data[k2+1];
    tempi=(float)wr*data[k2+1]+(float)wi*data[k2];
    data[k2]=data[k1]-tempr;
    data[k2+1]=data[k1+1]-tempi;
    data[k1] += tempr;
    data[k1+1] += tempi;
  }
       }
       wr=(wtemp=wr)*wpr-wi*wpi+wr;
       wi=wi*wpr+wtemp*wpi+wi;
     }
     ifp1=ifp2;
   }
   nprev *= n;
 }
}

canonical_original_code:
void nr_fourn(float data[], unsigned long nn[], int ndim, int isign)
{
 int idim;
 unsigned long i1; unsigned long i2; unsigned long i3; unsigned long i2rev; unsigned long i3rev; unsigned long ip1; unsigned long ip2; unsigned long ip3; unsigned long ifp1; unsigned long ifp2;
 unsigned long ibit; unsigned long k1; unsigned long k2; unsigned long n; unsigned long nprev; unsigned long nrem; unsigned long ntot;
 float tempi; float tempr;
 double theta; double wi; double wpi; double wpr; double wr; double wtemp;
 for (ntot=1,idim=1;idim<=ndim;idim++)
   ntot *= nn[idim];
 nprev=1;
 for (idim=ndim;idim>=1;idim--) {
   n=nn[idim];
   nrem=ntot/(n*nprev);
   ip1=nprev << 1;
   ip2=ip1*n;
   ip3=ip2*nrem;
   i2rev=1;
   for (i2=1;i2<=ip2;i2+=ip1) {
     if (i2 < i2rev) {
       for (i1=i2;i1<=i2+ip1-2;i1+=2) {
         for (i3=i1;i3<=ip3;i3+=ip2) {
    i3rev = i2rev+i3-i2;
    tempr=(data[i3]);(data[i3])=(data[i3rev]);(data[i3rev])=tempr;
    tempr=(data[i3+1]);(data[i3+1])=(data[i3rev+1]);(data[i3rev+1])=tempr;
  }
       }
     }
     ibit = ip2 >> 1;
     while (ibit >= ip1 && i2rev > ibit) {
       i2rev -= ibit;
       ibit >>= 1;
     }
     i2rev += ibit;
   }
   ifp1 = ip1;
   while (ifp1<ip2) {
     ifp2=ifp1 << 1;
     theta=isign*6.28318530717959/(ifp2/ip1);
     wtemp=sin(0.5*theta);
     wpr = -2.0*wtemp*wtemp;
     wpi=sin(theta);
     wr=1.0;
     wi=0.0;
     for (i3=1;i3<=ifp1;i3+=ip1) {
       for (i1=i3;i1<=i3+ip1-2;i1+=2) {
         for (i2=i1;i2<=ip3;i2+=ifp2) {
    k1=i2;
    k2=k1+ifp1;
    tempr=(float)wr*data[k2]-(float)wi*data[k2+1];
    tempi=(float)wr*data[k2+1]+(float)wi*data[k2];
    data[k2]=data[k1]-tempr;
    data[k2+1]=data[k1+1]-tempi;
    data[k1] += tempr;
    data[k1+1] += tempi;
  }
       }
       wr=(wtemp=wr)*wpr-wi*wpi+wr;
       wi=wi*wpr+wtemp*wpi+wi;
     }
     ifp1=ifp2;
   }
   nprev *= n;
 }
}

variable_types:
data
float []

variable_types:
nn
unsigned long []

variable_types: ndim int

variable_types: idim int

variable_types:
ibit
unsigned long

variable_types:
n
unsigned long

variable_types:
nprev
unsigned long

variable_types:
nrem
unsigned long

variable_types:
ntot
unsigned long

variable_types: tempi float

variable_types: tempr float


decompiled_code:
__int64 __fastcall test_parse_stdarguments(int a1, __int64 a2, const char *a3, const char *a4, _DWORD *a5, __int64 a6, _DWORD *a7)
{
const void **v10; // rbx
__int64 v11; // r12
int v12; // er8
int v14; // ebp

if ( a1 > 1 )
{
v10 = (const void **)(a2 + 8);
v11 = a2 + 8LL * (unsigned int)(a1 - 2) + 16;
v12 = 0;
while ( !memcmp(&unk_1CB, *v10, 2uLL) )
{
if ( !memcmp("--help", *v10, 6uLL) )
goto LABEL_3;
if ( memcmp("--debug", *v10, 7uLL) )
{
if ( !memcmp("--version", *v10, 9uLL) )
{
fprintf(stdout, "v%s\n", a4);
return 901LL;
}
LABEL_6:
v14 = v12 + 1;
strcpy(*(char **)(a6 + 8LL * v12), (const char *)*v10);
v12 = v14;
goto LABEL_7;
}
*a5 |= 4u;
LABEL_7:
if ( ++v10 == (const void **)v11 )
goto LABEL_18;
}
if ( *(_BYTE *)*v10 == 45 )
{
if ( !memcmp("-h", *v10, 2uLL) )
{
LABEL_3:
fputs(a3, stdout);
return 901LL;
}
if ( !memcmp("-v", *v10, 2uLL) )
{
*a5 |= 1u;
goto LABEL_7;
}
}
goto LABEL_6;
}
v12 = 0;
LABEL_18:
*a7 = v12;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, const char *a3, const char *a4, _DWORD *a5, __int64 a6, _DWORD *a7)
{
const void **v10; // rbx
__int64 v11; // r12
int v12; // er8
int v14; // ebp

if ( a1 > 1 )
{
v10 = (const void **)(a2 + 8);
v11 = a2 + 8LL * (unsigned int)(a1 - 2) + 16;
v12 = 0;
while ( !memcmp(&unk_1CB, *v10, 2uLL) )
{
if ( !memcmp("--help", *v10, 6uLL) )
goto LABEL_3;
if ( memcmp("--debug", *v10, 7uLL) )
{
if ( !memcmp("--version", *v10, 9uLL) )
{
fprintf(stdout, "v%s\n", a4);
return 901LL;
}
LABEL_6:
v14 = v12 + 1;
strcpy(*(char **)(a6 + 8LL * v12), (const char *)*v10);
v12 = v14;
goto LABEL_7;
}
*a5 |= 4u;
LABEL_7:
if ( ++v10 == (const void **)v11 )
goto LABEL_18;
}
if ( *(_BYTE *)*v10 == 45 )
{
if ( !memcmp("-h", *v10, 2uLL) )
{
LABEL_3:
fputs(a3, stdout);
return 901LL;
}
if ( !memcmp("-v", *v10, 2uLL) )
{
*a5 |= 1u;
goto LABEL_7;
}
}
goto LABEL_6;
}
v12 = 0;
LABEL_18:
*a7 = v12;
return 0LL;
}

original_code:
int test_parse_stdarguments(int argc, char *argv[], char help[],
  char version[], int *FLAGS, char *nonstdargs[], int *nnonstd)
{
 int status = 0;
 int i, n;
 i=0;
 n=0;
 while (++i < argc) {
  if (!strncmp("--",argv[i],2)) {
   if (!strncmp("--help", argv[i], 6)) {
    fprintf(stdout,"%s",help);
    return(901);
   }
   else if (!strncmp("--debug",argv[i],7)) {
    *FLAGS |= 1 << 2;
    continue;
   }
   else if (!strncmp("--version", argv[i],9)) {
    fprintf(stdout,"v%s\n", version);
    return(901);
   }
  } else if (!strncmp("-",argv[i],1)) {
   if (!strncmp("-h",argv[i],2)) {
    fprintf(stdout,"%s",help);
    return(901);
   }
   else if (!strncmp("-v", argv[i],2)) {
    *FLAGS |= 1 << 0;
    continue;
   }
  }
  strcpy(nonstdargs[n++], argv[i]);
 }
 *nnonstd=n;
 return(status);
}

canonical_original_code:
int test_parse_stdarguments(int argc, char *argv[], char help[], char version[], int *FLAGS, char *nonstdargs[], int *nnonstd)
{
 int status = 0;
 int i; int n;
 i=0;
 n=0;
 while (++i < argc) {
  if (!strncmp("--",argv[i],2)) {
   if (!strncmp("--help", argv[i], 6)) {
    fprintf(stdout,"%s",help);
    return(901);
   }
   else if (!strncmp("--debug",argv[i],7)) {
    *FLAGS |= 1 << 2;
    continue;
   }
   else if (!strncmp("--version", argv[i],9)) {
    fprintf(stdout,"v%s\n", version);
    return(901);
   }
  } else if (!strncmp("-",argv[i],1)) {
   if (!strncmp("-h",argv[i],2)) {
    fprintf(stdout,"%s",help);
    return(901);
   }
   else if (!strncmp("-v", argv[i],2)) {
    *FLAGS |= 1 << 0;
    continue;
   }
  }
  strcpy(nonstdargs[n++], argv[i]);
 }
 *nnonstd=n;
 return(status);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
help
char []

variable_types:
version
char []

variable_types:
FLAGS
int *

variable_types:
nonstdargs
char *[]

variable_types:
nnonstd
int *

variable_types: status int

variable_types: i int

variable_types: n int


decompiled_code:
__int64 __fastcall test_result_message(const char *a1, unsigned int a2)
{
__int64 result; // rax

if ( a2 )
{
printf("%s: %d failures\n", a1, a2);
result = 1LL;
}
else
{
printf("%s: PASS\n", a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, unsigned int a2)
{
__int64 result; // rax

if ( a2 )
{
printf("%s: %d failures\n", a1, a2);
result = 1LL;
}
else
{
printf("%s: PASS\n", a1);
result = 0LL;
}
return result;
}

original_code:
int test_result_message(char testname[], int nfailures)
{
 int status = 0;
 if (nfailures != 0) {
  status = 1;
  printf ("%s: %d failures\n",testname, nfailures);
 } else {
  printf ("%s: PASS\n",testname);
 }
 return(status);
}

variable_types:
testname
char []

variable_types: nfailures int


clipalloc

decompiled_code:
__int64 __fastcall clipalloc(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

a2[4] = ivector();
a2[1] = ulmatrixc(a1, 2LL);
a2[2] = dvectorc(a1);
result = dvectorc(a1);
a2[3] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

a2[4] = ivector();
a2[1] = ulmatrixc(a1, 2LL);
a2[2] = dvectorc(a1);
result = dvectorc(a1);
a2[3] = result;
return result;
}

original_code:
void clipalloc (long int n, CLIP *strct)
{
 strct->clip_tclip = ivector(n);
 strct->clip_sigbox = ulmatrixc(n,2);
 strct->clip_lsigma = dvectorc(n);
 strct->clip_hsigma = dvectorc(n);
 return;
}

canonical_original_code:
void clipalloc(long n, struct CLIP *strct)
{
 strct->clip_tclip = ivector(n);
 strct->clip_sigbox = ulmatrixc(n,2);
 strct->clip_lsigma = dvectorc(n);
 strct->clip_hsigma = dvectorc(n);
 return;
}

variable_types: n long

variable_types: struct CLIP { int clip_niter; unsigned long **clip_sigbox; double *clip_lsigma; int *clip_tclip; struct CCD { double ccd_rnoise; } clip_chip; } *

user_defined_types: struct CLIP { int clip_niter; unsigned long **clip_sigbox; double *clip_lsigma; int *clip_tclip; struct CCD clip_chip; }


decompiled_code:
__int64 __fastcall free_clip(_QWORD *a1)
{
free_ivector(a1[4]);
free_ulmatrix(a1[1]);
free_dvector(a1[2]);
return free_dvector(a1[3]);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
free_ivector(a1[4]);
free_ulmatrix(a1[1]);
free_dvector(a1[2]);
return free_dvector(a1[3]);
}

original_code:
void free_clip (CLIP *strct)
{
 free_ivector(strct->clip_tclip);
 free_ulmatrix(strct->clip_sigbox);
 free_dvector(strct->clip_lsigma);
 free_dvector(strct->clip_hsigma);
 return;
}

canonical_original_code:
void free_clip(struct CLIP *strct)
{
 free_ivector(strct->clip_tclip);
 free_ulmatrix(strct->clip_sigbox);
 free_dvector(strct->clip_lsigma);
 free_dvector(strct->clip_hsigma);
 return;
}


gettclip

decompiled_code:
__int64 __fastcall gettclip(const char **a1, _DWORD *a2, int a3)
{
const char **v3; // rbx
__int64 v5; // r14
unsigned __int64 v6; // rcx
const char *v7; // rbp
unsigned __int64 v8; // rax
unsigned __int64 v9; // rcx
unsigned __int64 v10; // rcx

if ( a3 <= 0 )
return 0LL;
v3 = a1;
v5 = (__int64)&a1[(unsigned int)(a3 - 1) + 1];
do
{
v7 = *v3;
v8 = strlen(*v3);
v9 = 8LL;
if ( v8 <= 8 )
v9 = v8;
if ( !memcmp(v7, "ccdclip", v9) )
{
*a2 = 1;
}
else
{
v6 = 8LL;
if ( v8 <= 8 )
v6 = v8;
if ( !memcmp(v7, "sigclip", v6) )
{
*a2 = 2;
}
else
{
v10 = 9LL;
if ( v8 <= 9 )
v10 = v8;
if ( !memcmp(v7, "sigclipr", v10) )
{
*a2 = 3;
}
else
{
if ( v8 > 9 )
v8 = 9LL;
if ( memcmp(v7, "sigclipb", v8) )
{
printf("ERROR: Unknown clipping (%s)\n", v7);
return 1LL;
}
*a2 = 4;
}
}
}
++v3;
++a2;
}
while ( v3 != (const char **)v5 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char **a1, _DWORD *a2, int a3)
{
const char **v3; // rbx
__int64 v5; // r14
unsigned __int64 v6; // rcx
const char *v7; // rbp
unsigned __int64 v8; // rax
unsigned __int64 v9; // rcx
unsigned __int64 v10; // rcx

if ( a3 <= 0 )
return 0LL;
v3 = a1;
v5 = (__int64)&a1[(unsigned int)(a3 - 1) + 1];
do
{
v7 = *v3;
v8 = strlen(*v3);
v9 = 8LL;
if ( v8 <= 8 )
v9 = v8;
if ( !memcmp(v7, "ccdclip", v9) )
{
*a2 = 1;
}
else
{
v6 = 8LL;
if ( v8 <= 8 )
v6 = v8;
if ( !memcmp(v7, "sigclip", v6) )
{
*a2 = 2;
}
else
{
v10 = 9LL;
if ( v8 <= 9 )
v10 = v8;
if ( !memcmp(v7, "sigclipr", v10) )
{
*a2 = 3;
}
else
{
if ( v8 > 9 )
v8 = 9LL;
if ( memcmp(v7, "sigclipb", v8) )
{
printf("ERROR: Unknown clipping (%s)\n", v7);
return 1LL;
}
*a2 = 4;
}
}
}
++v3;
++a2;
}
while ( v3 != (const char **)v5 );
return 0LL;
}

original_code:
int gettclip(char *types[], int tclip[], int niter)
{
 int i;
 for (i=0; i<niter; i++) {
   if (!strncmp(types[i], "ccdclip", strlen(types[i]))) {
      tclip[i] = 1;
   } else if (!strncmp(types[i], "sigclip", strlen(types[i]))) {
      tclip[i] = 2;
   } else if (!strncmp(types[i], "sigclipr", strlen(types[i]))) {
      tclip[i] = 3;
   } else if (!strncmp(types[i], "sigclipb", strlen(types[i]))) {
      tclip[i] = 4;
   } else {
     printf("ERROR: Unknown clipping (%s)\n",types[i]);
     return(1);
   }
 }
 return(0);
}

variable_types:
types
char *[]

variable_types:
tclip
int []

variable_types: niter int


nrerror

decompiled_code:
void __fastcall __noreturn nrerror(const char *a1)
{
fwrite("Numerical Recipes run-time error ...\n", 1uLL, 0x25uLL, stderr);
fprintf(stderr, "%s\n", a1);
fwrite("... now exiting to system ...\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fwrite("Numerical Recipes run-time error ...\n", 1uLL, 0x25uLL, stderr);
fprintf(stderr, "%s\n", a1);
fwrite("... now exiting to system ...\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}

original_code:
void nrerror(char error_text[])
{
 fprintf(stderr,"Numerical Recipes run-time error ...\n");
 fprintf(stderr,"%s\n",error_text);
 fprintf(stderr,"... now exiting to system ...\n");
 exit(1);
}


original_code:
float **nr_matrix(long nrl, long nrh, long ncl, long nch)
{
 long i, nrow=nrh-nrl+1, ncol=nch-ncl+1;
 float **m;
 m=(float **) malloc((size_t)((nrow+1)*sizeof(float*)));
 if (!m) nrerror("allocation failure 1 in nr_matrix()");
 m += 1;
 m -= nrl;
 m[nrl]=(float *) malloc((size_t)((nrow*ncol+1)*sizeof(float)));
 if (!m[nrl]) nrerror("allocation failure 2 in nr_matrix()");
 m[nrl] += 1;
 m[nrl] -= ncl;
 for (i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
 return m;
}

canonical_original_code:
float **nr_matrix(long nrl, long nrh, long ncl, long nch)
{
 long i; long nrow = nrh-nrl+1; long ncol = nch-ncl+1;
 float **m;
 m=(float **) malloc((unsigned long)((nrow+1)*sizeof(float *)));
 if (!m) nrerror("allocation failure 1 in nr_matrix()");
 m += 1;
 m -= nrl;
 m[nrl]=(float *) malloc((unsigned long)((nrow*ncol+1)*sizeof(float)));
 if (!m[nrl]) nrerror("allocation failure 2 in nr_matrix()");
 m[nrl] += 1;
 m[nrl] -= ncl;
 for (i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
 return m;
}

variable_types: nrl long

variable_types: nrh long

variable_types: ncl long

variable_types: nch long

variable_types: i long

variable_types: nrow long

variable_types: ncol long

variable_types:
m
float **

return_type: float **


original_code:
float ***nr_f3tensor(long nrl, long nrh, long ncl, long nch, long ndl,
 long ndh)
{
 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
 float ***t;
 t=(float ***) malloc((size_t)((nrow+1)*sizeof(float **)));
 if (!t) nrerror("allocation failure 1 in nr_f3tensor()");
 t += 1;
 t -= nrl;
 t[nrl]=(float **) malloc((size_t)((nrow*ncol+1)*sizeof(float *)));
 if (!t[nrl]) nrerror("allocation failure 2 in nr_f3tensor()");
 t[nrl] += 1;
 t[nrl] -= ncl;
 t[nrl][ncl]=(float *) malloc((size_t)((nrow*ncol*ndep+1)*sizeof(float)));
 if (!t[nrl][ncl]) nrerror("allocation failure 3 in f3tensor()");
 t[nrl][ncl] += 1;
 t[nrl][ncl] -= ndl;
 for (j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
 for (i=nrl+1;i<=nrh;i++) {
   t[i]=t[i-1]+ncol;
   t[i][ncl]=t[i-1][ncl]+ncol*ndep;
   for (j=ncl+i;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
 }
 return t;
}

canonical_original_code:
float ***nr_f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
{
 long i; long j; long nrow = nrh-nrl+1; long ncol = nch-ncl+1; long ndep = ndh-ndl+1;
 float ***t;
 t=(float ***) malloc((unsigned long)((nrow+1)*sizeof(float **)));
 if (!t) nrerror("allocation failure 1 in nr_f3tensor()");
 t += 1;
 t -= nrl;
 t[nrl]=(float **) malloc((unsigned long)((nrow*ncol+1)*sizeof(float *)));
 if (!t[nrl]) nrerror("allocation failure 2 in nr_f3tensor()");
 t[nrl] += 1;
 t[nrl] -= ncl;
 t[nrl][ncl]=(float *) malloc((unsigned long)((nrow*ncol*ndep+1)*sizeof(float)));
 if (!t[nrl][ncl]) nrerror("allocation failure 3 in f3tensor()");
 t[nrl][ncl] += 1;
 t[nrl][ncl] -= ndl;
 for (j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
 for (i=nrl+1;i<=nrh;i++) {
   t[i]=t[i-1]+ncol;
   t[i][ncl]=t[i-1][ncl]+ncol*ndep;
   for (j=ncl+i;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
 }
 return t;
}

variable_types: ndl long

variable_types: ndh long

variable_types: j long

variable_types: ndep long

variable_types:
t
float ***

return_type: float ***


original_code:
void nr_free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
{
 free((char*) (m[nrl]+ncl-1));
 free((char*) (m+nrl-1));
}

canonical_original_code:
void nr_free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
{
 free((char *) (m[nrl]+ncl-1));
 free((char *) (m+nrl-1));
}


original_code:
void nr_free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch,
 long ndl, long ndh)
{
 free((char*) (t[nrl][ncl]+ndl-1));
 free((char*) (t[nrl]+ncl-1));
 free((char*) (t+nrl-1));
}

canonical_original_code:
void nr_free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
{
 free((char *) (t[nrl][ncl]+ndl-1));
 free((char *) (t[nrl]+ncl-1));
 free((char *) (t+nrl-1));
}


fmoffatS

original_code:
void fmoffatS(double x[], double a[], double *y, double dyda[], int na)
{
 double brackett, arg1, arg2, arg3;
 arg1 = (x[0]-a[2])/a[5];
 arg2 = (x[1]-a[3])/a[6];
 brackett = 1 + arg1*arg1 + arg2*arg2;
 arg3 = -2.*a[1]*a[4]*pow(brackett,a[4]-1);
 *y = a[0] + a[1]*pow(brackett,a[4]);
 dyda[0] = 1;
 dyda[1] = (*y - a[0])/a[1];
 dyda[2] = arg3 * arg1/a[5];
 dyda[3] = arg3 * arg2/a[6];
 dyda[4] = (*y - a[0]) * log(brackett);
 dyda[5] = arg3 * arg1*arg1/a[5];
 dyda[6] = arg3 * arg2*arg2/a[6];
 return;
}

canonical_original_code:
void fmoffatS(double x[], double a[], double *y, double dyda[], int na)
{
 double brackett; double arg1; double arg2; double arg3;
 arg1 = (x[0]-a[2])/a[5];
 arg2 = (x[1]-a[3])/a[6];
 brackett = 1 + arg1*arg1 + arg2*arg2;
 arg3 = -2.*a[1]*a[4]*pow(brackett,a[4]-1);
 *y = a[0] + a[1]*pow(brackett,a[4]);
 dyda[0] = 1;
 dyda[1] = (*y - a[0])/a[1];
 dyda[2] = arg3 * arg1/a[5];
 dyda[3] = arg3 * arg2/a[6];
 dyda[4] = (*y - a[0]) * log(brackett);
 dyda[5] = arg3 * arg1*arg1/a[5];
 dyda[6] = arg3 * arg2*arg2/a[6];
 return;
}

variable_types:
x
double []

variable_types:
a
double []

variable_types:
y
double *

variable_types:
dyda
double []

variable_types: brackett double


decompiled_code:
void *__fastcall klfits_header_vector(int a1)
{
return malloc(192LL * a1);
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
return malloc(192LL * a1);
}

original_code:
KLFITS_HEADER *klfits_header_vector(int nh)
{
 KLFITS_HEADER *hv;
 hv=(KLFITS_HEADER *) malloc((size_t) (nh*sizeof(KLFITS_HEADER)));
 return(hv);
}

canonical_original_code:
struct klfits_header *klfits_header_vector(int nh)
{
 struct klfits_header *hv;
 hv=(struct klfits_header *) malloc((unsigned long) (nh*sizeof(KLFITS_HEADER)));
 return(hv);
}

variable_types: nh int

variable_types: struct klfits_header { char keyword[9]; char value_str[71]; char value_byte; long value_lint; double value_double; int datatype; char comment[71]; struct klfits_header *next; } *


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

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

original_code:
void free_klfits_header_vector(KLFITS_HEADER *hv)
{
 free((char*) hv);
}

canonical_original_code:
void free_klfits_header_vector(struct klfits_header *hv)
{
 free((char *) hv);
}

user_defined_types: struct klfits_header { char keyword[9]; char value_str[71]; char value_byte; long value_lint; double value_double; int datatype; char comment[71]; struct klfits_header *next; }


decompiled_code:
__int64 __fastcall klfits_update_key(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, char a15, __int64 a16, __int64 a17, __int64 a18, __int64 a19, __int64 a20, __int64 a21, __int64 a22, __int64 a23, __int64 a24, char a25, __int64 a26, double a27, __int64 a28)
{
float v20; // xmm0_4
float v22; // [rsp+4h] [rbp-24h] BYREF
__int64 v23; // [rsp+8h] [rbp-20h] BYREF
int v24; // [rsp+10h] [rbp-18h] BYREF
int v25; // [rsp+14h] [rbp-14h] BYREF
__int16 v26; // [rsp+18h] [rbp-10h] BYREF
__int16 v27; // [rsp+1Ah] [rbp-Eh] BYREF
int v28[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v28[0] = 0;
switch ( (int)a28 )
{
case 11:
if ( (unsigned int)ffuky(a1, 11LL, &a15, &a25, (char *)&a28 + 4, v28) )
goto LABEL_21;
break;
case 14:
case 31:
v25 = a26;
if ( (unsigned int)ffuky(a1, (unsigned int)a28, &a15, &v25, (char *)&a28 + 4, v28) )
printerror((unsigned int)v28[0]);
break;
case 16:
if ( (unsigned int)ffuky(a1, 16LL, &a15, (char *)&a16 + 1, (char *)&a28 + 4, v28) )
goto LABEL_21;
break;
case 20:
v26 = a26;
if ( (unsigned int)ffuky(a1, 20LL, &a15, &v26, (char *)&a28 + 4, v28) )
printerror((unsigned int)v28[0]);
break;
case 21:
v27 = a26;
if ( (unsigned int)ffuky(a1, 21LL, &a15, &v27, (char *)&a28 + 4, v28) )
printerror((unsigned int)v28[0]);
break;
case 30:
v24 = a26;
if ( (unsigned int)ffuky(a1, 30LL, &a15, &v24, (char *)&a28 + 4, v28) )
printerror((unsigned int)v28[0]);
break;
case 40:
v23 = a26;
if ( (unsigned int)ffuky(a1, 40LL, &a15, &v23, (char *)&a28 + 4, v28) )
printerror((unsigned int)v28[0]);
break;
case 41:
if ( (unsigned int)ffuky(a1, 41LL, &a15, &a26, (char *)&a28 + 4, v28) )
goto LABEL_21;
break;
case 42:
v20 = a27;
v22 = v20;
if ( (unsigned int)ffuky(a1, 42LL, &a15, &v22, (char *)&a28 + 4, v28) )
printerror((unsigned int)v28[0]);
break;
case 82:
if ( (unsigned int)ffuky(a1, 82LL, &a15, &a27, (char *)&a28 + 4, v28) )
LABEL_21:
printerror((unsigned int)v28[0]);
break;
default:
v28[0] = 410;
printerror(410LL);
break;
}
return (unsigned int)v28[0];
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, char a15, __int64 a16, __int64 a17, __int64 a18, __int64 a19, __int64 a20, __int64 a21, __int64 a22, __int64 a23, __int64 a24, char a25, __int64 a26, double a27, __int64 a28)
{
float v20; // xmm0_4
float v22; // [rsp+4h] [rbp-24h] BYREF
__int64 v23; // [rsp+8h] [rbp-20h] BYREF
int v24; // [rsp+10h] [rbp-18h] BYREF
int v25; // [rsp+14h] [rbp-14h] BYREF
__int16 v26; // [rsp+18h] [rbp-10h] BYREF
__int16 v27; // [rsp+1Ah] [rbp-Eh] BYREF
int v28[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v28[0] = 0;
switch ( (int)a28 )
{
case 11:
if ( (unsigned int)ffuky(a1, 11LL, &a15, &a25, (char *)&a28 + 4, v28) )
goto LABEL_21;
break;
case 14:
case 31:
v25 = a26;
if ( (unsigned int)ffuky(a1, (unsigned int)a28, &a15, &v25, (char *)&a28 + 4, v28) )
printerror((unsigned int)v28[0]);
break;
case 16:
if ( (unsigned int)ffuky(a1, 16LL, &a15, (char *)&a16 + 1, (char *)&a28 + 4, v28) )
goto LABEL_21;
break;
case 20:
v26 = a26;
if ( (unsigned int)ffuky(a1, 20LL, &a15, &v26, (char *)&a28 + 4, v28) )
printerror((unsigned int)v28[0]);
break;
case 21:
v27 = a26;
if ( (unsigned int)ffuky(a1, 21LL, &a15, &v27, (char *)&a28 + 4, v28) )
printerror((unsigned int)v28[0]);
break;
case 30:
v24 = a26;
if ( (unsigned int)ffuky(a1, 30LL, &a15, &v24, (char *)&a28 + 4, v28) )
printerror((unsigned int)v28[0]);
break;
case 40:
v23 = a26;
if ( (unsigned int)ffuky(a1, 40LL, &a15, &v23, (char *)&a28 + 4, v28) )
printerror((unsigned int)v28[0]);
break;
case 41:
if ( (unsigned int)ffuky(a1, 41LL, &a15, &a26, (char *)&a28 + 4, v28) )
goto LABEL_21;
break;
case 42:
v20 = a27;
v22 = v20;
if ( (unsigned int)ffuky(a1, 42LL, &a15, &v22, (char *)&a28 + 4, v28) )
printerror((unsigned int)v28[0]);
break;
case 82:
if ( (unsigned int)ffuky(a1, 82LL, &a15, &a27, (char *)&a28 + 4, v28) )
LABEL_21:
printerror((unsigned int)v28[0]);
break;
default:
v28[0] = 410;
printerror(410LL);
break;
}
return (unsigned int)v28[0];
}

original_code:
int klfits_update_key( fitsfile *fptr, KLFITS_HEADER header )
{
 int status=0;
 short int sivalue;
 unsigned short int usivalue;
 int ivalue;
 unsigned int uivalue;
 unsigned long int ulivalue;
 float fvalue;
 switch (header.datatype) {
   case 16:
    if ( ffuky(fptr, header.datatype, header.keyword,
   header.value_str, header.comment, &status) )
  printerror( status );
    break;
   case 11:
    if ( ffuky(fptr, header.datatype, header.keyword,
   &(header.value_byte), header.comment, &status) )
  printerror( status );
    break;
   case 21:
    sivalue = (short int)(header.value_lint);
    if ( ffuky(fptr, header.datatype, header.keyword, &sivalue,
   header.comment, &status) )
  printerror( status );
    break;
   case 20:
    usivalue = (unsigned short int)(header.value_lint);
    if ( ffuky(fptr, header.datatype, header.keyword, &usivalue,
   header.comment, &status) )
  printerror( status );
    break;
   case 14:
   case 31:
    ivalue = (int)(header.value_lint);
    if ( ffuky(fptr, header.datatype, header.keyword, &ivalue,
   header.comment, &status) )
  printerror( status );
    break;
   case 30:
    uivalue = (unsigned int)(header.value_lint);
    if ( ffuky(fptr, header.datatype, header.keyword, &uivalue,
   header.comment, &status) )
  printerror( status );
    break;
   case 41:
    if ( ffuky(fptr, header.datatype, header.keyword,
   &(header.value_lint), header.comment, &status) )
  printerror( status );
    break;
   case 40:
    ulivalue = (unsigned long int)(header.value_lint);
    if ( ffuky(fptr, header.datatype, header.keyword, &ulivalue,
   header.comment, &status) )
  printerror( status );
    break;
   case 42:
    fvalue = (float)(header.value_double);
 if ( ffuky(fptr, header.datatype, header.keyword, &fvalue,
   header.comment, &status) )
  printerror( status );
    break;
   case 82:
    if ( ffuky(fptr, header.datatype, header.keyword,
   &(header.value_double), header.comment, &status) )
  printerror( status );
    break;
   default:
    status = 410;
    printerror( status );
 break;
 }
 return(status);
}

canonical_original_code:
int klfits_update_key(struct fitsfile *fptr, struct klfits_header header)
{
 int status = 0;
 short sivalue;
 unsigned short usivalue;
 int ivalue;
 unsigned int uivalue;
 unsigned long ulivalue;
 float fvalue;
 switch (header.datatype) {
   case 16:
    if ( ffuky(fptr, header.datatype, header.keyword,
   header.value_str, header.comment, &status) )
  printerror( status );
    break;
   case 11:
    if ( ffuky(fptr, header.datatype, header.keyword,
   &(header.value_byte), header.comment, &status) )
  printerror( status );
    break;
   case 21:
    sivalue = (short)(header.value_lint);
    if ( ffuky(fptr, header.datatype, header.keyword, &sivalue,
   header.comment, &status) )
  printerror( status );
    break;
   case 20:
    usivalue = (unsigned short)(header.value_lint);
    if ( ffuky(fptr, header.datatype, header.keyword, &usivalue,
   header.comment, &status) )
  printerror( status );
    break;
   case 14:
   case 31:
    ivalue = (int)(header.value_lint);
    if ( ffuky(fptr, header.datatype, header.keyword, &ivalue,
   header.comment, &status) )
  printerror( status );
    break;
   case 30:
    uivalue = (unsigned int)(header.value_lint);
    if ( ffuky(fptr, header.datatype, header.keyword, &uivalue,
   header.comment, &status) )
  printerror( status );
    break;
   case 41:
    if ( ffuky(fptr, header.datatype, header.keyword,
   &(header.value_lint), header.comment, &status) )
  printerror( status );
    break;
   case 40:
    ulivalue = (unsigned long)(header.value_lint);
    if ( ffuky(fptr, header.datatype, header.keyword, &ulivalue,
   header.comment, &status) )
  printerror( status );
    break;
   case 42:
    fvalue = (float)(header.value_double);
 if ( ffuky(fptr, header.datatype, header.keyword, &fvalue,
   header.comment, &status) )
  printerror( status );
    break;
   case 82:
    if ( ffuky(fptr, header.datatype, header.keyword,
   &(header.value_double), header.comment, &status) )
  printerror( status );
    break;
   default:
    status = 410;
    printerror( status );
 break;
 }
 return(status);
}

variable_types: struct fitsfile { int HDUposition; struct FITSfile { int filehandle; int driver; int open_count; char *filename; int validcode; int only_one; long long filesize; long long logfilesize; int lasthdu; long long bytepos; long long io_pos; int curbuf; int curhdu; int hdutype; int writemode; int maxhdu; int MAXHDU; long long *headstart; long long headend; long long ENDpos; long long nextkey; long long datastart; int imgdim; long long imgnaxis[99]; int tfield; int startcol; long long origrows; long long numrows; long long rowlength; struct tcolumn { char ttype[70]; long long tbcol; int tdatatype; long long trepeat; double tscale; double tzero; long long tnull; char strnull[20]; char tform[10]; long twidth; } *tableptr; long long heapstart; long long heapsize; int request_compress_type; long request_tilesize[6]; float request_quantize_level; int request_quantize_method; int request_dither_seed; int request_lossy_int_compress; int request_huge_hdu; float request_hcomp_scale; int request_hcomp_smooth; int compress_type; long tilesize[6]; float quantize_level; int quantize_method; int dither_seed; int compressimg; char zcmptype[12]; int zbitpix; int zndim; long znaxis[6]; long maxtilelen; long maxelem; int cn_compressed; int cn_uncompressed; int cn_gzip_data; int cn_zscale; int cn_zzero; int cn_zblank; double zscale; double zzero; double cn_bscale; double cn_bzero; double cn_actual_bzero; int zblank; int rice_blocksize; int rice_bytepix; float hcomp_scale; int hcomp_smooth; int *tilerow; long *tiledatasize; int *tiletype; void **tiledata; void **tilenullarray; int *tileanynull; char *iobuffer; long bufrecnum[40]; int dirty[40]; int ageindex[40]; } *Fptr; } *

variable_types: struct klfits_header { char keyword[9]; char value_str[71]; char value_byte; long value_lint; double value_double; int datatype; char comment[71]; struct klfits_header *next; }

variable_types: status int

variable_types: sivalue short

variable_types:
usivalue
unsigned short

variable_types: ivalue int

variable_types:
uivalue
unsigned int

variable_types:
ulivalue
unsigned long

variable_types: fvalue float