// File: /workspace/github_c_makefile_star2_O2/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 $0x838, %rsp            # imm = 0x838
movq %rdi, %rbx
xorl %r14d, %r14d
cmpq $0x0, 0x8(%rdi)
jne 0x402ea8
movq 0x3e0(%rbx), %rax
movq %rax, 0x28(%rsp)
movq 0x408(%rbx), %rdx
movl 0x3e8(%rbx), %ecx
shll $0x4, %ecx
leaq 0xcfa4c(%rip), %rsi     # 0x4d20ce
movq %rbx, %rdi
callq 0x404490
testl %eax, %eax
je 0x402699
movq $0x5, 0x115e97(%rip) # 0x518530
movsd 0x20(%rbx), %xmm0
xorl %ecx, %ecx
movsd 0xcf960(%rip), %xmm1    # 0x4d2008
ucomisd %xmm0, %xmm1
movl $0x0, %edx
ja 0x4026df
movsd 0xcf955(%rip), %xmm1    # 0x4d2010
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movsd 0xcf94d(%rip), %xmm3    # 0x4d2018
addsd %xmm3, %xmm2
cvttsd2si %xmm2, %ecx
divsd %xmm0, %xmm1
addsd %xmm3, %xmm1
cvttsd2si %xmm1, %edx
movl %ecx, 0xc(%rsp)
movl $0x46464952, 0x30(%rsp) # imm = 0x46464952
movl 0x3e0(%rbx), %ecx
andq $0x0, 0x54(%rsp)
addl $-0x8, %ecx
movl %ecx, %r8d
movb %cl, 0x34(%rsp)
movb %ch, 0x35(%rsp)
shrl $0x10, %ecx
shrl $0x18, %r8d
movl %edx, %esi
shrl $0x10, %esi
movl %edx, %edi
shrl $0x18, %edi
xorl %ebp, %ebp
movb %cl, 0x36(%rsp)
movb %r8b, 0x37(%rsp)
movaps 0xcf8f8(%rip), %xmm0    # 0x4d2020
movups %xmm0, 0x38(%rsp)
movabsq $0x3868697661, %rcx     # imm = 0x3868697661
movq %rcx, 0x48(%rsp)
movb %dl, 0x50(%rsp)
movb %dh, 0x51(%rsp)
movb %sil, 0x52(%rsp)
movb %dil, 0x53(%rsp)
movl $0x0, %ecx
movl %eax, 0x1c(%rsp)
testl %eax, %eax
jne 0x40276b
cmpl $0x0, 0x428(%rbx)
setne %cl
shlb $0x5, %cl
orb $0x10, %cl
movb %cl, 0x5c(%rsp)
movw $0x1, 0x5d(%rsp)
movb $0x0, 0x5f(%rsp)
movq 0x40(%rbx), %rcx
movb %cl, 0x60(%rsp)
movl %ecx, %esi
shrl $0x8, %esi
movb %sil, 0x61(%rsp)
movl %ecx, %edi
shrl $0x10, %edi
movb %dil, 0x62(%rsp)
movl %ecx, %r8d
shrl $0x18, %r8d
movb %r8b, 0x63(%rsp)
andl $0x0, 0x64(%rsp)
movl 0x438(%rbx), %r15d
leal 0x1(%r15), %eax
movb %al, 0x68(%rsp)
movb %ah, 0x69(%rsp)
movl %eax, %r9d
shrl $0x10, %r9d
movb %r9b, 0x6a(%rsp)
shrl $0x18, %eax
movb %al, 0x6b(%rsp)
andl $0x0, 0x6c(%rsp)
movq 0x10(%rbx), %rdx
movl %edx, 0x70(%rsp)
movq 0x18(%rbx), %r9
movb %r9b, 0x74(%rsp)
movl %r9d, %r10d
shrl $0x8, %r10d
movb %r10b, 0x75(%rsp)
movl %r9d, %r11d
shrl $0x10, %r11d
movb %r11b, 0x76(%rsp)
movl %r9d, %r14d
shrl $0x18, %r14d
movb %r14b, 0x77(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x78(%rsp)
movl $0x5453494c, 0x88(%rsp) # imm = 0x5453494C
movaps 0xcf80e(%rip), %xmm1    # 0x4d2030
movaps %xmm1, 0x90(%rsp)
movl 0x28(%rbx), %r12d
movl %r12d, 0xa0(%rsp)
andq $0x0, 0xa4(%rsp)
movabsq $0xf424000000000, %r13  # imm = 0xF424000000000
movq %r13, 0xac(%rsp)
movl 0xc(%rsp), %eax
movb %al, 0xb4(%rsp)
movb %ah, 0xb5(%rsp)
movl %eax, %r13d
shrl $0x10, %r13d
movb %r13b, 0xb6(%rsp)
shrl $0x18, %eax
movb %al, 0xb7(%rsp)
andl $0x0, 0xb8(%rsp)
movb %cl, 0xbc(%rsp)
movb %sil, 0xbd(%rsp)
movb %dil, 0xbe(%rsp)
movb %r8b, 0xbf(%rsp)
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
movq %rcx, 0xc0(%rsp)
movabsq $0x6672747300000000, %rcx # imm = 0x6672747300000000
movq %rcx, 0xd0(%rsp)
andq $0x0, 0xc8(%rsp)
movabsq $0x2800000028, %rcx     # imm = 0x2800000028
movq %rcx, 0xd8(%rsp)
movl %edx, %ecx
shrl $0x10, %ecx
movb %dl, 0xe0(%rsp)
movb %dh, 0xe1(%rsp)
movb %cl, 0xe2(%rsp)
movl %edx, %ecx
shrl $0x18, %ecx
movb %cl, 0xe3(%rsp)
movb %r9b, 0xe4(%rsp)
movb %r10b, 0xe5(%rsp)
movb %r11b, 0xe6(%rsp)
movb %r14b, 0xe7(%rsp)
movl $0x180001, 0xe8(%rsp) # imm = 0x180001
movl %r12d, 0xec(%rsp)
imull %edx, %r9d
leal (%r9,%r9,2), %eax
movb %al, 0xf0(%rsp)
movb %ah, 0xf1(%rsp)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0xf2(%rsp)
shrl $0x18, %eax
movb %al, 0xf3(%rsp)
movups %xmm0, 0xf4(%rsp)
movl $0x74, 0x8c(%rsp)
leaq 0x60(%rbx), %rcx
testl %r15d, %r15d
cmovlel %ebp, %r15d
imulq $0x64, %r15, %rsi
movl $0xd4, %edi
movl $0x6c4, %r12d           # imm = 0x6C4
pushq $0x8
popq %r8
pushq $0x4
popq %r9
leaq 0xd4(%rbp), %r11
cmpq %rbp, %rsi
je 0x402cf1
movq 0x8(%rcx), %r14
movq 0x18(%rcx), %r13
leaq 0x7(%r13), %rax
cqto
idivq %r8
movl %r14d, %edx
imull %eax, %edx
cmpl $0x5, %edx
jge 0x4029cb
movl %r9d, %edx
cmpq $0x7fc, %r11            # imm = 0x7FC
ja 0x402ccd
movl $0x5453494c, 0x104(%rsp,%rbp) # imm = 0x5453494C
cmpq $0x7f9, %r11            # imm = 0x7F9
jae 0x402ccd
leaq 0xdc(%rbp), %r10
andl $0x0, 0x108(%rsp,%rbp)
cmpq $0x7f4, %r11            # imm = 0x7F4
ja 0x402cd1
movl $0x6c727473, 0x10c(%rsp,%rbp) # imm = 0x6C727473
cmpq $0x7f0, %r11            # imm = 0x7F0
ja 0x402cd1
movl $0x68727473, 0x110(%rsp,%rbp) # imm = 0x68727473
cmpq $0x7ec, %r11            # imm = 0x7EC
ja 0x402cd1
movl $0x38, 0x114(%rsp,%rbp)
cmpq $0x7e8, %r11            # imm = 0x7E8
ja 0x402cd1
movl $0x73647561, 0x118(%rsp,%rbp) # imm = 0x73647561
cmpq $0x7e4, %r11            # imm = 0x7E4
ja 0x402cd1
andl $0x0, 0x11c(%rsp,%rbp)
cmpq $0x7e0, %r11            # imm = 0x7E0
ja 0x402cd1
andl $0x0, 0x120(%rsp,%rbp)
cmpq $0x7dc, %r11            # imm = 0x7DC
ja 0x402cd1
andl $0x0, 0x124(%rsp,%rbp)
cmpq $0x7d8, %r11            # imm = 0x7D8
ja 0x402cd1
andl $0x0, 0x128(%rsp,%rbp)
cmpq $0x7d4, %r11            # imm = 0x7D4
ja 0x402cd1
movl %edx, %r15d
shrl $0x2, %r15d
movb %r15b, 0x12c(%rsp,%rbp)
movl %edx, %eax
shrl $0xa, %eax
movl %eax, 0xc(%rsp)
movb %al, 0x12d(%rsp,%rbp)
movl %edx, %eax
shrl $0x12, %eax
movl %eax, 0x18(%rsp)
movb %al, 0x12e(%rsp,%rbp)
movl %edx, %eax
shrl $0x1a, %eax
movb %al, 0x12f(%rsp,%rbp)
cmpq $0x7d0, %r11            # imm = 0x7D0
ja 0x402cd1
movl %r15d, 0x10(%rsp)
imull $0x7d, 0x20(%rcx), %r15d
movl %r15d, 0x14(%rsp)
movl %r15d, 0x130(%rsp,%rbp)
cmpq $0x7cc, %r11            # imm = 0x7CC
ja 0x402cd1
andl $0x0, 0x134(%rsp,%rbp)
cmpq $0x7c8, %r11            # imm = 0x7C8
ja 0x402cd1
movl %eax, %r15d
movq 0x30(%rcx), %rax
shlq $0x2, %rax
movl %edx, %edx
movq %rdx, 0x20(%rsp)
cqto
idivq 0x20(%rsp)
movl %eax, 0x138(%rsp,%rbp)
cmpq $0x7c4, %r11            # imm = 0x7C4
ja 0x402cd1
andl $0x0, 0x13c(%rsp,%rbp)
cmpq $0x7c0, %r11            # imm = 0x7C0
ja 0x402cd1
orl $-0x1, 0x140(%rsp,%rbp)
cmpq $0x7bc, %r11            # imm = 0x7BC
ja 0x402cd1
movl 0x10(%rsp), %eax
movb %al, 0x144(%rsp,%rbp)
movl 0xc(%rsp), %eax
movb %al, 0x145(%rsp,%rbp)
movl 0x18(%rsp), %eax
movb %al, 0x146(%rsp,%rbp)
movb %r15b, 0x147(%rsp,%rbp)
cmpq $0x7b8, %r11            # imm = 0x7B8
ja 0x402cd1
andl $0x0, 0x148(%rsp,%rbp)
cmpq $0x7b4, %r11            # imm = 0x7B4
ja 0x402cd1
andl $0x0, 0x14c(%rsp,%rbp)
cmpq $0x7b0, %r11            # imm = 0x7B0
ja 0x402cd1
movl $0x66727473, 0x150(%rsp,%rbp) # imm = 0x66727473
cmpq $0x7ac, %r11            # imm = 0x7AC
ja 0x402cd1
movl $0x10, 0x154(%rsp,%rbp)
cmpq $0x7aa, %r11            # imm = 0x7AA
ja 0x402cd1
movzwl (%rcx), %eax
movw %ax, 0x158(%rsp,%rbp)
cmpq $0x7a8, %r11            # imm = 0x7A8
ja 0x402cd1
movw %r14w, 0x15a(%rsp,%rbp)
cmpq $0x7a4, %r11            # imm = 0x7A4
ja 0x402cd1
movl 0x10(%rcx), %eax
movl %eax, 0x15c(%rsp,%rbp)
cmpq $0x7a0, %r11            # imm = 0x7A0
ja 0x402cd1
movl 0x14(%rsp), %eax
movl %eax, %r15d
shrl $0x8, %r15d
movl %eax, %edx
shrl $0x10, %edx
movl %eax, %r14d
shrl $0x18, %r14d
movb %al, 0x160(%rsp,%rbp)
movb %r15b, 0x161(%rsp,%rbp)
movb %dl, 0x162(%rsp,%rbp)
movb %r14b, 0x163(%rsp,%rbp)
cmpq $0x79e, %r11            # imm = 0x79E
ja 0x402cd1
movl 0x10(%rsp), %eax
movb %al, 0x164(%rsp,%rbp)
movl 0xc(%rsp), %eax
movb %al, 0x165(%rsp,%rbp)
cmpq $0x79c, %r11            # imm = 0x79C
ja 0x402cd1
movw %r13w, 0x166(%rsp,%rbp)
jmp 0x402cd1
leaq 0x8(%rdi), %r10
addq $0x64, %rdi
movslq %r10d, %rax
movl $0x5c, 0x2c(%rsp,%rax)
addq $0x64, %rbp
addq $0x70, %rcx
addl $-0x64, %r12d
jmp 0x40299c
leal 0xc0(%rbp), %eax
movl %eax, 0x40(%rsp)
cmpq $0x7fc, %r11            # imm = 0x7FC
ja 0x402d5f
movl $0x5453494c, 0x104(%rsp,%rbp) # imm = 0x5453494C
cmpq $0x7f8, %r11            # imm = 0x7F8
ja 0x402d5f
movl $0x4c, 0x108(%rsp,%rbp)
cmpq $0x7f4, %r11            # imm = 0x7F4
ja 0x402d5f
movl $0x4f464e49, 0x10c(%rsp,%rbp) # imm = 0x4F464E49
cmpq $0x7f0, %r11            # imm = 0x7F0
ja 0x402d5f
movl $0x54465349, 0x110(%rsp,%rbp) # imm = 0x54465349
cmpq $0x7ec, %r11            # imm = 0x7EC
ja 0x402d5f
movl $0x40, 0x114(%rsp,%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x148(%rsp,%rbp)
movups %xmm0, 0x138(%rsp,%rbp)
movups %xmm0, 0x128(%rsp,%rbp)
movups %xmm0, 0x118(%rsp,%rbp)
movl $0x6c4, %eax            # imm = 0x6C4
subq %rbp, %rax
testl %eax, %eax
jle 0x402f2b
cmpq $0x7a8, %r11            # imm = 0x7A8
ja 0x402dda
movl $0x4b4e554a, 0x158(%rsp,%rbp) # imm = 0x4B4E554A
cmpq $0x7a4, %r11            # imm = 0x7A4
ja 0x402dda
movb $-0x3c, %cl
subb %bpl, %cl
movb %cl, 0x15c(%rsp,%rbp)
movb %ah, 0x15d(%rsp,%rbp)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x15e(%rsp,%rbp)
movl %eax, %ecx
shrl $0x18, %ecx
movb %cl, 0x15f(%rsp,%rbp)
leaq (%rsp,%rbp), %r14
addq $0x30, %r14
movl $0x130, %r13d           # imm = 0x130
leaq (%r14,%r13), %rdi
movl %eax, %edx
xorl %esi, %esi
callq 0x4010e8
movl %r12d, %eax
leaq (%rax,%rbp), %rcx
addq %r13, %rcx
cmpq $0x7fc, %rcx            # imm = 0x7FC
ja 0x402e52
leaq (%rsp,%rax), %rdx
addq $0x30, %rdx
movl $0x5453494c, 0x130(%rbp,%rdx) # imm = 0x5453494C
cmpq $0x7f8, %rcx            # imm = 0x7F8
ja 0x402e52
movq 0x28(%rsp), %rdx
addl $0xfffff804, %edx       # imm = 0xFFFFF804
movl %edx, 0x134(%rax,%r14)
cmpq $0x7f4, %rcx            # imm = 0x7F4
ja 0x402e52
addq %rsp, %rax
addq $0x30, %rax
movl $0x69766f6d, 0x138(%rbp,%rax) # imm = 0x69766F6D
movl (%rbx), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x47efe0
testq %rax, %rax
js 0x402e99
movl (%rbx), %edi
leaq 0x30(%rsp), %rsi
movl $0x800, %edx            # imm = 0x800
callq 0x4019c5
cmpq $0x800, %rax            # imm = 0x800
jne 0x402e99
movl (%rbx), %edi
movq 0x3e0(%rbx), %rsi
callq 0x47fde0
testl %eax, %eax
js 0x402e99
xorl %r14d, %r14d
negl 0x1c(%rsp)
sbbl %r14d, %r14d
jmp 0x402ea8
movq $0x6, 0x11568c(%rip) # 0x518530
pushq $-0x1
popq %r14
movl (%rbx), %edi
callq 0x47f140
movq 0x408(%rbx), %rdi
callq 0x4424a0
movq 0x410(%rbx), %rdi
callq 0x4424a0
movq 0x440(%rbx), %rdi
callq 0x4424a0
leaq 0x98(%rbx), %r15
xorl %r12d, %r12d
movslq 0x438(%rbx), %rax
cmpq %rax, %r12
jge 0x402f0e
movq 0x448(%rbx,%r12,8), %rdi
callq 0x4424a0
cmpq $0x0, (%r15)
je 0x402f05
movq 0x30(%r15), %rdi
callq 0x4424a0
incq %r12
addq $0x70, %r15
jmp 0x402edd
movq %rbx, %rdi
callq 0x4424a0
movl %r14d, %eax
addq $0x838, %rsp            # imm = 0x838
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x516868, %rax         # imm = 0x516868
movq (%rax), %rcx
leaq 0xcf154(%rip), %rdi     # 0x4d2090
pushq $0x33
popq %rsi
pushq $0x1
popq %rdx
callq 0x42be90
pushq $0x1
popq %rdi
callq 0x4239b0