// File: Crawler995[P]Cpp-Ray-Tracing/main.cpp
// Function: main
int main(int argc, char const *argv[])
{   
    PerspectiveCamera camera(
        1000, 
        Vector3(-WIDTH / 2, -HEIGHT / 2, -1000),
        Vector3(WIDTH, 0, 0),
        Vector3(0, HEIGHT, 0),
        Vector3(0, 0, 0)
    );
    PhongMaterial phong_white(
        0.2, 0.6, 0.4, 100,
        Color(255, 255, 255),
        Color(255, 255, 255),
        Color(255, 255, 255)
    );
    CookTorranceMaterial cook_torrance_white(
        0.2, 0.6, 0.4, 0.8, 0.1,
        Color(255, 255, 255),
        Color(255, 255, 255),
        Color(255, 255, 255)
    );
    CheckMaterial checker_material(
        0.005, 0.2, 0.6, 0.2, 10,
        Color(255, 255, 255),
        Color(255, 255, 255)
    );

    Sphere sphere_1(Vector3(-300, 0, -1200), 200, &cook_torrance_white);
    Sphere sphere_2(Vector3(300, 0, -1200), 200, &phong_white);
    Plane plane_1(Vector3(0, 1, 0), 200.0, &checker_material);

    Geometry *geos[3] = {&sphere_1, &sphere_2, &plane_1};

    GeometryUnion geometry_union(3, geos);
    
    FILE *f = fopen("test.png", "wb");
    if(!f) {
        std::cout << "Create file failed, please try again." << std::endl;
    }
    else {
        RenderEngine render_engine(WIDTH, HEIGHT, SAMPLE_TIMES, MAX_REFLECT_TIMES);
        render_engine.render(camera, geometry_union, f, output_img_data);
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x90(%rbp), %rdi
movsd 0x6bd0(%rip), %xmm0     # 0x9008
movsd 0x6bd0(%rip), %xmm1     # 0x9010
movsd 0x6bd0(%rip), %xmm2     # 0x9018
callq 0x2c50
leaq -0xa8(%rbp), %rdi
movsd 0x6bc4(%rip), %xmm0     # 0x9020
xorps %xmm2, %xmm2
movsd %xmm2, -0x408(%rbp)
movaps %xmm2, %xmm1
callq 0x2c50
movsd -0x408(%rbp), %xmm2
leaq -0xc0(%rbp), %rdi
movsd 0x6ba2(%rip), %xmm1     # 0x9028
movaps %xmm2, %xmm0
callq 0x2c50
movsd -0x408(%rbp), %xmm2
leaq -0xd8(%rbp), %rdi
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x2c50
movq -0xc8(%rbp), %rcx
movq %rsp, %rax
movq %rax, -0x448(%rbp)
movq %rcx, 0x58(%rax)
movups -0xd8(%rbp), %xmm0
movups %xmm0, 0x48(%rax)
movq -0xb0(%rbp), %rcx
movq %rcx, 0x40(%rax)
movups -0xc0(%rbp), %xmm0
movups %xmm0, 0x30(%rax)
movq -0x98(%rbp), %rcx
movq %rcx, 0x28(%rax)
movups -0xa8(%rbp), %xmm0
movups %xmm0, 0x18(%rax)
movq -0x80(%rbp), %rcx
movq %rcx, 0x10(%rax)
movups -0x90(%rbp), %xmm0
movups %xmm0, (%rax)
leaq -0x78(%rbp), %rdi
movsd 0x6b1e(%rip), %xmm0     # 0x9030
callq 0x3d00
leaq -0x134(%rbp), %rdi
movl $0xff, %ecx
movl %ecx, -0x434(%rbp)
movl %ecx, %esi
movl %ecx, %edx
callq 0x4c50
movl -0x434(%rbp), %ecx
leaq -0x140(%rbp), %rdi
movl %ecx, %esi
movl %ecx, %edx
callq 0x4c50
movl -0x434(%rbp), %ecx
leaq -0x150(%rbp), %rdi
movl %ecx, %esi
movl %ecx, %edx
callq 0x4c50
movl -0x12c(%rbp), %eax
movl %eax, -0x158(%rbp)
movq -0x134(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x160(%rbp), %rsi
movl -0x158(%rbp), %edx
movl -0x138(%rbp), %eax
movl %eax, -0x168(%rbp)
movq -0x140(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x170(%rbp), %rcx
movl -0x168(%rbp), %r8d
movl -0x148(%rbp), %edi
movq %rsp, %rax
movl %edi, 0x8(%rax)
movq -0x150(%rbp), %rdi
movq %rdi, (%rax)
leaq -0x128(%rbp), %rdi
movq %rdi, -0x410(%rbp)
movsd 0x6a5f(%rip), %xmm0     # 0x9038
movsd %xmm0, -0x428(%rbp)
movsd 0x6a57(%rip), %xmm1     # 0x9040
movsd %xmm1, -0x430(%rbp)
movsd 0x6a4f(%rip), %xmm2     # 0x9048
movsd %xmm2, -0x440(%rbp)
movsd 0x6a47(%rip), %xmm3     # 0x9050
callq 0x5240
movl -0x434(%rbp), %ecx
leaq -0x1d4(%rbp), %rdi
movl %ecx, %esi
movl %ecx, %edx
callq 0x4c50
movl -0x434(%rbp), %ecx
leaq -0x1e0(%rbp), %rdi
movl %ecx, %esi
movl %ecx, %edx
callq 0x4c50
movl -0x434(%rbp), %ecx
leaq -0x1f0(%rbp), %rdi
movl %ecx, %esi
movl %ecx, %edx
callq 0x4c50
movsd -0x440(%rbp), %xmm2
movsd -0x430(%rbp), %xmm1
movsd -0x428(%rbp), %xmm0
movl -0x1cc(%rbp), %eax
movl %eax, -0x1f8(%rbp)
movq -0x1d4(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x200(%rbp), %rsi
movl -0x1f8(%rbp), %edx
movl -0x1d8(%rbp), %eax
movl %eax, -0x208(%rbp)
movq -0x1e0(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x210(%rbp), %rcx
movl -0x208(%rbp), %r8d
movl -0x1e8(%rbp), %edi
movq %rsp, %rax
movl %edi, 0x8(%rax)
movq -0x1f0(%rbp), %rdi
movq %rdi, (%rax)
leaq -0x1c8(%rbp), %rdi
movq %rdi, -0x420(%rbp)
movsd 0x6975(%rip), %xmm3     # 0x9058
movsd 0x6975(%rip), %xmm4     # 0x9060
callq 0x5810
movl -0x434(%rbp), %ecx
leaq -0x274(%rbp), %rdi
movl %ecx, %esi
movl %ecx, %edx
callq 0x4c50
movl -0x434(%rbp), %ecx
leaq -0x280(%rbp), %rdi
movl %ecx, %esi
movl %ecx, %edx
callq 0x4c50
movsd -0x430(%rbp), %xmm2
movsd -0x428(%rbp), %xmm3
movl -0x26c(%rbp), %eax
movl %eax, -0x288(%rbp)
movq -0x274(%rbp), %rax
movq %rax, -0x290(%rbp)
movq -0x290(%rbp), %rsi
movl -0x288(%rbp), %edx
movl -0x278(%rbp), %eax
movl %eax, -0x298(%rbp)
movq -0x280(%rbp), %rax
movq %rax, -0x2a0(%rbp)
movq -0x2a0(%rbp), %rcx
movl -0x298(%rbp), %r8d
leaq -0x268(%rbp), %rdi
movq %rdi, -0x3f8(%rbp)
movsd 0x68d7(%rip), %xmm0     # 0x9068
movsd 0x68d7(%rip), %xmm4     # 0x9070
movaps %xmm3, %xmm1
callq 0x6500
movsd -0x408(%rbp), %xmm1
leaq -0x2e8(%rbp), %rdi
movsd 0x68c0(%rip), %xmm0     # 0x9078
movsd 0x68c0(%rip), %xmm2     # 0x9080
movsd %xmm2, -0x418(%rbp)
callq 0x2c50
movq -0x420(%rbp), %rsi
movq -0x2d8(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x10(%rax)
movups -0x2e8(%rbp), %xmm0
movups %xmm0, (%rax)
leaq -0x2d0(%rbp), %rdi
movq %rdi, -0x3f0(%rbp)
movsd 0x6886(%rip), %xmm0     # 0x9088
movsd %xmm0, -0x400(%rbp)
callq 0x3500
movsd -0x418(%rbp), %xmm2
movsd -0x408(%rbp), %xmm1
leaq -0x330(%rbp), %rdi
movsd 0x6862(%rip), %xmm0     # 0x9090
callq 0x2c50
movq -0x410(%rbp), %rsi
movsd -0x400(%rbp), %xmm0
movq -0x320(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x10(%rax)
movups -0x330(%rbp), %xmm1
movups %xmm1, (%rax)
leaq -0x318(%rbp), %rdi
movq %rdi, -0x3e8(%rbp)
callq 0x3500
movsd -0x408(%rbp), %xmm2
leaq -0x378(%rbp), %rdi
movsd 0x6814(%rip), %xmm1     # 0x9098
movaps %xmm2, %xmm0
callq 0x2c50
movsd -0x400(%rbp), %xmm0
movq -0x3f8(%rbp), %rsi
movq -0x368(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x10(%rax)
movups -0x378(%rbp), %xmm1
movups %xmm1, (%rax)
leaq -0x360(%rbp), %rdi
movq %rdi, -0x3e0(%rbp)
callq 0x6a90
movq -0x3f0(%rbp), %rdx
movq -0x3e8(%rbp), %rcx
movq -0x3e0(%rbp), %rax
movq %rdx, -0x390(%rbp)
movq %rcx, -0x388(%rbp)
movq %rax, -0x380(%rbp)
leaq -0x3a8(%rbp), %rdi
movl $0x3, %esi
leaq -0x390(%rbp), %rdx
callq 0x4160
leaq 0x6791(%rip), %rdi      # 0x90a0
leaq 0x6793(%rip), %rsi      # 0x90a9
callq 0x2160
movq %rax, -0x3d8(%rbp)
jmp 0x2924
movq -0x3d8(%rbp), %rax
movq %rax, -0x3b0(%rbp)
cmpq $0x0, -0x3b0(%rbp)
jne 0x298f
movq 0xa695(%rip), %rdi      # 0xcfd8
leaq 0x6762(%rip), %rsi      # 0x90ac
callq 0x2110
movq %rax, -0x450(%rbp)
jmp 0x2958
movq -0x450(%rbp), %rdi
movq 0xa662(%rip), %rsi      # 0xcfc8
callq 0x2150
jmp 0x296d
jmp 0x29db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x3b8(%rbp)
movl %eax, -0x3bc(%rbp)
leaq -0x3a8(%rbp), %rdi
callq 0x2a10
jmp 0x29fa
leaq -0x3cc(%rbp), %rdi
movl $0x780, %esi            # imm = 0x780
movl $0x438, %edx            # imm = 0x438
movl $0x1, %ecx
movl $0x14, %r8d
callq 0x7c90
jmp 0x29b2
movq -0x3b0(%rbp), %rcx
leaq 0xa790(%rip), %r8       # 0xd150
leaq -0x3cc(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x3a8(%rbp), %rdx
callq 0x8180
jmp 0x29d9
jmp 0x29db
movl $0x0, -0x4(%rbp)
leaq -0x3a8(%rbp), %rdi
callq 0x2a10
movl -0x4(%rbp), %eax
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbp
retq
movq -0x3b8(%rbp), %rdi
callq 0x21e0
nopw %cs:(%rax,%rax)