// File: /workspace/github_c_makefile_star2_O0/Nealsbo[P]C-Software-Renderer/src/objloader.c
// Function: Model_CreateBaseTriangle
obj_model_t *Model_CreateBaseTriangle( const char *model_name ){
    int i;

    obj_model_t *model = (obj_model_t *)malloc(sizeof(obj_model_t));
    if(model == NULL){
        printf("Error: Cannot create model object '%s'\n", model_name);
        return NULL;
    }

    memcpy(model->name, model_name, MAX_NAME_LENGTH);                   //Set object name by argument

    model->vertCount   = 3;                                             //Allocation prepared data for model, box in that case
    model->trisCount   = 1;

    float v_arr[3][3]  = {{-1.0, -1.0, 0.0},
                          { 0.0,  1.0, 0.0},
                          { 1.0, -1.0, 0.0}};

    float vn_arr[3][3] = {{ 0.0, 0.0, 1.0},
                          { 0.0, 0.0, 1.0},
                          { 0.0, 0.0, 1.0}};

    float vt_arr[3][2] = {{ 0.0,  0.0},
                          { 0.5,  1.0},
                          { 1.0,  0.0}};

    int   f_arr[1][9]  = {{ 1, 1, 1, 2, 2, 2, 3, 3, 3}};

    model->position    = vec3_create(0.0, 0.0, 0.0);
    model->rotation    = vec3_create(0.0, 0.0, 0.0);
    model->scale       = vec3_create(1.0, 1.0, 1.0);
    model->baseColor   = Color_Init(0, 245, 116, 255);
    model->diffmap     = NULL;
    model->normalmap   = NULL;

    model->vertices    = malloc(sizeof(vec3) * 3);
    if(model->vertices == NULL){
        printf("Error: Malloc vertices error'%s'\n", model->name);
        Model_Free(model);
        return NULL;
    }
    for(i = 0; i < 3; i++){
        model->vertices[i] = vec3_create(v_arr[i][0], v_arr[i][1], v_arr[i][2]);
    }

    model->normals     = (vec3 *)malloc(sizeof(vec3) * 3);
    for(i = 0; i < 3; i++){
        model->normals[i] = vec3_create(vn_arr[i][0], vn_arr[i][1], vn_arr[i][2]);
    }

    model->textcoords  = (vec2*)malloc(sizeof(vec2) * 3);
    for(i = 0; i < 3; i++){
        model->textcoords[i] = vec2_create(vt_arr[i][0], vt_arr[i][1]);
    }

    model->faces  = (obj_face_t *)malloc(sizeof(obj_face_t));
    model->faces[0]  = Face_Create(3, vec3i_arrayToVec3ip(9, f_arr[0] ));

    model->diffmap = (texture_t *)malloc(sizeof(texture_t));
    model->diffmap->bitmap = Bitmap_LoadPPM6("./assets/texture.ppm");

    return model;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x10(%rbp)
movl $0x170, %edi            # imm = 0x170
callq 0x11b0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x87f3
movq -0x10(%rbp), %rsi
leaq 0x61c1(%rip), %rdi      # 0xe9a0
movb $0x0, %al
callq 0x1040
movq $0x0, -0x8(%rbp)
jmp 0x8d25
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x1110
movq -0x20(%rbp), %rax
movl $0x3, 0x120(%rax)
movq -0x20(%rbp), %rax
movl $0x1, 0x12c(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movl $0x0, -0x30(%rbp)
movl $0xbf800000, -0x50(%rbp) # imm = 0xBF800000
movl $0xbf800000, -0x4c(%rbp) # imm = 0xBF800000
movl $0x3f800000, -0x40(%rbp) # imm = 0x3F800000
movl $0x3f800000, -0x38(%rbp) # imm = 0x3F800000
movl $0xbf800000, -0x34(%rbp) # imm = 0xBF800000
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movl $0x0, -0x60(%rbp)
movl $0x3f800000, -0x78(%rbp) # imm = 0x3F800000
movl $0x3f800000, -0x6c(%rbp) # imm = 0x3F800000
movl $0x3f800000, -0x60(%rbp) # imm = 0x3F800000
movaps 0x5c2f(%rip), %xmm0     # 0xe4b0
movaps %xmm0, -0xa0(%rbp)
movq $0x3f800000, -0x90(%rbp) # imm = 0x3F800000
movaps 0x5c46(%rip), %xmm0     # 0xe4e0
movaps %xmm0, -0xc0(%rbp)
movaps 0x5c28(%rip), %xmm0     # 0xe4d0
movaps %xmm0, -0xd0(%rbp)
movl $0x3, -0xb0(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x1b0(%rbp)
xorps %xmm2, %xmm2
movss %xmm2, -0x1a4(%rbp)
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x4270
movq -0x1b0(%rbp), %rax
movss -0x1a4(%rbp), %xmm2
movss %xmm1, -0xe8(%rbp)
movlpd %xmm0, -0xf0(%rbp)
movl -0xe8(%rbp), %ecx
movl %ecx, -0xd8(%rbp)
movq -0xf0(%rbp), %rcx
movq %rcx, -0xe0(%rbp)
movl -0xd8(%rbp), %ecx
movl %ecx, 0x138(%rax)
movq -0xe0(%rbp), %rcx
movq %rcx, 0x130(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x4270
movq -0x1a0(%rbp), %rax
movss %xmm1, -0x108(%rbp)
movlpd %xmm0, -0x110(%rbp)
movl -0x108(%rbp), %ecx
movl %ecx, -0xf8(%rbp)
movq -0x110(%rbp), %rcx
movq %rcx, -0x100(%rbp)
movl -0xf8(%rbp), %ecx
movl %ecx, 0x144(%rax)
movq -0x100(%rbp), %rcx
movq %rcx, 0x13c(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x198(%rbp)
movss 0x5663(%rip), %xmm2     # 0xe004
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x4270
movq -0x198(%rbp), %rax
movss %xmm1, -0x128(%rbp)
movlpd %xmm0, -0x130(%rbp)
movq -0x130(%rbp), %rcx
movq %rcx, -0x11c(%rbp)
movl -0x128(%rbp), %ecx
movl %ecx, -0x114(%rbp)
movq -0x11c(%rbp), %rcx
movq %rcx, 0x148(%rax)
movl -0x114(%rbp), %ecx
movl %ecx, 0x150(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x190(%rbp)
xorl %edi, %edi
movl $0xf5, %esi
movl $0x74, %edx
movl $0xff, %ecx
callq 0x2c20
movl %eax, %ecx
movq -0x190(%rbp), %rax
movl %ecx, -0x134(%rbp)
movl -0x134(%rbp), %ecx
movl %ecx, 0x154(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x158(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x160(%rax)
movl $0x24, %edi
callq 0x11b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x100(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x100(%rax)
jne 0x8a9f
movq -0x20(%rbp), %rsi
leaq 0x5f46(%rip), %rdi      # 0xe9c8
movb $0x0, %al
callq 0x1040
movq -0x20(%rbp), %rdi
callq 0x8d40
movq $0x0, -0x8(%rbp)
jmp 0x8d25
movl $0x0, -0x14(%rbp)
cmpl $0x3, -0x14(%rbp)
jge 0x8b3a
movq -0x20(%rbp), %rax
movq 0x100(%rax), %rcx
movslq -0x14(%rbp), %rax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rax
addq %rax, %rcx
movq %rcx, -0x1b8(%rbp)
movss -0x50(%rbp,%rax), %xmm0
movss -0x4c(%rbp,%rax), %xmm1
movss -0x48(%rbp,%rax), %xmm2
callq 0x4270
movq -0x1b8(%rbp), %rax
movss %xmm1, -0x148(%rbp)
movlpd %xmm0, -0x150(%rbp)
movq -0x150(%rbp), %rcx
movq %rcx, -0x140(%rbp)
movl -0x148(%rbp), %ecx
movl %ecx, -0x138(%rbp)
movq -0x140(%rbp), %rcx
movq %rcx, (%rax)
movl -0x138(%rbp), %ecx
movl %ecx, 0x8(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x8aa6
movl $0x24, %edi
callq 0x11b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x110(%rax)
movl $0x0, -0x14(%rbp)
cmpl $0x3, -0x14(%rbp)
jge 0x8bed
movq -0x20(%rbp), %rax
movq 0x110(%rax), %rcx
movslq -0x14(%rbp), %rax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rax
addq %rax, %rcx
movq %rcx, -0x1c0(%rbp)
movss -0x80(%rbp,%rax), %xmm0
movss -0x7c(%rbp,%rax), %xmm1
movss -0x78(%rbp,%rax), %xmm2
callq 0x4270
movq -0x1c0(%rbp), %rax
movss %xmm1, -0x168(%rbp)
movlpd %xmm0, -0x170(%rbp)
movq -0x170(%rbp), %rcx
movq %rcx, -0x15c(%rbp)
movl -0x168(%rbp), %ecx
movl %ecx, -0x154(%rbp)
movq -0x15c(%rbp), %rcx
movq %rcx, (%rax)
movl -0x154(%rbp), %ecx
movl %ecx, 0x8(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x8b59
movl $0x18, %edi
callq 0x11b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x118(%rax)
movl $0x0, -0x14(%rbp)
cmpl $0x3, -0x14(%rbp)
jge 0x8c75
movq -0x20(%rbp), %rax
movq 0x118(%rax), %rax
movq %rax, -0x1c8(%rbp)
movslq -0x14(%rbp), %rax
movq %rax, %rcx
movq %rcx, -0x1d0(%rbp)
movss -0xa0(%rbp,%rax,8), %xmm0
movss -0x9c(%rbp,%rax,8), %xmm1
callq 0x3b70
movq -0x1d0(%rbp), %rcx
movq -0x1c8(%rbp), %rax
movlpd %xmm0, -0x178(%rbp)
movq -0x178(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x8c0c
movl $0x10, %edi
callq 0x11b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x108(%rax)
movq -0x20(%rbp), %rax
movq 0x108(%rax), %rax
movq %rax, -0x1d8(%rbp)
leaq -0xd0(%rbp), %rsi
movl $0x9, %edi
callq 0x3f80
movq %rax, %rsi
movl $0x3, %edi
callq 0x83c0
movl %eax, %ecx
movq -0x1d8(%rbp), %rax
movl %ecx, -0x188(%rbp)
movq %rdx, -0x180(%rbp)
movq -0x188(%rbp), %rcx
movq %rcx, (%rax)
movq -0x180(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x8, %edi
callq 0x11b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x158(%rax)
leaq 0x5ce3(%rip), %rdi      # 0xe9ea
callq 0x31f0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq 0x158(%rax), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
nopw %cs:(%rax,%rax)