#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 noise3(double *);
double PerlinNoise3D(double x, double y, double z, double alpha, double beta,
                     int n) {
  int i;
  double val, sum = 0;
  double p[3], scale = 1;
  p[0] = x;
  p[1] = y;
  p[2] = z;
  for (i = 0; i < n; i++) {
    val = noise3(p);
    sum += val / scale;
    scale *= alpha;
    p[0] *= beta;
    p[1] *= beta;
    p[2] *= beta;
  }
  return (sum);
}


x86 assembly (clang, -O0):
<PerlinNoise3D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
mov    %edi,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11e6 <PerlinNoise3D+0xd6>
lea    -0x60(%rbp),%rdi
call   1030 <noise3@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
divsd  -0x68(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    116e <PerlinNoise3D+0x5e>
movsd  -0x40(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PerlinNoise3D>:
push   %r14
push   %rbx
sub    $0x58,%rsp
movaps %xmm4,0x30(%rsp)
movsd  %xmm0,(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
test   %edi,%edi
jle    11bb <PerlinNoise3D+0xab>
mov    %edi,%ebx
movapd 0x30(%rsp),%xmm0
unpcklpd %xmm0,%xmm0
movapd %xmm0,0x40(%rsp)
xorpd  %xmm1,%xmm1
movsd  0xead(%rip),%xmm2
mov    %rsp,%r14
movsd  %xmm3,0x18(%rsp)
nopl   0x0(%rax)
movsd  %xmm2,0x20(%rsp)
movsd  %xmm1,0x28(%rsp)
mov    %r14,%rdi
call   1030 <noise3@plt>
movsd  0x20(%rsp),%xmm2
movsd  0x28(%rsp),%xmm1
movsd  0x18(%rsp),%xmm3
divsd  %xmm2,%xmm0
addsd  %xmm0,%xmm1
mulsd  %xmm3,%xmm2
movapd (%rsp),%xmm0
mulpd  0x40(%rsp),%xmm0
movapd %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
add    $0xffffffff,%ebx
jne    1160 <PerlinNoise3D+0x50>
jmp    11bf <PerlinNoise3D+0xaf>
xorpd  %xmm1,%xmm1
movapd %xmm1,%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @PerlinNoise3D(double %0, double %1, double %2, double %3, double %4, i32 %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca [3 x double]
%17 = alloca double
store double %0, double* %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
store i32 %5, i32* %12
store double 0.000000e+00, double* %15
store double 1.000000e+00, double* %17
%18 = load double, double* %7
%19 = getelementptr inbounds [3 x double], [3 x double]* %16, i64 0, i64 0
store double %18, double* %19
%20 = load double, double* %8
%21 = getelementptr inbounds [3 x double], [3 x double]* %16, i64 0, i64 1
store double %20, double* %21
%22 = load double, double* %9
%23 = getelementptr inbounds [3 x double], [3 x double]* %16, i64 0, i64 2
store double %22, double* %23
store i32 0, i32* %13
br label %24
24: ; preds = %51, %6
%25 = load i32, i32* %13
%26 = load i32, i32* %12
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %54
28: ; preds = %24
%29 = getelementptr inbounds [3 x double], [3 x double]* %16, i64 0, i64 0
%30 = call double @noise3(double* %29)
store double %30, double* %14
%31 = load double, double* %14
%32 = load double, double* %17
%33 = fdiv double %31, %32
%34 = load double, double* %15
%35 = fadd double %34, %33
store double %35, double* %15
%36 = load double, double* %10
%37 = load double, double* %17
%38 = fmul double %37, %36
store double %38, double* %17
%39 = load double, double* %11
%40 = getelementptr inbounds [3 x double], [3 x double]* %16, i64 0, i64 0
%41 = load double, double* %40
%42 = fmul double %41, %39
store double %42, double* %40
%43 = load double, double* %11
%44 = getelementptr inbounds [3 x double], [3 x double]* %16, i64 0, i64 1
%45 = load double, double* %44
%46 = fmul double %45, %43
store double %46, double* %44
%47 = load double, double* %11
%48 = getelementptr inbounds [3 x double], [3 x double]* %16, i64 0, i64 2
%49 = load double, double* %48
%50 = fmul double %49, %47
store double %50, double* %48
br label %51
51: ; preds = %28
%52 = load i32, i32* %13
%53 = add nsw i32 %52, 1
store i32 %53, i32* %13
br label %24
54: ; preds = %24
%55 = load double, double* %15
ret double %55
}

LLVM IR (-O2):
define double @PerlinNoise3D(double %0, double %1, double %2, double %3, double %4, i32 %5) {
%7 = alloca [3 x double]
%8 = bitcast [3 x double]* %7 to i8*
%9 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
store double %0, double* %9
%10 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 1
store double %1, double* %10
%11 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 2
store double %2, double* %11
%12 = icmp sgt i32 %5, 0
br i1 %12, label %13, label %32
13: ; preds = %6
%14 = bitcast [3 x double]* %7 to <2 x double>*
%15 = insertelement <2 x double> poison, double %4, i64 0
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
%17 = bitcast [3 x double]* %7 to <2 x double>*
br label %18
18: ; preds = %13, %18
%19 = phi double [ %25, %18 ], [ 1.000000e+00, %13 ]
%20 = phi double [ %24, %18 ], [ 0.000000e+00, %13 ]
%21 = phi i32 [ %30, %18 ], [ 0, %13 ]
%22 = call double @noise3(double* %9)
%23 = fdiv double %22, %19
%24 = fadd double %20, %23
%25 = fmul double %19, %3
%26 = load <2 x double>, <2 x double>* %14
%27 = fmul <2 x double> %26, %16
store <2 x double> %27, <2 x double>* %17
%28 = load double, double* %11
%29 = fmul double %28, %4
store double %29, double* %11
%30 = add nuw nsw i32 %21, 1
%31 = icmp eq i32 %30, %5
br i1 %31, label %32, label %18
32: ; preds = %18, %6
%33 = phi double [ 0.000000e+00, %6 ], [ %24, %18 ]
ret double %33
}