// File: /workspace/github_c_makefile_star2_O1/orempel[P]multiboot_tool/filedata.c
// Function: file_write
int file_write(const char *filename, struct databuf *dbuf)
{
    if (strncmp(filename, "-", 1) == 0)
    {
        dbuf_dump(dbuf);
        return 0;
    }

    switch (get_filetype(filename))
    {
        case FILETYPE_BINARY:
            return binfile_write(filename, dbuf);

        case FILETYPE_INTELHEX:
            return hexfile_write(filename, dbuf);

        default:
            return -1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %rbx
cmpb $0x2d, (%rdi)
jne 0x4e5c
cmpl $0x0, 0x4(%rbx)
je 0x4f8e
leaq 0x8(%rbx), %rax
movq %rax, 0x8(%rsp)
movabsq $0x100000000, %r12      # imm = 0x100000000
xorl %ebp, %ebp
movl $0x0, 0x4(%rsp)
movl %ebp, %ebp
movq 0x8(%rsp), %rax
leaq (%rax,%rbp), %r13
xorl %r14d, %r14d
xorl %r15d, %r15d
leaq (%r14,%rbp), %rax
movl 0x4(%rbx), %ecx
movslq %r15d, %rdx
leaq (%rsp,%rdx), %rdi
addq $0x10, %rdi
cmpq %rcx, %rax
jae 0x4d71
movzbl (%r13,%r14), %edx
leaq 0x3cef(%rip), %rsi      # 0x8a57
xorl %eax, %eax
callq 0x2260
jmp 0x4d7f
movb $0x0, 0x2(%rdi)
movw $0x2020, (%rdi)         # imm = 0x2020
movl $0x2, %eax
addl %eax, %r15d
testb $0x1, %r14b
je 0x4d93
movslq %r15d, %rax
incl %r15d
movb $0x20, 0x10(%rsp,%rax)
incq %r14
cmpq $0x10, %r14
jne 0x4d44
movl 0x4(%rbx), %ecx
movslq %r15d, %rax
leaq (%rsp,%rax), %rsi
addq $0x10, %rsi
shlq $0x20, %rax
movl $0x1, %edx
xorl %edi, %edi
xorl %r11d, %r11d
leaq (%rdi,%rbp), %r8
cmpq %rcx, %r8
jae 0x4de8
movzbl (%r13,%rdi), %r8d
leal -0x20(%r8), %r10d
movl %r8d, %r9d
cmpb $0x5f, %r10b
jb 0x4dda
movl $0x2e, %r9d
movb %r9b, (%rsi,%rdi)
cmpb $-0x1, %r8b
cmovnel %r11d, %edx
jmp 0x4dec
movb $0x20, (%rsi,%rdi)
incq %rdi
addq %r12, %rax
cmpq $0x10, %rdi
jne 0x4db8
testq %rbp, %rbp
je 0x4e25
leal 0x10(%rbp), %esi
cmpl %ecx, %esi
jae 0x4e25
testl %edx, %edx
je 0x4e25
cmpl $0x0, 0x4(%rsp)
jne 0x4e4b
leaq 0x3cb3(%rip), %rdi      # 0x8ac9
callq 0x2080
movl $0x1, 0x4(%rsp)
jmp 0x4e4b
sarq $0x20, %rax
movb $0x0, 0x10(%rsp,%rax)
movl $0x0, 0x4(%rsp)
leaq 0x3c22(%rip), %rdi      # 0x8a5f
movl %ebp, %esi
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x20f0
addl $0x10, %ebp
cmpl 0x4(%rbx), %ebp
jb 0x4d33
jmp 0x4f8e
movq %rdi, %r14
callq 0x4895
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2, %eax
je 0x4ebd
cmpl $0x1, %eax
jne 0x4f90
movq %r14, %rdi
movl $0x242, %esi            # imm = 0x242
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x2200
testl %eax, %eax
js 0x4fa4
movl %eax, %r14d
leaq 0x8(%rbx), %rsi
movl 0x4(%rbx), %edx
movl %eax, %edi
callq 0x2090
movl 0x4(%rbx), %ecx
cmpq %rcx, %rax
jne 0x4fbb
movl %r14d, %edi
callq 0x2140
jmp 0x4f8e
leaq 0x366a(%rip), %rsi      # 0x852e
movq %r14, %rdi
callq 0x2210
testq %rax, %rax
je 0x4fad
movq %rax, %r14
movl 0x4(%rbx), %ecx
xorl %ebp, %ebp
movl %ecx, %edx
movl $0x0, %eax
testq %rcx, %rcx
je 0x4f13
xorl %esi, %esi
xorl %eax, %eax
movl %ecx, %edx
cmpl %esi, %edx
movl %esi, %edi
cmovbl %edx, %edi
cmpl %esi, %eax
movl %esi, %r8d
cmoval %eax, %r8d
cmpb $-0x1, 0x8(%rbx,%rsi)
cmovnel %edi, %edx
cmovnel %r8d, %eax
incq %rsi
cmpq %rsi, %rcx
jne 0x4eef
movl %edx, %esi
andl $-0x10, %esi
cmpl %eax, %edx
cmovael %ecx, %eax
cmovbl %esi, %ebp
addl $0xf, %eax
andl $-0x10, %eax
cmpl %eax, %ebp
jae 0x4f66
addq $0x8, %rbx
movl %ebp, %r12d
movl %eax, %r13d
leaq 0x10(%rsp), %r15
movb $0x10, 0x10(%rsp)
movw %r12w, 0x12(%rsp)
movb $0x0, 0x14(%rsp)
leaq (%rbx,%r12), %rax
movq %rax, 0x18(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x4fd1
addq $0x10, %r12
cmpq %r13, %r12
jb 0x4f39
leaq 0x10(%rsp), %rsi
movb $0x0, (%rsi)
movw %bp, 0x2(%rsi)
movb $0x1, 0x4(%rsi)
movq $0x0, 0x8(%rsi)
movq %r14, %rdi
callq 0x4fd1
movq %r14, %rdi
callq 0x20a0
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3abf(%rip), %rdi      # 0x8a6a
jmp 0x4fb4
leaq 0x3ae7(%rip), %rdi      # 0x8a9b
callq 0x2230
jmp 0x4f90
leaq 0x3ac0(%rip), %rdi      # 0x8a82
callq 0x2230
movl %r14d, %edi
callq 0x2140
jmp 0x4f90