// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movss %xmm0, 0xc(%rsp)
movq %rdi, %r14
leaq 0x2877f(%rip), %rax     # 0x47970
movq %rax, (%rdi)
addq $0x8, %rdi
callq 0x7666
leaq 0x24(%r14), %rbx
cvtss2sd 0xc(%rsp), %xmm0
mulsd 0x12151(%rip), %xmm0    # 0x31360
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
callq 0x6370
movss %xmm0, 0x18(%r14)
movss 0xc(%rsp), %xmm0
callq 0x6310
movss %xmm0, 0x1c(%r14)
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movss 0x10fc0(%rip), %xmm1    # 0x30204
xorps %xmm0, %xmm0
movq %rbx, %rsi
callq *0x8(%rax)
movb %al, 0x20(%r14)
movsd 0x12117(%rip), %xmm0    # 0x31370
movsd %xmm0, 0x38(%rsp)
movl $0x7f7fffff, 0x40(%rsp) # imm = 0x7F7FFFFF
movsd 0x12111(%rip), %xmm0    # 0x31380
movsd %xmm0, 0x28(%rsp)
movl $0xff7fffff, 0x30(%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 0x11069(%rip), %xmm8    # 0x30320
xorps %xmm6, %xmm8
xorl %eax, %eax
pushq $0x1
popq %rcx
cmpl $0x2, %eax
je 0x1f3bd
cvtsi2ss %eax, %xmm9
movl %ecx, %edx
subl %eax, %edx
cvtsi2ss %edx, %xmm10
mulss %xmm2, %xmm10
mulss %xmm0, %xmm9
addss %xmm10, %xmm9
xorl %edx, %edx
movaps %xmm7, %xmm10
mulss %xmm9, %xmm10
mulss %xmm8, %xmm9
cmpl $0x2, %edx
je 0x1f3b6
cvtsi2ss %edx, %xmm11
movl %ecx, %esi
subl %edx, %esi
cvtsi2ss %esi, %xmm12
mulss %xmm5, %xmm12
mulss %xmm4, %xmm11
addss %xmm12, %xmm11
xorl %esi, %esi
cmpl $0x2, %esi
je 0x1f3af
cvtsi2ss %esi, %xmm12
movl %ecx, %edi
subl %esi, %edi
cvtsi2ss %edi, %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, 0x10(%rsp)
movss %xmm11, 0x14(%rsp)
movss %xmm13, 0x18(%rsp)
xorl %edi, %edi
cmpq $0x3, %rdi
je 0x1f3a8
movss 0x10(%rsp,%rdi,4), %xmm12
ucomiss 0x28(%rsp,%rdi,4), %xmm12
jbe 0x1f38f
movss %xmm12, 0x28(%rsp,%rdi,4)
movss 0x38(%rsp,%rdi,4), %xmm13
ucomiss %xmm12, %xmm13
jbe 0x1f3a3
movss %xmm12, 0x38(%rsp,%rdi,4)
incq %rdi
jmp 0x1f373
incl %esi
jmp 0x1f31e
incl %edx
jmp 0x1f2f6
incl %eax
jmp 0x1f2c0
movl 0x40(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x1c(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x10(%rsp), %rax
movq %rax, (%rbx)
movl 0x18(%rsp), %eax
movl %eax, 0x8(%rbx)
movl 0x1c(%rsp), %eax
movl %eax, 0xc(%rbx)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r14
retq
movq %rax, %rbx
addq $0x10, %r14
movq %r14, %rdi
callq 0x7426
movq %rbx, %rdi
callq 0x6710
nop