LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/flashtool.c
// Function: dump_console_info
int dump_console_info(unsigned char *flashdata, unsigned char *path) {
    struct nvs_console_info cinfo;
    char macaddress[6];
    FILE *fp = NULL;
    int i;

    // read console info and mac address
    nvs_read(flashdata, 0, 2, NVS_VAR_BLOCK2_CONSOLE_INF0, sizeof(cinfo), (unsigned char *)&cinfo);
    nvs_read(flashdata, 0, 0, NVS_VAR_BLOCK0_MAC_ADDRESS, sizeof(macaddress), macaddress);

    fp = fopen(path, "w");
    if(!fp) {
        return 1;
    }

    fprintf(fp, "motherboard serial: %.*s\n", (int)sizeof(cinfo.moboserial), cinfo.moboserial);
    fprintf(fp, "serial: %.*s\n", (int)sizeof(cinfo.serial), cinfo.serial);
    fprintf(fp, "model: %.*s\n", (int)sizeof(cinfo.model), cinfo.model);
    fprintf(fp, "mac address: ");
    for(i = 0; i < sizeof(macaddress); i++) {
        fprintf(fp, "%02X%c", macaddress[i] & 0xFF, (i == sizeof(macaddress) - 1) ? '\n' : ':');
    }

    fprintf(fp, "\n");

    fclose(fp);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xa(%rsp), %r9
xorl %esi, %esi
movl $0x2, %edx
xorl %ecx, %ecx
movl $0x4e, %r8d
callq 0x4c30
leaq 0x4(%rsp), %r9
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl $0x21, %ecx
movl $0x6, %r8d
callq 0x4c30
leaq 0x4b5e(%rip), %rsi      # 0x83aa
movq %rbx, %rdi
callq 0x2170
testq %rax, %rax
je 0x3919
movq %rax, %rbx
leaq 0x4c7c(%rip), %rsi      # 0x84e3
leaq 0xa(%rsp), %rcx
movq %rax, %rdi
movl $0xe, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x3a(%rsp), %rcx
leaq 0x4c78(%rip), %rsi      # 0x84ff
movl $0xa, %ebp
movq %rbx, %rdi
movl $0xa, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x4b(%rsp), %rcx
leaq 0x4c68(%rip), %rsi      # 0x850f
movq %rbx, %rdi
movl $0xd, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x4c61(%rip), %rdi      # 0x851e
movl $0xd, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2180
movq $-0x6, %r15
leaq 0x4bfd(%rip), %r14      # 0x84da
movzbl 0xa(%rsp,%r15), %edx
incq %r15
movl $0x3a, %ecx
cmovel %ebp, %ecx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x2110
testq %r15, %r15
jne 0x38dd
movl $0xa, %edi
movq %rbx, %rsi
callq 0x20e0
movq %rbx, %rdi
callq 0x2080
xorl %eax, %eax
jmp 0x391e
movl $0x1, %eax
addq $0x58, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/flashtool.c
// Function: print_flashinfo
void print_flashinfo(unsigned char *flashdata) {
    struct nvs_console_info cinfo;
    char macaddress[6];
    int i;

    // read console info and mac address
    nvs_read(flashdata, 0, 2, NVS_VAR_BLOCK2_CONSOLE_INF0, sizeof(cinfo), (unsigned char *)&cinfo);
    nvs_read(flashdata, 0, 0, NVS_VAR_BLOCK0_MAC_ADDRESS, sizeof(macaddress), macaddress);

    printf("* motherboard serial: %.*s\n", (int)sizeof(cinfo.moboserial), cinfo.moboserial);
    printf("* serial: %.*s\n", (int)sizeof(cinfo.serial), cinfo.serial);
    printf("* model: %.*s\n", (int)sizeof(cinfo.model), cinfo.model);
    printf("* mac address: ");
    for(i = 0; i < sizeof(macaddress); i++) {
        printf("%02X%c", macaddress[i] & 0xFF, (i == sizeof(macaddress) - 1) ? '\n' : ':');
    }

    printf("\n");
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x60, %rsp
movq %rdi, %rbx
leaq 0x12(%rsp), %r14
xorl %esi, %esi
movl $0x2, %edx
xorl %ecx, %ecx
movl $0x4e, %r8d
movq %r14, %r9
callq 0x4c30
leaq 0xc(%rsp), %r9
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl $0x21, %ecx
movl $0x6, %r8d
callq 0x4c30
leaq 0x4b6e(%rip), %rdi      # 0x84e1
movl $0xe, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0x20b0
leaq 0x42(%rsp), %rdx
leaq 0x4b6f(%rip), %rdi      # 0x84fd
movl $0xa, %ebp
movl $0xa, %esi
xorl %eax, %eax
callq 0x20b0
leaq 0x53(%rsp), %rdx
leaq 0x4b62(%rip), %rdi      # 0x850d
movl $0xd, %esi
xorl %eax, %eax
callq 0x20b0
leaq 0x4b5e(%rip), %rdi      # 0x851c
xorl %eax, %eax
callq 0x20b0
movq $-0x6, %r14
leaq 0x4b07(%rip), %rbx      # 0x84da
movzbl 0x12(%rsp,%r14), %esi
incq %r14
movl $0x3a, %edx
cmovel %ebp, %edx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x20b0
testq %r14, %r14
jne 0x39d3
movl $0xa, %edi
callq 0x2040
addq $0x60, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/flashtool.c
// Function: extract_flashdump
int extract_flashdump(unsigned char *flashdata, char *extractdir) {
    unsigned char *ptr;
    int len;
    char path[512];
    
    printf("extracting flash to '%s' directory ...\n", extractdir);
    
    mkdir(extractdir, S_IRWXU);

    snprintf(path, sizeof(path), "%s/%s", extractdir, "emcipl.bin");
    if(decrypt_emc_ipl(flashdata, &ptr, &len)) {
        return 1;
    }

    dumpbin(path, ptr, len);
    free(ptr);

    printf("extracted EMC IPL to '%s'!\n", path);

    snprintf(path, sizeof(path), "%s/%s", extractdir, "eapkbl.elf");
    if(decrypt_eap_kbl(flashdata, &ptr, &len)) {
        return 1;
    }

    dumpbin(path, ptr, len);
    free(ptr);
    
    printf("extracted EAP KBL to '%s'!\n", path);

    snprintf(path, sizeof(path), "%s/%s", extractdir, "consoleinfo.txt");
    dump_console_info(flashdata, path);
    
    printf("wrote console info to '%s'!\n", path);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x4ad0(%rip), %rdi      # 0x852c
xorl %eax, %eax
callq 0x20b0
movq %r14, %rdi
movl $0x1c0, %esi            # imm = 0x1C0
callq 0x2050
leaq 0x4add(%rip), %rdx      # 0x8554
leaq 0x4adc(%rip), %r8       # 0x855a
leaq 0x10(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
movq %r14, %rcx
xorl %eax, %eax
callq 0x20c0
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
callq 0x6581
movl $0x1, %ebp
testl %eax, %eax
jne 0x3b89
leaq 0x8(%rsp), %r15
movq (%r15), %rsi
leaq 0x4(%rsp), %r12
movl (%r12), %edx
leaq 0x10(%rsp), %r13
movq %r13, %rdi
callq 0x36ac
movq (%r15), %rdi
callq 0x2030
leaq 0x4ac3(%rip), %rdi      # 0x85a1
movq %r13, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x4a65(%rip), %rdx      # 0x8554
leaq 0x4a6f(%rip), %r8       # 0x8565
movl $0x200, %esi            # imm = 0x200
movq %r13, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x6a11
testl %eax, %eax
jne 0x3b89
movq 0x8(%rsp), %rsi
movl 0x4(%rsp), %edx
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x36ac
movq 0x8(%rsp), %rdi
callq 0x2030
leaq 0x4a80(%rip), %rdi      # 0x85c1
movq %r15, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x4a02(%rip), %rdx      # 0x8554
leaq 0x4a17(%rip), %r8       # 0x8570
movl $0x200, %esi            # imm = 0x200
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3800
leaq 0x4a03(%rip), %rdi      # 0x8580
movq %r15, %rsi
xorl %eax, %eax
callq 0x20b0
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/flashtool.c
// Function: rawextract_flashdump
int rawextract_flashdump(unsigned char *flashdata, char *extractdir) {
    struct bldr_hdr *emc_blhdr = flash_locate_emc_ipl(flashdata, 0);
    struct bldr_hdr *eap_blhdr = flash_locate_eap_kbl(flashdata);
    char path[512];

    snprintf(path, sizeof(path), "%s/%s", extractdir, "emcipl.bin");
    dumpbin(path, (unsigned char *)emc_blhdr, emc_blhdr->hdr_len + emc_blhdr->body_len);

    printf("raw extracted EMC IPL to '%s'!\n", path);

    snprintf(path, sizeof(path), "%s/%s", extractdir, "eapkbl.elf");
    dumpbin(path, (unsigned char *)eap_blhdr, eap_blhdr->hdr_len + eap_blhdr->body_len);

    printf("raw extracted EAP KBL to '%s'!\n", path);

    snprintf(path, sizeof(path), "%s/%s", extractdir, "consoleinfo.txt");
    dump_console_info(flashdata, path);
    
    printf("wrote console info to '%s'!\n", path);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rsi, %r14
movq %rdi, %rbx
xorl %esi, %esi
callq 0x6210
movq %rax, %rbp
movq %rbx, %rdi
callq 0x62d9
movq %rax, %r13
leaq 0x4984(%rip), %r12      # 0x8554
leaq 0x4983(%rip), %r8       # 0x855a
movq %rsp, %r15
movl $0x200, %esi            # imm = 0x200
movq %r15, %rdi
movq %r12, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x20c0
movl 0xc(%rbp), %edx
addl 0x8(%rbp), %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x36ac
leaq 0x4996(%rip), %rdi      # 0x859d
movq %r15, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x494d(%rip), %r8       # 0x8565
movl $0x200, %esi            # imm = 0x200
movq %r15, %rdi
movq %r12, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x20c0
movl 0xc(%r13), %edx
addl 0x8(%r13), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x36ac
leaq 0x4976(%rip), %rdi      # 0x85bd
movq %r15, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x4918(%rip), %r8       # 0x8570
movl $0x200, %esi            # imm = 0x200
movq %r15, %rdi
movq %r12, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3800
leaq 0x4901(%rip), %rdi      # 0x8580
movq %r15, %rsi
xorl %eax, %eax
callq 0x20b0
xorl %eax, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/hmac-sha1.c
// Function: memxor
void *
memxor (void */*restrict*/ dest, const void */*restrict*/ src, size_t n)
{
  char const *s = (char const*)src;
  char *d = (char*)dest;

  for (; n > 0; n--)
    *d++ ^= *s++;

  return dest;
}

// Assembly:
movq %rdi, %rax
testq %rdx, %rdx
je 0x4832
xorl %ecx, %ecx
movb (%rsi,%rcx), %dil
xorb %dil, (%rax,%rcx)
incq %rcx
cmpq %rcx, %rdx
jne 0x4822
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/hmac-sha1.c
// Function: hmac_sha1
int
hmac_sha1 (const void *key, size_t keylen,
	   const void *in, size_t inlen, void *resbuf)
{
  struct sha1_ctx inner;
  struct sha1_ctx outer;
  char optkeybuf[20];
  char block[64];
  char innerhash[20];

  /* Reduce the key's size, so that it becomes <= 64 bytes large.  */

  if (keylen > 64)
    {
      struct sha1_ctx keyhash;

      sha1_init_ctx (&keyhash);
      sha1_process_bytes (key, keylen, &keyhash);
      sha1_finish_ctx (&keyhash, optkeybuf);

      key = optkeybuf;
      keylen = 20;
    }

  /* Compute INNERHASH from KEY and IN.  */

  sha1_init_ctx (&inner);

  memset (block, IPAD, sizeof (block));
  memxor (block, key, keylen);

  sha1_process_block (block, 64, &inner);
  sha1_process_bytes (in, inlen, &inner);

  sha1_finish_ctx (&inner, innerhash);

  /* Compute result from KEY and INNERHASH.  */

  sha1_init_ctx (&outer);

  memset (block, OPAD, sizeof (block));
  memxor (block, key, keylen);

  sha1_process_block (block, 64, &outer);
  sha1_process_bytes (innerhash, 20, &outer);

  sha1_finish_ctx (&outer, resbuf);

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r14
cmpq $0x41, %rsi
movq %r8, 0x8(%rsp)
jb 0x488f
leaq 0x88(%rsp), %rbp
movq %rbp, %rdi
callq 0x4d00
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x60b0
leaq 0x70(%rsp), %r14
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4d41
movl $0x14, %r15d
leaq 0x88(%rsp), %rdi
callq 0x4d00
movaps 0x478d(%rip), %xmm0     # 0x9030
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
testq %r15, %r15
je 0x4947
xorl %eax, %eax
movb (%r14,%rax), %cl
xorb %cl, 0x30(%rsp,%rax)
incq %rax
cmpq %rax, %r15
jne 0x48c2
leaq 0x30(%rsp), %rbp
leaq 0x88(%rsp), %rbx
movl $0x40, %esi
movq %rbp, %rdi
movq %rbx, %rdx
callq 0x4e36
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x60b0
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x4d41
leaq 0x128(%rsp), %rdi
callq 0x4d00
movaps 0x4722(%rip), %xmm0     # 0x9040
movaps %xmm0, 0x30(%rbp)
movaps %xmm0, 0x20(%rbp)
movaps %xmm0, 0x10(%rbp)
movaps %xmm0, (%rbp)
testq %r15, %r15
je 0x49a2
xorl %eax, %eax
movb (%r14,%rax), %cl
xorb %cl, 0x30(%rsp,%rax)
incq %rax
cmpq %rax, %r15
jne 0x4935
jmp 0x49a2
leaq 0x30(%rsp), %rbx
leaq 0x88(%rsp), %r14
movl $0x40, %esi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4e36
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x60b0
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x4d41
leaq 0x128(%rsp), %rdi
callq 0x4d00
movaps 0x46ad(%rip), %xmm0     # 0x9040
movaps %xmm0, 0x30(%rbx)
movaps %xmm0, 0x20(%rbx)
movaps %xmm0, 0x10(%rbx)
movaps %xmm0, (%rbx)
leaq 0x30(%rsp), %rdi
leaq 0x128(%rsp), %rbx
movl $0x40, %esi
movq %rbx, %rdx
callq 0x4e36
leaq 0x10(%rsp), %rdi
movl $0x14, %esi
movq %rbx, %rdx
callq 0x60b0
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x4d41
xorl %eax, %eax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/keymgr.c
// Function: keymgr_loadkeys
int keymgr_loadkeys(const char *keyfile) {
    FILE *fkeyfile;
    long filesize;
    unsigned char *ptr;
    int i;
    int sz;

    fkeyfile = fopen(keyfile, "rb");
    if(!fkeyfile) {
        printf("keymgr: invalid key file!\n");
        return 1;
    }

    kmgrstate.keynames = (char **)malloc(MAXIMUM_KEYS * sizeof(char *));
    kmgrstate.keytypes = (int *)malloc(MAXIMUM_KEYS * sizeof(int));
    kmgrstate.keydata = (unsigned char **)malloc(MAXIMUM_KEYS * sizeof(char *));

    fseek(fkeyfile, 0, SEEK_END);
    filesize = ftell(fkeyfile);
    fseek(fkeyfile, 0, SEEK_SET);

    kmgrstate.filedata = (char *)malloc(filesize);
    fread(kmgrstate.filedata, 1, filesize, fkeyfile);
    fclose(fkeyfile);

    // parse all the keys
    ptr = kmgrstate.filedata;
    kmgrstate.numkeys = *(unsigned int *)ptr;
    ptr += 4;

    for(i = 0; i < kmgrstate.numkeys; i++) {
        // name
        sz = *(unsigned int *)ptr; ptr += 4;
        kmgrstate.keynames[i] = ptr; ptr += sz;

        // keytype
        kmgrstate.keytypes[i] = *(unsigned int *)ptr; ptr += 4;

        // keydat
        sz = *(unsigned int *)ptr; ptr += 4;
        kmgrstate.keydata[i] = ptr; ptr += sz;
    }

    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
leaq 0x3abe(%rip), %rsi      # 0x84ba
callq 0x2170
testq %rax, %rax
je 0x4b01
movq %rax, %r14
movl $0x8000, %edi           # imm = 0x8000
callq 0x2140
movq %rax, 0x7912(%rip)      # 0xc330
movl $0x4000, %edi           # imm = 0x4000
callq 0x2140
movq %rax, 0x7909(%rip)      # 0xc338
movl $0x8000, %edi           # imm = 0x8000
callq 0x2140
movq %rax, 0x7900(%rip)      # 0xc340
xorl %ebx, %ebx
movq %r14, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2150
movq %r14, %rdi
callq 0x2120
movq %rax, %r15
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2150
movq %r15, %rdi
callq 0x2140
movq %rax, 0x78d1(%rip)      # 0xc348
movl $0x1, %esi
movq %rax, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x2070
movq %r14, %rdi
callq 0x2080
movq 0x78af(%rip), %rax      # 0xc348
movl (%rax), %ecx
movl %ecx, 0x78af(%rip)      # 0xc350
testl %ecx, %ecx
jle 0x4b12
addq $0x4, %rax
xorl %ebx, %ebx
xorl %ecx, %ecx
movslq (%rax), %rdx
leaq 0x4(%rax), %rsi
movq 0x7875(%rip), %rdi      # 0xc330
movq %rsi, (%rdi,%rcx,8)
leaq (%rax,%rdx), %rsi
addq $0x4, %rsi
leaq 0xc(%rax,%rdx), %rax
movl -0x8(%rax), %edx
movq 0x7862(%rip), %rdi      # 0xc338
movl %edx, (%rdi,%rcx,4)
movslq -0x4(%rax), %rdx
movq 0x785c(%rip), %rdi      # 0xc340
movq %rax, (%rdi,%rcx,8)
leaq (%rdx,%rsi), %rax
addq $0x8, %rax
incq %rcx
movslq 0x7856(%rip), %rdx      # 0xc350
cmpq %rdx, %rcx
jl 0x4aad
jmp 0x4b12
leaq 0x4563(%rip), %rdi      # 0x906b
callq 0x2060
movl $0x1, %ebx
movl %ebx, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/keymgr.c
// Function: keymgr_cleanup
void keymgr_cleanup() {
    if(kmgrstate.keynames) {
        free(kmgrstate.keynames);
    }

    if(kmgrstate.keytypes) {
        free(kmgrstate.keytypes);
    }

    if(kmgrstate.keydata) {
        free(kmgrstate.keydata);
    }

    if(kmgrstate.filedata) {
        free(kmgrstate.filedata);
    }
}

// Assembly:
pushq %rax
movq 0x780e(%rip), %rdi      # 0xc330
testq %rdi, %rdi
je 0x4b2c
callq 0x2030
movq 0x7805(%rip), %rdi      # 0xc338
testq %rdi, %rdi
je 0x4b3d
callq 0x2030
movq 0x77fc(%rip), %rdi      # 0xc340
testq %rdi, %rdi
je 0x4b4e
callq 0x2030
movq 0x77f3(%rip), %rdi      # 0xc348
testq %rdi, %rdi
je 0x4b60
popq %rax
jmp 0x2030
popq %rax
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/keymgr.c
// Function: keymgr_printkeys
void keymgr_printkeys() {
    int i;

    printf("\nkey manager state:\n");
    for(i = 0; i < kmgrstate.numkeys; i++) {
        printf("\tname: '%s' keytype: 0x%X\n", kmgrstate.keynames[i], kmgrstate.keytypes[i]);
        //hexdump(kmgrstate.keydata[i], 0x10);
    }
    printf("\n");
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
leaq 0x4518(%rip), %rdi      # 0x9085
callq 0x2060
cmpl $0x0, 0x77d7(%rip)      # 0xc350
jle 0x4bb4
leaq 0x44ce(%rip), %rbx      # 0x9050
xorl %r14d, %r14d
movq 0x77a4(%rip), %rax      # 0xc330
movq (%rax,%r14,8), %rsi
movq 0x77a1(%rip), %rax      # 0xc338
movl (%rax,%r14,4), %edx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x20b0
incq %r14
movslq 0x77a1(%rip), %rax      # 0xc350
cmpq %rax, %r14
jl 0x4b85
movl $0xa, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2040
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/keymgr.c
// Function: keymgr_getkey
unsigned char *keymgr_getkey(const char *keyname, int keytype) {
    int i;

    for(i = 0; i < kmgrstate.numkeys; i++) {
        if(!strcmp(kmgrstate.keynames[i], keyname) && kmgrstate.keytypes[i] == keytype) {
            return kmgrstate.keydata[i];
        }
    }

    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movslq 0x7779(%rip), %r15      # 0xc350
testq %r15, %r15
jle 0x4c10
movl %esi, %ebp
movq %rdi, %r14
movq 0x7748(%rip), %r12      # 0xc330
movq 0x7749(%rip), %r13      # 0xc338
xorl %ebx, %ebx
movq (%r12,%rbx,8), %rdi
movq %r14, %rsi
callq 0x2100
testl %eax, %eax
jne 0x4c08
cmpl %ebp, (%r13,%rbx,4)
je 0x4c21
incq %rbx
cmpq %rbx, %r15
jne 0x4bf1
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x7718(%rip), %rax      # 0xc340
movq (%rax,%rbx,8), %rax
jmp 0x4c12
nop
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/nvs.c
// Function: nvs_read
int nvs_read(unsigned char *flashdata, unsigned int bank, unsigned int block, unsigned int offset, int size, unsigned char *buffer) {
    if(bank != 0) {
        printf("error: invalid NVS bank number %i\n", bank);
        return 1;
    }

    if(block > 4) {
        printf("error: invalid NVS block number %i\n", block);
        return 1;
    }

    if(offset >= g_nvs_block_sizes[block]) {
        printf("error: invalid NVS offset 0x%X\n", offset);
        return 1;
    }

    memcpy(buffer, flashdata + g_nvs_block_offsets[block] + offset, size);

    return 0;
}

// Assembly:
pushq %rax
testl %esi, %esi
je 0x4c3e
leaq 0x445d(%rip), %rdi      # 0x9099
jmp 0x4c8c
cmpl $0x5, %edx
jb 0x4c4e
leaq 0x4472(%rip), %rdi      # 0x90bc
movl %edx, %esi
jmp 0x4c8c
movl %edx, %edx
leaq 0x44a9(%rip), %rsi      # 0x9100
cmpl %ecx, (%rsi,%rdx,4)
jbe 0x4c83
movq %rdi, %rax
leaq 0x44ba(%rip), %rsi      # 0x9120
movl (%rsi,%rdx,4), %edx
movl %ecx, %ecx
addq %rcx, %rax
addq %rdx, %rax
movslq %r8d, %rdx
movq %r9, %rdi
movq %rax, %rsi
callq 0x2130
xorl %eax, %eax
jmp 0x4c98
leaq 0x4456(%rip), %rdi      # 0x90e0
movl %ecx, %esi
xorl %eax, %eax
callq 0x20b0
movl $0x1, %eax
popq %rcx
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/nvs.c
// Function: nvs_write
int nvs_write(unsigned char *flashdata, unsigned int bank, unsigned int block, unsigned int offset, int size, unsigned char *buffer) {
    if(bank != 0) {
        printf("error: invalid NVS bank number %i\n", bank);
        return 1;
    }

    if(block > 4) {
        printf("error: invalid NVS block number %i\n", block);
        return 1;
    }

    if(offset >= g_nvs_block_sizes[block]) {
        printf("error: invalid NVS offset 0x%X\n", offset);
        return 1;
    }

    memcpy(flashdata + g_nvs_block_offsets[block] + offset, buffer, size);

    return 0;
}

// Assembly:
pushq %rax
testl %esi, %esi
je 0x4ca8
leaq 0x43f3(%rip), %rdi      # 0x9099
jmp 0x4cf0
cmpl $0x5, %edx
jb 0x4cb8
leaq 0x4408(%rip), %rdi      # 0x90bc
movl %edx, %esi
jmp 0x4cf0
movl %edx, %eax
leaq 0x443f(%rip), %rdx      # 0x9100
cmpl %ecx, (%rdx,%rax,4)
jbe 0x4ce7
leaq 0x4453(%rip), %rdx      # 0x9120
movl (%rdx,%rax,4), %eax
movl %ecx, %ecx
addq %rcx, %rdi
addq %rax, %rdi
movslq %r8d, %rdx
movq %r9, %rsi
callq 0x2130
xorl %eax, %eax
jmp 0x4cfc
leaq 0x43f2(%rip), %rdi      # 0x90e0
movl %ecx, %esi
xorl %eax, %eax
callq 0x20b0
movl $0x1, %eax
popq %rcx
retq
nop
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/sha1.c
// Function: sha1_read_ctx
void *
sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
{
  char *r = (char*)resbuf;
  set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A));
  set_uint32 (r + 1 * sizeof ctx->B, SWAP (ctx->B));
  set_uint32 (r + 2 * sizeof ctx->C, SWAP (ctx->C));
  set_uint32 (r + 3 * sizeof ctx->D, SWAP (ctx->D));
  set_uint32 (r + 4 * sizeof ctx->E, SWAP (ctx->E));

  return resbuf;
}

// Assembly:
movq %rsi, %rax
movl (%rdi), %ecx
bswapl %ecx
movl %ecx, (%rsi)
movl 0x4(%rdi), %ecx
bswapl %ecx
movl %ecx, 0x4(%rsi)
movl 0x8(%rdi), %ecx
bswapl %ecx
movl %ecx, 0x8(%rsi)
movl 0xc(%rdi), %ecx
bswapl %ecx
movl %ecx, 0xc(%rsi)
movl 0x10(%rdi), %ecx
bswapl %ecx
movl %ecx, 0x10(%rsi)
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/sha1.c
// Function: sha1_finish_ctx
void *
sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
{
  /* Take yet unprocessed bytes into account.  */
  uint32_t bytes = ctx->buflen;
  size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;

  /* Now count remaining bytes.  */
  ctx->total[0] += bytes;
  if (ctx->total[0] < bytes)
    ++ctx->total[1];

  /* Put the 64-bit file length in *bits* at the end of the buffer.  */
  ctx->buffer[size - 2] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
  ctx->buffer[size - 1] = SWAP (ctx->total[0] << 3);

  memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);

  /* Process last bytes.  */
  sha1_process_block (ctx->buffer, size * 4, ctx);

  return sha1_read_ctx (ctx, resbuf);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl 0x1c(%rdi), %eax
movl 0x14(%rdi), %ecx
addl %eax, %ecx
movl %ecx, 0x14(%rdi)
jae 0x4d60
incl 0x18(%r14)
xorl %r15d, %r15d
cmpl $0x38, %eax
setae %r15b
movl 0x18(%r14), %esi
shldl $0x3, %ecx, %esi
movl %esi, %edx
shll $0x18, %edx
movl %esi, %edi
shll $0x8, %edi
movl $0xff0000, %r8d         # imm = 0xFF0000
andl %r8d, %edi
orl %edx, %edi
movl %esi, %edx
shrl $0x8, %edx
movl $0xff00, %r9d           # imm = 0xFF00
andl %r9d, %edx
orl %edi, %edx
shrl $0x18, %esi
orl %edx, %esi
leaq 0x20(%r14), %r12
shll $0x6, %r15d
leal 0x38(%r15), %edx
movl %esi, 0x20(%r14,%rdx)
movl %ecx, %esi
shll $0x1b, %esi
movl %ecx, %edi
shll $0xb, %edi
andl %r8d, %edi
orl %esi, %edi
movl %ecx, %esi
shrl $0x5, %esi
andl %r9d, %esi
orl %edi, %esi
shrl $0x15, %ecx
movzbl %cl, %ecx
orl %esi, %ecx
movl %ecx, 0x5c(%r15,%r14)
leaq (%r14,%rax), %rdi
addq $0x20, %rdi
subq %rax, %rdx
leaq 0x438b(%rip), %rsi      # 0x9170
callq 0x2130
addq $0x40, %r15
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4e36
movl (%r14), %eax
bswapl %eax
movl %eax, (%rbx)
movl 0x4(%r14), %eax
bswapl %eax
movl %eax, 0x4(%rbx)
movl 0x8(%r14), %eax
bswapl %eax
movl %eax, 0x8(%rbx)
movl 0xc(%r14), %eax
bswapl %eax
movl %eax, 0xc(%rbx)
movl 0x10(%r14), %eax
bswapl %eax
movl %eax, 0x10(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/sha1.c
// Function: sha1_buffer
void *
sha1_buffer (const char *buffer, size_t len, void *resblock)
{
  struct sha1_ctx ctx;

  /* Initialize the computation context.  */
  sha1_init_ctx (&ctx);

  /* Process whole buffer but last len % 64 bytes.  */
  sha1_process_bytes (buffer, len, &ctx);

  /* Put result in desired memory area.  */
  return sha1_finish_ctx (&ctx, resblock);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0xa8, %rsp
movq %rdx, %rbx
movaps 0x30c7(%rip), %xmm0     # 0x9140
leaq 0x8(%rsp), %r14
movups %xmm0, (%r14)
movss 0x30d6(%rip), %xmm0     # 0x9160
movups %xmm0, 0x10(%r14)
movq %r14, %rdx
callq 0x60b0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4d41
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/southbridge.c
// Function: flash_locate_emc_ipl
struct bldr_hdr *flash_locate_emc_ipl(unsigned char *flashdata, int forcehdr) {
    // reversed from EMC bootrom
    // I want to start calling the first header the meta header and then the second header the main header.
    // I cannot tell if the two slots for booting are for updates or for testkit/devkit vs retail?
    struct flashheader0 *hdr0 = NULL;
    struct flashheader1 *hdr1 = NULL;
    struct bldr_hdr *blhdr = NULL;
    unsigned char flag;
    int blocknum;

    hdr0 = (struct flashheader0 *)flashdata;

    if(verbose) {
        printf("* flash branding '%s'\n", hdr0->branding);
    }

    blocknum = hdr0->secondHeaderBlockNum2;
    flag = *(unsigned int *)(flashdata + (hdr0->headerInfoBlockNum * 0x200));
    if(!((flag >> 7) & 1)) {
        if(verbose && !forcehdr) {
            printf("* using header block num 1\n");
        }

        blocknum = hdr0->secondHeaderBlockNum1;
    } else if(verbose && !forcehdr) {
        printf("* using header block num 2\n");
    }

    hdr1 = (struct flashheader1 *)(flashdata + (blocknum * 0x200));
    blhdr = (struct bldr_hdr *)(flashdata + ((blocknum + hdr1->dataBlockNumber) * 0x200));
    
    if(blhdr->magic != BLDR_MAGIC) {
        printf("error: invalid EMC IPL bootloader header magic!\n");
        return NULL;
    }

    if(blhdr->type != BLDR_TYPE_EMC) {
        printf("error: invalid EMC IPL bootloader header type!\n");
        return NULL;
    }

    if(forcehdr == 1) {
        return (struct bldr_hdr *)(flashdata + ((hdr0->secondHeaderBlockNum1 + hdr1->dataBlockNumber) * 0x200));
    } else if(forcehdr == 2) {
        return (struct bldr_hdr *)(flashdata + ((hdr0->secondHeaderBlockNum2 + hdr1->dataBlockNumber) * 0x200));
    }

    return blhdr;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x6104(%rip), %r14      # 0xc324
cmpl $0x0, (%r14)
je 0x6237
leaq 0x2f83(%rip), %rdi      # 0x91b0
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20b0
movl 0x34(%rbx), %ecx
shll $0x9, %ecx
cmpl $0x0, (%r14)
sete %dl
testl %ebp, %ebp
setne %al
orb %dl, %al
testb $-0x80, (%rbx,%rcx)
jne 0x6267
testb %al, %al
jne 0x6261
leaq 0x32ad(%rip), %rdi      # 0x9509
callq 0x2060
movl 0x24(%rbx), %r14d
jmp 0x627b
movl 0x28(%rbx), %r14d
testb %al, %al
jne 0x627b
leaq 0x32ae(%rip), %rdi      # 0x9524
callq 0x2060
movslq %r14d, %rax
movq %rax, %rcx
shlq $0x9, %rcx
movl 0x30(%rbx,%rcx), %ecx
addl %ecx, %eax
shll $0x9, %eax
cmpl $0xd48ff9aa, (%rbx,%rax) # imm = 0xD48FF9AA
jne 0x62af
addq %rbx, %rax
cmpb $0x48, 0x7(%rax)
jne 0x62b8
cmpl $0x2, %ebp
je 0x62cb
cmpl $0x1, %ebp
jne 0x62c6
addl 0x24(%rbx), %ecx
jmp 0x62ce
leaq 0x32b8(%rip), %rdi      # 0x956e
jmp 0x62bf
leaq 0x3280(%rip), %rdi      # 0x953f
callq 0x2060
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
addl 0x28(%rbx), %ecx
shll $0x9, %ecx
addq %rbx, %rcx
movq %rcx, %rax
jmp 0x62c6
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/southbridge.c
// Function: flash_locate_eap_kbl
struct bldr_hdr *flash_locate_eap_kbl(unsigned char *flashdata) {
    struct bldr_hdr *blhdr = NULL;
    struct slb2_header *slbhdr = (struct slb2_header *)(flashdata + 0xC4000);
    struct slb2_entry *entry = NULL;
    int i;

    if(slbhdr->magic != SLB2_MAGIC) {
        printf("error: invalid KBL SLB2 magic!\n");
        return NULL;
    }

    for(i = 0; i < slbhdr->file_count; i++) {
        entry = &slbhdr->entry_list[i];

        if(!strcmp(entry->file_name, "C0010001") || !strcmp(entry->file_name, "eap_kbl")) {
            break;
        }
    }
    
    return (struct bldr_hdr *)(flashdata + 0xC4000 + (entry->block_offset << 9));
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpl $0x32424c53, 0xc4000(%rdi) # imm = 0x32424C53
jne 0x634f
leaq 0xc4000(%rdi), %rbx
movl 0xc400c(%rdi), %r13d
decq %r13
addq $0xc4030, %rdi          # imm = 0xC4030
leaq 0x214f(%rip), %r14      # 0x845c
leaq 0x2eb3(%rip), %r15      # 0x91c7
movq %rdi, %r12
movq %r14, %rsi
callq 0x2100
testl %eax, %eax
je 0x6342
movq %r12, %rdi
movq %r15, %rsi
callq 0x2100
subq $0x1, %r13
setb %cl
testl %eax, %eax
je 0x6342
leaq 0x30(%r12), %rdi
testb %cl, %cl
je 0x6314
movl -0x10(%r12), %eax
shll $0x9, %eax
addq %rax, %rbx
jmp 0x635d
leaq 0x3248(%rip), %rdi      # 0x959e
callq 0x2060
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/southbridge.c
// Function: decrypt_emc_ipl
int decrypt_emc_ipl(unsigned char *flashdata, unsigned char **data, unsigned int *length) {
    struct bldr_hdr *blhdr = flash_locate_emc_ipl(flashdata, 0);
    unsigned char *hdraeskey = keymgr_getkey("emciplaes", KEY_TYPE_AES_128);
    
    if(verbose) {
        printf("* EMC IPL header aes key: ");
        hexdump(hdraeskey, 0x10, 0);
    }

    struct bldr_hdr dechdr;
    unsigned char *decbody = (unsigned char *)malloc(blhdr->body_len);

    // copy the header on to the stack, we dont want to modify anything
    memcpy(&dechdr, blhdr, blhdr->hdr_len);
    aes128_cbc_iv_zero_decrypt(hdraeskey, &blhdr->crypteddata, &dechdr.crypteddata, 0x50);
    aes128_cbc_iv_zero_decrypt(dechdr.crypteddata.iplbodyaeskey, &blhdr->bodystart, decbody, blhdr->body_len);

    if(data) {
        *data = decbody;
    }

    if(length) {
        *length = blhdr->body_len;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, %rbx
movq %rsi, %r14
xorl %esi, %esi
callq 0x6210
movq %rax, %r15
leaq 0x2c26(%rip), %rdi      # 0x91cf
movl $0xa1, %esi
callq 0x4bc5
movq %rax, %r12
leaq 0x5d67(%rip), %rax      # 0xc324
cmpl $0x0, (%rax)
je 0x65df
leaq 0x2c1b(%rip), %rdi      # 0x91e4
xorl %eax, %eax
callq 0x20b0
movq %r12, %rdi
movl $0x10, %esi
xorl %edx, %edx
callq 0x3639
movl 0xc(%r15), %edi
callq 0x2140
movq %rax, %r13
movl 0x8(%r15), %edx
leaq 0x7(%rsp), %rdi
movq %r15, %rsi
callq 0x2130
leaq 0x30(%r15), %rsi
leaq 0x37(%rsp), %rbp
movq %r12, %rdi
movq %rbp, %rdx
movl $0x50, %ecx
callq 0x2aa4
movq %r15, %rsi
subq $-0x80, %rsi
movl 0xc(%r15), %ecx
movq %rbp, %rdi
movq %r13, %rdx
callq 0x2aa4
testq %r14, %r14
je 0x6633
movq %r13, (%r14)
testq %rbx, %rbx
je 0x663e
movl 0xc(%r15), %eax
movl %eax, (%rbx)
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/southbridge.c
// Function: decrypt_eap_kbl
int decrypt_eap_kbl(unsigned char *flashdata, unsigned char **data, unsigned int *length) {
    struct bldr_hdr *blhdr = flash_locate_eap_kbl(flashdata);
    unsigned char *hdraeskey = keymgr_getkey("eapkblaes", KEY_TYPE_AES_128);
    
    if(verbose) {
        printf("* EAP KBL header aes key: ");
        hexdump(hdraeskey, 0x10, 0);
    }

    struct bldr_hdr dechdr;
    unsigned char *decbody = (unsigned char *)malloc(blhdr->body_len);

    // copy the header on to the stack, we dont want to modify anything
    memcpy(&dechdr, blhdr, blhdr->hdr_len);
    aes128_cbc_iv_zero_decrypt(hdraeskey, &blhdr->crypteddata, &dechdr.crypteddata, 0x50);
    aes128_cbc_iv_zero_decrypt(dechdr.crypteddata.iplbodyaeskey, &blhdr->bodystart, decbody, blhdr->body_len);

    if(data) {
        *data = decbody;
    }

    if(length) {
        *length = blhdr->body_len;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, %rbx
movq %rsi, %r15
callq 0x62d9
movq %rax, %r14
leaq 0x2935(%rip), %rdi      # 0x936c
movl $0xa1, %esi
callq 0x4bc5
movq %rax, %r12
leaq 0x58d9(%rip), %rax      # 0xc324
cmpl $0x0, (%rax)
je 0x6a6d
leaq 0x292a(%rip), %rdi      # 0x9381
xorl %eax, %eax
callq 0x20b0
movq %r12, %rdi
movl $0x10, %esi
xorl %edx, %edx
callq 0x3639
movl 0xc(%r14), %edi
callq 0x2140
movq %rax, %r13
movl 0x8(%r14), %edx
leaq 0x7(%rsp), %rdi
movq %r14, %rsi
callq 0x2130
leaq 0x30(%r14), %rsi
leaq 0x37(%rsp), %rbp
movq %r12, %rdi
movq %rbp, %rdx
movl $0x50, %ecx
callq 0x2aa4
movq %r14, %rsi
subq $-0x80, %rsi
movl 0xc(%r14), %ecx
movq %rbp, %rdi
movq %r13, %rdx
callq 0x2aa4
testq %r15, %r15
je 0x6ac1
movq %r13, (%r15)
testq %rbx, %rbx
je 0x6acc
movl 0xc(%r14), %eax
movl %eax, (%rbx)
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/jogolden[P]ps4flashtool/southbridge.c
// Function: mersenne_twister
unsigned int mersenne_twister(int *seed) {
    int var1; // r12
    int *var2; // r1
    unsigned int var3; // r4
    int var4; // r2
    int var5; // r5
    int var6; // r0
    unsigned int var7; // r4
    int *var8; // r5

    var1 = *seed;
    var2 = &seed[*seed + 1];
    var3 = *var2;
    var4 = *seed + 1;
    if(*seed >= 623) {
        var5 = seed[1];
        var4 = 0;
    } else {
        var5 = var2[1];
    }
    *seed = var4;
    var6 = var3 ^ (var3 >> 11);
    var7 = (var3 & 0x80000000 | var5 & 0x7FFFFFFF) >> 1;
    if(var5 & 1 ) {
        var7 ^= 0x9908B0DF;
    }
    var8 = var2 - 227;
    if( var1 < 227 ) {
        var8 = var2 + 397;
    }
    *var2 = var7 ^ *var8;
    
    return var6 ^ (var6 << 7) & 0x9D2C5680 ^ ((var6 ^ (var6 << 7) & 0x9D2C5680) << 15) & 0xEFC60000 ^ ((var6 ^ (var6 << 7) & 0x9D2C5680 ^ ((var6 ^ (var6 << 7) & 0x9D2C5680) << 15) & 0xEFC60000) >> 18);
}

// Assembly:
movslq (%rdi), %rcx
leaq 0x1(%rcx), %rdx
xorl %esi, %esi
cmpq $0x26f, %rcx            # imm = 0x26F
leaq 0x4(%rdi,%rcx,4), %rax
movl (%rax), %r8d
movq %rax, %r9
cmovgeq %rdi, %r9
cmovgel %esi, %edx
movl 0x4(%r9), %esi
movl %r8d, %r9d
andl $0x80000000, %r9d       # imm = 0x80000000
movl %esi, %r10d
andl $0x7ffffffe, %r10d      # imm = 0x7FFFFFFE
orl %r9d, %r10d
shrl %r10d
movl %r10d, %r9d
xorl $0x9908b0df, %r9d       # imm = 0x9908B0DF
testb $0x1, %sil
cmovel %r10d, %r9d
cmpq $0xe3, %rcx
movl %edx, (%rdi)
leaq 0x638(%rdi,%rcx,4), %rdx
leaq -0x388(%rdi,%rcx,4), %rcx
cmovlq %rdx, %rcx
movl %r8d, %edx
shrl $0xb, %edx
xorl %r8d, %edx
xorl (%rcx), %r9d
movl %r9d, (%rax)
movl %edx, %eax
shll $0x7, %eax
andl $0x9d2c5680, %eax       # imm = 0x9D2C5680
xorl %edx, %eax
movl %eax, %ecx
shll $0xf, %ecx
andl $0xefc60000, %ecx       # imm = 0xEFC60000
xorl %eax, %ecx
movl %ecx, %eax
shrl $0x12, %eax
xorl %ecx, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]libcperciva/tests/optional_mutex/pthread/../main.c
// Function: inc_dec_counter
static void *
inc_dec_counter(void * cookie)
{
	int i;
	int rc;

	(void)cookie; /* UNUSED */

	for (i = 0; i < NUM_TIMES; i++) {
		/* Lock if we're using pthread. */
		if ((rc = optional_mutex_lock(&mutex)) != 0) {
			warn0("optional_mutex_lock: %s", strerror(rc));
			goto err0;
		}

		/* Increment, wait, decrement value. */
		value++;
		millisleep(10);
		value--;

		/* Increment overall counter. */
		counter++;

		/* Unlock if we're using pthread. */
		if ((rc = optional_mutex_unlock(&mutex)) != 0) {
			warn0("optional_mutex_unlock: %s", strerror(rc));
			goto err0;
		}
	}

	/* Success! */
	return (NULL);

err0:
	/* Failure! */
	pthread_exit(NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl $0x64, %ebp
leaq 0x2c18(%rip), %r14      # 0x40e8
leaq 0xb51(%rip), %rbx       # 0x2028
movq %rsp, %r15
leaq 0xb5f(%rip), %r12       # 0x2040
movq %r14, %rdi
callq 0x1828
testl %eax, %eax
jne 0x153c
incl 0x2c1d(%rip)            # 0x4110
movq $0x0, (%rsp)
movq $0x989680, 0x8(%rsp)    # imm = 0x989680
movq %r15, %rdi
xorl %esi, %esi
callq 0x1080
decl 0x2bfc(%rip)            # 0x4110
incl 0x2bfa(%rip)            # 0x4114
movq %r14, %rdi
callq 0x182d
testl %eax, %eax
jne 0x1539
decl %ebp
jne 0x14e1
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rbx
movl %eax, %edi
callq 0x1170
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x1703
callq 0x1060
movl $0x0, (%rax)
xorl %edi, %edi
callq 0x10e0
nop
// File: /workspace/github_c_makefile_star2_O1/ramirezsebas[P]TP-LISTINGS/./src/capitulo_4/4.5/detached.c
// Function: thread_function
void* thread_function (void* thread_arg)
{
	/* Do work here... */
	struct DatosCliente cliente;
	FILE *cuentaPtr, *salida;
	float total = 0;

	salida = fopen("deuda_total.txt", "w");
	
	if ((cuentaPtr = fopen("../../src/capitulo_4/4.5/cliente.dat","r")) == NULL)
		printf("No se puede abrir el archivo\n");
	else
	{
		while (!feof(cuentaPtr))
		{
			fread(&cliente, sizeof(struct DatosCliente), 1, cuentaPtr);
			if (cliente.id != 0){
				total += cliente.deuda;
			}
		}
	}

	fprintf(salida, "%.2f\n", total);
	
	fclose(cuentaPtr);
	fclose(salida);

	complete = 1;

	printf("La deuda total es: %.2f\n", total);

	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
leaq 0xe18(%rip), %rdi       # 0x2008
leaq 0xe21(%rip), %rsi       # 0x2018
callq 0x10c0
movq %rax, %rbx
leaq 0xe14(%rip), %rdi       # 0x201a
leaq 0xe32(%rip), %rsi       # 0x203f
callq 0x10c0
movq %rax, %r14
testq %rax, %rax
je 0x1275
movq %r14, %rdi
callq 0x1090
xorps %xmm0, %xmm0
testl %eax, %eax
jne 0x1284
xorps %xmm0, %xmm0
movss %xmm0, -0x20(%rbp)
leaq -0x5c(%rbp), %r15
movl $0x3c, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1040
cmpl $0x0, -0x5c(%rbp)
je 0x125f
movss -0x20(%rbp), %xmm0
addss -0x24(%rbp), %xmm0
movss %xmm0, -0x20(%rbp)
movq %r14, %rdi
callq 0x1090
testl %eax, %eax
je 0x1235
xorps %xmm0, %xmm0
cvtss2sd -0x20(%rbp), %xmm0
jmp 0x1284
leaq 0xdfd(%rip), %rdi       # 0x2079
callq 0x1030
xorps %xmm0, %xmm0
leaq 0xdc9(%rip), %rsi       # 0x2054
movq %rbx, %rdi
movsd %xmm0, -0x20(%rbp)
movb $0x1, %al
callq 0x1080
movq %r14, %rdi
callq 0x1050
movq %rbx, %rdi
callq 0x1050
movl $0x1, 0x2dd0(%rip)      # 0x4084
leaq 0xd86(%rip), %rdi       # 0x2041
movsd -0x20(%rbp), %xmm0
movb $0x1, %al
callq 0x1060
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/ramirezsebas[P]TP-LISTINGS/./src/capitulo_4/4.5/detached.c
// Function: main
int main ()
{
	pthread_attr_t attr;
	pthread_t thread;
	pthread_attr_init (&attr);
	pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
	pthread_create (&thread, &attr, &thread_function, NULL);
	pthread_attr_destroy (&attr);

	/* Do work here...*/

	struct DatosCliente cliente;
	FILE *cuentaPtr, *salida;

	salida = fopen("deudas_altas.txt", "w");
	
	if ((cuentaPtr = fopen("../../src/capitulo_4/4.5/cliente.dat","r")) == NULL)
		printf("No se puede abrir el archivo\n");
	else
	{
		while (!feof(cuentaPtr))
		{
			fread(&cliente, sizeof(struct DatosCliente), 1, cuentaPtr);
			if (cliente.id != 0){
				if(cliente.deuda > 6000.0)
					fprintf(salida, "%d; %s; %.2f\n", cliente.id,cliente.nombre, cliente.deuda);
			}
		}
	}
	fclose(cuentaPtr);
	fclose(salida);

	while(!complete);

	/* No need to join the second thread.*/

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0x1070
movq %rbx, %rdi
movl $0x1, %esi
callq 0x10a0
leaq -0x12f(%rip), %rdx      # 0x11dc
leaq -0x30(%rbp), %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x10b0
movq %rbx, %rdi
callq 0x10d0
leaq 0xd32(%rip), %rdi       # 0x205a
leaq 0xce9(%rip), %rsi       # 0x2018
callq 0x10c0
movq %rax, %rbx
leaq 0xcdc(%rip), %rdi       # 0x201a
leaq 0xcfa(%rip), %rsi       # 0x203f
callq 0x10c0
movq %rax, %r14
testq %rax, %rax
je 0x13b9
movq %r14, %rdi
callq 0x1090
testl %eax, %eax
jne 0x13c5
leaq -0x68(%rbp), %r15
leaq -0x6c(%rbp), %r12
leaq 0xcfe(%rip), %r13       # 0x206b
movl $0x3c, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rcx
callq 0x1040
movl -0x6c(%rbp), %edx
testl %edx, %edx
je 0x13ab
movss -0x34(%rbp), %xmm0
ucomiss 0xc6f(%rip), %xmm0      # 0x2004
jbe 0x13ab
cvtss2sd %xmm0, %xmm0
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rcx
movb $0x1, %al
callq 0x1080
movq %r14, %rdi
callq 0x1090
testl %eax, %eax
je 0x136d
jmp 0x13c5
leaq 0xcb9(%rip), %rdi       # 0x2079
callq 0x1030
movq %r14, %rdi
callq 0x1050
movq %rbx, %rdi
callq 0x1050
cmpl $0x0, 0x2ca8(%rip)      # 0x4084
je 0x13f2
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x13f2
// File: /workspace/github_c_makefile_star2_O1/mesbahamin[P]star-sim/src/star.c
// Function: star_accelerate
void star_accelerate(struct Star *s, float angle, float acceleration)
{
    struct Vec2d *new_vec = vec2d_add(s->angle, s->speed, angle, acceleration);
    s->angle = new_vec->angle;
    s->speed = new_vec->length;
    free(new_vec);
}

// Assembly:
pushq %rbx
movaps %xmm1, %xmm3
movaps %xmm0, %xmm2
movq %rdi, %rbx
movss (%rdi), %xmm0
movss 0x4(%rdi), %xmm1
callq 0x2820
movss (%rax), %xmm0
movss %xmm0, (%rbx)
movss 0x4(%rax), %xmm0
movss %xmm0, 0x4(%rbx)
movq %rax, %rdi
popq %rbx
jmp 0x11a0
// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/redis-cli.c
// Function: slaveMode
static void slaveMode(void) {
    int fd = context->fd;
    unsigned long long payload = sendSync(fd);
    char buf[1024];
    int original_output = config.output;

    fprintf(stderr,"SYNC with master, discarding %llu "
                   "bytes of bulk transfer...\n", payload);

    /* Discard the payload. */
    while(payload) {
        ssize_t nread;

        nread = read(fd,buf,(payload > sizeof(buf)) ? sizeof(buf) : payload);
        if (nread <= 0) {
            fprintf(stderr,"Error reading RDB payload while SYNCing\n");
            exit(1);
        }
        payload -= nread;
    }
    fprintf(stderr,"SYNC done. Logging commands from master.\n");

    /* Now we can use hiredis to read the incoming protocol. */
    config.output = OUTPUT_CSV;
    while (cliReadReply(0) == REDIS_OK);
    config.output = original_output;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
movq 0x36758(%rip), %rax     # 0x43e70
movl 0x84(%rax), %ebx
movl %ebx, %edi
callq 0x106a8
movq %rax, %r14
movl 0x3669a(%rip), %ebp     # 0x43dc8
movq 0x348bb(%rip), %r12     # 0x41ff0
movq (%r12), %rdi
leaq 0x26110(%rip), %rsi     # 0x33850
movq %rax, %rdx
xorl %eax, %eax
callq 0xd350
testq %r14, %r14
je 0xd778
movl $0x400, %r13d           # imm = 0x400
movq %rsp, %r15
cmpq %r13, %r14
movl $0x400, %edx            # imm = 0x400
cmovbq %r14, %rdx
movl %ebx, %edi
movq %r15, %rsi
callq 0xd2b0
testq %rax, %rax
jle 0xd7bb
subq %rax, %r14
jne 0xd758
movq (%r12), %rcx
leaq 0x26133(%rip), %rdi     # 0x338b6
pushq $0x29
popq %rsi
pushq $0x1
popq %rdx
callq 0xd5f0
movl $0x2, 0x36630(%rip)     # 0x43dc8
xorl %edi, %edi
callq 0x12cfa
testl %eax, %eax
je 0xd798
movl %ebp, 0x3661f(%rip)     # 0x43dc8
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rcx
leaq 0x260c7(%rip), %rdi     # 0x3388d
pushq $0x28
popq %rsi
pushq $0x1
popq %rdx
callq 0xd5f0
pushq $0x1
popq %rdi
callq 0xd5d0
// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/redis-cli.c
// Function: sendSync
unsigned long long sendSync(int fd) {
    /* To start we need to send the SYNC command and return the payload.
     * The hiredis client lib does not understand this part of the protocol
     * and we don't want to mess with its buffers, so everything is performed
     * using direct low-level I/O. */
    char buf[4096], *p;
    ssize_t nread;

    /* Send the SYNC command. */
    if (write(fd,"SYNC\r\n",6) != 6) {
        fprintf(stderr,"Error writing to master\n");
        exit(1);
    }

    /* Read $<payload>\r\n, making sure to read just up to "\n" */
    p = buf;
    while(1) {
        nread = read(fd,p,1);
        if (nread <= 0) {
            fprintf(stderr,"Error reading bulk length while SYNCing\n");
            exit(1);
        }
        if (*p == '\n' && p != buf) break;
        if (*p != '\n') p++;
    }
    *p = '\0';
    if (buf[0] == '-') {
        printf("SYNC with master failed: %s\n", buf);
        exit(1);
    }
    return strtoull(buf+1,NULL,10);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x1000, %rsp           # imm = 0x1000
movl %edi, %ebx
leaq 0x2250a(%rip), %rsi     # 0x32bc7
movl $0x6, %edx
callq 0xd160
cmpq $0x6, %rax
jne 0x10744
movq %rsp, %r14
movl $0x1, %edx
movl %ebx, %edi
movq %r14, %rsi
callq 0xd2b0
testq %rax, %rax
jle 0x10717
movq %r14, %r15
movb (%r15), %al
cmpb $0xa, %al
sete %cl
cmpq %r14, %r15
setne %dl
testb %cl, %dl
jne 0x1071c
xorl %ecx, %ecx
cmpb $0xa, %al
setne %cl
addq %rcx, %r15
movl $0x1, %edx
movl %ebx, %edi
movq %r15, %rsi
callq 0xd2b0
testq %rax, %rax
jg 0x106e7
callq 0xd7fe
movb $0x0, (%r15)
cmpb $0x2d, (%rsp)
je 0x10749
leaq 0x1(%rsp), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0xd310
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r14
popq %r15
retq
callq 0xd7d9
leaq 0x224c0(%rip), %rdi     # 0x32c10
movq %rsp, %rsi
xorl %eax, %eax
callq 0xd1d0
movl $0x1, %edi
callq 0xd5d0
// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/redis-cli.c
// Function: cliConnect
static int cliConnect(int force) {
    if (context == NULL || force) {
        if (context != NULL)
            redisFree(context);

        if (config.hostsocket == NULL) {
            context = redisConnect(config.hostip,config.hostport);
        } else {
            context = redisConnectUnix(config.hostsocket);
        }

        if (context->err) {
            fprintf(stderr,"Could not connect to Redis at ");
            if (config.hostsocket == NULL)
                fprintf(stderr,"%s:%d: %s\n",config.hostip,config.hostport,context->errstr);
            else
                fprintf(stderr,"%s: %s\n",config.hostsocket,context->errstr);
            redisFree(context);
            context = NULL;
            return REDIS_ERR;
        }

        /* Set aggressive KEEP_ALIVE socket option in the Redis context socket
         * in order to prevent timeouts caused by the execution of long
         * commands. At the same time this improves the detection of real
         * errors. */
        anetKeepAlive(NULL, context->fd, REDIS_CLI_KEEPALIVE_INTERVAL);

        /* Do AUTH and select the right DB. */
        if (cliAuth() != REDIS_OK)
            return REDIS_ERR;
        if (cliSelect() != REDIS_OK)
            return REDIS_ERR;
    }
    return REDIS_OK;
}

// Assembly:
pushq %rbx
movl %edi, %eax
movq 0x31319(%rip), %rdi     # 0x43e70
testq %rdi, %rdi
setne %cl
testl %eax, %eax
sete %al
xorl %ebx, %ebx
testb %cl, %al
jne 0x12c23
testq %rdi, %rdi
je 0x12b76
callq 0x15984
movq 0x311cb(%rip), %rdi     # 0x43d48
testq %rdi, %rdi
je 0x12b89
callq 0x15ab1
jmp 0x12b9b
movq 0x311a8(%rip), %rdi     # 0x43d38
movl 0x311aa(%rip), %esi     # 0x43d40
callq 0x159c2
movq %rax, 0x312ce(%rip)     # 0x43e70
cmpl $0x0, (%rax)
jne 0x12c19
movl 0x84(%rax), %esi
xorl %ebx, %ebx
xorl %edi, %edi
movl $0xf, %edx
callq 0xe046
movq 0x311fe(%rip), %rdx     # 0x43dc0
testq %rdx, %rdx
je 0x12be9
movq 0x312a2(%rip), %rdi     # 0x43e70
leaq 0x20c0e(%rip), %rsi     # 0x337e3
xorl %eax, %eax
callq 0x16086
testq %rax, %rax
je 0x12c1e
movq %rax, %rdi
callq 0x14824
movl 0x31171(%rip), %edx     # 0x43d60
testl %edx, %edx
je 0x12c23
movq 0x31276(%rip), %rdi     # 0x43e70
leaq 0x20bea(%rip), %rsi     # 0x337eb
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x16086
testq %rax, %rax
je 0x12c1e
movq %rax, %rdi
callq 0x14824
jmp 0x12c23
callq 0xdd44
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
popq %rbx
retq