#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 */
double noise1(double);
double PerlinNoise1D(double x, double alpha, double beta, int n) {
  int i;
  double val, sum = 0;
  double p, scale = 1;
  p = x;
  for (i = 0; i < n; i++) {
    val = noise1(p);
    sum += val / scale;
    scale *= alpha;
    p *= beta;
  }
  return (sum);
}


x86 assembly (clang, -O0):
<PerlinNoise1D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xec6(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ab <PerlinNoise1D+0x9b>
movsd  -0x38(%rbp),%xmm0
call   1030 <noise1@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1150 <PerlinNoise1D+0x40>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PerlinNoise1D>:
push   %rbx
sub    $0x30,%rsp
test   %edi,%edi
jle    119c <PerlinNoise1D+0x8c>
mov    %edi,%ebx
movapd %xmm0,%xmm3
xorpd  %xmm0,%xmm0
movsd  0xed1(%rip),%xmm4
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
nopl   0x0(%rax,%rax,1)
movsd  %xmm4,0x20(%rsp)
movsd  %xmm3,0x28(%rsp)
movsd  %xmm0,0x8(%rsp)
movapd %xmm3,%xmm0
call   1030 <noise1@plt>
movsd  0x20(%rsp),%xmm4
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
divsd  %xmm4,%xmm0
movsd  0x8(%rsp),%xmm3
addsd  %xmm0,%xmm3
movsd  %xmm3,0x8(%rsp)
movsd  0x28(%rsp),%xmm3
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm4
mulsd  %xmm2,%xmm3
add    $0xffffffff,%ebx
jne    1140 <PerlinNoise1D+0x30>
jmp    11a0 <PerlinNoise1D+0x90>
xorpd  %xmm0,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @PerlinNoise1D(double %0, double %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store i32 %3, i32* %8
store double 0.000000e+00, double* %11
store double 1.000000e+00, double* %13
%14 = load double, double* %5
store double %14, double* %12
store i32 0, i32* %9
br label %15
15: ; preds = %33, %4
%16 = load i32, i32* %9
%17 = load i32, i32* %8
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = load double, double* %12
%21 = call double @noise1(double %20)
store double %21, double* %10
%22 = load double, double* %10
%23 = load double, double* %13
%24 = fdiv double %22, %23
%25 = load double, double* %11
%26 = fadd double %25, %24
store double %26, double* %11
%27 = load double, double* %6
%28 = load double, double* %13
%29 = fmul double %28, %27
store double %29, double* %13
%30 = load double, double* %7
%31 = load double, double* %12
%32 = fmul double %31, %30
store double %32, double* %12
br label %33
33: ; preds = %19
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %15
36: ; preds = %15
%37 = load double, double* %11
ret double %37
}

LLVM IR (-O2):
define double @PerlinNoise1D(double %0, double %1, double %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %18
6: ; preds = %4, %6
%7 = phi double [ %14, %6 ], [ 1.000000e+00, %4 ]
%8 = phi double [ %15, %6 ], [ %0, %4 ]
%9 = phi double [ %13, %6 ], [ 0.000000e+00, %4 ]
%10 = phi i32 [ %16, %6 ], [ 0, %4 ]
%11 = tail call double @noise1(double %8)
%12 = fdiv double %11, %7
%13 = fadd double %9, %12
%14 = fmul double %7, %1
%15 = fmul double %8, %2
%16 = add nuw nsw i32 %10, 1
%17 = icmp eq i32 %16, %3
br i1 %17, label %18, label %6
18: ; preds = %6, %4
%19 = phi double [ 0.000000e+00, %4 ], [ %13, %6 ]
ret double %19
}