// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/avilib.c
// Function: AVI_open_output_file
avi_t* AVI_open_output_file(char * filename)
{
   avi_t *AVI;
   int i;

   int mask;

   unsigned char AVI_header[HEADERBYTES];

   /* Allocate the avi_t struct and zero it */

   AVI = (avi_t *) malloc(sizeof(avi_t));
   if(AVI==0)
   {
      AVI_errno = AVI_ERR_NO_MEM;
      return 0;
   }
   memset((void *)AVI,0,sizeof(avi_t));

   /* Since Linux needs a long time when deleting big files,
      we do not truncate the file when we open it.
      Instead it is truncated when the AVI file is closed */

   mask = umask (0);
   umask (mask);

#ifdef WIN32
   AVI->fdes = open(filename, O_RDWR|O_CREAT|O_BINARY, (S_IRUSR | S_IWUSR) &~ mask);
#else
   AVI->fdes = open(filename, O_RDWR|O_CREAT, (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) &~ mask);
#endif
   if (AVI->fdes < 0)
   {
      AVI_errno = AVI_ERR_OPEN;
      free(AVI);
      return 0;
   }

   /* Write out HEADERBYTES bytes, the header will go here
      when we are finished with writing */

   for (i=0;i<HEADERBYTES;i++) AVI_header[i] = 0;
   i = avi_write(AVI->fdes,(char *)AVI_header,HEADERBYTES);
   if (i != HEADERBYTES)
   {
      close(AVI->fdes);
      AVI_errno = AVI_ERR_WRITE;
      free(AVI);
      return 0;
   }

   AVI->pos  = HEADERBYTES;
   AVI->mode = AVI_MODE_WRITE; /* open for writing */

   //init
   AVI->anum = 0;
   AVI->aptr = 0;

   return AVI;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x820, %rsp            # imm = 0x820
movq %rdi, -0x10(%rbp)
movl $0x488, %edi            # imm = 0x488
callq 0x452d20
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x4018ec
movq $0x8, 0x127051(%rip) # 0x528930
movq $0x0, -0x8(%rbp)
jmp 0x401a17
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x488, %edx            # imm = 0x488
callq 0x4010e0
xorl %edi, %edi
callq 0x48f8f0
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %edi
callq 0x48f8f0
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %edx
xorl $-0x1, %edx
andl $0x1a4, %edx            # imm = 0x1A4
movl $0x42, %esi
movb $0x0, %al
callq 0x48f930
movslq %eax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jge 0x40195f
movq $0x2, 0x126fe7(%rip) # 0x528930
movq -0x18(%rbp), %rdi
callq 0x453060
movq $0x0, -0x8(%rbp)
jmp 0x401a17
movl $0x0, -0x1c(%rbp)
cmpl $0x800, -0x1c(%rbp)     # imm = 0x800
jge 0x401986
movslq -0x1c(%rbp), %rax
movb $0x0, -0x820(%rbp,%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x401966
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
leaq -0x820(%rbp), %rsi
movl $0x800, %edx            # imm = 0x800
callq 0x401a30
movl %eax, -0x1c(%rbp)
cmpl $0x800, -0x1c(%rbp)     # imm = 0x800
je 0x4019d8
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
callq 0x48fd00
movq $0x4, 0x126f6b(%rip) # 0x528930
movq -0x18(%rbp), %rdi
callq 0x453060
movq $0x0, -0x8(%rbp)
jmp 0x401a17
movq -0x18(%rbp), %rax
movq $0x800, 0x3e0(%rax) # imm = 0x800
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x438(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x43c(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x820, %rsp            # imm = 0x820
popq %rbp
retq
nopw %cs:(%rax,%rax)