// File: /workspace/github_c_makefile_star2_O2/jogolden[P]ps4flashtool/flashtool.c
// Function: print_usage
void print_usage() {
    char strbuffer[1024];

    printf("Usage: flashtool [option(s)]\n");
    printf("Examples:\n");
    printf("\tflashtool -k CXD42G.keys --extract dumps -i flashdump.bin\n");
    printf("\tflashtool --emcipl patchedipl.bin -k CXD44G.keys --input flashdump.bin --output flashout.bin\n");
    printf("\tflashtool --eapkbl patchedkbl.bin -k cec_h4x_sram_dmp_CXD36G.keys --input flashdump.bin --output flashout.bin\n");
    printf("\tflashtool -k CXD42G.keys -v -n --input flashdump.bin\n");
    printf("\tflashtool --extract dumps -n --input flashdump.bin\n");
    printf("\tflashtool --eapkern eapkern_hdd_enc.bin,eapkern_hdd_dec.bin\n");
    printf("Options:\n");

    #define PRINT_OPTION(short, long, hasarg, arg, comment) if(hasarg) { \
                snprintf(strbuffer, sizeof(strbuffer), "\t-%s [%s], --%s [%s]", short, arg, long, arg); \
            } else { \
                snprintf(strbuffer, sizeof(strbuffer), "\t-%s, --%s", short, long); \
            } printf("%s %*s\n", strbuffer, (int)(80 - strlen(strbuffer)), comment);
    #define PRINT_LONG_OPTION(long, hasarg, arg, comment) if(hasarg) { \
                snprintf(strbuffer, sizeof(strbuffer), "\t--%s [%s]", long, arg); \
            } else { \
                snprintf(strbuffer, sizeof(strbuffer), "\t--%s", long); \
            } printf("%s %*s\n", strbuffer, (int)(80 - strlen(strbuffer)), comment);

    PRINT_OPTION("h", "help", 0, "", "show this help message")
    PRINT_OPTION("v", "verbose", 0, "", "verbose output")
    PRINT_OPTION("i", "input", 1, "flash", "flash file input")
    PRINT_OPTION("o", "output", 1, "flash", "flash file output")
    PRINT_OPTION("n", "noverify", 0, "", "do not verify the flash signatures")
    PRINT_OPTION("k", "keyfile", 0, "", "override the default key file")
    PRINT_LONG_OPTION("extract", 1, "dir", "extract files to directory")
    PRINT_LONG_OPTION("rawextract", 1, "dir", "raw extract files to directory")
    PRINT_LONG_OPTION("emcipl", 1, "emcipl", "replace EMC IPL (initial program loader)")
    PRINT_LONG_OPTION("eapkbl", 1, "eapkbl", "replace EAP KBL (kernel boot loader)")
    PRINT_LONG_OPTION("eapkern", 1, "input,output", "decrypt the EAP kernel")

    printf("\n");
    printf("Everything you can replace in the flash is resigned when you replace it.\n");
    printf("Also, when the extract option is enabled, the files will be extracted after the replacement/resigning.\n");
    printf("!! This tool will never overwrite your existing flash dump file! You must specify an output. !!\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
leaq 0x3df1(%rip), %rdi      # 0x798f
callq 0x2060
leaq 0x3e02(%rip), %rdi      # 0x79ac
callq 0x2060
leaq 0x3e00(%rip), %rdi      # 0x79b6
callq 0x2060
leaq 0x3e2f(%rip), %rdi      # 0x79f1
callq 0x2060
leaq 0x3e81(%rip), %rdi      # 0x7a4f
callq 0x2060
leaq 0x3ee4(%rip), %rdi      # 0x7abe
callq 0x2060
leaq 0x3f0e(%rip), %rdi      # 0x7af4
callq 0x2060
leaq 0x3f36(%rip), %rdi      # 0x7b28
callq 0x2060
leaq 0x3f67(%rip), %rdi      # 0x7b65
callq 0x2060
leaq 0x39e3(%rip), %r15      # 0x75ed
leaq 0x3a3f(%rip), %rcx      # 0x7650
leaq 0x39e0(%rip), %r8       # 0x75f8
leaq 0x10(%rsp), %rbx
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
callq 0x2090
pushq $0x50
popq %rbp
movl %ebp, %edx
subl %eax, %edx
leaq 0x39b8(%rip), %r14      # 0x75fd
leaq 0x39b9(%rip), %rcx      # 0x7605
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x39bc(%rip), %rcx      # 0x761c
leaq 0x39b7(%rip), %r8       # 0x761e
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
callq 0x2090
movl %ebp, %edx
subl %eax, %edx
leaq 0x399a(%rip), %rcx      # 0x7626
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x39ac(%rip), %r12      # 0x764c
movq %r12, (%rsp)
leaq 0x398a(%rip), %r13      # 0x7635
leaq 0x3998(%rip), %rcx      # 0x764a
leaq 0x39a4(%rip), %r9       # 0x765d
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r13, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
callq 0x2090
movl %ebp, %edx
subl %eax, %edx
leaq 0x3971(%rip), %rcx      # 0x7652
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20b0
movq %r12, (%rsp)
leaq 0x396a(%rip), %rcx      # 0x7663
leaq 0x3970(%rip), %r9       # 0x7670
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r13, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
callq 0x2090
movl %ebp, %edx
subl %eax, %edx
leaq 0x393d(%rip), %rcx      # 0x7665
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x3e27(%rip), %rcx      # 0x7b63
leaq 0x3934(%rip), %r8       # 0x7677
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
callq 0x2090
movl %ebp, %edx
subl %eax, %edx
leaq 0x3918(%rip), %rcx      # 0x7680
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x3927(%rip), %rcx      # 0x76a3
leaq 0x3922(%rip), %r8       # 0x76a5
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
callq 0x2090
movl %ebp, %edx
subl %eax, %edx
leaq 0x3905(%rip), %rcx      # 0x76ad
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x390f(%rip), %r15      # 0x76cb
leaq 0x391a(%rip), %rcx      # 0x76dd
leaq 0x390c(%rip), %r12      # 0x76d6
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r15, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
callq 0x2090
movl %ebp, %edx
subl %eax, %edx
leaq 0x38f7(%rip), %rcx      # 0x76e9
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x38d4(%rip), %rcx      # 0x76da
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r15, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
callq 0x2090
movl %ebp, %edx
subl %eax, %edx
leaq 0x38b7(%rip), %rcx      # 0x76e5
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x38c2(%rip), %rcx      # 0x7704
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r15, %rdx
movq %rcx, %r8
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
callq 0x2090
movl %ebp, %edx
subl %eax, %edx
leaq 0x38a1(%rip), %rcx      # 0x770b
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x38b6(%rip), %rcx      # 0x7734
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r15, %rdx
movq %rcx, %r8
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
callq 0x2090
movl %ebp, %edx
subl %eax, %edx
leaq 0x3895(%rip), %rcx      # 0x773b
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20b0
leaq 0x38a6(%rip), %rcx      # 0x7760
leaq 0x38a7(%rip), %r8       # 0x7768
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
callq 0x2090
subl %eax, %ebp
leaq 0x3891(%rip), %rcx      # 0x7775
movq %r14, %rdi
movq %rbx, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x20b0
pushq $0xa
popq %rdi
callq 0x2040
leaq 0x3c6c(%rip), %rdi      # 0x7b6e
callq 0x2060
leaq 0x3ca9(%rip), %rdi      # 0x7bb7
callq 0x2060
leaq 0x3d04(%rip), %rdi      # 0x7c1e
callq 0x2060
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq