// File: /workspace/github_c_makefile_star2_O0/teodorst[P]app-huffman/huffman.c
// Function: decode_bytes
void decode_bytes(FILE *in_fp, FILE *out_fp, node_t *root, unsigned long long int nbits) {
    size_t nread = 0;
    unsigned long long int total_bytes = 0L;
    unsigned long long int nbytes = nbits % 8L == 0L ? nbits / 8L : nbits/8L + 1L;
    char *aux_buf = (char *) calloc (CHUNK, sizeof(char));
    char *result = (char *) calloc (2*nbytes, sizeof(char));
    node_t *remainig_node;
    remainig_node = root;

    int length = 0;
    int minimum_size = CHUNK * 8;
    // fprintf(stderr, "in decode");

    while((nread = fread(aux_buf, 1, CHUNK, in_fp)) > 0) {
        fprintf(stderr, "in decode");
        if (nbits > minimum_size) {
            length = decode_bytes_for_chunk(root, aux_buf, (CHUNK * 8), &remainig_node, result);
            nbits -= minimum_size;
        } else {
            length = decode_bytes_for_chunk(root, aux_buf, nbits, &remainig_node, result);
        }

        /* write in out file the result for that CHUNK*/
        fwrite(result, 1, length, out_fp);

        total_bytes += CHUNK > nread ? nread : CHUNK;

        memset(aux_buf, '\0', CHUNK);
        memset(result, '\0', nbytes);

    }

    free(aux_buf);
    free(result);
    if (total_bytes < nbytes)
        printf("less number of bytes %llu\n", total_bytes);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0x1f24
movq -0x20(%rbp), %rax
shrq $0x3, %rax
movq %rax, -0x60(%rbp)
jmp 0x1f34
movq -0x20(%rbp), %rax
shrq $0x3, %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x6400000, %edi        # imm = 0x6400000
movl $0x1, %esi
callq 0x10b0
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
shlq %rdi
movl $0x1, %esi
callq 0x10b0
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x32000000, -0x58(%rbp) # imm = 0x32000000
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl $0x1, %esi
movl $0x6400000, %edx        # imm = 0x6400000
callq 0x1050
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jbe 0x2074
movq 0x3052(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x10ec(%rip), %rsi      # 0x309c
movb $0x0, %al
callq 0x10d0
movq -0x20(%rbp), %rax
movslq -0x58(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x1ff2
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %r8
movl $0x32000000, %edx       # imm = 0x32000000
leaq -0x50(%rbp), %rcx
callq 0x1c40
movl %eax, -0x54(%rbp)
movslq -0x58(%rbp), %rcx
movq -0x20(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x20(%rbp)
jmp 0x200e
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x48(%rbp), %r8
leaq -0x50(%rbp), %rcx
callq 0x1c40
movl %eax, -0x54(%rbp)
movq -0x48(%rbp), %rdi
movslq -0x54(%rbp), %rdx
movq -0x10(%rbp), %rcx
movl $0x1, %esi
callq 0x1170
movl $0x6400000, %eax        # imm = 0x6400000
cmpq -0x28(%rbp), %rax
jbe 0x2039
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x2044
movl $0x6400000, %eax        # imm = 0x6400000
movq %rax, -0x68(%rbp)
jmp 0x2044
movq -0x68(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x6400000, %edx        # imm = 0x6400000
callq 0x1090
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rdx
xorl %esi, %esi
callq 0x1090
jmp 0x1f7a
movq -0x40(%rbp), %rdi
callq 0x1030
movq -0x48(%rbp), %rdi
callq 0x1030
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x20a2
movq -0x30(%rbp), %rsi
leaq 0x100b(%rip), %rdi      # 0x30a6
movb $0x0, %al
callq 0x1080
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)