// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x5543(%rip), %rsi      # 0xc4ba
callq 0x2130
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x6fa1
leaq 0x60e2(%rip), %rdi      # 0xd070
movb $0x0, %al
callq 0x2080
movl $0x1, -0x4(%rbp)
jmp 0x7114
movl $0x8000, %edi           # imm = 0x8000
callq 0x2100
movq %rax, 0x939e(%rip)      # 0x10350
movl $0x4000, %edi           # imm = 0x4000
callq 0x2100
movq %rax, 0x9395(%rip)      # 0x10358
movl $0x8000, %edi           # imm = 0x8000
callq 0x2100
movq %rax, 0x938c(%rip)      # 0x10360
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x2110
movq -0x18(%rbp), %rdi
callq 0x20e0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2110
movq -0x20(%rbp), %rdi
callq 0x2100
movq %rax, 0x9356(%rip)      # 0x10368
movq 0x934f(%rip), %rdi      # 0x10368
movq -0x20(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x2050
movq -0x18(%rbp), %rdi
callq 0x2060
movq 0x932d(%rip), %rax      # 0x10368
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, 0x9325(%rip)      # 0x10370
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl 0x9309(%rip), %eax      # 0x10370
jge 0x710d
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdx
movq 0x92c3(%rip), %rax      # 0x10350
movslq -0x2c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %edx
movq 0x92a5(%rip), %rax      # 0x10358
movslq -0x2c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdx
movq 0x927a(%rip), %rax      # 0x10360
movslq -0x2c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x705e
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)