// File: /workspace/github_c_makefile_star2_O0/Nealsbo[P]C-Software-Renderer/src/objloader.c
// Function: Model_CreateBasePlane
obj_model_t *Model_CreateBasePlane( 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   = 4;                                             //Allocation prepared data for model, box in that case
    model->trisCount   = 2;

    float v_arr[4][3]  = {{-1.0, -1.0, 0.0},
                          {-1.0,  1.0, 0.0},
                          { 1.0,  1.0, 0.0},
                          { 1.0, -1.0, 0.0}};

    float vn_arr[4][3] = {{ 0.0, 0.0, -1.0},
                          { 0.0, 0.0, -1.0},
                          { 0.0, 0.0, -1.0},
                          { 0.0, 0.0, -1.0}};

    float vt_arr[4][2] = {{ 0.0,  0.0},
                          { 0.0,  1.0},
                          { 1.0,  1.0},
                          { 1.0,  0.0}};

    int   f_arr[2][9]  = {{ 1, 1, 1, 2, 2, 2, 3, 3, 3},
                          { 1, 1, 1, 3, 3, 3, 4, 4, 4}};

    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    = (vec3 *)malloc(sizeof(vec3) * 4);
    for(i = 0; i < 4; i++){
        model->vertices[i] = vec3_create(v_arr[i][0], v_arr[i][1], v_arr[i][2]);
    }

    model->normals     = (vec3 *)malloc(sizeof(vec3) * 4);
    for(i = 0; i < 4; i++){
        model->normals[i] = vec3_create(vn_arr[i][0], vn_arr[i][1], vn_arr[i][2]);
    }

    model->textcoords  = (vec2*)malloc(sizeof(vec2) * 4);
    for(i = 0; i < 4; i++){
        model->textcoords[i] = vec2_create(vt_arr[i][0], vt_arr[i][1]);
    }

    model->faces       = (obj_face_t *)malloc(sizeof(obj_face_t) * 2);
    for(i = 0; i < 2; i++){
        model->faces[i]  = Face_Create(3, vec3i_arrayToVec3ip(9, f_arr[i] ));
    }

    model->diffmap = (texture_t *)malloc(sizeof(texture_t));
    model->diffmap->bitmap = Bitmap_LoadPPM6("./assets/texture.ppm");
    
    model->normalmap = (texture_t *)malloc(sizeof(texture_t));
    model->normalmap->bitmap = Bitmap_LoadPPM6("./assets/texture_n.ppm");

    return model;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x10(%rbp)
movl $0x170, %edi            # imm = 0x170
callq 0x11b0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x8f43
movq -0x10(%rbp), %rsi
leaq 0x5a71(%rip), %rdi      # 0xe9a0
movb $0x0, %al
callq 0x1040
movq $0x0, -0x8(%rbp)
jmp 0x94be
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x1110
movq -0x20(%rbp), %rax
movl $0x4, 0x120(%rax)
movq -0x20(%rbp), %rax
movl $0x2, 0x12c(%rax)
movaps 0x55a8(%rip), %xmm0     # 0xe520
movaps %xmm0, -0x30(%rbp)
movaps 0x558d(%rip), %xmm0     # 0xe510
movaps %xmm0, -0x40(%rbp)
movaps 0x5572(%rip), %xmm0     # 0xe500
movaps %xmm0, -0x50(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movl $0xbf800000, -0x78(%rbp) # imm = 0xBF800000
movl $0xbf800000, -0x6c(%rbp) # imm = 0xBF800000
movl $0xbf800000, -0x60(%rbp) # imm = 0xBF800000
movl $0xbf800000, -0x54(%rbp) # imm = 0xBF800000
movaps 0x5bec(%rip), %xmm0     # 0xebb0
movaps %xmm0, -0x90(%rbp)
movaps 0x5bce(%rip), %xmm0     # 0xeba0
movaps %xmm0, -0xa0(%rbp)
movabsq $0x400000004, %rax      # imm = 0x400000004
movq %rax, -0xb0(%rbp)
movaps 0x556f(%rip), %xmm0     # 0xe560
movaps %xmm0, -0xc0(%rbp)
movaps 0x5551(%rip), %xmm0     # 0xe550
movaps %xmm0, -0xd0(%rbp)
movaps 0x5533(%rip), %xmm0     # 0xe540
movaps %xmm0, -0xe0(%rbp)
movaps 0x5515(%rip), %xmm0     # 0xe530
movaps %xmm0, -0xf0(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x1d0(%rbp)
xorps %xmm2, %xmm2
movss %xmm2, -0x1c4(%rbp)
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x4270
movq -0x1d0(%rbp), %rax
movss -0x1c4(%rbp), %xmm2
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, 0x138(%rax)
movq -0x100(%rbp), %rcx
movq %rcx, 0x130(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x4270
movq -0x1c0(%rbp), %rax
movss %xmm1, -0x128(%rbp)
movlpd %xmm0, -0x130(%rbp)
movl -0x128(%rbp), %ecx
movl %ecx, -0x118(%rbp)
movq -0x130(%rbp), %rcx
movq %rcx, -0x120(%rbp)
movl -0x118(%rbp), %ecx
movl %ecx, 0x144(%rax)
movq -0x120(%rbp), %rcx
movq %rcx, 0x13c(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movss 0x4efa(%rip), %xmm2     # 0xe004
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x4270
movq -0x1b8(%rbp), %rax
movss %xmm1, -0x148(%rbp)
movlpd %xmm0, -0x150(%rbp)
movq -0x150(%rbp), %rcx
movq %rcx, -0x13c(%rbp)
movl -0x148(%rbp), %ecx
movl %ecx, -0x134(%rbp)
movq -0x13c(%rbp), %rcx
movq %rcx, 0x148(%rax)
movl -0x134(%rbp), %ecx
movl %ecx, 0x150(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x1b0(%rbp)
xorl %edi, %edi
movl $0xf5, %esi
movl $0x74, %edx
movl $0xff, %ecx
callq 0x2c20
movl %eax, %ecx
movq -0x1b0(%rbp), %rax
movl %ecx, -0x154(%rbp)
movl -0x154(%rbp), %ecx
movl %ecx, 0x154(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x158(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x160(%rax)
movl $0x30, %edi
callq 0x11b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x100(%rax)
movl $0x0, -0x14(%rbp)
cmpl $0x4, -0x14(%rbp)
jge 0x926d
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, -0x1d8(%rbp)
movss -0x50(%rbp,%rax), %xmm0
movss -0x4c(%rbp,%rax), %xmm1
movss -0x48(%rbp,%rax), %xmm2
callq 0x4270
movq -0x1d8(%rbp), %rax
movss %xmm1, -0x168(%rbp)
movlpd %xmm0, -0x170(%rbp)
movq -0x170(%rbp), %rcx
movq %rcx, -0x160(%rbp)
movl -0x168(%rbp), %ecx
movl %ecx, -0x158(%rbp)
movq -0x160(%rbp), %rcx
movq %rcx, (%rax)
movl -0x158(%rbp), %ecx
movl %ecx, 0x8(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x91d9
movl $0x30, %edi
callq 0x11b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x110(%rax)
movl $0x0, -0x14(%rbp)
cmpl $0x4, -0x14(%rbp)
jge 0x9320
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, -0x1e0(%rbp)
movss -0x80(%rbp,%rax), %xmm0
movss -0x7c(%rbp,%rax), %xmm1
movss -0x78(%rbp,%rax), %xmm2
callq 0x4270
movq -0x1e0(%rbp), %rax
movss %xmm1, -0x188(%rbp)
movlpd %xmm0, -0x190(%rbp)
movq -0x190(%rbp), %rcx
movq %rcx, -0x17c(%rbp)
movl -0x188(%rbp), %ecx
movl %ecx, -0x174(%rbp)
movq -0x17c(%rbp), %rcx
movq %rcx, (%rax)
movl -0x174(%rbp), %ecx
movl %ecx, 0x8(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x928c
movl $0x20, %edi
callq 0x11b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x118(%rax)
movl $0x0, -0x14(%rbp)
cmpl $0x4, -0x14(%rbp)
jge 0x93a8
movq -0x20(%rbp), %rax
movq 0x118(%rax), %rax
movq %rax, -0x1e8(%rbp)
movslq -0x14(%rbp), %rax
movq %rax, %rcx
movq %rcx, -0x1f0(%rbp)
movss -0xa0(%rbp,%rax,8), %xmm0
movss -0x9c(%rbp,%rax,8), %xmm1
callq 0x3b70
movq -0x1f0(%rbp), %rcx
movq -0x1e8(%rbp), %rax
movlpd %xmm0, -0x198(%rbp)
movq -0x198(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x933f
movl $0x20, %edi
callq 0x11b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x108(%rax)
movl $0x0, -0x14(%rbp)
cmpl $0x2, -0x14(%rbp)
jge 0x944c
movq -0x20(%rbp), %rax
movq 0x108(%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x1f8(%rbp)
movslq -0x14(%rbp), %rax
leaq -0xf0(%rbp), %rsi
imulq $0x24, %rax, %rax
addq %rax, %rsi
movl $0x9, %edi
callq 0x3f80
movq %rax, %rsi
movl $0x3, %edi
callq 0x83c0
movl %eax, %ecx
movq -0x1f8(%rbp), %rax
movl %ecx, -0x1a8(%rbp)
movq %rdx, -0x1a0(%rbp)
movq -0x1a8(%rbp), %rcx
movq %rcx, (%rax)
movq -0x1a0(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x93c7
movl $0x8, %edi
callq 0x11b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x158(%rax)
leaq 0x557f(%rip), %rdi      # 0xe9ea
callq 0x31f0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq 0x158(%rax), %rax
movq %rcx, (%rax)
movl $0x8, %edi
callq 0x11b0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x160(%rax)
leaq 0x555f(%rip), %rdi      # 0xe9ff
callq 0x31f0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq 0x160(%rax), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
nopl (%rax,%rax)