// File: alan0201tw[P]RayTracer/src/perlin.cpp
// Function: perlin::get_noise(vec3 const&)
float perlin::get_noise(const vec3& _p)
{
    float u = _p.x() - std::floor(_p.x());
    float v = _p.y() - std::floor(_p.y());
    float w = _p.z() - std::floor(_p.z());
    int i = std::floor(_p.x());
    int j = std::floor(_p.y());
    int k = std::floor(_p.z());

    vec3 data[2][2][2];
    for(int di = 0; di < 2; di++)
    {
        for(int dj = 0; dj < 2; dj++)
        {
            for(int dk = 0; dk < 2; dk++)
            {
                data[di][dj][dk] = 
                    random_vecs[perm_x[(i + di) & 255] ^ perm_y[(j + dj) & 255] ^ perm_z[(k + dk) & 255]];
            }
        }
    }

    return perlin_interpolate(data, u, v, w);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8d70
movss %xmm0, -0xac(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8d70
callq 0x19320
movaps %xmm0, %xmm1
movss -0xac(%rbp), %xmm0
subss %xmm1, %xmm0
movss %xmm0, -0xc(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8d90
movss %xmm0, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8d90
callq 0x19320
movaps %xmm0, %xmm1
movss -0xa8(%rbp), %xmm0
subss %xmm1, %xmm0
movss %xmm0, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8db0
movss %xmm0, -0xa4(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8db0
callq 0x19320
movaps %xmm0, %xmm1
movss -0xa4(%rbp), %xmm0
subss %xmm1, %xmm0
movss %xmm0, -0x14(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8d70
callq 0x19320
cvttss2si %xmm0, %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8d90
callq 0x19320
cvttss2si %xmm0, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8db0
callq 0x19320
cvttss2si %xmm0, %eax
movl %eax, -0x20(%rbp)
leaq -0x80(%rbp), %rax
movq %rax, %rcx
addq $0x60, %rcx
movq %rcx, -0xa0(%rbp)
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x10660
movq -0xb8(%rbp), %rax
movq -0xa0(%rbp), %rcx
addq $0xc, %rax
cmpq %rcx, %rax
movq %rax, -0x98(%rbp)
jne 0x18de0
movl $0x0, -0x84(%rbp)
cmpl $0x2, -0x84(%rbp)
jge 0x18f5d
movl $0x0, -0x88(%rbp)
cmpl $0x2, -0x88(%rbp)
jge 0x18f47
movl $0x0, -0x8c(%rbp)
cmpl $0x2, -0x8c(%rbp)
jge 0x18f31
movl -0x18(%rbp), %eax
addl -0x84(%rbp), %eax
andl $0xff, %eax
movslq %eax, %rsi
leaq 0x97c62(%rip), %rdi     # 0xb0ad0
callq 0x19360
movl (%rax), %eax
movl %eax, -0xc0(%rbp)
movl -0x1c(%rbp), %eax
addl -0x88(%rbp), %eax
andl $0xff, %eax
movslq %eax, %rsi
leaq 0x97c55(%rip), %rdi     # 0xb0ae8
callq 0x19360
movq %rax, %rcx
movl -0xc0(%rbp), %eax
xorl (%rcx), %eax
movl %eax, -0xbc(%rbp)
movl -0x20(%rbp), %eax
addl -0x8c(%rbp), %eax
andl $0xff, %eax
movslq %eax, %rsi
leaq 0x97c3f(%rip), %rdi     # 0xb0b00
callq 0x19360
movq %rax, %rcx
movl -0xbc(%rbp), %eax
xorl (%rcx), %eax
movslq %eax, %rsi
leaq 0x97bdd(%rip), %rdi     # 0xb0ab8
callq 0x19340
movq %rax, %rcx
movslq -0x84(%rbp), %rdx
leaq -0x80(%rbp), %rax
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movslq -0x88(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movslq -0x8c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x18e49
jmp 0x18f33
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x18e32
jmp 0x18f49
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x18e1b
leaq -0x80(%rbp), %rdi
movss -0xc(%rbp), %xmm0
movss -0x10(%rbp), %xmm1
movss -0x14(%rbp), %xmm2
callq 0x24c80
addq $0xc0, %rsp
popq %rbp
retq
nop