// File: Lut99[P]RayTracer/src/lib/Material.cpp
// Function: RayTracer::Material::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>)
Material* Material::from_json(json json_obj) {
    // Check if the object has an object type
    if (!json_obj.is_object()) {
        throw InvalidObjectFormat("Material", json::object().type_name(), json_obj.type_name());
    }

    // Check for the type field
    if (json_obj["type"].is_null()) {
        throw MissingFieldException("Material", "type");
    }

    // Parse the raw type
    MaterialType type;
    try {
        type = (MaterialType) json_obj["type"].get<unsigned long>();
    } catch (nlohmann::detail::type_error&) {
        throw InvalidFieldFormat("Material", "type", "unsigned long", json_obj["type"].type_name());
    }

    // Return the correct parser
    if (type == lambertian) {
        return (Material*) Lambertian::from_json(json_obj);
    } else if (type == metal) {
        return (Material*) Metal::from_json(json_obj);
    } else if (type == dielectric) {
        return (Material*) Dielectric::from_json(json_obj);
    } else {
        throw UnknownSubtypeException("Material", type);
    }
}

// Assembly:
subq $0x2e8, %rsp            # imm = 0x2E8
movq %rdi, 0xd8(%rsp)
movq %rdi, 0x2d8(%rsp)
callq 0xd9b20
testb $0x1, %al
jne 0x165a39
movb $0x1, 0x236(%rsp)
movl $0x88, %edi
callq 0xd02b0
movq %rax, 0xc8(%rsp)
leaq 0x2b7(%rsp), %rdi
movq %rdi, 0xd0(%rsp)
callq 0xd0a20
movq 0xd0(%rsp), %rdx
leaq 0x12acd(%rip), %rsi     # 0x1782ff
leaq 0x2b8(%rsp), %rdi
callq 0xd8b80
jmp 0x165841
leaq 0x260(%rsp), %rdi
callq 0x155e60
movq 0x260(%rsp), %rsi
movq 0x268(%rsp), %rdx
leaq 0x270(%rsp), %rdi
callq 0x15a2a0
jmp 0x16586d
leaq 0x270(%rsp), %rdi
callq 0x1302d0
movq %rax, 0xb8(%rsp)
leaq 0x25f(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
callq 0xd0a20
movq 0xb8(%rsp), %rsi
movq 0xc0(%rsp), %rdx
leaq 0x280(%rsp), %rdi
callq 0xd8b80
jmp 0x1658b6
movq 0xd8(%rsp), %rdi
callq 0x1302d0
movq %rax, 0xa8(%rsp)
leaq 0x237(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0xd0a20
movq 0xa8(%rsp), %rsi
movq 0xb0(%rsp), %rdx
leaq 0x238(%rsp), %rdi
callq 0xd8b80
jmp 0x1658ff
movq 0xc8(%rsp), %rdi
leaq 0x2b8(%rsp), %rsi
leaq 0x280(%rsp), %rdx
leaq 0x238(%rsp), %rcx
callq 0x156180
jmp 0x165926
movq 0xc8(%rsp), %rdi
movb $0x0, 0x236(%rsp)
leaq 0x45b33(%rip), %rsi     # 0x1ab470
leaq -0xf5b4(%rip), %rdx     # 0x156390
callq 0xd09b0
jmp 0x166108
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0x165a0e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0x165a01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0x1659e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0x1659cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0x238(%rsp), %rdi
callq 0xd0b38
leaq 0x237(%rsp), %rdi
callq 0xd0630
leaq 0x280(%rsp), %rdi
callq 0xd0b38
leaq 0x25f(%rsp), %rdi
callq 0xd0630
leaq 0x270(%rsp), %rdi
callq 0xd9f30
leaq 0x2b8(%rsp), %rdi
callq 0xd0b38
leaq 0x2b7(%rsp), %rdi
callq 0xd0630
testb $0x1, 0x236(%rsp)
jne 0x165a27
jmp 0x165a34
movq 0xc8(%rsp), %rdi
callq 0xd0430
jmp 0x1660f3
movq 0xd8(%rsp), %rdi
leaq 0x111eb(%rip), %rsi     # 0x176c33
callq 0xd9b40
movq %rax, %rdi
callq 0xd9da0
testb $0x1, %al
jne 0x165a5e
jmp 0x165bb7
movb $0x1, 0x1e6(%rsp)
movl $0x68, %edi
callq 0xd02b0
movq %rax, 0x98(%rsp)
leaq 0x20f(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0xd0a20
movq 0xa0(%rsp), %rdx
leaq 0x12863(%rip), %rsi     # 0x1782ff
leaq 0x210(%rsp), %rdi
callq 0xd8b80
jmp 0x165aab
leaq 0x1e7(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0xd0a20
movq 0x90(%rsp), %rdx
leaq 0x11164(%rip), %rsi     # 0x176c33
leaq 0x1e8(%rsp), %rdi
callq 0xd8b80
jmp 0x165ade
movq 0x98(%rsp), %rdi
leaq 0x210(%rsp), %rsi
leaq 0x1e8(%rsp), %rdx
callq 0x15a2f0
jmp 0x165afd
movq 0x98(%rsp), %rdi
movb $0x0, 0x1e6(%rsp)
leaq 0x45aac(%rip), %rsi     # 0x1ab5c0
leaq -0xb6eb(%rip), %rdx     # 0x15a430
callq 0xd09b0
jmp 0x166108
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0x165b8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0x165b72
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0xd0b38
leaq 0x1e7(%rsp), %rdi
callq 0xd0630
leaq 0x210(%rsp), %rdi
callq 0xd0b38
leaq 0x20f(%rsp), %rdi
callq 0xd0630
testb $0x1, 0x1e6(%rsp)
jne 0x165ba5
jmp 0x165bb2
movq 0x98(%rsp), %rdi
callq 0xd0430
jmp 0x1660f3
movq 0xd8(%rsp), %rdi
leaq 0x1106d(%rip), %rsi     # 0x176c33
callq 0xd9b40
movq %rax, 0x88(%rsp)
jmp 0x165bd5
movq 0x88(%rsp), %rdi
callq 0x15a470
movq %rax, 0x80(%rsp)
jmp 0x165bec
movq 0x80(%rsp), %rax
movl %eax, 0x1e0(%rsp)
jmp 0x165e93
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
movl 0x2a4(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1660f3
movq 0x2a8(%rsp), %rdi
callq 0xd0210
movq %rax, 0x1d8(%rsp)
movb $0x1, 0x13e(%rsp)
movl $0xa8, %edi
callq 0xd02b0
movq %rax, 0x70(%rsp)
leaq 0x1b7(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0xd0a20
movq 0x78(%rsp), %rdx
leaq 0x1268d(%rip), %rsi     # 0x1782ff
leaq 0x1b8(%rsp), %rdi
callq 0xd8b80
jmp 0x165c81
leaq 0x18f(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0xd0a20
movq 0x68(%rsp), %rdx
leaq 0x10f94(%rip), %rsi     # 0x176c33
leaq 0x190(%rsp), %rdi
callq 0xd8b80
jmp 0x165cae
leaq 0x167(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0xd0a20
movq 0x60(%rsp), %rdx
leaq 0x12039(%rip), %rsi     # 0x177d05
leaq 0x168(%rsp), %rdi
callq 0xd8b80
jmp 0x165cdb
movq 0xd8(%rsp), %rdi
leaq 0x10f49(%rip), %rsi     # 0x176c33
callq 0xd9b40
movq %rax, 0x58(%rsp)
jmp 0x165cf6
movq 0x58(%rsp), %rdi
callq 0x1302d0
movq %rax, 0x48(%rsp)
leaq 0x13f(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0xd0a20
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
leaq 0x140(%rsp), %rdi
callq 0xd8b80
jmp 0x165d30
movq 0x70(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
leaq 0x190(%rsp), %rdx
leaq 0x168(%rsp), %rcx
leaq 0x140(%rsp), %r8
callq 0x15a4a0
jmp 0x165d5c
movq 0x70(%rsp), %rdi
movb $0x0, 0x13e(%rsp)
leaq 0x45868(%rip), %rsi     # 0x1ab5d8
leaq -0xb5d7(%rip), %rdx     # 0x15a7a0
callq 0xd09b0
jmp 0x166108
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0x165e64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0x165e4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0x165e30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0x165e23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0x165e16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0x140(%rsp), %rdi
callq 0xd0b38
leaq 0x13f(%rsp), %rdi
callq 0xd0630
leaq 0x168(%rsp), %rdi
callq 0xd0b38
leaq 0x167(%rsp), %rdi
callq 0xd0630
leaq 0x190(%rsp), %rdi
callq 0xd0b38
leaq 0x18f(%rsp), %rdi
callq 0xd0630
leaq 0x1b8(%rsp), %rdi
callq 0xd0b38
leaq 0x1b7(%rsp), %rdi
callq 0xd0630
testb $0x1, 0x13e(%rsp)
jne 0x165e7d
jmp 0x165e87
movq 0x70(%rsp), %rdi
callq 0xd0430
callq 0xd0940
jmp 0x165e8e
jmp 0x1660f3
cmpl $0x0, 0x1e0(%rsp)
jne 0x165f0d
movq 0xd8(%rsp), %rsi
leaq 0x128(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0xd9dc0
movq 0x38(%rsp), %rdi
callq 0x166460
movq %rax, 0x40(%rsp)
jmp 0x165ec8
movq 0x40(%rsp), %rax
movq %rax, 0x2e0(%rsp)
leaq 0x128(%rsp), %rdi
callq 0xd9f30
jmp 0x1660e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0x128(%rsp), %rdi
callq 0xd9f30
jmp 0x1660f3
cmpl $0x1, 0x1e0(%rsp)
jne 0x165f87
movq 0xd8(%rsp), %rsi
leaq 0x118(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0xd9dc0
movq 0x28(%rsp), %rdi
callq 0x166d80
movq %rax, 0x30(%rsp)
jmp 0x165f42
movq 0x30(%rsp), %rax
movq %rax, 0x2e0(%rsp)
leaq 0x118(%rsp), %rdi
callq 0xd9f30
jmp 0x1660e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0x118(%rsp), %rdi
callq 0xd9f30
jmp 0x1660f3
cmpl $0x2, 0x1e0(%rsp)
jne 0x166001
movq 0xd8(%rsp), %rsi
leaq 0x108(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0xd9dc0
movq 0x18(%rsp), %rdi
callq 0x167fd0
movq %rax, 0x20(%rsp)
jmp 0x165fbc
movq 0x20(%rsp), %rax
movq %rax, 0x2e0(%rsp)
leaq 0x108(%rsp), %rdi
callq 0xd9f30
jmp 0x1660e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0x108(%rsp), %rdi
callq 0xd9f30
jmp 0x1660f3
movb $0x1, 0xe6(%rsp)
movl $0x50, %edi
callq 0xd02b0
movq %rax, 0x8(%rsp)
leaq 0xe7(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xd0a20
movq 0x10(%rsp), %rdx
leaq 0x122c9(%rip), %rsi     # 0x1782ff
leaq 0xe8(%rsp), %rdi
callq 0xd8b80
jmp 0x166045
movq 0x8(%rsp), %rdi
movl 0x1e0(%rsp), %eax
movl %eax, %edx
leaq 0xe8(%rsp), %rsi
callq 0x15a7e0
jmp 0x166062
movq 0x8(%rsp), %rdi
movb $0x0, 0xe6(%rsp)
leaq 0x4557a(%rip), %rsi     # 0x1ab5f0
leaq -0xb73d(%rip), %rdx     # 0x15a940
callq 0xd09b0
jmp 0x166108
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
jmp 0x1660be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2a8(%rsp)
movl %eax, 0x2a4(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0xd0b38
leaq 0xe7(%rsp), %rdi
callq 0xd0630
testb $0x1, 0xe6(%rsp)
jne 0x1660d7
jmp 0x1660e1
movq 0x8(%rsp), %rdi
callq 0xd0430
jmp 0x1660f3
movq 0x2e0(%rsp), %rax
addq $0x2e8, %rsp            # imm = 0x2E8
retq
movq 0x2a8(%rsp), %rdi
callq 0xd0a10
movq %rax, %rdi
callq 0xd9890
nopl (%rax,%rax)