#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int tdFNoiseAt(float, float);
float tdPerlin2D(float x, float y) {
  int ndepth = 5;
  int depth;
  float ret = 0;
  for (depth = 0; depth < ndepth; depth++) {
    float nx = x / (1 << (ndepth - depth - 1));
    float ny = y / (1 << (ndepth - depth - 1));
    ret += tdFNoiseAt(nx, ny) / (1 << (depth + 1));
  }
  return ret;
}


x86 assembly (clang, -O0):
<tdPerlin2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movl   $0x5,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c5 <tdPerlin2D+0xb5>
movss  -0x4(%rbp),%xmm0
mov    -0xc(%rbp),%ecx
sub    -0x10(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
mov    -0xc(%rbp),%ecx
sub    -0x10(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x18(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm1
call   1030 <tdFNoiseAt@plt>
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1138 <tdPerlin2D+0x28>
movss  -0x14(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tdPerlin2D>:
sub    $0x18,%rsp
movaps %xmm1,%xmm2
movss  %xmm1,0x10(%rsp)
movss  %xmm0,0x14(%rsp)
movss  0xed5(%rip),%xmm1
mulss  %xmm1,%xmm0
mulss  %xmm2,%xmm1
call   1030 <tdFNoiseAt@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
movss  %xmm0,0xc(%rsp)
movss  0xeae(%rip),%xmm1
movss  0x14(%rsp),%xmm0
mulss  %xmm1,%xmm0
mulss  0x10(%rsp),%xmm1
call   1030 <tdFNoiseAt@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x2,%ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movss  0xe77(%rip),%xmm1
movss  0x14(%rsp),%xmm0
mulss  %xmm1,%xmm0
mulss  0x10(%rsp),%xmm1
call   1030 <tdFNoiseAt@plt>
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x3,%ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movss  0xe40(%rip),%xmm1
movss  0x14(%rsp),%xmm0
mulss  %xmm1,%xmm0
mulss  0x10(%rsp),%xmm1
call   1030 <tdFNoiseAt@plt>
lea    0xf(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x4,%ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x14(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
call   1030 <tdFNoiseAt@plt>
lea    0x1f(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x5,%ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
addss  0xc(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define float @tdPerlin2D(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
%8 = alloca float
%9 = alloca float
store float %0, float* %3
store float %1, float* %4
store i32 5, i32* %5
store float 0.000000e+00, float* %7
store i32 0, i32* %6
br label %10
10: ; preds = %41, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %44
14: ; preds = %10
%15 = load float, float* %3
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = sub nsw i32 %16, %17
%19 = sub nsw i32 %18, 1
%20 = shl i32 1, %19
%21 = sitofp i32 %20 to float
%22 = fdiv float %15, %21
store float %22, float* %8
%23 = load float, float* %4
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = sub nsw i32 %24, %25
%27 = sub nsw i32 %26, 1
%28 = shl i32 1, %27
%29 = sitofp i32 %28 to float
%30 = fdiv float %23, %29
store float %30, float* %9
%31 = load float, float* %8
%32 = load float, float* %9
%33 = call i32 @tdFNoiseAt(float %31, float %32)
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
%36 = shl i32 1, %35
%37 = sdiv i32 %33, %36
%38 = sitofp i32 %37 to float
%39 = load float, float* %7
%40 = fadd float %39, %38
store float %40, float* %7
br label %41
41: ; preds = %14
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %10
44: ; preds = %10
%45 = load float, float* %7
ret float %45
}

LLVM IR (-O2):
define float @tdPerlin2D(float %0, float %1) {
%3 = fmul float %0, 6.250000e-02
%4 = fmul float %1, 6.250000e-02
%5 = tail call i32 @tdFNoiseAt(float %3, float %4)
%6 = sdiv i32 %5, 2
%7 = sitofp i32 %6 to float
%8 = fmul float %0, 1.250000e-01
%9 = fmul float %1, 1.250000e-01
%10 = tail call i32 @tdFNoiseAt(float %8, float %9)
%11 = sdiv i32 %10, 4
%12 = sitofp i32 %11 to float
%13 = fadd float %7, %12
%14 = fmul float %0, 2.500000e-01
%15 = fmul float %1, 2.500000e-01
%16 = tail call i32 @tdFNoiseAt(float %14, float %15)
%17 = sdiv i32 %16, 8
%18 = sitofp i32 %17 to float
%19 = fadd float %13, %18
%20 = fmul float %0, 5.000000e-01
%21 = fmul float %1, 5.000000e-01
%22 = tail call i32 @tdFNoiseAt(float %20, float %21)
%23 = sdiv i32 %22, 16
%24 = sitofp i32 %23 to float
%25 = fadd float %19, %24
%26 = tail call i32 @tdFNoiseAt(float %0, float %1)
%27 = sdiv i32 %26, 32
%28 = sitofp i32 %27 to float
%29 = fadd float %25, %28
ret float %29
}