// File: /workspace/github_c_makefile_star2_O3/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 0x402e2b
movq 0x3e0(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x408(%rbx), %rdx
movl 0x3e8(%rbx), %ecx
shll $0x4, %ecx
movq %rbx, %rdi
movl $0x31786469, %esi       # imm = 0x31786469
callq 0x404715
testl %eax, %eax
je 0x4026c5
movq $0x5, 0x118e4b(%rip) # 0x51b510
movsd 0x20(%rbx), %xmm0
xorl %edx, %edx
movsd 0xd3934(%rip), %xmm1    # 0x4d6008
ucomisd %xmm0, %xmm1
movl $0x0, %ecx
ja 0x40270b
movsd 0xd3929(%rip), %xmm1    # 0x4d6010
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movsd 0xd3921(%rip), %xmm3    # 0x4d6018
addsd %xmm3, %xmm2
cvttsd2si %xmm2, %edx
divsd %xmm0, %xmm1
addsd %xmm3, %xmm1
cvttsd2si %xmm1, %ecx
movl %edx, (%rsp)
movl $0x46464952, 0x10(%rsp) # imm = 0x46464952
movl 0x3e0(%rbx), %edx
addl $-0x8, %edx
movl %edx, %esi
movb %dl, 0x14(%rsp)
movb %dh, 0x15(%rsp)
shrl $0x10, %edx
shrl $0x18, %esi
movl %ecx, %edi
shrl $0x10, %edi
movl %ecx, %r8d
shrl $0x18, %r8d
xorl %r10d, %r10d
movb %dl, 0x16(%rsp)
movb %sil, 0x17(%rsp)
movaps 0xd38d2(%rip), %xmm0    # 0x4d6020
movups %xmm0, 0x18(%rsp)
movabsq $0x3868697661, %rdx     # imm = 0x3868697661
movq %rdx, 0x28(%rsp)
movb %cl, 0x30(%rsp)
movb %ch, 0x31(%rsp)
movb %dil, 0x32(%rsp)
movb %r8b, 0x33(%rsp)
movq $0x0, 0x34(%rsp)
movl $0x0, %ecx
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x40279a
cmpl $0x0, 0x428(%rbx)
setne %cl
shlb $0x5, %cl
orb $0x10, %cl
movb %cl, 0x3c(%rsp)
movw $0x1, 0x3d(%rsp)
movb $0x0, 0x3f(%rsp)
movq 0x40(%rbx), %rsi
movb %sil, 0x40(%rsp)
movl %esi, %edi
shrl $0x8, %edi
movb %dil, 0x41(%rsp)
movl %esi, %r8d
shrl $0x10, %r8d
movb %r8b, 0x42(%rsp)
movl %esi, %r9d
shrl $0x18, %r9d
movb %r9b, 0x43(%rsp)
movl %r10d, 0x44(%rsp)
movslq 0x438(%rbx), %rdx
leal 0x1(%rdx), %ecx
movb %cl, 0x48(%rsp)
movb %ch, 0x49(%rsp)
movl %ecx, %r11d
shrl $0x10, %r11d
movb %r11b, 0x4a(%rsp)
shrl $0x18, %ecx
movb %cl, 0x4b(%rsp)
movl %r10d, 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)
movl $0x5453494c, 0x68(%rsp) # imm = 0x5453494C
movaps 0xd37e0(%rip), %xmm1    # 0x4d6030
movaps %xmm1, 0x70(%rsp)
movl 0x28(%rbx), %r15d
movl %r15d, 0x80(%rsp)
movabsq $0xf424000000000, %rbp  # imm = 0xF424000000000
movq %rbp, 0x8c(%rsp)
movl (%rsp), %eax
movl %eax, %ebp
shrl $0x10, %ebp
movq %r10, 0x84(%rsp)
movb %al, 0x94(%rsp)
movb %ah, 0x95(%rsp)
movb %bpl, 0x96(%rsp)
shrl $0x18, %eax
movb %al, 0x97(%rsp)
movl %r10d, 0x98(%rsp)
movb %sil, 0x9c(%rsp)
movb %dil, 0x9d(%rsp)
movb %r8b, 0x9e(%rsp)
movb %r9b, 0x9f(%rsp)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0xa0(%rsp)
movq %r10, 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 %rdx, %rdx
jle 0x402cad
imulq $0x70, %rdx, %rcx
movl $0xd4, %r12d
xorl %esi, %esi
movl $0x4, %edi
movq 0x78(%rbx,%rsi), %r9
leaq 0x7(%r9), %rax
leaq 0xe(%r9), %r8
testq %rax, %rax
cmovnsq %rax, %r8
movq 0x68(%rbx,%rsi), %r10
shrq $0x3, %r8
movl %r10d, %edx
imull %r8d, %edx
cmpl $0x5, %edx
cmovll %edi, %edx
cmpq $0x7fc, %r12            # imm = 0x7FC
ja 0x402c8a
movl $0x5453494c, 0x10(%rsp,%r12) # imm = 0x5453494C
cmpq $0x7f9, %r12            # imm = 0x7F9
jae 0x402c8a
leaq 0x8(%r12), %r8
movl $0x0, 0x14(%rsp,%r12)
cmpq $0x7f4, %r12            # imm = 0x7F4
ja 0x402c8f
movl $0x6c727473, 0x18(%rsp,%r12) # imm = 0x6C727473
cmpq $0x7f0, %r12            # imm = 0x7F0
ja 0x402c8f
movl $0x68727473, 0x1c(%rsp,%r12) # imm = 0x68727473
cmpq $0x7ec, %r12            # imm = 0x7EC
ja 0x402c8f
movl $0x38, 0x20(%rsp,%r12)
cmpq $0x7e8, %r12            # imm = 0x7E8
ja 0x402c8f
movl $0x73647561, 0x24(%rsp,%r12) # imm = 0x73647561
cmpq $0x7e4, %r12            # imm = 0x7E4
ja 0x402c8f
movl $0x0, 0x28(%rsp,%r12)
cmpq $0x7e0, %r12            # imm = 0x7E0
ja 0x402c8f
movl $0x0, 0x2c(%rsp,%r12)
cmpq $0x7dc, %r12            # imm = 0x7DC
ja 0x402c8f
movl $0x0, 0x30(%rsp,%r12)
cmpq $0x7d8, %r12            # imm = 0x7D8
ja 0x402c8f
movl $0x0, 0x34(%rsp,%r12)
cmpq $0x7d4, %r12            # imm = 0x7D4
ja 0x402c8f
movl %edx, %r11d
shrl $0x2, %r11d
movb %r11b, 0x38(%rsp,%r12)
movl %edx, %r14d
shrl $0xa, %r14d
movb %r14b, 0x39(%rsp,%r12)
movl %edx, %r15d
shrl $0x12, %r15d
movb %r15b, 0x3a(%rsp,%r12)
movl %edx, %r13d
shrl $0x1a, %r13d
movb %r13b, 0x3b(%rsp,%r12)
cmpq $0x7d0, %r12            # imm = 0x7D0
ja 0x402c8f
imull $0x7d, 0x80(%rbx,%rsi), %eax
movl %eax, 0x3c(%rsp,%r12)
cmpq $0x7cc, %r12            # imm = 0x7CC
ja 0x402c8f
movl $0x0, 0x40(%rsp,%r12)
cmpq $0x7c8, %r12            # imm = 0x7C8
ja 0x402c8f
movl %eax, (%rsp)
movq 0x90(%rbx,%rsi), %rax
shlq $0x2, %rax
movl %edx, %ebp
cqto
idivq %rbp
movl %eax, 0x44(%rsp,%r12)
cmpq $0x7c4, %r12            # imm = 0x7C4
ja 0x402c8f
movl $0x0, 0x48(%rsp,%r12)
cmpq $0x7c0, %r12            # imm = 0x7C0
ja 0x402c8f
movl $0xffffffff, 0x4c(%rsp,%r12) # imm = 0xFFFFFFFF
cmpq $0x7bc, %r12            # imm = 0x7BC
ja 0x402c8f
movb %r11b, 0x50(%rsp,%r12)
movb %r14b, 0x51(%rsp,%r12)
movb %r15b, 0x52(%rsp,%r12)
movb %r13b, 0x53(%rsp,%r12)
cmpq $0x7b8, %r12            # imm = 0x7B8
ja 0x402c8f
movl $0x0, 0x54(%rsp,%r12)
cmpq $0x7b4, %r12            # imm = 0x7B4
ja 0x402c8f
movl $0x0, 0x58(%rsp,%r12)
cmpq $0x7b0, %r12            # imm = 0x7B0
ja 0x402c8f
movl $0x66727473, 0x5c(%rsp,%r12) # imm = 0x66727473
cmpq $0x7ac, %r12            # imm = 0x7AC
ja 0x402c8f
movl $0x10, 0x60(%rsp,%r12)
cmpq $0x7aa, %r12            # imm = 0x7AA
ja 0x402c8f
movzwl 0x60(%rbx,%rsi), %eax
movw %ax, 0x64(%rsp,%r12)
cmpq $0x7a8, %r12            # imm = 0x7A8
ja 0x402c8f
movw %r10w, 0x66(%rsp,%r12)
cmpq $0x7a4, %r12            # imm = 0x7A4
ja 0x402c8f
movl 0x70(%rbx,%rsi), %eax
movl %eax, 0x68(%rsp,%r12)
cmpq $0x7a0, %r12            # imm = 0x7A0
ja 0x402c8f
movl (%rsp), %ebp
movl %ebp, %eax
shrl $0x8, %eax
movl %ebp, %edx
shrl $0x10, %edx
movl %ebp, %r10d
shrl $0x18, %r10d
movb %bpl, 0x6c(%rsp,%r12)
movb %al, 0x6d(%rsp,%r12)
movb %dl, 0x6e(%rsp,%r12)
movb %r10b, 0x6f(%rsp,%r12)
cmpq $0x79e, %r12            # imm = 0x79E
ja 0x402c8f
movb %r11b, 0x70(%rsp,%r12)
movb %r14b, 0x71(%rsp,%r12)
cmpq $0x79c, %r12            # imm = 0x79C
ja 0x402c8f
movw %r9w, 0x72(%rsp,%r12)
jmp 0x402c8f
leaq 0x8(%r12), %r8
addq $0x64, %r12
movslq %r8d, %rax
movl $0x5c, 0xc(%rsp,%rax)
addq $0x70, %rsi
cmpq %rsi, %rcx
jne 0x4029b7
jmp 0x402cb3
movl $0xd4, %r12d
leal -0x14(%r12), %eax
movl %eax, 0x20(%rsp)
cmpq $0x7fc, %r12            # imm = 0x7FC
ja 0x402d16
movl $0x5453494c, 0x10(%rsp,%r12) # imm = 0x5453494C
cmpq $0x7f8, %r12            # imm = 0x7F8
ja 0x402d16
movl $0x4c, 0x14(%rsp,%r12)
cmpq $0x7f4, %r12            # imm = 0x7F4
ja 0x402d16
movl $0x4f464e49, 0x18(%rsp,%r12) # imm = 0x4F464E49
cmpq $0x7f0, %r12            # imm = 0x7F0
ja 0x402d16
movl $0x54465349, 0x1c(%rsp,%r12) # imm = 0x54465349
cmpq $0x7ec, %r12            # imm = 0x7EC
ja 0x402d16
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 0x402ec9
cmpq $0x7a8, %r12            # imm = 0x7A8
ja 0x402d67
movl $0x4b4e554a, 0x64(%rsp,%r12) # imm = 0x4B4E554A
cmpq $0x7a4, %r12            # imm = 0x7A4
ja 0x402d67
leaq (%rsp,%r12), %rcx
addq $0x10, %rcx
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 0x402dbb
movl $0x5453494c, 0x10(%rsp,%rax) # imm = 0x5453494C
cmpq $0x7f8, %rax            # imm = 0x7F8
ja 0x402dbb
movq 0x8(%rsp), %rcx
addl $0xfffff804, %ecx       # imm = 0xFFFFF804
movl %ecx, 0x14(%rsp,%rax)
cmpq $0x7f4, %rax            # imm = 0x7F4
ja 0x402dbb
movl $0x69766f6d, 0x18(%rsp,%rax) # imm = 0x69766F6D
movl (%rbx), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x482720
testq %rax, %rax
js 0x402e1a
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 0x482680
testq %rax, %rax
js 0x402e1a
addq %rax, %r15
cmpq $0x800, %r15            # imm = 0x800
jb 0x402dd1
jne 0x402e1a
movl (%rbx), %edi
movq 0x3e0(%rbx), %rsi
callq 0x483520
testl %eax, %eax
js 0x402e1a
xorl %r14d, %r14d
negl 0x4(%rsp)
sbbl %r14d, %r14d
jmp 0x402e2b
movq $0x6, 0x1186eb(%rip) # 0x51b510
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl (%rbx), %edi
callq 0x482880
movq 0x408(%rbx), %rdi
testq %rdi, %rdi
je 0x402e43
callq 0x445c00
movq 0x410(%rbx), %rdi
testq %rdi, %rdi
je 0x402e54
callq 0x445c00
movq 0x440(%rbx), %rdi
testq %rdi, %rdi
je 0x402e65
callq 0x445c00
cmpl $0x0, 0x438(%rbx)
jle 0x402eac
leaq 0x98(%rbx), %r15
xorl %r12d, %r12d
movq 0x448(%rbx,%r12,8), %rdi
testq %rdi, %rdi
je 0x402e8a
callq 0x445c00
cmpq $0x0, (%r15)
je 0x402e99
movq 0x30(%r15), %rdi
callq 0x445c00
incq %r12
movslq 0x438(%rbx), %rax
addq $0x70, %r15
cmpq %rax, %r12
jl 0x402e78
movq %rbx, %rdi
callq 0x445c00
movl %r14d, %eax
addq $0x818, %rsp            # imm = 0x818
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x401224