// File: Lut99[P]RayTracer/src/lib/RenderObject.cpp
// Function: RayTracer::RenderObject::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>)
RenderObject* RenderObject::from_json(json json_obj) {
    // Check if the object has an object type
    if (!json_obj.is_object()) {
        throw InvalidObjectFormat("RenderObject", json::object().type_name(), json_obj.type_name());
    }

    // Check for the type field
    if (json_obj["type"].is_null()) {
        throw MissingFieldException("RenderObject", "type");
    }

    // Parse the raw type
    RenderObjectType type;
    try {
        type = (RenderObjectType) json_obj["type"].get<unsigned long>();
    } catch (nlohmann::detail::type_error&) {
        throw InvalidFieldFormat("RenderObject", "type", "unsigned long", json_obj["type"].type_name());
    }
    // If the animation field is defined, parse it as such
    RenderAnimation* animation = nullptr;
    if (!json_obj["animation"].is_null()) {
        animation = RenderAnimation::from_json(json_obj["animation"]);
    }

    // Parse the rest of the object based on the type field
    RenderObject* to_return;
    if (type == sphere) {
        to_return = (RenderObject*) Sphere::from_json(json_obj);
    } else if (type == render_object_collection) {
        to_return = (RenderObject*) RenderObjectCollection::from_json(json_obj);
    } else {
        throw UnknownSubtypeException("RenderObject", type);
    }

    // If needed, add the animation
    if (animation != nullptr) {
        to_return->set_animation(animation);
    }

    // Return
    return to_return;
}

