// File: /workspace/github_c_makefile_star2_O0/nkanaev[P]tipsy/src/tipsy.c
// Function: mtl_readfile
Mtl* mtl_readfile(const char *filepath) {
  FILE *f = fopen(filepath, "r");
  if (f == NULL) error("failed to open mtl file: %s", filepath);

  char *line = NULL, *tline = NULL;
  size_t len = 0;

  Mtl *m = NULL;

  while (readline(&line, &len, f) != -1) {
    tline = trim(line);
    if (strncmp(tline, "newmtl ", 7) == 0) {
      char *mtlname = &line[7];
      Mtl *newm = calloc(1, sizeof(Mtl));
      newm->name = strdup(mtlname);
      newm->next = m;
      m = newm;
    } else if (strncmp(tline, "map_Ka ", 7) == 0 && m != NULL) {
      char *imgname = strdup(tline+7);
      char *imgpath = relpath(imgname, filepath);
      Tigr *img = tigrLoadImage(imgpath);
      if (img == NULL) error("failed to open image: {%s}", imgpath);
      m->map_Ka = img;
      free(imgpath);
      free(imgname);
    } else if (strncmp(tline, "map_Kd ", 7) == 0 && m != NULL) {
      char *imgname = strdup(tline+7);
      char *imgpath = relpath(imgname, filepath);
      Tigr *img = tigrLoadImage(imgpath);
      if (img == NULL) error("failed to open image: {%s}", imgpath);
      m->map_Kd = img;
      free(imgpath);
      free(imgname);
    }
  }
  free(line);
  fclose(f);
  return m;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x505c(%rip), %rsi      # 0x10663
callq 0x3400
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xb629
movq -0x8(%rbp), %rsi
leaq 0x51ae(%rip), %rdi      # 0x107d0
movb $0x0, %al
callq 0xb810
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rdx
leaq -0x18(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xb8d0
cmpl $-0x1, %eax
je 0xb7f1
movq -0x18(%rbp), %rdi
callq 0xaa30
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x5171(%rip), %rsi      # 0x107ec
movl $0x7, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0xb6d5
movq -0x18(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x38(%rbp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x3270
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0x3740
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0xb7ec
movq -0x20(%rbp), %rdi
leaq 0x5114(%rip), %rsi      # 0x107f4
movl $0x7, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0xb761
cmpq $0x0, -0x30(%rbp)
je 0xb761
movq -0x20(%rbp), %rdi
addq $0x7, %rdi
callq 0x3740
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0xa950
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x54b0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0xb73e
movq -0x50(%rbp), %rsi
leaq 0x50c5(%rip), %rdi      # 0x107fc
movb $0x0, %al
callq 0xb810
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rdi
callq 0x3410
movq -0x48(%rbp), %rdi
callq 0x3410
jmp 0xb7ea
movq -0x20(%rbp), %rdi
leaq 0x50ab(%rip), %rsi      # 0x10817
movl $0x7, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0xb7e8
cmpq $0x0, -0x30(%rbp)
je 0xb7e8
movq -0x20(%rbp), %rdi
addq $0x7, %rdi
callq 0x3740
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0xa950
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0x54b0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0xb7ca
movq -0x68(%rbp), %rsi
leaq 0x5039(%rip), %rdi      # 0x107fc
movb $0x0, %al
callq 0xb810
movq -0x70(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x68(%rbp), %rdi
callq 0x3410
movq -0x60(%rbp), %rdi
callq 0x3410
jmp 0xb7ea
jmp 0xb7ec
jmp 0xb649
movq -0x18(%rbp), %rdi
callq 0x3410
movq -0x10(%rbp), %rdi
callq 0x3350
movq -0x30(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)