#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 /*<<< orphan*/ init_perlin(int);
double p_noise(double, double);
int /*<<< orphan*/ printf(char *, ...);
int test_perlin() {
  int i, j;
  double d, x, y;
  printf("\n### PERLIN NOISE TEST ###\n");
  init_perlin(false);
  for (i = 0; i < 10; i++) {
    for (j = 0; j < 10; j++) {
      x = ((double)i) + 0.5;
      y = ((double)j) + 0.5;
      d = p_noise(x, y);
      printf("noise: %lf\n", d);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_perlin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <init_perlin@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
jge    11e3 <test_perlin+0xb3>
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    11d0 <test_perlin+0xa0>
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xe84(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1040 <p_noise@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xe69(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1165 <test_perlin+0x35>
jmp    11d5 <test_perlin+0xa5>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1154 <test_perlin+0x24>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_perlin>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xf17(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <init_perlin@plt>
xorpd  %xmm0,%xmm0
mov    $0xa,%ebp
lea    0xeef(%rip),%rbx
nopl   0x0(%rax)
movsd  %xmm0,0x10(%rsp)
movsd  0xe82(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <p_noise@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xe63(%rip),%xmm1
call   1050 <p_noise@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xe4e(%rip),%xmm1
call   1050 <p_noise@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xe39(%rip),%xmm1
call   1050 <p_noise@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xe24(%rip),%xmm1
call   1050 <p_noise@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xe0f(%rip),%xmm1
call   1050 <p_noise@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xdfa(%rip),%xmm1
call   1050 <p_noise@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xde5(%rip),%xmm1
call   1050 <p_noise@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xdd0(%rip),%xmm1
call   1050 <p_noise@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xdbb(%rip),%xmm1
call   1050 <p_noise@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x10(%rsp),%xmm0
addsd  0xda6(%rip),%xmm0
add    $0xffffffff,%ebp
jne    1170 <test_perlin+0x30>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"\0A### PERLIN NOISE TEST ###\0A\00"
@.str.1 = [12 x i8] c"noise: %lf\0A\00"
define i32 @test_perlin() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @init_perlin(i32 0)
store i32 0, i32* %1
br label %8
8: ; preds = %31, %0
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 10
br i1 %10, label %11, label %34
11: ; preds = %8
store i32 0, i32* %2
br label %12
12: ; preds = %27, %11
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 10
br i1 %14, label %15, label %30
15: ; preds = %12
%16 = load i32, i32* %1
%17 = sitofp i32 %16 to double
%18 = fadd double %17, 5.000000e-01
store double %18, double* %4
%19 = load i32, i32* %2
%20 = sitofp i32 %19 to double
%21 = fadd double %20, 5.000000e-01
store double %21, double* %5
%22 = load double, double* %4
%23 = load double, double* %5
%24 = call double @p_noise(double %22, double %23)
store double %24, double* %3
%25 = load double, double* %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %25)
br label %27
27: ; preds = %15
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %12
30: ; preds = %12
br label %31
31: ; preds = %30
%32 = load i32, i32* %1
%33 = add nsw i32 %32, 1
store i32 %33, i32* %1
br label %8
34: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"noise: %lf\0A\00"
@str = [27 x i8] c"\0A### PERLIN NOISE TEST ###\00"
define i32 @test_perlin() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @init_perlin(i32 0)
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 0, %0 ], [ %27, %3 ]
%5 = sitofp i32 %4 to double
%6 = fadd double %5, 5.000000e-01
%7 = tail call double @p_noise(double %6, double 5.000000e-01)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %7)
%9 = tail call double @p_noise(double %6, double 1.500000e+00)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %9)
%11 = tail call double @p_noise(double %6, double 2.500000e+00)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %11)
%13 = tail call double @p_noise(double %6, double 3.500000e+00)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %13)
%15 = tail call double @p_noise(double %6, double 4.500000e+00)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %15)
%17 = tail call double @p_noise(double %6, double 5.500000e+00)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %17)
%19 = tail call double @p_noise(double %6, double 6.500000e+00)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %19)
%21 = tail call double @p_noise(double %6, double 7.500000e+00)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %21)
%23 = tail call double @p_noise(double %6, double 8.500000e+00)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %23)
%25 = tail call double @p_noise(double %6, double 9.500000e+00)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %25)
%27 = add nuw nsw i32 %4, 1
%28 = icmp eq i32 %27, 10
br i1 %28, label %29, label %3
29: ; preds = %3
ret i32 0
}