#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 */
float interpolate(float, float, float);
float smooth_noise(int, int);
float noise_handler(float x, float y) {
  int int_val[2];
  float frac_val[2];
  float value[4];
  float res[2];
  int_val[0] = (int)x;
  int_val[1] = (int)y;
  frac_val[0] = x - int_val[0];
  frac_val[1] = y - int_val[1];
  value[0] = smooth_noise(int_val[0], int_val[1]);
  value[1] = smooth_noise(int_val[0] + 1, int_val[1]);
  value[2] = smooth_noise(int_val[0], int_val[1] + 1);
  value[3] = smooth_noise(int_val[0] + 1, int_val[1] + 1);
  res[0] = interpolate(value[0], value[1], frac_val[0]);
  res[1] = interpolate(value[2], value[3], frac_val[0]);
  return (interpolate(res[0], res[1], frac_val[1]));
}


x86 assembly (clang, -O0):
<noise_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
cvttss2si -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
cvttss2si -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movss  -0x4(%rbp),%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <smooth_noise@plt>
movss  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%edi
add    $0x1,%edi
mov    -0xc(%rbp),%esi
call   1030 <smooth_noise@plt>
movss  %xmm0,-0x2c(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
call   1030 <smooth_noise@plt>
movss  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%edi
add    $0x1,%edi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
call   1030 <smooth_noise@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x30(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm1
movss  -0x18(%rbp),%xmm2
call   1040 <interpolate@plt>
movss  %xmm0,-0x38(%rbp)
movss  -0x28(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
movss  -0x18(%rbp),%xmm2
call   1040 <interpolate@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0x38(%rbp),%xmm0
movss  -0x34(%rbp),%xmm1
movss  -0x14(%rbp),%xmm2
call   1040 <interpolate@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<noise_handler>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
cvttss2si %xmm0,%r14d
cvttss2si %xmm1,%ebx
cvttps2dq %xmm0,%xmm2
cvtdq2ps %xmm2,%xmm2
subss  %xmm2,%xmm0
movaps %xmm0,0x10(%rsp)
cvttps2dq %xmm1,%xmm0
cvtdq2ps %xmm0,%xmm0
subss  %xmm0,%xmm1
movaps %xmm1,0x20(%rsp)
mov    %r14d,%edi
mov    %ebx,%esi
call   1030 <smooth_noise@plt>
movss  %xmm0,(%rsp)
lea    0x1(%r14),%ebp
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <smooth_noise@plt>
movss  %xmm0,0xc(%rsp)
add    $0x1,%ebx
mov    %r14d,%edi
mov    %ebx,%esi
call   1030 <smooth_noise@plt>
movss  %xmm0,0x8(%rsp)
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <smooth_noise@plt>
movss  %xmm0,0x4(%rsp)
movss  (%rsp),%xmm0
movss  0xc(%rsp),%xmm1
movaps 0x10(%rsp),%xmm2
call   1040 <interpolate@plt>
movss  %xmm0,(%rsp)
movss  0x8(%rsp),%xmm0
movss  0x4(%rsp),%xmm1
movaps 0x10(%rsp),%xmm2
call   1040 <interpolate@plt>
movaps %xmm0,%xmm1
movss  (%rsp),%xmm0
movaps 0x20(%rsp),%xmm2
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <interpolate@plt>

LLVM IR (-O0):
define float @noise_handler(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca [2 x i32]
%6 = alloca [2 x float]
%7 = alloca [4 x float]
%8 = alloca [2 x float]
store float %0, float* %3
store float %1, float* %4
%9 = load float, float* %3
%10 = fptosi float %9 to i32
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
store i32 %10, i32* %11
%12 = load float, float* %4
%13 = fptosi float %12 to i32
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
store i32 %13, i32* %14
%15 = load float, float* %3
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%17 = load i32, i32* %16
%18 = sitofp i32 %17 to float
%19 = fsub float %15, %18
%20 = getelementptr inbounds [2 x float], [2 x float]* %6, i64 0, i64 0
store float %19, float* %20
%21 = load float, float* %4
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%23 = load i32, i32* %22
%24 = sitofp i32 %23 to float
%25 = fsub float %21, %24
%26 = getelementptr inbounds [2 x float], [2 x float]* %6, i64 0, i64 1
store float %25, float* %26
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call float @smooth_noise(i32 %28, i32 %30)
%32 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 0
store float %31, float* %32
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%37 = load i32, i32* %36
%38 = call float @smooth_noise(i32 %35, i32 %37)
%39 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 1
store float %38, float* %39
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%41 = load i32, i32* %40
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%43 = load i32, i32* %42
%44 = add nsw i32 %43, 1
%45 = call float @smooth_noise(i32 %41, i32 %44)
%46 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 2
store float %45, float* %46
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%48 = load i32, i32* %47
%49 = add nsw i32 %48, 1
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%51 = load i32, i32* %50
%52 = add nsw i32 %51, 1
%53 = call float @smooth_noise(i32 %49, i32 %52)
%54 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 3
store float %53, float* %54
%55 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 0
%56 = load float, float* %55
%57 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 1
%58 = load float, float* %57
%59 = getelementptr inbounds [2 x float], [2 x float]* %6, i64 0, i64 0
%60 = load float, float* %59
%61 = call float @interpolate(float %56, float %58, float %60)
%62 = getelementptr inbounds [2 x float], [2 x float]* %8, i64 0, i64 0
store float %61, float* %62
%63 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 2
%64 = load float, float* %63
%65 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 3
%66 = load float, float* %65
%67 = getelementptr inbounds [2 x float], [2 x float]* %6, i64 0, i64 0
%68 = load float, float* %67
%69 = call float @interpolate(float %64, float %66, float %68)
%70 = getelementptr inbounds [2 x float], [2 x float]* %8, i64 0, i64 1
store float %69, float* %70
%71 = getelementptr inbounds [2 x float], [2 x float]* %8, i64 0, i64 0
%72 = load float, float* %71
%73 = getelementptr inbounds [2 x float], [2 x float]* %8, i64 0, i64 1
%74 = load float, float* %73
%75 = getelementptr inbounds [2 x float], [2 x float]* %6, i64 0, i64 1
%76 = load float, float* %75
%77 = call float @interpolate(float %72, float %74, float %76)
ret float %77
}

LLVM IR (-O2):
define float @noise_handler(float %0, float %1) {
%3 = fptosi float %0 to i32
%4 = fptosi float %1 to i32
%5 = sitofp i32 %3 to float
%6 = fsub float %0, %5
%7 = sitofp i32 %4 to float
%8 = fsub float %1, %7
%9 = tail call float @smooth_noise(i32 %3, i32 %4)
%10 = add nsw i32 %3, 1
%11 = tail call float @smooth_noise(i32 %10, i32 %4)
%12 = add nsw i32 %4, 1
%13 = tail call float @smooth_noise(i32 %3, i32 %12)
%14 = tail call float @smooth_noise(i32 %10, i32 %12)
%15 = tail call float @interpolate(float %9, float %11, float %6)
%16 = tail call float @interpolate(float %13, float %14, float %6)
%17 = tail call float @interpolate(float %15, float %16, float %8)
ret float %17
}