// Assembly:
subq $0x2e8, %rsp            # imm = 0x2E8
movq %rdi, 0xd0(%rsp)
movq %rdi, 0x2e0(%rsp)
callq 0xd9b20
testb $0x1, %al
jne 0x159af9
movb $0x1, 0x23e(%rsp)
movl $0x88, %edi
callq 0xd02b0
movq %rax, 0xc0(%rsp)
leaq 0x2bf(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0xd0a20
movq 0xc8(%rsp), %rdx
leaq 0x1e406(%rip), %rsi     # 0x177cf8
leaq 0x2c0(%rsp), %rdi
callq 0xd8b80
jmp 0x159901
leaq 0x268(%rsp), %rdi
callq 0x155e60
movq 0x268(%rsp), %rsi
movq 0x270(%rsp), %rdx
leaq 0x278(%rsp), %rdi
callq 0x15a2a0
jmp 0x15992d
leaq 0x278(%rsp), %rdi
callq 0x1302d0
movq %rax, 0xb0(%rsp)
leaq 0x267(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0xd0a20
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
leaq 0x288(%rsp), %rdi
callq 0xd8b80
jmp 0x159976
movq 0xd0(%rsp), %rdi
callq 0x1302d0
movq %rax, 0xa0(%rsp)
leaq 0x23f(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0xd0a20
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
leaq 0x240(%rsp), %rdi
callq 0xd8b80
jmp 0x1599bf
movq 0xc0(%rsp), %rdi
leaq 0x2c0(%rsp), %rsi
leaq 0x288(%rsp), %rdx
leaq 0x240(%rsp), %rcx
callq 0x156180
jmp 0x1599e6
movq 0xc0(%rsp), %rdi
movb $0x0, 0x23e(%rsp)
leaq 0x51a73(%rip), %rsi     # 0x1ab470
leaq -0x3674(%rip), %rdx     # 0x156390
callq 0xd09b0
jmp 0x15a20f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x159ace
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x159ac1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x159aa7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x159a8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x240(%rsp), %rdi
callq 0xd0b38
leaq 0x23f(%rsp), %rdi
callq 0xd0630
leaq 0x288(%rsp), %rdi
callq 0xd0b38
leaq 0x267(%rsp), %rdi
callq 0xd0630
leaq 0x278(%rsp), %rdi
callq 0xd9f30
leaq 0x2c0(%rsp), %rdi
callq 0xd0b38
leaq 0x2bf(%rsp), %rdi
callq 0xd0630
testb $0x1, 0x23e(%rsp)
jne 0x159ae7
jmp 0x159af4
movq 0xc0(%rsp), %rdi
callq 0xd0430
jmp 0x15a1fa
movq 0xd0(%rsp), %rdi
leaq 0x1d12b(%rip), %rsi     # 0x176c33
callq 0xd9b40
movq %rax, %rdi
callq 0xd9da0
testb $0x1, %al
jne 0x159b1e
jmp 0x159c77
movb $0x1, 0x1ee(%rsp)
movl $0x68, %edi
callq 0xd02b0
movq %rax, 0x90(%rsp)
leaq 0x217(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0xd0a20
movq 0x98(%rsp), %rdx
leaq 0x1e19c(%rip), %rsi     # 0x177cf8
leaq 0x218(%rsp), %rdi
callq 0xd8b80
jmp 0x159b6b
leaq 0x1ef(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0xd0a20
movq 0x88(%rsp), %rdx
leaq 0x1d0a4(%rip), %rsi     # 0x176c33
leaq 0x1f0(%rsp), %rdi
callq 0xd8b80
jmp 0x159b9e
movq 0x90(%rsp), %rdi
leaq 0x218(%rsp), %rsi
leaq 0x1f0(%rsp), %rdx
callq 0x15a2f0
jmp 0x159bbd
movq 0x90(%rsp), %rdi
movb $0x0, 0x1ee(%rsp)
leaq 0x519ec(%rip), %rsi     # 0x1ab5c0
leaq 0x855(%rip), %rdx       # 0x15a430
callq 0xd09b0
jmp 0x15a20f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x159c4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x159c32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x1f0(%rsp), %rdi
callq 0xd0b38
leaq 0x1ef(%rsp), %rdi
callq 0xd0630
leaq 0x218(%rsp), %rdi
callq 0xd0b38
leaq 0x217(%rsp), %rdi
callq 0xd0630
testb $0x1, 0x1ee(%rsp)
jne 0x159c65
jmp 0x159c72
movq 0x90(%rsp), %rdi
callq 0xd0430
jmp 0x15a1fa
movq 0xd0(%rsp), %rdi
leaq 0x1cfad(%rip), %rsi     # 0x176c33
callq 0xd9b40
movq %rax, 0x80(%rsp)
jmp 0x159c95
movq 0x80(%rsp), %rdi
callq 0x15a470
movq %rax, 0x78(%rsp)
jmp 0x159ca9
movq 0x78(%rsp), %rax
movl %eax, 0x1e8(%rsp)
jmp 0x159f4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
movl 0x2ac(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x15a1fa
movq 0x2b0(%rsp), %rdi
callq 0xd0210
movq %rax, 0x1e0(%rsp)
movb $0x1, 0x146(%rsp)
movl $0xa8, %edi
callq 0xd02b0
movq %rax, 0x68(%rsp)
leaq 0x1bf(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0xd0a20
movq 0x70(%rsp), %rdx
leaq 0x1dfcc(%rip), %rsi     # 0x177cf8
leaq 0x1c0(%rsp), %rdi
callq 0xd8b80
jmp 0x159d3b
leaq 0x197(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0xd0a20
movq 0x60(%rsp), %rdx
leaq 0x1ceda(%rip), %rsi     # 0x176c33
leaq 0x198(%rsp), %rdi
callq 0xd8b80
jmp 0x159d68
leaq 0x16f(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0xd0a20
movq 0x58(%rsp), %rdx
leaq 0x1df7f(%rip), %rsi     # 0x177d05
leaq 0x170(%rsp), %rdi
callq 0xd8b80
jmp 0x159d95
movq 0xd0(%rsp), %rdi
leaq 0x1ce8f(%rip), %rsi     # 0x176c33
callq 0xd9b40
movq %rax, 0x50(%rsp)
jmp 0x159db0
movq 0x50(%rsp), %rdi
callq 0x1302d0
movq %rax, 0x40(%rsp)
leaq 0x147(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0xd0a20
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
leaq 0x148(%rsp), %rdi
callq 0xd8b80
jmp 0x159dea
movq 0x68(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
leaq 0x198(%rsp), %rdx
leaq 0x170(%rsp), %rcx
leaq 0x148(%rsp), %r8
callq 0x15a4a0
jmp 0x159e16
movq 0x68(%rsp), %rdi
movb $0x0, 0x146(%rsp)
leaq 0x517ae(%rip), %rsi     # 0x1ab5d8
leaq 0x96f(%rip), %rdx       # 0x15a7a0
callq 0xd09b0
jmp 0x15a20f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x159f1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x159f04
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x159eea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x159edd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x159ed0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x148(%rsp), %rdi
callq 0xd0b38
leaq 0x147(%rsp), %rdi
callq 0xd0630
leaq 0x170(%rsp), %rdi
callq 0xd0b38
leaq 0x16f(%rsp), %rdi
callq 0xd0630
leaq 0x198(%rsp), %rdi
callq 0xd0b38
leaq 0x197(%rsp), %rdi
callq 0xd0630
leaq 0x1c0(%rsp), %rdi
callq 0xd0b38
leaq 0x1bf(%rsp), %rdi
callq 0xd0630
testb $0x1, 0x146(%rsp)
jne 0x159f37
jmp 0x159f41
movq 0x68(%rsp), %rdi
callq 0xd0430
callq 0xd0940
jmp 0x159f48
jmp 0x15a1fa
movq 0xd0(%rsp), %rdi
movq $0x0, 0x138(%rsp)
leaq 0x170f2(%rip), %rsi     # 0x17105a
callq 0xd9b40
movq %rax, %rdi
callq 0xd9da0
testb $0x1, %al
jne 0x159ff5
movq 0xd0(%rsp), %rdi
leaq 0x170d2(%rip), %rsi     # 0x17105a
callq 0xd9b40
movq %rax, %rsi
leaq 0x128(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xd9dc0
movq 0x30(%rsp), %rdi
callq 0x168ad0
movq %rax, 0x38(%rsp)
jmp 0x159fb3
movq 0x38(%rsp), %rax
movq %rax, 0x138(%rsp)
leaq 0x128(%rsp), %rdi
callq 0xd9f30
jmp 0x159ff5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x128(%rsp), %rdi
callq 0xd9f30
jmp 0x15a1fa
cmpl $0x0, 0x1e8(%rsp)
jne 0x15a06f
movq 0xd0(%rsp), %rsi
leaq 0x110(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0xd9dc0
movq 0x20(%rsp), %rdi
callq 0x15b710
movq %rax, 0x28(%rsp)
jmp 0x15a02a
movq 0x28(%rsp), %rax
movq %rax, 0x120(%rsp)
leaq 0x110(%rsp), %rdi
callq 0xd9f30
jmp 0x15a1c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x110(%rsp), %rdi
callq 0xd9f30
jmp 0x15a1fa
cmpl $0x1, 0x1e8(%rsp)
jne 0x15a0e9
movq 0xd0(%rsp), %rsi
leaq 0x100(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xd9dc0
movq 0x10(%rsp), %rdi
callq 0x15cec0
movq %rax, 0x18(%rsp)
jmp 0x15a0a4
movq 0x18(%rsp), %rax
movq %rax, 0x120(%rsp)
leaq 0x100(%rsp), %rdi
callq 0xd9f30
jmp 0x15a1c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x100(%rsp), %rdi
callq 0xd9f30
jmp 0x15a1fa
movb $0x1, 0xde(%rsp)
movl $0x50, %edi
callq 0xd02b0
movq %rax, (%rsp)
leaq 0xdf(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0xd0a20
movq 0x8(%rsp), %rdx
leaq 0x1dbdb(%rip), %rsi     # 0x177cf8
leaq 0xe0(%rsp), %rdi
callq 0xd8b80
jmp 0x15a12c
movq (%rsp), %rdi
movl 0x1e8(%rsp), %eax
movl %eax, %edx
leaq 0xe0(%rsp), %rsi
callq 0x15a7e0
jmp 0x15a148
movq (%rsp), %rdi
movb $0x0, 0xde(%rsp)
leaq 0x51495(%rip), %rsi     # 0x1ab5f0
leaq 0x7de(%rip), %rdx       # 0x15a940
callq 0xd09b0
jmp 0x15a20f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x15a1a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0xd0b38
leaq 0xdf(%rsp), %rdi
callq 0xd0630
testb $0x1, 0xde(%rsp)
jne 0x15a1bc
jmp 0x15a1c5
movq (%rsp), %rdi
callq 0xd0430
jmp 0x15a1fa
jmp 0x15a1c9
cmpq $0x0, 0x138(%rsp)
je 0x15a1ea
movq 0x120(%rsp), %rdi
movq 0x138(%rsp), %rsi
movq (%rdi), %rax
callq *0x48(%rax)
movq 0x120(%rsp), %rax
addq $0x2e8, %rsp            # imm = 0x2E8
retq
movq 0x2b0(%rsp), %rdi
callq 0xd0a10
movq %rax, %rdi
callq 0xd9890
nop