// File: attractivechaos[P]udb2/stb/./stb.h
// Function: stb_fopen
FILE *  stb_fopen(char *filename, char *mode)
{
   FILE *f;
   char name_full[4096];
   char temp_full[sizeof(name_full) + 12];
   int p;
#ifdef _MSC_VER
   int j;
#endif
   if (mode[0] != 'w' && !strchr(mode, '+'))
      return stb__fopen(filename, mode);

   // save away the full path to the file so if the program
   // changes the cwd everything still works right! unix has
   // better ways to do this, but we have to work in windows
   name_full[0] = '\0'; // stb_fullpath reads name_full[0]
   if (stb_fullpath(name_full, sizeof(name_full), filename)==0)
      return 0;

   // try to generate a temporary file in the same directory
   p = strlen(name_full)-1;
   while (p > 0 && name_full[p] != '/' && name_full[p] != '\\'
                && name_full[p] != ':' && name_full[p] != '~')
      --p;
   ++p;

   memcpy(temp_full, name_full, p);

   #ifdef _MSC_VER
   // try multiple times to make a temp file... just in
   // case some other process makes the name first
   for (j=0; j < 32; ++j) {
      strcpy(temp_full+p, "stmpXXXXXX");
      if (stb_mktemp(temp_full) == NULL)
         return 0;

      f = fopen(temp_full, mode);
      if (f != NULL)
         break;
   }
   #else
   {
      strcpy(temp_full+p, "stmpXXXXXX");
      #ifdef __MINGW32__
         int fd = open(mktemp(temp_full), O_RDWR);
      #else
         int fd = mkstemp(temp_full);
      #endif
      if (fd == -1) return NULL;
      f = fdopen(fd, mode);
      if (f == NULL) {
         unlink(temp_full);
         close(fd);
         return NULL;
      }
   }
   #endif
   if (f != NULL) {
      stb__file_data *d = (stb__file_data *) malloc(sizeof(*d));
      if (!d) { assert(0);  /* NOTREACHED */fclose(f); return NULL; }
      if (stb__files == NULL) stb__files = stb_ptrmap_create();
      d->temp_name = strdup(temp_full);
      d->name      = strdup(name_full);
      d->errors    = 0;
      stb_ptrmap_add(stb__files, f, d);
      return f;
   }

   return NULL;
}

// Assembly:
subq $0x2058, %rsp           # imm = 0x2058
movq %rdi, 0x2048(%rsp)
movq %rsi, 0x2040(%rsp)
movq 0x2040(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x77, %eax
je 0xd3b1
movq 0x2040(%rsp), %rdi
movl $0x2b, %esi
callq 0x2110
cmpq $0x0, %rax
jne 0xd3b1
movq 0x2048(%rsp), %rdi
movq 0x2040(%rsp), %rsi
callq 0x22f0
movq %rax, 0x2050(%rsp)
jmp 0xd5f9
movb $0x0, 0x1030(%rsp)
leaq 0x1030(%rsp), %rdi
movq 0x2048(%rsp), %rdx
movl $0x1000, %esi           # imm = 0x1000
callq 0xde80
cmpl $0x0, %eax
jne 0xd3e9
movq $0x0, 0x2050(%rsp)
jmp 0xd5f9
leaq 0x1030(%rsp), %rdi
callq 0x2100
subq $0x1, %rax
movl %eax, 0x1c(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x1c(%rsp)
movb %al, 0xf(%rsp)
jle 0xd46a
movslq 0x1c(%rsp), %rax
movsbl 0x1030(%rsp,%rax), %ecx
xorl %eax, %eax
cmpl $0x2f, %ecx
movb %al, 0xf(%rsp)
je 0xd46a
movslq 0x1c(%rsp), %rax
movsbl 0x1030(%rsp,%rax), %ecx
xorl %eax, %eax
cmpl $0x5c, %ecx
movb %al, 0xf(%rsp)
je 0xd46a
movslq 0x1c(%rsp), %rax
movsbl 0x1030(%rsp,%rax), %ecx
xorl %eax, %eax
cmpl $0x3a, %ecx
movb %al, 0xf(%rsp)
je 0xd46a
movslq 0x1c(%rsp), %rax
movsbl 0x1030(%rsp,%rax), %eax
cmpl $0x7e, %eax
setne %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0xd474
jmp 0xd484
movl 0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0xd3fe
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x1030(%rsp), %rsi
movslq 0x1c(%rsp), %rdx
callq 0x2230
leaq 0x20(%rsp), %rdi
movslq 0x1c(%rsp), %rax
addq %rax, %rdi
leaq 0x12239(%rip), %rsi     # 0x1f6f3
callq 0x2070
leaq 0x20(%rsp), %rdi
callq 0x2290
movl %eax, 0x18(%rsp)
cmpl $-0x1, 0x18(%rsp)
jne 0xd4e5
movq $0x0, 0x2050(%rsp)
jmp 0xd5f9
movl 0x18(%rsp), %edi
movq 0x2040(%rsp), %rsi
callq 0x22c0
movq %rax, 0x2038(%rsp)
cmpq $0x0, 0x2038(%rsp)
jne 0xd52d
leaq 0x20(%rsp), %rdi
callq 0x2040
movl 0x18(%rsp), %edi
callq 0x2190
movq $0x0, 0x2050(%rsp)
jmp 0xd5f9
cmpq $0x0, 0x2038(%rsp)
je 0xd5ed
movl $0x18, %edi
callq 0x2260
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0xd572
leaq 0x12154(%rip), %rdi     # 0x1f6ae
leaq 0x11e28(%rip), %rsi     # 0x1f389
movl $0x157d, %edx           # imm = 0x157D
leaq 0x12191(%rip), %rcx     # 0x1f6fe
callq 0x2140
cmpq $0x0, 0x1cb66(%rip)     # 0x2a0e0
jne 0xd588
callq 0x9c10
movq %rax, 0x1cb58(%rip)     # 0x2a0e0
leaq 0x20(%rsp), %rdi
callq 0x2390
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, (%rax)
leaq 0x1030(%rsp), %rdi
callq 0x2390
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movl $0x0, 0x10(%rax)
movq 0x1cb17(%rip), %rdi     # 0x2a0e0
movq 0x2038(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0xa470
movq 0x2038(%rsp), %rax
movq %rax, 0x2050(%rsp)
jmp 0xd5f9
movq $0x0, 0x2050(%rsp)
movq 0x2050(%rsp), %rax
addq $0x2058, %rsp           # imm = 0x2058
retq
nopl (%rax)