// File: /workspace/github_c_makefile_star2_O0/salextpuru[P]speccy-toochain/src/mhmt/mhmt-emit.c
// Function: emit_file
ULONG emit_file(UBYTE * bytes, LONG length)
{
    static UBYTE buffer[EMIT_FILEBUF_SIZE];
    static ULONG position;

    if( length==EMIT_FILE_INIT ) {
        position = 0;
        return 1;

    } else if( length>0 ) {
        while( (position+length) >= EMIT_FILEBUF_SIZE ) { // if we have to flush buffer
            length -= (EMIT_FILEBUF_SIZE-position);

            while( position < EMIT_FILEBUF_SIZE ) { // fill buffer to the end, if possible
                buffer[position++] = *(bytes++);
            }

            if( EMIT_FILEBUF_SIZE!=fwrite(buffer, 1, EMIT_FILEBUF_SIZE, wrk.file_out) ) {
                printf("mhmt-emit.c:emit_file() can't write to file!\n");
                return 0;
            }

            position=0;
        }

        while( length-- ) { // if something left that does not need flushing
            buffer[position++] = *(bytes++);
        }

        return 1;

    } else if( length==EMIT_FILE_FINISH ) {
        if( position>0 ) { // do we have anything to flush?
            if( position!=fwrite(buffer, 1, position, wrk.file_out) ) {
                printf("mhmt-emit.c:emit_file() can't write to file!\n");
                return 0;
            }
        }

        return 1;

    } else {
        printf("mhmt-emit.c:emit_file() encountered invalid arguments!\n");
        return 0;
    }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movl %esi, 0x14(%rsp)
cmpl $-0x1, 0x14(%rsp)
jne 0x197b
movl $0x0, 0xc912(%rip)      # 0xe280
movl $0x1, 0x24(%rsp)
jmp 0x1b25
cmpl $0x0, 0x14(%rsp)
jle 0x1a9f
jmp 0x1988
movl 0xc8f2(%rip), %eax      # 0xe280
addl 0x14(%rsp), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jb 0x1a4a
movl $0x1000, %ecx           # imm = 0x1000
subl 0xc8d8(%rip), %ecx      # 0xe280
movl 0x14(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x14(%rsp)
cmpl $0x1000, 0xc8c4(%rip)   # imm = 0x1000
jae 0x19f2
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rsp)
movb (%rax), %dl
movl 0xc8a9(%rip), %eax      # 0xe280
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0xc89e(%rip)      # 0xe280
movl %eax, %eax
movl %eax, %ecx
leaq 0xb893(%rip), %rax      # 0xd280
movb %dl, (%rax,%rcx)
jmp 0x19b2
leaq 0xc9a7(%rip), %rax      # 0xe3a0
movq 0x38(%rax), %rcx
leaq 0xb87c(%rip), %rdi      # 0xd280
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x1110
movq %rax, %rcx
movl $0x1000, %eax           # imm = 0x1000
cmpq %rcx, %rax
je 0x1a3b
leaq 0x786f(%rip), %rdi      # 0x9296
movb $0x0, %al
callq 0x1040
movl $0x0, 0x24(%rsp)
jmp 0x1b25
movl $0x0, 0xc83b(%rip)      # 0xe280
jmp 0x1988
jmp 0x1a4c
movl 0x14(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0x14(%rsp)
cmpl $0x0, %eax
je 0x1a92
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rsp)
movb (%rax), %dl
movl 0xc809(%rip), %eax      # 0xe280
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0xc7fe(%rip)      # 0xe280
movl %eax, %eax
movl %eax, %ecx
leaq 0xb7f3(%rip), %rax      # 0xd280
movb %dl, (%rax,%rcx)
jmp 0x1a4c
movl $0x1, 0x24(%rsp)
jmp 0x1b25
cmpl $0x0, 0x14(%rsp)
jne 0x1b0f
cmpl $0x0, 0xc7d3(%rip)      # 0xe280
jbe 0x1b05
movl 0xc7cb(%rip), %eax      # 0xe280
movq %rax, 0x8(%rsp)
movl 0xc7c0(%rip), %eax      # 0xe280
movl %eax, %edx
leaq 0xc8d7(%rip), %rax      # 0xe3a0
movq 0x38(%rax), %rcx
leaq 0xb7ac(%rip), %rdi      # 0xd280
movl $0x1, %esi
callq 0x1110
movq %rax, %rcx
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
je 0x1b03
leaq 0x77a4(%rip), %rdi      # 0x9296
movb $0x0, %al
callq 0x1040
movl $0x0, 0x24(%rsp)
jmp 0x1b25
jmp 0x1b05
movl $0x1, 0x24(%rsp)
jmp 0x1b25
leaq 0x77ae(%rip), %rdi      # 0x92c4
movb $0x0, %al
callq 0x1040
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nop