// File: /workspace/github_c_makefile_star2_O1/archer1357[P]Offline-Raytracer/avilib.c
// Function: AVI_close
int AVI_close(avi_t *AVI)
{
   int ret, i;

   /* If the file was open for writing, the header and index still have
      to be written */

   if(AVI->mode == AVI_MODE_WRITE)
      ret = avi_close_output_file(AVI);
   else
      ret = 0;

   /* Even if there happened an error, we first clean up */

   close(AVI->fdes);
   if(AVI->idx) free(AVI->idx);
   if(AVI->video_index) free(AVI->video_index);
   //FIXME
   //if(AVI->audio_index) free(AVI->audio_index);
   if (AVI->bitmap_info_header)
     free(AVI->bitmap_info_header);
   for (i = 0; i < AVI->anum; i++) {
     if (AVI->wave_format_ex[i])
       free(AVI->wave_format_ex[i]);
     if (AVI->track[i].audio_chunks)
       free(AVI->track[i].audio_index);
   }
   free(AVI);

   return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x818, %rsp            # imm = 0x818
movq %rdi, %rbx
xorl %r14d, %r14d
cmpq $0x0, 0x8(%rdi)
jne 0x402dc6
movq 0x3e0(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x408(%rbx), %rdx
movl 0x3e8(%rbx), %ecx
shll $0x4, %ecx
leaq 0xd2a8a(%rip), %rsi     # 0x4d5102
movq %rbx, %rdi
callq 0x404729
movl %eax, %r9d
testl %eax, %eax
je 0x402692
movq $0x5, 0x117e9e(%rip) # 0x51a530
movsd 0x20(%rbx), %xmm0
xorl %ebp, %ebp
movsd 0xd2967(%rip), %xmm1    # 0x4d5008
ucomisd %xmm0, %xmm1
movl $0x0, %edx
ja 0x4026d8
movsd 0xd295c(%rip), %xmm1    # 0x4d5010
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movsd 0xd2954(%rip), %xmm3    # 0x4d5018
addsd %xmm3, %xmm2
cvttsd2si %xmm2, %ebp
divsd %xmm0, %xmm1
addsd %xmm3, %xmm1
cvttsd2si %xmm1, %edx
xorl %ecx, %ecx
testl %r9d, %r9d
sete %cl
movl $0x46464952, 0x10(%rsp) # imm = 0x46464952
movl 0x3e0(%rbx), %eax
addl $-0x8, %eax
movl %eax, %esi
movb %al, 0x14(%rsp)
movb %ah, 0x15(%rsp)
shrl $0x10, %eax
shrl $0x18, %esi
movl %edx, %edi
shrl $0x10, %edi
movl %edx, %r8d
shrl $0x18, %r8d
orl $0x10, %ecx
shll $0x4, %ecx
movb %al, 0x16(%rsp)
movb %sil, 0x17(%rsp)
movaps 0xd292d(%rip), %xmm0    # 0x4d5050
movups %xmm0, 0x18(%rsp)
movabsq $0x3868697661, %rax     # imm = 0x3868697661
movq %rax, 0x28(%rsp)
movb %dl, 0x30(%rsp)
movb %dh, 0x31(%rsp)
movb %dil, 0x32(%rsp)
movb %r8b, 0x33(%rsp)
movq $0x0, 0x34(%rsp)
testl %r9d, %r9d
movl %r9d, 0x4(%rsp)
jne 0x40276b
movl %ecx, %eax
orl $0x20, %eax
cmpl $0x0, 0x428(%rbx)
cmovnel %eax, %ecx
movb %cl, 0x3c(%rsp)
movw $0x1, 0x3d(%rsp)
movb $0x0, 0x3f(%rsp)
movq 0x40(%rbx), %rdx
movb %dl, 0x40(%rsp)
movl %edx, %esi
shrl $0x8, %esi
movb %sil, 0x41(%rsp)
movl %edx, %edi
shrl $0x10, %edi
movb %dil, 0x42(%rsp)
movl %edx, %r8d
shrl $0x18, %r8d
movb %r8b, 0x43(%rsp)
xorl %r9d, %r9d
movl %r9d, 0x44(%rsp)
movslq 0x438(%rbx), %r10
leal 0x1(%r10), %eax
movb %al, 0x48(%rsp)
movb %ah, 0x49(%rsp)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x4a(%rsp)
shrl $0x18, %eax
movb %al, 0x4b(%rsp)
movl %r9d, 0x4c(%rsp)
movq 0x10(%rbx), %rcx
movl %ecx, 0x50(%rsp)
movq 0x18(%rbx), %r11
movl %r11d, %r14d
shrl $0x8, %r14d
movl %r11d, %r12d
shrl $0x10, %r12d
movl %r11d, %r13d
shrl $0x18, %r13d
movb %r11b, 0x54(%rsp)
movb %r14b, 0x55(%rsp)
movb %r12b, 0x56(%rsp)
movb %r13b, 0x57(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x58(%rsp)
movaps 0xd2829(%rip), %xmm1    # 0x4d5040
movups %xmm1, 0x68(%rsp)
movabsq $0x7364697600000038, %rax # imm = 0x7364697600000038
movq %rax, 0x78(%rsp)
movl 0x28(%rbx), %r15d
movl %r15d, 0x80(%rsp)
movabsq $0xf424000000000, %rax  # imm = 0xF424000000000
movq %rax, 0x8c(%rsp)
movl %ebp, %eax
shrl $0x10, %ebp
movq %r9, 0x84(%rsp)
movb %al, 0x94(%rsp)
movb %ah, 0x95(%rsp)
movb %bpl, 0x96(%rsp)
shrl $0x18, %eax
movb %al, 0x97(%rsp)
movl %r9d, 0x98(%rsp)
movb %dl, 0x9c(%rsp)
movb %sil, 0x9d(%rsp)
movb %dil, 0x9e(%rsp)
movb %r8b, 0x9f(%rsp)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0xa0(%rsp)
movq %r9, 0xa8(%rsp)
movabsq $0x6672747300000000, %rax # imm = 0x6672747300000000
movq %rax, 0xb0(%rsp)
movabsq $0x2800000028, %rax     # imm = 0x2800000028
movq %rax, 0xb8(%rsp)
movb %cl, 0xc0(%rsp)
movb %ch, 0xc1(%rsp)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0xc2(%rsp)
movl %r11d, %eax
imull %ecx, %eax
shrl $0x18, %ecx
movb %cl, 0xc3(%rsp)
movb %r11b, 0xc4(%rsp)
movb %r14b, 0xc5(%rsp)
movb %r12b, 0xc6(%rsp)
movb %r13b, 0xc7(%rsp)
leal (%rax,%rax,2), %eax
movl $0x180001, 0xc8(%rsp) # imm = 0x180001
movl %r15d, 0xcc(%rsp)
movb %al, 0xd0(%rsp)
movb %ah, 0xd1(%rsp)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0xd2(%rsp)
shrl $0x18, %eax
movb %al, 0xd3(%rsp)
movups %xmm0, 0xd4(%rsp)
movl $0x74, 0x6c(%rsp)
testq %r10, %r10
jle 0x402c3e
imulq $0x70, %r10, %rcx
movl $0xd4, %r12d
movabsq $0xdc00000000, %rsi     # imm = 0xDC00000000
xorl %edi, %edi
movl $0x4, %r8d
movabsq $0x6400000000, %r9      # imm = 0x6400000000
movq 0x78(%rbx,%rdi), %r10
leaq 0x7(%r10), %rax
addq $0xe, %r10
testq %rax, %rax
cmovnsq %rax, %r10
shrq $0x3, %r10
imull 0x68(%rbx,%rdi), %r10d
cmpl $0x5, %r10d
cmovll %r8d, %r10d
cmpq $0x7fc, %r12            # imm = 0x7FC
ja 0x4029d6
movl $0x5453494c, 0x10(%rsp,%r12) # imm = 0x5453494C
cmpq $0x7f8, %r12            # imm = 0x7F8
ja 0x4029e8
movl $0x0, 0x14(%rsp,%r12)
cmpq $0x7f4, %r12            # imm = 0x7F4
ja 0x4029fa
movl $0x6c727473, 0x18(%rsp,%r12) # imm = 0x6C727473
cmpq $0x7f0, %r12            # imm = 0x7F0
ja 0x402a0c
movl $0x68727473, 0x1c(%rsp,%r12) # imm = 0x68727473
cmpq $0x7ec, %r12            # imm = 0x7EC
ja 0x402a1e
movl $0x38, 0x20(%rsp,%r12)
cmpq $0x7e8, %r12            # imm = 0x7E8
ja 0x402a30
movl $0x73647561, 0x24(%rsp,%r12) # imm = 0x73647561
cmpq $0x7e4, %r12            # imm = 0x7E4
ja 0x402a42
movl $0x0, 0x28(%rsp,%r12)
cmpq $0x7e0, %r12            # imm = 0x7E0
ja 0x402a54
movl $0x0, 0x2c(%rsp,%r12)
cmpq $0x7dc, %r12            # imm = 0x7DC
ja 0x402a66
movl $0x0, 0x30(%rsp,%r12)
cmpq $0x7d8, %r12            # imm = 0x7D8
ja 0x402a78
movl $0x0, 0x34(%rsp,%r12)
cmpq $0x7d4, %r12            # imm = 0x7D4
ja 0x402aad
movl %r10d, %eax
shrl $0x2, %eax
movb %al, 0x38(%rsp,%r12)
movl %r10d, %eax
shrl $0xa, %eax
movb %al, 0x39(%rsp,%r12)
movl %r10d, %eax
shrl $0x12, %eax
movb %al, 0x3a(%rsp,%r12)
movl %r10d, %eax
shrl $0x1a, %eax
movb %al, 0x3b(%rsp,%r12)
cmpq $0x7d0, %r12            # imm = 0x7D0
ja 0x402ac3
imull $0x7d, 0x80(%rbx,%rdi), %eax
movl %eax, 0x3c(%rsp,%r12)
cmpq $0x7cc, %r12            # imm = 0x7CC
ja 0x402ad5
movl $0x0, 0x40(%rsp,%r12)
cmpq $0x7c8, %r12            # imm = 0x7C8
ja 0x402af7
movq 0x90(%rbx,%rdi), %rax
shlq $0x2, %rax
movl %r10d, %r11d
cqto
idivq %r11
movl %eax, 0x44(%rsp,%r12)
cmpq $0x7c4, %r12            # imm = 0x7C4
ja 0x402b09
movl $0x0, 0x48(%rsp,%r12)
cmpq $0x7c0, %r12            # imm = 0x7C0
ja 0x402b1b
movl $0xffffffff, 0x4c(%rsp,%r12) # imm = 0xFFFFFFFF
cmpq $0x7bc, %r12            # imm = 0x7BC
ja 0x402b50
movl %r10d, %eax
shrl $0x2, %eax
movb %al, 0x50(%rsp,%r12)
movl %r10d, %eax
shrl $0xa, %eax
movb %al, 0x51(%rsp,%r12)
movl %r10d, %eax
shrl $0x12, %eax
movb %al, 0x52(%rsp,%r12)
movl %r10d, %eax
shrl $0x1a, %eax
movb %al, 0x53(%rsp,%r12)
cmpq $0x7b8, %r12            # imm = 0x7B8
ja 0x402b62
movl $0x0, 0x54(%rsp,%r12)
cmpq $0x7b4, %r12            # imm = 0x7B4
ja 0x402b74
movl $0x0, 0x58(%rsp,%r12)
cmpq $0x7b0, %r12            # imm = 0x7B0
ja 0x402b86
movl $0x66727473, 0x5c(%rsp,%r12) # imm = 0x66727473
cmpq $0x7ac, %r12            # imm = 0x7AC
ja 0x402b98
movl $0x10, 0x60(%rsp,%r12)
cmpq $0x7aa, %r12            # imm = 0x7AA
ja 0x402bac
movzwl 0x60(%rbx,%rdi), %eax
movw %ax, 0x64(%rsp,%r12)
cmpq $0x7a8, %r12            # imm = 0x7A8
ja 0x402bc0
movzwl 0x68(%rbx,%rdi), %eax
movw %ax, 0x66(%rsp,%r12)
cmpq $0x7a4, %r12            # imm = 0x7A4
ja 0x402bd2
movl 0x70(%rbx,%rdi), %eax
movl %eax, 0x68(%rsp,%r12)
cmpq $0x7a0, %r12            # imm = 0x7A0
ja 0x402be8
imull $0x7d, 0x80(%rbx,%rdi), %eax
movl %eax, 0x6c(%rsp,%r12)
cmpq $0x79e, %r12            # imm = 0x79E
ja 0x402c05
movl %r10d, %eax
shrl $0x2, %eax
movb %al, 0x70(%rsp,%r12)
shrl $0xa, %r10d
movb %r10b, 0x71(%rsp,%r12)
cmpq $0x79c, %r12            # imm = 0x79C
ja 0x402c19
movzwl 0x78(%rbx,%rdi), %eax
movw %ax, 0x72(%rsp,%r12)
addq $0x64, %r12
movq %rsi, %rax
sarq $0x20, %rax
movl $0x5c, 0xc(%rsp,%rax)
addq $0x70, %rdi
addq %r9, %rsi
cmpq %rdi, %rcx
jne 0x40299e
jmp 0x402c44
movl $0xd4, %r12d
leal -0x14(%r12), %eax
movl %eax, 0x20(%rsp)
cmpq $0x7fc, %r12            # imm = 0x7FC
ja 0x402c5f
movl $0x5453494c, 0x10(%rsp,%r12) # imm = 0x5453494C
cmpq $0x7f8, %r12            # imm = 0x7F8
ja 0x402c71
movl $0x4c, 0x14(%rsp,%r12)
cmpq $0x7f4, %r12            # imm = 0x7F4
ja 0x402c83
movl $0x4f464e49, 0x18(%rsp,%r12) # imm = 0x4F464E49
cmpq $0x7f0, %r12            # imm = 0x7F0
ja 0x402c95
movl $0x54465349, 0x1c(%rsp,%r12) # imm = 0x54465349
cmpq $0x7ec, %r12            # imm = 0x7EC
ja 0x402ca7
movl $0x40, 0x20(%rsp,%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x54(%rsp,%r12)
movups %xmm0, 0x44(%rsp,%r12)
movups %xmm0, 0x34(%rsp,%r12)
movups %xmm0, 0x24(%rsp,%r12)
movl $0x798, %eax            # imm = 0x798
subl %r12d, %eax
testl %eax, %eax
jle 0x402e64
leaq (%rsp,%r12), %rcx
addq $0x10, %rcx
cmpq $0x7a8, %r12            # imm = 0x7A8
ja 0x402cea
movl $0x4b4e554a, 0x54(%rcx) # imm = 0x4B4E554A
cmpq $0x7a4, %r12            # imm = 0x7A4
ja 0x402cf6
movl %eax, 0x58(%rcx)
leaq (%rsp,%r12), %rdi
addq $0x6c, %rdi
movl %eax, %r14d
xorl %esi, %esi
movq %r14, %rdx
callq 0x4010e0
leaq (%r12,%r14), %rax
addq $0x5c, %rax
cmpq $0x7fc, %rax            # imm = 0x7FC
ja 0x402d23
movl $0x5453494c, 0x10(%rsp,%rax) # imm = 0x5453494C
cmpq $0x7f8, %rax            # imm = 0x7F8
ja 0x402d3a
movq 0x8(%rsp), %rcx
addl $0xfffff804, %ecx       # imm = 0xFFFFF804
movl %ecx, 0x14(%rsp,%rax)
cmpq $0x7f4, %rax            # imm = 0x7F4
ja 0x402d4a
movl $0x69766f6d, 0x18(%rsp,%rax) # imm = 0x69766F6D
movl (%rbx), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x481860
testq %rax, %rax
js 0x402db5
movl (%rbx), %r14d
xorl %r15d, %r15d
leaq (%rsp,%r15), %rsi
addq $0x10, %rsi
movl $0x800, %edx            # imm = 0x800
subq %r15, %rdx
movl %r14d, %edi
callq 0x4817c0
testq %rax, %rax
js 0x402d8b
addq %rax, %r15
cmpq $0x800, %r15            # imm = 0x800
jb 0x402d60
jmp 0x402d8e
movq %rax, %r15
cmpq $0x800, %r15            # imm = 0x800
jne 0x402db5
movl (%rbx), %edi
movq 0x3e0(%rbx), %rsi
callq 0x482660
testl %eax, %eax
js 0x402db5
xorl %r14d, %r14d
negl 0x4(%rsp)
sbbl %r14d, %r14d
jmp 0x402dc6
movq $0x6, 0x117770(%rip) # 0x51a530
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl (%rbx), %edi
callq 0x4819c0
movq 0x408(%rbx), %rdi
testq %rdi, %rdi
je 0x402dde
callq 0x444d10
movq 0x410(%rbx), %rdi
testq %rdi, %rdi
je 0x402def
callq 0x444d10
movq 0x440(%rbx), %rdi
testq %rdi, %rdi
je 0x402e00
callq 0x444d10
cmpl $0x0, 0x438(%rbx)
jle 0x402e47
leaq 0x98(%rbx), %r15
xorl %r12d, %r12d
movq 0x448(%rbx,%r12,8), %rdi
testq %rdi, %rdi
je 0x402e25
callq 0x444d10
cmpq $0x0, (%r15)
je 0x402e34
movq 0x30(%r15), %rdi
callq 0x444d10
incq %r12
movslq 0x438(%rbx), %rax
addq $0x70, %r15
cmpq %rax, %r12
jl 0x402e13
movq %rbx, %rdi
callq 0x444d10
movl %r14d, %eax
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x401224