// File: /workspace/github_c_makefile_star2_O0/nkanaev[P]tipsy/src/tipsy.c
// Function: obj_readfile
Obj* obj_readfile(char *filepath) {
  Obj *o = calloc(1, sizeof(Obj));
  o->v = list_new(sizeof(Vec));
  o->vn = list_new(sizeof(Vec));
  o->vt = list_new(sizeof(Vec));
  o->f = list_new(sizeof(Face));

  FILE *f = fopen(filepath, "r");
  if (f == NULL) error("failed to open obj file: %s", filepath);

  char *line = NULL;
  size_t len = 0;

  Mtl *mtl = NULL;

  while (readline(&line, &len, f) != -1) {
    Vec v = {0, 0, 0};
    if (strncmp(line, "v ", 2) == 0) {
      sscanf(line, "v %f %f %f", &v.x, &v.y, &v.z);
      list_add(o->v, &v);
    } else if (strncmp(line, "vn ", 3) == 0) {
      sscanf(line, "vn %f %f %f", &v.x, &v.y, &v.z);
      list_add(o->vn, &v);
    } else if (strncmp(line, "vt ", 3) == 0) {
      sscanf(line, "vt %f %f %f", &v.x, &v.y, &v.z);
      list_add(o->vt, &v);
    } else if (strncmp(line, "f ", 2) == 0) {
      int offset = 2;
      int i = 0, v1, v2, v3, vt1, vt2, vt3, vn1, vn2, vn3;
      while (++i) {
        int v = 0, vt = 0, vn = 0, nread = 0;
        if (!(
          sscanf(line+offset, "%d/%d/%d%n", &v, &vt, &vn, &nread) >= 3 ||
          sscanf(line+offset, "%d/%d%n", &v, &vt, &nread) >= 2 ||
          sscanf(line+offset, "%d//%d%n", &v, &vn, &nread) >= 2 ||
          sscanf(line+offset, "%d%n", &v, &nread) >= 1
        )) break;
        offset += nread;

        if (i == 1) { v1 = v; vt1 = vt; vn1 = vn; continue; }
        v2 = v3; v3 = v;
        vt2 = vt3; vt3 = vt;
        vn2 = vn3; vn3 = vn;

        if (i >= 3) {
          Face f = {
            .v1=v1, .v2=v2, .v3=v3, .vt1=vt1, .vt2=vt2, .vt3=vt3,
            .vn1=vn1, .vn2=vn2, .vn3=vn3, .mtl=mtl
          };
          list_add(o->f, &f);
        }
      }
    } else if (strncmp(line, "mtllib ", 7) == 0) {
      char *mtlname = line+7;
      char *mtlpath = relpath(mtlname, filepath);
      o->mtl = mtl_readfile(mtlpath);
      free(mtlpath);
    } else if (strncmp(line, "usemtl ", 7) == 0) {
      char *name = line+7;
      mtl = mtl_get(o->mtl, name);
      if (mtl == NULL) error("failed to find mtl: %s", name);
    }
  }
  free(line);
  fclose(f);

  return o;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movl $0x1, %edi
movl $0x28, %esi
callq 0x3270
movq %rax, -0x10(%rbp)
movl $0xc, %edi
callq 0xaaa0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0xc, %edi
callq 0xaaa0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0xc, %edi
callq 0xaaa0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x30, %edi
callq 0xaaa0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
leaq 0x4b53(%rip), %rsi      # 0x10663
callq 0x3400
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xbb32
movq -0x8(%rbp), %rsi
leaq 0x4cf4(%rip), %rdi      # 0x1081f
movb $0x0, %al
callq 0xb810
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rdx
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xb8d0
cmpl $-0x1, %eax
je 0xbf16
leaq -0x3c(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x31d0
movq -0x20(%rbp), %rdi
leaq 0x4cbc(%rip), %rsi      # 0x1083b
movl $0x2, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0xbbc9
movq -0x20(%rbp), %rdi
leaq -0x3c(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
addq $0x4, %rcx
leaq -0x3c(%rbp), %r8
addq $0x8, %r8
leaq 0x4c91(%rip), %rsi      # 0x1083e
movb $0x0, %al
callq 0x3340
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x3c(%rbp), %rsi
callq 0xab10
jmp 0xbf11
movq -0x20(%rbp), %rdi
leaq 0x4c75(%rip), %rsi      # 0x10849
movl $0x3, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0xbc1f
movq -0x20(%rbp), %rdi
leaq -0x3c(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
addq $0x4, %rcx
leaq -0x3c(%rbp), %r8
addq $0x8, %r8
leaq 0x4c4b(%rip), %rsi      # 0x1084d
movb $0x0, %al
callq 0x3340
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x3c(%rbp), %rsi
callq 0xab10
jmp 0xbf0f
movq -0x20(%rbp), %rdi
leaq 0x4c2f(%rip), %rsi      # 0x10859
movl $0x3, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0xbc75
movq -0x20(%rbp), %rdi
leaq -0x3c(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
addq $0x4, %rcx
leaq -0x3c(%rbp), %r8
addq $0x8, %r8
leaq 0x4c05(%rip), %rsi      # 0x1085d
movb $0x0, %al
callq 0x3340
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x3c(%rbp), %rsi
callq 0xab10
jmp 0xbf0d
movq -0x20(%rbp), %rdi
leaq 0x4be9(%rip), %rsi      # 0x10869
movl $0x2, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0xbe43
movl $0x2, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
je 0xbe3e
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x40(%rbp), %rax
addq %rax, %rdi
leaq 0x4b8b(%rip), %rsi      # 0x1086c
leaq -0x6c(%rbp), %rdx
leaq -0x70(%rbp), %rcx
leaq -0x74(%rbp), %r8
leaq -0x78(%rbp), %r9
movb $0x0, %al
callq 0x3340
cmpl $0x3, %eax
jge 0xbd7c
movq -0x20(%rbp), %rdi
movslq -0x40(%rbp), %rax
addq %rax, %rdi
leaq 0x4b60(%rip), %rsi      # 0x1086f
leaq -0x6c(%rbp), %rdx
leaq -0x70(%rbp), %rcx
leaq -0x78(%rbp), %r8
movb $0x0, %al
callq 0x3340
cmpl $0x2, %eax
jge 0xbd7c
movq -0x20(%rbp), %rdi
movslq -0x40(%rbp), %rax
addq %rax, %rdi
leaq 0x4b3e(%rip), %rsi      # 0x10877
leaq -0x6c(%rbp), %rdx
leaq -0x74(%rbp), %rcx
leaq -0x78(%rbp), %r8
movb $0x0, %al
callq 0x3340
cmpl $0x2, %eax
jge 0xbd7c
movq -0x20(%rbp), %rdi
movslq -0x40(%rbp), %rax
addq %rax, %rdi
leaq 0x4b18(%rip), %rsi      # 0x1087b
leaq -0x6c(%rbp), %rdx
leaq -0x78(%rbp), %rcx
movb $0x0, %al
callq 0x3340
cmpl $0x1, %eax
jge 0xbd7c
jmp 0xbe3e
movl -0x78(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x1, -0x44(%rbp)
jne 0xbda2
movl -0x6c(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0xbca1
movl -0x50(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0x68(%rbp)
cmpl $0x3, -0x44(%rbp)
jl 0xbe39
movl -0x48(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0xa0(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x9c(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x98(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x88(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xab10
jmp 0xbca1
jmp 0xbf0b
movq -0x20(%rbp), %rdi
leaq 0x4a32(%rip), %rsi      # 0x10880
movl $0x7, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0xbea8
movq -0x20(%rbp), %rax
addq $0x7, %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0xa950
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
callq 0xb5f0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0xb8(%rbp), %rdi
callq 0x3410
jmp 0xbf09
movq -0x20(%rbp), %rdi
leaq 0x49d5(%rip), %rsi      # 0x10888
movl $0x7, %edx
callq 0x3160
cmpl $0x0, %eax
jne 0xbf07
movq -0x20(%rbp), %rax
addq $0x7, %rax
movq %rax, -0xc0(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0xc0(%rbp), %rsi
callq 0xb9b0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xbf05
movq -0xc0(%rbp), %rsi
leaq 0x4992(%rip), %rdi      # 0x10890
movb $0x0, %al
callq 0xb810
jmp 0xbf07
jmp 0xbf09
jmp 0xbf0b
jmp 0xbf0d
jmp 0xbf0f
jmp 0xbf11
jmp 0xbb4a
movq -0x20(%rbp), %rdi
callq 0x3410
movq -0x18(%rbp), %rdi
callq 0x3350
movq -0x10(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)