#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 */
scalar_t__ fabs(float);
float sxnoise_2d(float, float, int /*<<< orphan*/);
float fractal_sxnoise_2d(float x, float y, int octaves, float frequency_ratio,
                         float persistence, float offset_x, float offset_y) {
  int oct;
  float n = 0;
  float power = 0;
  float scale = 1.0;
  float amplitude = 1.0;
  float orix = 0.0;
  float oriy = 0.0;
  for (oct = 0; oct < octaves; ++oct) {
    orix += offset_x;
    oriy += offset_y;
    scale *= frequency_ratio;
    amplitude *= persistence;
    float tx = (x - orix) * scale;
    float ty = (y - oriy) * scale;
    n += amplitude * sxnoise_2d(tx, ty, 0);
    power += fabs(amplitude);
  }
  return n / power;
}


x86 assembly (clang, -O0):
<fractal_sxnoise_2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
movss  %xmm3,-0x14(%rbp)
movss  %xmm4,-0x18(%rbp)
movss  %xmm5,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  0xe9f(%rip),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  0xe92(%rip),%xmm0
movss  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x38(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1256 <fractal_sxnoise_2d+0x136>
movss  -0x18(%rbp),%xmm0
addss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x1c(%rbp),%xmm0
addss  -0x38(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x10(%rbp),%xmm0
mulss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x4(%rbp),%xmm0
subss  -0x34(%rbp),%xmm0
mulss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x8(%rbp),%xmm0
subss  -0x38(%rbp),%xmm0
mulss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x3c(%rbp),%xmm0
movss  -0x40(%rbp),%xmm1
xor    %edi,%edi
call   1030 <sxnoise_2d@plt>
movaps %xmm0,%xmm2
movss  -0x44(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x30(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2ss %rax,%xmm0
addss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118a <fractal_sxnoise_2d+0x6a>
movss  -0x24(%rbp),%xmm0
divss  -0x28(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fractal_sxnoise_2d>:
push   %rbx
sub    $0x30,%rsp
test   %edi,%edi
jle    1256 <fractal_sxnoise_2d+0x136>
mov    %edi,%ebx
movaps %xmm0,%xmm9
movss  0xec8(%rip),%xmm8
xorps  %xmm0,%xmm0
movss  %xmm0,(%rsp)
xorps  %xmm10,%xmm10
xorps  %xmm6,%xmm6
movss  %xmm8,0x4(%rsp)
movaps %xmm8,%xmm7
xorps  %xmm8,%xmm8
movss  %xmm5,0x1c(%rsp)
movss  %xmm4,0x18(%rsp)
movss  %xmm3,0x14(%rsp)
movss  %xmm2,0x10(%rsp)
movss  %xmm1,0xc(%rsp)
movss  %xmm9,0x8(%rsp)
nop
movss  %xmm8,0x24(%rsp)
addss  %xmm4,%xmm6
movss  %xmm6,0x28(%rsp)
addss  %xmm5,%xmm10
movss  %xmm10,0x2c(%rsp)
mulss  %xmm2,%xmm7
movss  %xmm7,0x20(%rsp)
movss  0x4(%rsp),%xmm0
mulss  %xmm3,%xmm0
movss  %xmm0,0x4(%rsp)
subss  %xmm6,%xmm9
mulss  %xmm7,%xmm9
movss  0xc(%rsp),%xmm1
subss  %xmm10,%xmm1
mulss  %xmm7,%xmm1
movaps %xmm9,%xmm0
xor    %edi,%edi
call   1030 <sxnoise_2d@plt>
movss  0x4(%rsp),%xmm2
mulss  %xmm2,%xmm0
movss  (%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
movaps %xmm2,%xmm0
call   1040 <fabs@plt>
movss  0x20(%rsp),%xmm7
movss  0x24(%rsp),%xmm8
movss  0x28(%rsp),%xmm6
movss  0x2c(%rsp),%xmm10
movss  0x8(%rsp),%xmm9
movss  0x10(%rsp),%xmm2
movss  0x14(%rsp),%xmm3
movss  0x18(%rsp),%xmm4
movss  0x1c(%rsp),%xmm5
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm8
add    $0xffffffff,%ebx
jne    1180 <fractal_sxnoise_2d+0x60>
movss  (%rsp),%xmm0
divss  %xmm8,%xmm0
jmp    125e <fractal_sxnoise_2d+0x13e>
movss  0xda2(%rip),%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define float @fractal_sxnoise_2d(float %0, float %1, i32 %2, float %3, float %4, float %5, float %6) {
%8 = alloca float
%9 = alloca float
%10 = alloca i32
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca i32
%16 = alloca float
%17 = alloca float
%18 = alloca float
%19 = alloca float
%20 = alloca float
%21 = alloca float
%22 = alloca float
%23 = alloca float
store float %0, float* %8
store float %1, float* %9
store i32 %2, i32* %10
store float %3, float* %11
store float %4, float* %12
store float %5, float* %13
store float %6, float* %14
store float 0.000000e+00, float* %16
store float 0.000000e+00, float* %17
store float 1.000000e+00, float* %18
store float 1.000000e+00, float* %19
store float 0.000000e+00, float* %20
store float 0.000000e+00, float* %21
store i32 0, i32* %15
br label %24
24: ; preds = %62, %7
%25 = load i32, i32* %15
%26 = load i32, i32* %10
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %65
28: ; preds = %24
%29 = load float, float* %13
%30 = load float, float* %20
%31 = fadd float %30, %29
store float %31, float* %20
%32 = load float, float* %14
%33 = load float, float* %21
%34 = fadd float %33, %32
store float %34, float* %21
%35 = load float, float* %11
%36 = load float, float* %18
%37 = fmul float %36, %35
store float %37, float* %18
%38 = load float, float* %12
%39 = load float, float* %19
%40 = fmul float %39, %38
store float %40, float* %19
%41 = load float, float* %8
%42 = load float, float* %20
%43 = fsub float %41, %42
%44 = load float, float* %18
%45 = fmul float %43, %44
store float %45, float* %22
%46 = load float, float* %9
%47 = load float, float* %21
%48 = fsub float %46, %47
%49 = load float, float* %18
%50 = fmul float %48, %49
store float %50, float* %23
%51 = load float, float* %19
%52 = load float, float* %22
%53 = load float, float* %23
%54 = call float @sxnoise_2d(float %52, float %53, i32 0)
%55 = load float, float* %16
%56 = call float @llvm.fmuladd.f32(float %51, float %54, float %55)
store float %56, float* %16
%57 = load float, float* %19
%58 = call i64 @fabs(float %57)
%59 = sitofp i64 %58 to float
%60 = load float, float* %17
%61 = fadd float %60, %59
store float %61, float* %17
br label %62
62: ; preds = %28
%63 = load i32, i32* %15
%64 = add nsw i32 %63, 1
store i32 %64, i32* %15
br label %24
65: ; preds = %24
%66 = load float, float* %16
%67 = load float, float* %17
%68 = fdiv float %66, %67
ret float %68
}

LLVM IR (-O2):
define float @fractal_sxnoise_2d(float %0, float %1, i32 %2, float %3, float %4, float %5, float %6) {
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %34
9: ; preds = %7, %9
%10 = phi i32 [ %30, %9 ], [ 0, %7 ]
%11 = phi float [ %26, %9 ], [ 0.000000e+00, %7 ]
%12 = phi float [ %18, %9 ], [ 0.000000e+00, %7 ]
%13 = phi float [ %17, %9 ], [ 0.000000e+00, %7 ]
%14 = phi float [ %20, %9 ], [ 1.000000e+00, %7 ]
%15 = phi float [ %19, %9 ], [ 1.000000e+00, %7 ]
%16 = phi float [ %29, %9 ], [ 0.000000e+00, %7 ]
%17 = fadd float %13, %5
%18 = fadd float %12, %6
%19 = fmul float %15, %3
%20 = fmul float %14, %4
%21 = fsub float %0, %17
%22 = fmul float %19, %21
%23 = fsub float %1, %18
%24 = fmul float %19, %23
%25 = tail call float @sxnoise_2d(float %22, float %24, i32 0)
%26 = tail call float @llvm.fmuladd.f32(float %20, float %25, float %11)
%27 = tail call i64 @fabs(float %20)
%28 = sitofp i64 %27 to float
%29 = fadd float %16, %28
%30 = add nuw nsw i32 %10, 1
%31 = icmp eq i32 %30, %2
br i1 %31, label %32, label %9
32: ; preds = %9
%33 = fdiv float %26, %29
br label %34
34: ; preds = %32, %7
%35 = phi float [ %33, %32 ], [ 0x7FF8000000000000, %7 ]
ret float %35
}