// File: /workspace/github_cpp_makefile_star2_O3/alan0201tw[P]RayTracer/src/transform.cpp
// Function: rotate_y::rotate_y(std::shared_ptr<hitable>, float)
rotate_y::rotate_y(std::shared_ptr<hitable> _target, float _angle)
    : target(_target)
{
    float angle_in_radians = DEGREE_TO_RADIAN_COEF_F * _angle;
    sin_theta = std::sin(angle_in_radians);
    cos_theta = std::cos(angle_in_radians);
    isBoundedByBox = target->bounding_box(0.0f, 1.0f, target_aabb);


    vec3 minimal(FLOAT_MAX, FLOAT_MAX, FLOAT_MAX);
    vec3 maximal(-FLOAT_MAX, -FLOAT_MAX, -FLOAT_MAX);

    for(int i = 0; i < 2; i++)
    {
        for(int j = 0; j < 2; j++)
        {
            for(int k = 0; k < 2; k++)
            {
                float x = i * target_aabb.get_max().x()
                    + (1 - i) * target_aabb.get_min().x();
                float y = j * target_aabb.get_max().y()     
                    + (1 - j) * target_aabb.get_min().y();
                float z = k * target_aabb.get_max().z()
                    + (1 - k) * target_aabb.get_min().z();

                float new_x = cos_theta * x + sin_theta * z;
                float new_z = -sin_theta * x + cos_theta * z;
                vec3 tester(new_x, y, new_z);
                for(int c = 0; c < 3; c++)
                {
                    if(tester[c] > maximal[c])
                        maximal[c] = tester[c];
                    if(tester[c] < minimal[c])
                        minimal[c] = tester[c];
                }
            }
        }
    }
    target_aabb = aabb(minimal, maximal);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
leaq 0x2b56d(%rip), %rax     # 0x4e940
movq %rax, (%rdi)
movq (%rsi), %rax
movq %rax, 0x8(%rdi)
movq 0x8(%rsi), %rax
movq %rax, 0x10(%rdi)
testq %rax, %rax
je 0x233ff
movq 0x2bbaf(%rip), %rcx     # 0x4efa0
cmpb $0x0, (%rcx)
je 0x233fb
incl 0x8(%rax)
jmp 0x233ff
lock
incl 0x8(%rax)
leaq 0x24(%r14), %rbx
cvtss2sd %xmm0, %xmm0
mulsd 0x19f91(%rip), %xmm0    # 0x3d3a0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x34(%rsp)
callq 0x6340
movss %xmm0, 0x18(%r14)
movss 0x34(%rsp), %xmm0
callq 0x62f0
movss %xmm0, 0x1c(%r14)
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movss 0x18dc0(%rip), %xmm1    # 0x3c204
xorps %xmm0, %xmm0
movq %rbx, %rsi
callq *0x8(%rax)
movb %al, 0x20(%r14)
movsd 0x19f57(%rip), %xmm0    # 0x3d3b0
movsd %xmm0, 0x28(%rsp)
movl $0x7f7fffff, 0x30(%rsp) # imm = 0x7F7FFFFF
movsd 0x19f51(%rip), %xmm0    # 0x3d3c0
movsd %xmm0, 0x18(%rsp)
movl $0xff7fffff, 0x20(%rsp) # imm = 0xFF7FFFFF
movsd 0x30(%r14), %xmm0
movss 0x38(%r14), %xmm1
movsd 0x24(%r14), %xmm2
movss 0x2c(%r14), %xmm3
movaps %xmm0, %xmm4
shufps $0x55, %xmm0, %xmm4     # xmm4 = xmm4[1,1],xmm0[1,1]
movaps %xmm2, %xmm5
shufps $0x55, %xmm2, %xmm5     # xmm5 = xmm5[1,1],xmm2[1,1]
movss 0x18(%r14), %xmm6
movss 0x1c(%r14), %xmm7
movaps 0x18e69(%rip), %xmm8    # 0x3c320
xorps %xmm6, %xmm8
xorl %ecx, %ecx
movb $0x1, %al
xorps %xmm9, %xmm9
cvtsi2ss %ecx, %xmm9
xorl $0x1, %ecx
xorps %xmm10, %xmm10
cvtsi2ss %ecx, %xmm10
mulss %xmm2, %xmm10
mulss %xmm0, %xmm9
addss %xmm10, %xmm9
movaps %xmm7, %xmm10
mulss %xmm9, %xmm10
mulss %xmm8, %xmm9
movb $0x1, %cl
xorl %edx, %edx
xorps %xmm11, %xmm11
cvtsi2ss %edx, %xmm11
xorl $0x1, %edx
xorps %xmm12, %xmm12
cvtsi2ss %edx, %xmm12
mulss %xmm5, %xmm12
mulss %xmm4, %xmm11
addss %xmm12, %xmm11
xorl %esi, %esi
movb $0x1, %dl
xorps %xmm12, %xmm12
cvtsi2ss %esi, %xmm12
xorl $0x1, %esi
xorps %xmm13, %xmm13
cvtsi2ss %esi, %xmm13
mulss %xmm1, %xmm12
mulss %xmm3, %xmm13
addss %xmm12, %xmm13
movaps %xmm6, %xmm12
mulss %xmm13, %xmm12
addss %xmm10, %xmm12
mulss %xmm7, %xmm13
addss %xmm9, %xmm13
movss %xmm12, (%rsp)
movss %xmm11, 0x4(%rsp)
movss %xmm13, 0x8(%rsp)
xorl %esi, %esi
movss (%rsp,%rsi,4), %xmm12
ucomiss 0x18(%rsp,%rsi,4), %xmm12
jbe 0x23584
movss %xmm12, 0x18(%rsp,%rsi,4)
movss 0x28(%rsp,%rsi,4), %xmm13
ucomiss %xmm12, %xmm13
jbe 0x23598
movss %xmm12, 0x28(%rsp,%rsi,4)
incq %rsi
cmpq $0x3, %rsi
jne 0x2356f
movl $0x1, %esi
testb $0x1, %dl
movl $0x0, %edx
jne 0x2351d
movl $0x1, %edx
testb $0x1, %cl
movl $0x0, %ecx
jne 0x234f5
movl $0x1, %ecx
testb $0x1, %al
movl $0x0, %eax
jne 0x234bf
movl 0x30(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0xc(%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0x14(%rsp)
movq (%rsp), %rax
movq %rax, (%rbx)
movl 0x8(%rsp), %eax
movl %eax, 0x8(%rbx)
movl 0xc(%rsp), %eax
movl %eax, 0xc(%rbx)
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rbx)
addq $0x38, %rsp
popq %rbx
popq %r14
retq
movq %rax, %rbx
movq 0x10(%r14), %rdi
testq %rdi, %rdi
je 0x23633
callq 0x7774
movq %rbx, %rdi
callq 0x66e0
nop