// File: /workspace/github_c_makefile_star2_O0/Nealsbo[P]C-Software-Renderer/src/render.c
// Function: Renderer_DrawObject
void Renderer_DrawObject( scene_t *scene, renderer_t *renderer, obj_model_t *model, SDL_Surface *Surface ) {
    int i, j;
    obj_face_t face;
    vec4 rast_verts[3];
    vertex_t vertex[3], vertexx[3];
    mat4 camMat = {0.0f}, lookAtMat = {0.0f}, tmp = {0.0f};
    mat4 translation = {0.0f}, rotation = {0.0f}, scale = {0.0f};
    mat4 modelMat = {0.0f}, viewMat = {0.0f}, projMat = {0.0f};
    
    renderer_       = renderer;
    camera_t *cam   = scene->mainCamera;
    shader_t shader = { 0 };
    
    Shader_SetLight( &shader, scene->directLight, scene->directLightColor, scene->ambientLightColor );

    mat4_lookAt( lookAtMat,
                 Camera_GetPosition( cam ),
                 vec3_add( Camera_GetPosition( cam ), Camera_GetFront( cam ) ),
                 vec3_create( 0.0, 1.0, 0.0 ) );

    mat4_translate( translation, model->position.x, model->position.y, model->position.z );
    mat4_rotation(  rotation,    model->rotation.x, model->rotation.y, model->rotation.z );
    mat4_scale(     scale,       model->scale.x,    model->scale.y,    model->scale.z );
    
    mat4_mlt( translation, rotation, tmp );
    mat4_mlt( tmp, scale, modelMat );
    mat4_mlt( lookAtMat, modelMat, viewMat );
    mat4_mlt( scene->mainCamera->projection, viewMat, projMat );

    Shader_SetMatrices( &shader, modelMat, lookAtMat, projMat );
    Shader_SetCamera( &shader, Camera_GetPosition( cam ) );
    Shader_InvertNormal( &shader, TRUE );

    for( i = 0; i < model->trisCount; i++ ) {
        face = model->faces[i];
        for( j = 0; j < face.vcount; j++ ) {
            vertex[j]     = Vertex_Init( vec3_toVec4( model->vertices  [face.indexes[j].x - 1] ),
                                         vec3_toVec4( model->normals   [face.indexes[j].z - 1] ),
                                         model->textcoords[face.indexes[j].y - 1] );

            rast_verts[j] = Shader_Vertex( &shader, &vertex[j], j );
        }
        
        if( Renderer_ClipTriangle( rast_verts ) )
			continue;

        switch( renderer->flagState ) {
            case RENDER_STATE_WIREFRAME:
                Raster_DrawLine( rast_verts[0], rast_verts[1], Surface, model->baseColor );
                Raster_DrawLine( rast_verts[1], rast_verts[2], Surface, model->baseColor );
                Raster_DrawLine( rast_verts[0], rast_verts[2], Surface, model->baseColor );
                break;
                
            case RENDER_STATE_UNLIT:
				Shader_UseLight( &shader, FALSE );
				Raster_DrawTriangle( rast_verts, Surface, model, &shader );
				break;

            case RENDER_STATE_LIT:
				Shader_UseLight( &shader, TRUE );
                Raster_DrawTriangle( rast_verts, Surface, model, &shader );
                break;
                
            case RENDER_STATE_Z_BUFFER:
				Raster_DrawTriangle( rast_verts, Surface, model, &shader );
				break;
				
            default:
                break;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x7f0, %rsp            # imm = 0x7F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x7d0(%rbp)
movaps %xmm0, -0x180(%rbp)
movaps %xmm0, -0x190(%rbp)
movaps %xmm0, -0x1a0(%rbp)
movaps %xmm0, -0x1b0(%rbp)
movaps %xmm0, -0x1c0(%rbp)
movaps %xmm0, -0x1d0(%rbp)
movaps %xmm0, -0x1e0(%rbp)
movaps %xmm0, -0x1f0(%rbp)
movaps %xmm0, -0x200(%rbp)
movaps %xmm0, -0x210(%rbp)
movaps %xmm0, -0x220(%rbp)
movaps %xmm0, -0x230(%rbp)
movaps %xmm0, -0x240(%rbp)
movaps %xmm0, -0x250(%rbp)
movaps %xmm0, -0x260(%rbp)
movaps %xmm0, -0x270(%rbp)
movaps %xmm0, -0x280(%rbp)
movaps %xmm0, -0x290(%rbp)
movaps %xmm0, -0x2a0(%rbp)
movaps %xmm0, -0x2b0(%rbp)
movaps %xmm0, -0x2c0(%rbp)
movaps %xmm0, -0x2d0(%rbp)
movaps %xmm0, -0x2e0(%rbp)
movaps %xmm0, -0x2f0(%rbp)
movaps %xmm0, -0x300(%rbp)
movaps %xmm0, -0x310(%rbp)
movaps %xmm0, -0x320(%rbp)
movaps %xmm0, -0x330(%rbp)
movaps %xmm0, -0x340(%rbp)
movaps %xmm0, -0x350(%rbp)
movaps %xmm0, -0x360(%rbp)
movaps %xmm0, -0x370(%rbp)
movaps %xmm0, -0x380(%rbp)
movaps %xmm0, -0x390(%rbp)
movaps %xmm0, -0x3a0(%rbp)
movaps %xmm0, -0x3b0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, 0x7134(%rip)      # 0x13230
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x3b8(%rbp)
leaq -0x5a8(%rbp), %rdi
movq %rdi, -0x790(%rbp)
xorl %esi, %esi
movl $0x1f0, %edx            # imm = 0x1F0
callq 0x10c0
movq -0x790(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
movl %ecx, -0x5b0(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x5b8(%rbp)
movsd -0x5b8(%rbp), %xmm0
movss -0x5b0(%rbp), %xmm1
movl 0x1c(%rax), %ecx
movl %ecx, -0x5c0(%rbp)
movq 0x14(%rax), %rcx
movq %rcx, -0x5c8(%rbp)
movsd -0x5c8(%rbp), %xmm2
movss -0x5c0(%rbp), %xmm3
movl 0x28(%rax), %ecx
movl %ecx, -0x5d0(%rbp)
movq 0x20(%rax), %rax
movq %rax, -0x5d8(%rbp)
movsd -0x5d8(%rbp), %xmm4
movss -0x5d0(%rbp), %xmm5
callq 0xdec0
movq -0x3b8(%rbp), %rdi
callq 0x23a0
movss %xmm1, -0x5f0(%rbp)
movlpd %xmm0, -0x5f8(%rbp)
movl -0x5f0(%rbp), %eax
movl %eax, -0x5e0(%rbp)
movq -0x5f8(%rbp), %rax
movq %rax, -0x5e8(%rbp)
movq -0x3b8(%rbp), %rdi
callq 0x23a0
movss %xmm1, -0x620(%rbp)
movlpd %xmm0, -0x628(%rbp)
movl -0x620(%rbp), %eax
movl %eax, -0x610(%rbp)
movq -0x628(%rbp), %rax
movq %rax, -0x618(%rbp)
movq -0x3b8(%rbp), %rdi
callq 0x23e0
movss %xmm1, -0x640(%rbp)
movlpd %xmm0, -0x648(%rbp)
movl -0x640(%rbp), %eax
movl %eax, -0x630(%rbp)
movq -0x648(%rbp), %rax
movq %rax, -0x638(%rbp)
movl -0x610(%rbp), %eax
movl %eax, -0x650(%rbp)
movq -0x618(%rbp), %rax
movq %rax, -0x658(%rbp)
movsd -0x658(%rbp), %xmm0
movss -0x650(%rbp), %xmm1
movl -0x630(%rbp), %eax
movl %eax, -0x660(%rbp)
movq -0x638(%rbp), %rax
movq %rax, -0x668(%rbp)
movsd -0x668(%rbp), %xmm2
movss -0x660(%rbp), %xmm3
callq 0x4320
movss %xmm1, -0x670(%rbp)
movlpd %xmm0, -0x678(%rbp)
movl -0x670(%rbp), %eax
movl %eax, -0x600(%rbp)
movq -0x678(%rbp), %rax
movq %rax, -0x608(%rbp)
movss 0x1d37(%rip), %xmm1     # 0xe004
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
callq 0x4270
movss %xmm1, -0x690(%rbp)
movlpd %xmm0, -0x698(%rbp)
movl -0x690(%rbp), %eax
movl %eax, -0x680(%rbp)
movq -0x698(%rbp), %rax
movq %rax, -0x688(%rbp)
movl -0x5e0(%rbp), %eax
movl %eax, -0x6a0(%rbp)
movq -0x5e8(%rbp), %rax
movq %rax, -0x6a8(%rbp)
movsd -0x6a8(%rbp), %xmm0
movss -0x6a0(%rbp), %xmm1
movl -0x600(%rbp), %eax
movl %eax, -0x6b0(%rbp)
movq -0x608(%rbp), %rax
movq %rax, -0x6b8(%rbp)
movsd -0x6b8(%rbp), %xmm2
movss -0x6b0(%rbp), %xmm3
movl -0x680(%rbp), %eax
movl %eax, -0x6c0(%rbp)
movq -0x688(%rbp), %rax
movq %rax, -0x6c8(%rbp)
movsd -0x6c8(%rbp), %xmm4
movss -0x6c0(%rbp), %xmm5
leaq -0x1f0(%rbp), %rdi
movq %rdi, -0x780(%rbp)
callq 0x7a80
movq -0x18(%rbp), %rax
movss 0x130(%rax), %xmm0
movss 0x134(%rax), %xmm1
movss 0x138(%rax), %xmm2
leaq -0x270(%rbp), %rdi
movq %rdi, -0x7b8(%rbp)
callq 0x70e0
movq -0x18(%rbp), %rax
movss 0x13c(%rax), %xmm0
movss 0x140(%rax), %xmm1
movss 0x144(%rax), %xmm2
leaq -0x2b0(%rbp), %rdi
movq %rdi, -0x7b0(%rbp)
callq 0x74a0
movq -0x18(%rbp), %rax
movss 0x148(%rax), %xmm0
movss 0x14c(%rax), %xmm1
movss 0x150(%rax), %xmm2
leaq -0x2f0(%rbp), %rdi
movq %rdi, -0x7a0(%rbp)
callq 0x7170
movq -0x7b8(%rbp), %rdi
movq -0x7b0(%rbp), %rsi
leaq -0x230(%rbp), %rdx
movq %rdx, -0x7a8(%rbp)
callq 0x58a0
movq -0x7a8(%rbp), %rdi
movq -0x7a0(%rbp), %rsi
leaq -0x330(%rbp), %rdx
movq %rdx, -0x788(%rbp)
callq 0x58a0
movq -0x788(%rbp), %rsi
movq -0x780(%rbp), %rdi
leaq -0x370(%rbp), %rdx
movq %rdx, -0x798(%rbp)
callq 0x58a0
movq -0x798(%rbp), %rsi
movq -0x8(%rbp), %rax
movq (%rax), %rdi
addq $0x3c, %rdi
leaq -0x3b0(%rbp), %rdx
movq %rdx, -0x778(%rbp)
callq 0x58a0
movq -0x790(%rbp), %rdi
movq -0x788(%rbp), %rsi
movq -0x780(%rbp), %rdx
movq -0x778(%rbp), %rcx
callq 0xde00
movq -0x3b8(%rbp), %rdi
callq 0x23a0
movss %xmm1, -0x6e0(%rbp)
movlpd %xmm0, -0x6e8(%rbp)
movl -0x6e0(%rbp), %eax
movl %eax, -0x6d0(%rbp)
movq -0x6e8(%rbp), %rax
movq %rax, -0x6d8(%rbp)
movl -0x6d0(%rbp), %eax
movl %eax, -0x6f0(%rbp)
movq -0x6d8(%rbp), %rax
movq %rax, -0x6f8(%rbp)
movsd -0x6f8(%rbp), %xmm0
movss -0x6f0(%rbp), %xmm1
leaq -0x5a8(%rbp), %rdi
callq 0xde80
leaq -0x5a8(%rbp), %rdi
movl $0x1, %esi
callq 0xdde0
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x12c(%rcx), %eax
jge 0xc886
movq -0x18(%rbp), %rax
movq 0x108(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x38(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0xc74e
movslq -0x28(%rbp), %rdx
leaq (%rdx,%rdx,4), %rax
movq %rax, -0x7e0(%rbp)
movq -0x18(%rbp), %rax
movq 0x100(%rax), %rax
movq -0x30(%rbp), %rcx
leaq (%rdx,%rdx,2), %rdx
movl (%rcx,%rdx,4), %ecx
decl %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rax,%rcx,4), %edx
movl %edx, -0x738(%rbp)
movq (%rax,%rcx,4), %rax
movq %rax, -0x740(%rbp)
movsd -0x740(%rbp), %xmm0
movss -0x738(%rbp), %xmm1
callq 0x4c60
movlpd %xmm0, -0x730(%rbp)
movlpd %xmm1, -0x728(%rbp)
movq -0x18(%rbp), %rax
movq 0x110(%rax), %rax
movq -0x30(%rbp), %rcx
movslq -0x28(%rbp), %rdx
leaq (%rdx,%rdx,2), %rdx
movl 0x8(%rcx,%rdx,4), %ecx
decl %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rax,%rcx,4), %edx
movl %edx, -0x758(%rbp)
movq (%rax,%rcx,4), %rax
movq %rax, -0x760(%rbp)
movsd -0x760(%rbp), %xmm0
movss -0x758(%rbp), %xmm1
callq 0x4c60
movlpd %xmm0, -0x750(%rbp)
movlpd %xmm1, -0x748(%rbp)
movq -0x18(%rbp), %rax
movq 0x118(%rax), %rax
movq -0x30(%rbp), %rcx
movslq -0x28(%rbp), %rdx
leaq (%rdx,%rdx,2), %rdx
movl 0x4(%rcx,%rdx,4), %ecx
decl %ecx
movslq %ecx, %rcx
movsd -0x730(%rbp), %xmm0
movsd -0x728(%rbp), %xmm1
movsd -0x750(%rbp), %xmm2
movsd -0x748(%rbp), %xmm3
movsd (%rax,%rcx,8), %xmm4
leaq -0x720(%rbp), %rdi
callq 0x81c0
movq -0x7e0(%rbp), %rax
movq -0x700(%rbp), %rcx
movq %rcx, -0xd0(%rbp,%rax,8)
movups -0x720(%rbp), %xmm0
movups -0x710(%rbp), %xmm1
movups %xmm1, -0xe0(%rbp,%rax,8)
movups %xmm0, -0xf0(%rbp,%rax,8)
movslq -0x28(%rbp), %rax
movl %eax, %edx
movq %rax, %rcx
shlq $0x4, %rcx
leaq -0x70(%rbp,%rcx), %rcx
movq %rcx, -0x7d8(%rbp)
leaq (%rax,%rax,4), %rax
leaq -0xf0(%rbp,%rax,8), %rsi
leaq -0x5a8(%rbp), %rdi
callq 0xcd20
movq -0x7d8(%rbp), %rax
movlpd %xmm0, -0x770(%rbp)
movlpd %xmm1, -0x768(%rbp)
movq -0x770(%rbp), %rcx
movq %rcx, (%rax)
movq -0x768(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xc58c
leaq -0x70(%rbp), %rdi
callq 0xbeb0
cmpl $0x0, %eax
je 0xc761
jmp 0xc878
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x7e8(%rbp)
subq $0x3, %rax
ja 0xc874
movq -0x7e8(%rbp), %rax
leaq 0x2459(%rip), %rcx      # 0xebe0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd -0x70(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
movsd -0x60(%rbp), %xmm2
movsd -0x58(%rbp), %xmm3
movl 0x154(%rax), %esi
callq 0xab20
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd -0x60(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
movsd -0x50(%rbp), %xmm2
movsd -0x48(%rbp), %xmm3
movl 0x154(%rax), %esi
callq 0xab20
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd -0x70(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
movsd -0x50(%rbp), %xmm2
movsd -0x48(%rbp), %xmm3
movl 0x154(%rax), %esi
callq 0xab20
jmp 0xc876
leaq -0x5a8(%rbp), %rdi
xorl %esi, %esi
callq 0xddc0
leaq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x5a8(%rbp), %rcx
callq 0xae40
jmp 0xc876
leaq -0x5a8(%rbp), %rdi
movl $0x1, %esi
callq 0xddc0
leaq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x5a8(%rbp), %rcx
callq 0xae40
jmp 0xc876
leaq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x5a8(%rbp), %rcx
callq 0xae40
jmp 0xc876
jmp 0xc876
jmp 0xc878
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xc54d
addq $0x7f0, %rsp            # imm = 0x7F0
popq %rbp
retq
nop