// File: /workspace/github_cpp_makefile_star2_O2/Lut99[P]RayTracer/src/lib/Camera.cpp
// Function: RayTracer::Camera::from_json(nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>)
Camera* Camera::from_json(nlohmann::json json_obj) {
    // Check if it is an object
    if (!json_obj.is_object()) {
        throw InvalidObjectFormat("Camera", json::object().type_name(), json_obj.type_name());
    }

    // Next, check if the required fields are present
    if (json_obj["lookat"].is_null()) {
        throw MissingFieldException("Camera", "lookat");
    }
    if (json_obj["lookfrom"].is_null()) {
        throw MissingFieldException("Camera", "lookfrom");
    }
    if (json_obj["up"].is_null()) {
        throw MissingFieldException("Camera", "up");
    }
    if (json_obj["vfov"].is_null()) {
        throw MissingFieldException("Camera", "vfov");
    }
    if (json_obj["aperture"].is_null()) {
        throw MissingFieldException("Camera", "aperture");
    }

    // Parse the objects
    Vec3 lookat = Vec3::from_json(json_obj["lookat"]);
    Vec3 lookfrom = Vec3::from_json(json_obj["lookfrom"]);
    Vec3 up = Vec3::from_json(json_obj["up"]);
    double vfov, aperture;
    try {
        vfov = json_obj["vfov"].get<double>();
        aperture = json_obj["aperture"].get<double>();
    } catch (nlohmann::detail::type_error&) {
        throw InvalidFieldFormat("Camera", "vfov or aperture", "double", json_obj[0].type_name());
    }
    // Only parse the animation if it is present
    CameraMovement* animation = nullptr;
    if (!json_obj["animation"].is_null()) {
        animation = CameraMovement::from_json(json_obj["animation"]);
    }
    
    // Put everything in the camera
    Camera* to_return = new Camera(lookfrom, lookat, up, vfov, aperture);
    if (animation != nullptr) {
        to_return->set_animation(animation);
    }

    // Return it
    return to_return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x338, %rsp            # imm = 0x338
movq %rdi, %r14
cmpb $0x1, (%rdi)
jne 0x83dbd
leaq 0xeea0(%rip), %rsi      # 0x92a10
movq %r14, %rdi
callq 0x56e34
cmpb $0x0, (%rax)
je 0x83e70
leaq 0xee8f(%rip), %rsi      # 0x92a17
movq %r14, %rdi
callq 0x56e34
cmpb $0x0, (%rax)
je 0x83ee5
leaq 0xee80(%rip), %rsi      # 0x92a20
movq %r14, %rdi
callq 0x56e34
cmpb $0x0, (%rax)
je 0x83f5a
leaq 0x7e58(%rip), %rsi      # 0x8ba10
movq %r14, %rdi
callq 0x56e34
cmpb $0x0, (%rax)
je 0x83fcf
leaq 0xee62(%rip), %rsi      # 0x92a32
movq %r14, %rdi
callq 0x56e34
cmpb $0x0, (%rax)
je 0x84044
leaq 0xee28(%rip), %rsi      # 0x92a10
movq %r14, %rdi
callq 0x56e34
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x56f56
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x7e90c
leaq 0x88(%rsp), %rdi
callq 0x56fca
leaq 0xedf3(%rip), %rsi      # 0x92a17
movq %r14, %rdi
callq 0x56e34
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x56f56
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x7e90c
leaq 0x78(%rsp), %rdi
callq 0x56fca
leaq 0xedc6(%rip), %rsi      # 0x92a20
movq %r14, %rdi
callq 0x56e34
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x56f56
leaq 0x98(%rsp), %rdi
movq %rbx, %rsi
callq 0x7e90c
leaq 0x68(%rsp), %rdi
callq 0x56fca
leaq 0x7d7d(%rip), %rsi      # 0x8ba10
movq %r14, %rdi
callq 0x56e34
movq %rax, %rdi
callq 0x7f350
movsd %xmm0, 0x50(%rsp)
leaq 0xed82(%rip), %rsi      # 0x92a32
movq %r14, %rdi
callq 0x56e34
movq %rax, %rdi
callq 0x7f350
movsd %xmm0, 0x48(%rsp)
leaq 0x7f3d(%rip), %rsi      # 0x8bc0a
movq %r14, %rdi
callq 0x56e34
cmpb $0x0, (%rax)
je 0x83d10
leaq 0x7f29(%rip), %rsi      # 0x8bc0a
movq %r14, %rdi
callq 0x56e34
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x56f56
movq %rbx, %rdi
callq 0x87a42
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x56fca
jmp 0x83d12
xorl %ebx, %ebx
movl $0x178, %edi            # imm = 0x178
callq 0x52470
movq %rax, %r14
leaq 0x2d752(%rip), %rax     # 0xb1478
addq $0x10, %rax
leaq 0x318(%rsp), %rsi
movq %rax, (%rsi)
movups 0x30(%rsp), %xmm0
movups %xmm0, 0x8(%rsi)
movq 0x40(%rsp), %rcx
movq %rcx, 0x18(%rsi)
leaq 0x2f8(%rsp), %rdx
movq %rax, (%rdx)
movups 0x10(%rsp), %xmm0
movups %xmm0, 0x8(%rdx)
movq 0x20(%rsp), %rcx
movq %rcx, 0x18(%rdx)
leaq 0x2d8(%rsp), %rcx
movq %rax, (%rcx)
movups 0xa0(%rsp), %xmm0
movups %xmm0, 0x8(%rcx)
movq 0xb0(%rsp), %rax
movq %rax, 0x18(%rcx)
movq %r14, %rdi
movsd 0x50(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
callq 0x836be
testq %rbx, %rbx
je 0x83dac
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
callq *0x10(%rax)
movq %r14, %rax
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x88, %edi
callq 0x52220
movq %rax, %r15
leaq 0xec52(%rip), %rsi      # 0x92a23
leaq 0x2b8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x56548
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x8067c
leaq 0x8(%rsp), %rdi
callq 0x6f406
leaq 0x298(%rsp), %rdi
leaq 0x98(%rsp), %rdx
movq %rax, %rsi
callq 0x56548
movq %r14, %rdi
callq 0x6f406
leaq 0x278(%rsp), %rdi
leaq 0x4(%rsp), %rdx
movq %rax, %rsi
callq 0x56548
movb $0x1, %bpl
leaq 0x2b8(%rsp), %rsi
leaq 0x298(%rsp), %rdx
leaq 0x278(%rsp), %rcx
movq %r15, %rdi
callq 0x7f052
xorl %ebp, %ebp
leaq 0x2d65c(%rip), %rsi     # 0xb14b8
leaq -0x4cbd(%rip), %rdx     # 0x7f1a6
movq %r15, %rdi
callq 0x52760
jmp 0x8430a
pushq $0x68
popq %rdi
callq 0x52220
movq %rax, %r14
leaq 0xeba1(%rip), %rsi      # 0x92a23
leaq 0x258(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x56548
leaq 0xeb75(%rip), %rsi      # 0x92a10
leaq 0x238(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x56548
movb $0x1, %bpl
leaq 0x258(%rsp), %rsi
leaq 0x238(%rsp), %rdx
movq %r14, %rdi
callq 0x80690
xorl %ebp, %ebp
leaq 0x2d737(%rip), %rsi     # 0xb1608
leaq -0x3778(%rip), %rdx     # 0x80760
movq %r14, %rdi
callq 0x52760
jmp 0x8430a
pushq $0x68
popq %rdi
callq 0x52220
movq %rax, %r14
leaq 0xeb2c(%rip), %rsi      # 0x92a23
leaq 0x218(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x56548
leaq 0xeb07(%rip), %rsi      # 0x92a17
leaq 0x1f8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x56548
movb $0x1, %bpl
leaq 0x218(%rsp), %rsi
leaq 0x1f8(%rsp), %rdx
movq %r14, %rdi
callq 0x80690
xorl %ebp, %ebp
leaq 0x2d6c2(%rip), %rsi     # 0xb1608
leaq -0x37ed(%rip), %rdx     # 0x80760
movq %r14, %rdi
callq 0x52760
jmp 0x8430a
pushq $0x68
popq %rdi
callq 0x52220
movq %rax, %r14
leaq 0xeab7(%rip), %rsi      # 0x92a23
leaq 0x1d8(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x56548
leaq 0xea9b(%rip), %rsi      # 0x92a20
leaq 0x1b8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x56548
movb $0x1, %bpl
leaq 0x1d8(%rsp), %rsi
leaq 0x1b8(%rsp), %rdx
movq %r14, %rdi
callq 0x80690
xorl %ebp, %ebp
leaq 0x2d64d(%rip), %rsi     # 0xb1608
leaq -0x3862(%rip), %rdx     # 0x80760
movq %r14, %rdi
callq 0x52760
jmp 0x8430a
pushq $0x68
popq %rdi
callq 0x52220
movq %rax, %r14
leaq 0xea42(%rip), %rsi      # 0x92a23
leaq 0x198(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x56548
leaq 0x7a16(%rip), %rsi      # 0x8ba10
leaq 0x178(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x56548
movb $0x1, %bpl
leaq 0x198(%rsp), %rsi
leaq 0x178(%rsp), %rdx
movq %r14, %rdi
callq 0x80690
xorl %ebp, %ebp
leaq 0x2d5d8(%rip), %rsi     # 0xb1608
leaq -0x38d7(%rip), %rdx     # 0x80760
movq %r14, %rdi
callq 0x52760
jmp 0x8430a
pushq $0x68
popq %rdi
callq 0x52220
movq %rax, %r14
leaq 0xe9cd(%rip), %rsi      # 0x92a23
leaq 0x158(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x56548
leaq 0xe9c3(%rip), %rsi      # 0x92a32
leaq 0x138(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x56548
movb $0x1, %bpl
leaq 0x158(%rsp), %rsi
leaq 0x138(%rsp), %rdx
movq %r14, %rdi
callq 0x80690
xorl %ebp, %ebp
leaq 0x2d563(%rip), %rsi     # 0xb1608
leaq -0x394c(%rip), %rdx     # 0x80760
movq %r14, %rdi
callq 0x52760
jmp 0x8430a
movq %rax, %rbx
leaq 0x278(%rsp), %rdi
callq 0x52888
jmp 0x840d1
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x298(%rsp), %rdi
callq 0x52888
jmp 0x840e6
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x8(%rsp), %rdi
callq 0x56fca
jmp 0x841b5
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x52888
jmp 0x8410d
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x158(%rsp), %rdi
jmp 0x841a0
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x52888
jmp 0x84132
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x198(%rsp), %rdi
jmp 0x841a0
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x52888
jmp 0x84154
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x1d8(%rsp), %rdi
jmp 0x841a0
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0x52888
jmp 0x84176
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x218(%rsp), %rdi
jmp 0x841a0
movq %rax, %rbx
leaq 0x238(%rsp), %rdi
callq 0x52888
jmp 0x84198
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x258(%rsp), %rdi
callq 0x52888
testb %bpl, %bpl
jne 0x841d7
jmp 0x84372
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x2b8(%rsp), %rdi
callq 0x52888
testb %bpl, %bpl
jne 0x841e7
jmp 0x84372
jmp 0x841d4
jmp 0x841d4
jmp 0x841d4
jmp 0x841d4
movq %rax, %rbx
movq %r14, %rdi
callq 0x52350
jmp 0x84372
movq %rax, %rbx
movq %r15, %rdi
jmp 0x841da
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0x8422a
movq %rax, %rbx
movl $0x178, %esi            # imm = 0x178
movq %r14, %rdi
callq 0x52480
jmp 0x84372
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x8422a
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x8422a
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x56fca
jmp 0x84372
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x84372
movq %rbx, %rdi
callq 0x521b0
movl $0xa8, %edi
callq 0x52220
movq %rax, %r15
leaq 0xe7c7(%rip), %rsi      # 0x92a23
leaq 0x118(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0x56548
leaq 0xe7b5(%rip), %rsi      # 0x92a2a
leaq 0xf8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x56548
leaq 0xdf93(%rip), %rsi      # 0x92221
leaq 0xd8(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x56548
movq %r14, %rdi
xorl %esi, %esi
callq 0x7eefe
movq %rax, %rdi
callq 0x6f406
leaq 0xb8(%rsp), %rdi
leaq 0x5(%rsp), %rdx
movq %rax, %rsi
callq 0x56548
movb $0x1, %bpl
leaq 0x118(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
leaq 0xd8(%rsp), %rcx
leaq 0xb8(%rsp), %r8
movq %r15, %rdi
callq 0x8079c
xorl %ebp, %ebp
leaq 0x2d325(%rip), %rsi     # 0xb1620
leaq -0x3974(%rip), %rdx     # 0x8098e
movq %r15, %rdi
callq 0x52760
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x52888
jmp 0x84324
jmp 0x8431e
movq %rax, %rbx
movb $0x1, %bpl
leaq 0xd8(%rsp), %rdi
callq 0x52888
jmp 0x84339
movq %rax, %rbx
movb $0x1, %bpl
leaq 0xf8(%rsp), %rdi
callq 0x52888
jmp 0x8434e
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x118(%rsp), %rdi
callq 0x52888
testb %bpl, %bpl
jne 0x84365
jmp 0x8436d
movq %rax, %rbx
movq %r15, %rdi
callq 0x52350
callq 0x52720
movq %rbx, %rdi
callq 0x527a0
movq %rax, %rdi
callq 0x56ca4