#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 sqrt(int);
float perlin2D(float x, float y, float res) {
  float tempX, tempY;
  int x0, y0, ii, jj, gi0, gi1, gi2, gi3;
  float unit = 1.0f / sqrt(2);
  float tmp, s, t, u, v, Cx, Cy, Li1, Li2;
  float gradient2[][2] = {{unit, unit},   {-unit, unit}, {unit, -unit},
                          {-unit, -unit}, {1, 0},        {-1, 0},
                          {0, 1},         {0, -1}};
  unsigned int perm[] = {
      151, 160, 137, 91,  90,  15,  131, 13,  201, 95,  96,  53,  194, 233, 7,
      225, 140, 36,  103, 30,  69,  142, 8,   99,  37,  240, 21,  10,  23,  190,
      6,   148, 247, 120, 234, 75,  0,   26,  197, 62,  94,  252, 219, 203, 117,
      35,  11,  32,  57,  177, 33,  88,  237, 149, 56,  87,  174, 20,  125, 136,
      171, 168, 68,  175, 74,  165, 71,  134, 139, 48,  27,  166, 77,  146, 158,
      231, 83,  111, 229, 122, 60,  211, 133, 230, 220, 105, 92,  41,  55,  46,
      245, 40,  244, 102, 143, 54,  65,  25,  63,  161, 1,   216, 80,  73,  209,
      76,  132, 187, 208, 89,  18,  169, 200, 196, 135, 130, 116, 188, 159, 86,
      164, 100, 109, 198, 173, 186, 3,   64,  52,  217, 226, 250, 124, 123, 5,
      202, 38,  147, 118, 126, 255, 82,  85,  212, 207, 206, 59,  227, 47,  16,
      58,  17,  182, 189, 28,  42,  223, 183, 170, 213, 119, 248, 152, 2,   44,
      154, 163, 70,  221, 153, 101, 155, 167, 43,  172, 9,   129, 22,  39,  253,
      19,  98,  108, 110, 79,  113, 224, 232, 178, 185, 112, 104, 218, 246, 97,
      228, 251, 34,  242, 193, 238, 210, 144, 12,  191, 179, 162, 241, 81,  51,
      145, 235, 249, 14,  239, 107, 49,  192, 214, 31,  181, 199, 106, 157, 184,
      84,  204, 176, 115, 121, 50,  45,  127, 4,   150, 254, 138, 236, 205, 93,
      222, 114, 67,  29,  24,  72,  243, 141, 128, 195, 78,  66,  215, 61,  156,
      180};
  x /= res;
  y /= res;
  x0 = (int)(x);
  y0 = (int)(y);
  ii = x0 & 255;
  jj = y0 & 255;
  gi0 = perm[ii + perm[jj]] % 8;
  gi1 = perm[ii + 1 + perm[jj]] % 8;
  gi2 = perm[ii + perm[jj + 1]] % 8;
  gi3 = perm[ii + 1 + perm[jj + 1]] % 8;
  tempX = x - x0;
  tempY = y - y0;
  s = gradient2[gi0][0] * tempX + gradient2[gi0][1] * tempY;
  tempX = x - (x0 + 1);
  tempY = y - y0;
  t = gradient2[gi1][0] * tempX + gradient2[gi1][1] * tempY;
  tempX = x - x0;
  tempY = y - (y0 + 1);
  u = gradient2[gi2][0] * tempX + gradient2[gi2][1] * tempY;
  tempX = x - (x0 + 1);
  tempY = y - (y0 + 1);
  v = gradient2[gi3][0] * tempX + gradient2[gi3][1] * tempY;
  tmp = x - x0;
  Cx = 3 * tmp * tmp - 2 * tmp * tmp * tmp;
  Li1 = s + Cx * (t - s);
  Li2 = u + Cx * (v - u);
  tmp = y - y0;
  Cy = 3 * tmp * tmp - 2 * tmp * tmp * tmp;
  return (Li1 + Cy * (Li2 - Li1) + 1.) / 2.;
}


x86 assembly (clang, -O0):
<perlin2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
mov    $0x2,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movss  0xecd(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x38(%rbp),%xmm0
movss  %xmm0,-0xa0(%rbp)
ff
movss  -0x38(%rbp),%xmm0
movss  %xmm0,-0x9c(%rbp)
ff
movss  -0x38(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x98(%rbp)
ff
movss  -0x38(%rbp),%xmm0
movss  %xmm0,-0x94(%rbp)
ff
movss  -0x38(%rbp),%xmm0
movss  %xmm0,-0x90(%rbp)
ff
movss  -0x38(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x8c(%rbp)
ff
movss  -0x38(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x88(%rbp)
ff
movss  -0x38(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x84(%rbp)
ff
movss  0xe20(%rip),%xmm0
movss  %xmm0,-0x80(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x7c(%rbp)
movss  0xe07(%rip),%xmm0
movss  %xmm0,-0x78(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x74(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x70(%rbp)
movss  0xdee(%rip),%xmm0
movss  %xmm0,-0x6c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x68(%rbp)
movss  0xdd5(%rip),%xmm0
movss  %xmm0,-0x64(%rbp)
lea    -0x4a0(%rbp),%rdi
lea    0xdca(%rip),%rsi
mov    $0x400,%edx
call   1030 <memcpy@plt>
movss  -0xc(%rbp),%xmm1
movss  -0x4(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0xc(%rbp),%xmm1
movss  -0x8(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
cvttss2si -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
cvttss2si -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
movslq -0x24(%rbp),%rcx
add    -0x4a0(%rbp,%rcx,4),%eax
mov    %eax,%eax
mov    -0x4a0(%rbp,%rax,4),%eax
and    $0x7,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
movslq -0x24(%rbp),%rcx
add    -0x4a0(%rbp,%rcx,4),%eax
mov    %eax,%eax
mov    -0x4a0(%rbp,%rax,4),%eax
and    $0x7,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    -0x4a0(%rbp,%rcx,4),%eax
mov    %eax,%eax
mov    -0x4a0(%rbp,%rax,4),%eax
and    $0x7,%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    -0x4a0(%rbp,%rcx,4),%eax
mov    %eax,%eax
mov    -0x4a0(%rbp,%rax,4),%eax
and    $0x7,%eax
mov    %eax,-0x34(%rbp)
movss  -0x4(%rbp),%xmm0
cvtsi2ssl -0x18(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
cvtsi2ssl -0x1c(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movslq -0x28(%rbp),%rax
movss  -0xa0(%rbp,%rax,8),%xmm0
ff ff
movss  -0x10(%rbp),%xmm2
movslq -0x28(%rbp),%rax
movss  -0x9c(%rbp,%rax,8),%xmm1
ff ff
mulss  -0x14(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x4(%rbp),%xmm0
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
cvtsi2ssl -0x1c(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movslq -0x2c(%rbp),%rax
movss  -0xa0(%rbp,%rax,8),%xmm0
ff ff
movss  -0x10(%rbp),%xmm2
movslq -0x2c(%rbp),%rax
movss  -0x9c(%rbp,%rax,8),%xmm1
ff ff
mulss  -0x14(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x4(%rbp),%xmm0
cvtsi2ssl -0x18(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movslq -0x30(%rbp),%rax
movss  -0xa0(%rbp,%rax,8),%xmm0
ff ff
movss  -0x10(%rbp),%xmm2
movslq -0x30(%rbp),%rax
movss  -0x9c(%rbp,%rax,8),%xmm1
ff ff
mulss  -0x14(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x4(%rbp),%xmm0
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movslq -0x34(%rbp),%rax
movss  -0xa0(%rbp,%rax,8),%xmm0
ff ff
movss  -0x10(%rbp),%xmm2
movslq -0x34(%rbp),%rax
movss  -0x9c(%rbp,%rax,8),%xmm1
ff ff
mulss  -0x14(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x4(%rbp),%xmm0
cvtsi2ssl -0x18(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  0xb59(%rip),%xmm0
mulss  -0x3c(%rbp),%xmm0
movss  -0x3c(%rbp),%xmm2
movss  0xb43(%rip),%xmm1
mulss  -0x3c(%rbp),%xmm1
mulss  -0x3c(%rbp),%xmm1
mulss  -0x3c(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x50(%rbp)
movss  -0x40(%rbp),%xmm1
movss  -0x50(%rbp),%xmm0
movss  -0x44(%rbp),%xmm2
subss  -0x40(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x58(%rbp)
movss  -0x48(%rbp),%xmm1
movss  -0x50(%rbp),%xmm0
movss  -0x4c(%rbp),%xmm2
subss  -0x48(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x5c(%rbp)
movss  -0x8(%rbp),%xmm0
cvtsi2ssl -0x1c(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  0xac1(%rip),%xmm0
mulss  -0x3c(%rbp),%xmm0
movss  -0x3c(%rbp),%xmm2
movss  0xaab(%rip),%xmm1
mulss  -0x3c(%rbp),%xmm1
mulss  -0x3c(%rbp),%xmm1
mulss  -0x3c(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x54(%rbp)
movss  -0x58(%rbp),%xmm1
movss  -0x54(%rbp),%xmm0
movss  -0x5c(%rbp),%xmm2
subss  -0x58(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xa52(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xa3e(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x4a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perlin2D>:
sub    $0x78,%rsp
movss  %xmm2,0xc(%rsp)
movaps %xmm1,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
mov    $0x2,%edi
call   1030 <sqrt@plt>
movss  0xeca(%rip),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x10(%rsp)
movss  %xmm1,0x14(%rsp)
movaps 0xec3(%rip),%xmm0
xorps  %xmm1,%xmm0
movss  %xmm0,0x18(%rsp)
movss  %xmm1,0x1c(%rsp)
movss  %xmm1,0x20(%rsp)
movss  %xmm0,0x24(%rsp)
movss  %xmm0,0x28(%rsp)
movss  %xmm0,0x2c(%rsp)
movaps 0xea5(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xea9(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0x50(%rsp),%xmm9
movss  0xc(%rsp),%xmm0
divss  %xmm0,%xmm9
movaps 0x60(%rsp),%xmm8
divss  %xmm0,%xmm8
cvttss2si %xmm9,%edi
cvttss2si %xmm8,%edx
movzbl %dil,%ecx
movzbl %dl,%esi
lea    0xe90(%rip),%r10
mov    (%r10,%rsi,4),%eax
mov    0x4(%r10,%rsi,4),%r9d
lea    (%rax,%rcx,1),%esi
mov    (%r10,%rsi,4),%esi
and    $0x7,%esi
add    %ecx,%eax
add    $0x1,%eax
mov    (%r10,%rax,4),%r8d
and    $0x7,%r8d
lea    (%r9,%rcx,1),%eax
add    $0x1,%eax
add    %r9d,%ecx
mov    (%r10,%rcx,4),%ecx
and    $0x7,%ecx
mov    (%r10,%rax,4),%eax
and    $0x7,%eax
cvttps2dq %xmm9,%xmm0
add    $0x1,%edi
xorps  %xmm1,%xmm1
cvtsi2ss %edi,%xmm1
cvtdq2ps %xmm0,%xmm2
movaps %xmm9,%xmm0
subss  %xmm2,%xmm0
subss  %xmm1,%xmm9
movd   %edx,%xmm1
add    $0x1,%edx
movd   %edx,%xmm2
punpckldq %xmm1,%xmm2
cvtdq2ps %xmm2,%xmm1
shufps $0x0,%xmm8,%xmm8
subps  %xmm1,%xmm8
movss  0x10(%rsp,%rsi,8),%xmm1
movss  0x14(%rsp,%rsi,8),%xmm3
movss  0x10(%rsp,%rcx,8),%xmm2
unpcklps %xmm1,%xmm2
movss  0x14(%rsp,%rcx,8),%xmm4
unpcklps %xmm3,%xmm4
mulps  %xmm8,%xmm4
movss  0xda8(%rip),%xmm3
movaps %xmm0,%xmm1
mulss  %xmm3,%xmm1
movss  0xd9d(%rip),%xmm5
movaps %xmm0,%xmm6
mulss  %xmm5,%xmm6
mulss  %xmm0,%xmm6
mulss  %xmm0,%xmm6
mulss  %xmm0,%xmm1
shufps $0x0,%xmm0,%xmm0
mulps  %xmm2,%xmm0
addps  %xmm4,%xmm0
movss  0x10(%rsp,%r8,8),%xmm2
movss  0x14(%rsp,%r8,8),%xmm4
movss  0x10(%rsp,%rax,8),%xmm7
unpcklps %xmm2,%xmm7
movss  0x14(%rsp,%rax,8),%xmm2
unpcklps %xmm4,%xmm2
movaps %xmm9,%xmm4
shufps $0x0,%xmm9,%xmm4
mulps  %xmm7,%xmm4
mulps  %xmm8,%xmm2
addps  %xmm2,%xmm4
addss  %xmm6,%xmm1
subps  %xmm0,%xmm4
shufps $0x0,%xmm1,%xmm1
mulps  %xmm4,%xmm1
addps  %xmm0,%xmm1
movaps %xmm8,%xmm0
shufps $0x55,%xmm8,%xmm0
mulss  %xmm0,%xmm3
mulss  %xmm0,%xmm5
mulss  %xmm0,%xmm5
mulss  %xmm0,%xmm5
mulss  %xmm0,%xmm3
addss  %xmm5,%xmm3
movaps %xmm1,%xmm0
shufps $0x55,%xmm1,%xmm0
subss  %xmm0,%xmm1
mulss  %xmm3,%xmm1
addss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
addsd  0xd31(%rip),%xmm0
mulsd  0xd31(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x78,%rsp
ret

LLVM IR (-O0):
@__const.perlin2D.perm = [256 x i32] [i32 151, i32 160, i32 137, i32 91, i32 90, i32 15, i32 131, i32 13, i32 201, i32 95, i32 96, i32 53, i32 194, i32 233, i32 7, i32 225, i32 140, i32 36, i32 103, i32 30, i32 69, i32 142, i32 8, i32 99, i32 37, i32 240, i32 21, i32 10, i32 23, i32 190, i32 6, i32 148, i32 247, i32 120, i32 234, i32 75, i32 0, i32 26, i32 197, i32 62, i32 94, i32 252, i32 219, i32 203, i32 117, i32 35, i32 11, i32 32, i32 57, i32 177, i32 33, i32 88, i32 237, i32 149, i32 56, i32 87, i32 174, i32 20, i32 125, i32 136, i32 171, i32 168, i32 68, i32 175, i32 74, i32 165, i32 71, i32 134, i32 139, i32 48, i32 27, i32 166, i32 77, i32 146, i32 158, i32 231, i32 83, i32 111, i32 229, i32 122, i32 60, i32 211, i32 133, i32 230, i32 220, i32 105, i32 92, i32 41, i32 55, i32 46, i32 245, i32 40, i32 244, i32 102, i32 143, i32 54, i32 65, i32 25, i32 63, i32 161, i32 1, i32 216, i32 80, i32 73, i32 209, i32 76, i32 132, i32 187, i32 208, i32 89, i32 18, i32 169, i32 200, i32 196, i32 135, i32 130, i32 116, i32 188, i32 159, i32 86, i32 164, i32 100, i32 109, i32 198, i32 173, i32 186, i32 3, i32 64, i32 52, i32 217, i32 226, i32 250, i32 124, i32 123, i32 5, i32 202, i32 38, i32 147, i32 118, i32 126, i32 255, i32 82, i32 85, i32 212, i32 207, i32 206, i32 59, i32 227, i32 47, i32 16, i32 58, i32 17, i32 182, i32 189, i32 28, i32 42, i32 223, i32 183, i32 170, i32 213, i32 119, i32 248, i32 152, i32 2, i32 44, i32 154, i32 163, i32 70, i32 221, i32 153, i32 101, i32 155, i32 167, i32 43, i32 172, i32 9, i32 129, i32 22, i32 39, i32 253, i32 19, i32 98, i32 108, i32 110, i32 79, i32 113, i32 224, i32 232, i32 178, i32 185, i32 112, i32 104, i32 218, i32 246, i32 97, i32 228, i32 251, i32 34, i32 242, i32 193, i32 238, i32 210, i32 144, i32 12, i32 191, i32 179, i32 162, i32 241, i32 81, i32 51, i32 145, i32 235, i32 249, i32 14, i32 239, i32 107, i32 49, i32 192, i32 214, i32 31, i32 181, i32 199, i32 106, i32 157, i32 184, i32 84, i32 204, i32 176, i32 115, i32 121, i32 50, i32 45, i32 127, i32 4, i32 150, i32 254, i32 138, i32 236, i32 205, i32 93, i32 222, i32 114, i32 67, i32 29, i32 24, i32 72, i32 243, i32 141, i32 128, i32 195, i32 78, i32 66, i32 215, i32 61, i32 156, i32 180]
define float @perlin2D(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca float
%18 = alloca float
%19 = alloca float
%20 = alloca float
%21 = alloca float
%22 = alloca float
%23 = alloca float
%24 = alloca float
%25 = alloca float
%26 = alloca float
%27 = alloca [8 x [2 x float]]
%28 = alloca [256 x i32]
store float %0, float* %4
store float %1, float* %5
store float %2, float* %6
%29 = call float @sqrt(i32 2)
%30 = fdiv float 1.000000e+00, %29
store float %30, float* %17
%31 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %27, i64 0, i64 0
%32 = getelementptr inbounds [2 x float], [2 x float]* %31, i64 0, i64 0
%33 = load float, float* %17
store float %33, float* %32
%34 = getelementptr inbounds float, float* %32, i64 1
%35 = load float, float* %17
store float %35, float* %34
%36 = getelementptr inbounds [2 x float], [2 x float]* %31, i64 1
%37 = getelementptr inbounds [2 x float], [2 x float]* %36, i64 0, i64 0
%38 = load float, float* %17
%39 = fneg float %38
store float %39, float* %37
%40 = getelementptr inbounds float, float* %37, i64 1
%41 = load float, float* %17
store float %41, float* %40
%42 = getelementptr inbounds [2 x float], [2 x float]* %36, i64 1
%43 = getelementptr inbounds [2 x float], [2 x float]* %42, i64 0, i64 0
%44 = load float, float* %17
store float %44, float* %43
%45 = getelementptr inbounds float, float* %43, i64 1
%46 = load float, float* %17
%47 = fneg float %46
store float %47, float* %45
%48 = getelementptr inbounds [2 x float], [2 x float]* %42, i64 1
%49 = getelementptr inbounds [2 x float], [2 x float]* %48, i64 0, i64 0
%50 = load float, float* %17
%51 = fneg float %50
store float %51, float* %49
%52 = getelementptr inbounds float, float* %49, i64 1
%53 = load float, float* %17
%54 = fneg float %53
store float %54, float* %52
%55 = getelementptr inbounds [2 x float], [2 x float]* %48, i64 1
%56 = getelementptr inbounds [2 x float], [2 x float]* %55, i64 0, i64 0
store float 1.000000e+00, float* %56
%57 = getelementptr inbounds float, float* %56, i64 1
store float 0.000000e+00, float* %57
%58 = getelementptr inbounds [2 x float], [2 x float]* %55, i64 1
%59 = getelementptr inbounds [2 x float], [2 x float]* %58, i64 0, i64 0
store float -1.000000e+00, float* %59
%60 = getelementptr inbounds float, float* %59, i64 1
store float 0.000000e+00, float* %60
%61 = getelementptr inbounds [2 x float], [2 x float]* %58, i64 1
%62 = getelementptr inbounds [2 x float], [2 x float]* %61, i64 0, i64 0
store float 0.000000e+00, float* %62
%63 = getelementptr inbounds float, float* %62, i64 1
store float 1.000000e+00, float* %63
%64 = getelementptr inbounds [2 x float], [2 x float]* %61, i64 1
%65 = getelementptr inbounds [2 x float], [2 x float]* %64, i64 0, i64 0
store float 0.000000e+00, float* %65
%66 = getelementptr inbounds float, float* %65, i64 1
store float -1.000000e+00, float* %66
%67 = bitcast [256 x i32]* %28 to i8*
%68 = load float, float* %6
%69 = load float, float* %4
%70 = fdiv float %69, %68
store float %70, float* %4
%71 = load float, float* %6
%72 = load float, float* %5
%73 = fdiv float %72, %71
store float %73, float* %5
%74 = load float, float* %4
%75 = fptosi float %74 to i32
store i32 %75, i32* %9
%76 = load float, float* %5
%77 = fptosi float %76 to i32
store i32 %77, i32* %10
%78 = load i32, i32* %9
%79 = and i32 %78, 255
store i32 %79, i32* %11
%80 = load i32, i32* %10
%81 = and i32 %80, 255
store i32 %81, i32* %12
%82 = load i32, i32* %11
%83 = load i32, i32* %12
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [256 x i32], [256 x i32]* %28, i64 0, i64 %84
%86 = load i32, i32* %85
%87 = add i32 %82, %86
%88 = zext i32 %87 to i64
%89 = getelementptr inbounds [256 x i32], [256 x i32]* %28, i64 0, i64 %88
%90 = load i32, i32* %89
%91 = urem i32 %90, 8
store i32 %91, i32* %13
%92 = load i32, i32* %11
%93 = add nsw i32 %92, 1
%94 = load i32, i32* %12
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [256 x i32], [256 x i32]* %28, i64 0, i64 %95
%97 = load i32, i32* %96
%98 = add i32 %93, %97
%99 = zext i32 %98 to i64
%100 = getelementptr inbounds [256 x i32], [256 x i32]* %28, i64 0, i64 %99
%101 = load i32, i32* %100
%102 = urem i32 %101, 8
store i32 %102, i32* %14
%103 = load i32, i32* %11
%104 = load i32, i32* %12
%105 = add nsw i32 %104, 1
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [256 x i32], [256 x i32]* %28, i64 0, i64 %106
%108 = load i32, i32* %107
%109 = add i32 %103, %108
%110 = zext i32 %109 to i64
%111 = getelementptr inbounds [256 x i32], [256 x i32]* %28, i64 0, i64 %110
%112 = load i32, i32* %111
%113 = urem i32 %112, 8
store i32 %113, i32* %15
%114 = load i32, i32* %11
%115 = add nsw i32 %114, 1
%116 = load i32, i32* %12
%117 = add nsw i32 %116, 1
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds [256 x i32], [256 x i32]* %28, i64 0, i64 %118
%120 = load i32, i32* %119
%121 = add i32 %115, %120
%122 = zext i32 %121 to i64
%123 = getelementptr inbounds [256 x i32], [256 x i32]* %28, i64 0, i64 %122
%124 = load i32, i32* %123
%125 = urem i32 %124, 8
store i32 %125, i32* %16
%126 = load float, float* %4
%127 = load i32, i32* %9
%128 = sitofp i32 %127 to float
%129 = fsub float %126, %128
store float %129, float* %7
%130 = load float, float* %5
%131 = load i32, i32* %10
%132 = sitofp i32 %131 to float
%133 = fsub float %130, %132
store float %133, float* %8
%134 = load i32, i32* %13
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %27, i64 0, i64 %135
%137 = getelementptr inbounds [2 x float], [2 x float]* %136, i64 0, i64 0
%138 = load float, float* %137
%139 = load float, float* %7
%140 = load i32, i32* %13
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %27, i64 0, i64 %141
%143 = getelementptr inbounds [2 x float], [2 x float]* %142, i64 0, i64 1
%144 = load float, float* %143
%145 = load float, float* %8
%146 = fmul float %144, %145
%147 = call float @llvm.fmuladd.f32(float %138, float %139, float %146)
store float %147, float* %19
%148 = load float, float* %4
%149 = load i32, i32* %9
%150 = add nsw i32 %149, 1
%151 = sitofp i32 %150 to float
%152 = fsub float %148, %151
store float %152, float* %7
%153 = load float, float* %5
%154 = load i32, i32* %10
%155 = sitofp i32 %154 to float
%156 = fsub float %153, %155
store float %156, float* %8
%157 = load i32, i32* %14
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %27, i64 0, i64 %158
%160 = getelementptr inbounds [2 x float], [2 x float]* %159, i64 0, i64 0
%161 = load float, float* %160
%162 = load float, float* %7
%163 = load i32, i32* %14
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %27, i64 0, i64 %164
%166 = getelementptr inbounds [2 x float], [2 x float]* %165, i64 0, i64 1
%167 = load float, float* %166
%168 = load float, float* %8
%169 = fmul float %167, %168
%170 = call float @llvm.fmuladd.f32(float %161, float %162, float %169)
store float %170, float* %20
%171 = load float, float* %4
%172 = load i32, i32* %9
%173 = sitofp i32 %172 to float
%174 = fsub float %171, %173
store float %174, float* %7
%175 = load float, float* %5
%176 = load i32, i32* %10
%177 = add nsw i32 %176, 1
%178 = sitofp i32 %177 to float
%179 = fsub float %175, %178
store float %179, float* %8
%180 = load i32, i32* %15
%181 = sext i32 %180 to i64
%182 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %27, i64 0, i64 %181
%183 = getelementptr inbounds [2 x float], [2 x float]* %182, i64 0, i64 0
%184 = load float, float* %183
%185 = load float, float* %7
%186 = load i32, i32* %15
%187 = sext i32 %186 to i64
%188 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %27, i64 0, i64 %187
%189 = getelementptr inbounds [2 x float], [2 x float]* %188, i64 0, i64 1
%190 = load float, float* %189
%191 = load float, float* %8
%192 = fmul float %190, %191
%193 = call float @llvm.fmuladd.f32(float %184, float %185, float %192)
store float %193, float* %21
%194 = load float, float* %4
%195 = load i32, i32* %9
%196 = add nsw i32 %195, 1
%197 = sitofp i32 %196 to float
%198 = fsub float %194, %197
store float %198, float* %7
%199 = load float, float* %5
%200 = load i32, i32* %10
%201 = add nsw i32 %200, 1
%202 = sitofp i32 %201 to float
%203 = fsub float %199, %202
store float %203, float* %8
%204 = load i32, i32* %16
%205 = sext i32 %204 to i64
%206 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %27, i64 0, i64 %205
%207 = getelementptr inbounds [2 x float], [2 x float]* %206, i64 0, i64 0
%208 = load float, float* %207
%209 = load float, float* %7
%210 = load i32, i32* %16
%211 = sext i32 %210 to i64
%212 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %27, i64 0, i64 %211
%213 = getelementptr inbounds [2 x float], [2 x float]* %212, i64 0, i64 1
%214 = load float, float* %213
%215 = load float, float* %8
%216 = fmul float %214, %215
%217 = call float @llvm.fmuladd.f32(float %208, float %209, float %216)
store float %217, float* %22
%218 = load float, float* %4
%219 = load i32, i32* %9
%220 = sitofp i32 %219 to float
%221 = fsub float %218, %220
store float %221, float* %18
%222 = load float, float* %18
%223 = fmul float 3.000000e+00, %222
%224 = load float, float* %18
%225 = load float, float* %18
%226 = fmul float 2.000000e+00, %225
%227 = load float, float* %18
%228 = fmul float %226, %227
%229 = load float, float* %18
%230 = fmul float %228, %229
%231 = fneg float %230
%232 = call float @llvm.fmuladd.f32(float %223, float %224, float %231)
store float %232, float* %23
%233 = load float, float* %19
%234 = load float, float* %23
%235 = load float, float* %20
%236 = load float, float* %19
%237 = fsub float %235, %236
%238 = call float @llvm.fmuladd.f32(float %234, float %237, float %233)
store float %238, float* %25
%239 = load float, float* %21
%240 = load float, float* %23
%241 = load float, float* %22
%242 = load float, float* %21
%243 = fsub float %241, %242
%244 = call float @llvm.fmuladd.f32(float %240, float %243, float %239)
store float %244, float* %26
%245 = load float, float* %5
%246 = load i32, i32* %10
%247 = sitofp i32 %246 to float
%248 = fsub float %245, %247
store float %248, float* %18
%249 = load float, float* %18
%250 = fmul float 3.000000e+00, %249
%251 = load float, float* %18
%252 = load float, float* %18
%253 = fmul float 2.000000e+00, %252
%254 = load float, float* %18
%255 = fmul float %253, %254
%256 = load float, float* %18
%257 = fmul float %255, %256
%258 = fneg float %257
%259 = call float @llvm.fmuladd.f32(float %250, float %251, float %258)
store float %259, float* %24
%260 = load float, float* %25
%261 = load float, float* %24
%262 = load float, float* %26
%263 = load float, float* %25
%264 = fsub float %262, %263
%265 = call float @llvm.fmuladd.f32(float %261, float %264, float %260)
%266 = fpext float %265 to double
%267 = fadd double %266, 1.000000e+00
%268 = fdiv double %267, 2.000000e+00
%269 = fptrunc double %268 to float
ret float %269
}

LLVM IR (-O2):
@__const.perlin2D.perm = [256 x i32] [i32 151, i32 160, i32 137, i32 91, i32 90, i32 15, i32 131, i32 13, i32 201, i32 95, i32 96, i32 53, i32 194, i32 233, i32 7, i32 225, i32 140, i32 36, i32 103, i32 30, i32 69, i32 142, i32 8, i32 99, i32 37, i32 240, i32 21, i32 10, i32 23, i32 190, i32 6, i32 148, i32 247, i32 120, i32 234, i32 75, i32 0, i32 26, i32 197, i32 62, i32 94, i32 252, i32 219, i32 203, i32 117, i32 35, i32 11, i32 32, i32 57, i32 177, i32 33, i32 88, i32 237, i32 149, i32 56, i32 87, i32 174, i32 20, i32 125, i32 136, i32 171, i32 168, i32 68, i32 175, i32 74, i32 165, i32 71, i32 134, i32 139, i32 48, i32 27, i32 166, i32 77, i32 146, i32 158, i32 231, i32 83, i32 111, i32 229, i32 122, i32 60, i32 211, i32 133, i32 230, i32 220, i32 105, i32 92, i32 41, i32 55, i32 46, i32 245, i32 40, i32 244, i32 102, i32 143, i32 54, i32 65, i32 25, i32 63, i32 161, i32 1, i32 216, i32 80, i32 73, i32 209, i32 76, i32 132, i32 187, i32 208, i32 89, i32 18, i32 169, i32 200, i32 196, i32 135, i32 130, i32 116, i32 188, i32 159, i32 86, i32 164, i32 100, i32 109, i32 198, i32 173, i32 186, i32 3, i32 64, i32 52, i32 217, i32 226, i32 250, i32 124, i32 123, i32 5, i32 202, i32 38, i32 147, i32 118, i32 126, i32 255, i32 82, i32 85, i32 212, i32 207, i32 206, i32 59, i32 227, i32 47, i32 16, i32 58, i32 17, i32 182, i32 189, i32 28, i32 42, i32 223, i32 183, i32 170, i32 213, i32 119, i32 248, i32 152, i32 2, i32 44, i32 154, i32 163, i32 70, i32 221, i32 153, i32 101, i32 155, i32 167, i32 43, i32 172, i32 9, i32 129, i32 22, i32 39, i32 253, i32 19, i32 98, i32 108, i32 110, i32 79, i32 113, i32 224, i32 232, i32 178, i32 185, i32 112, i32 104, i32 218, i32 246, i32 97, i32 228, i32 251, i32 34, i32 242, i32 193, i32 238, i32 210, i32 144, i32 12, i32 191, i32 179, i32 162, i32 241, i32 81, i32 51, i32 145, i32 235, i32 249, i32 14, i32 239, i32 107, i32 49, i32 192, i32 214, i32 31, i32 181, i32 199, i32 106, i32 157, i32 184, i32 84, i32 204, i32 176, i32 115, i32 121, i32 50, i32 45, i32 127, i32 4, i32 150, i32 254, i32 138, i32 236, i32 205, i32 93, i32 222, i32 114, i32 67, i32 29, i32 24, i32 72, i32 243, i32 141, i32 128, i32 195, i32 78, i32 66, i32 215, i32 61, i32 156, i32 180]
define float @perlin2D(float %0, float %1, float %2) {
%4 = alloca [8 x [2 x float]]
%5 = tail call float @sqrt(i32 2)
%6 = fdiv float 1.000000e+00, %5
%7 = bitcast [8 x [2 x float]]* %4 to i8*
%8 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 0, i64 0
store float %6, float* %8
%9 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 0, i64 1
store float %6, float* %9
%10 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 1, i64 0
%11 = fneg float %6
store float %11, float* %10
%12 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 1, i64 1
store float %6, float* %12
%13 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 2, i64 0
store float %6, float* %13
%14 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 2, i64 1
store float %11, float* %14
%15 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 3, i64 0
store float %11, float* %15
%16 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 3, i64 1
store float %11, float* %16
%17 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 4, i64 0
%18 = bitcast float* %17 to <4 x float>*
store <4 x float> <float 1.000000e+00, float 0.000000e+00, float -1.000000e+00, float 0.000000e+00>, <4 x float>* %18
%19 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 6, i64 0
%20 = bitcast float* %19 to <4 x float>*
store <4 x float> <float 0.000000e+00, float 1.000000e+00, float 0.000000e+00, float -1.000000e+00>, <4 x float>* %20
%21 = fdiv float %0, %2
%22 = fdiv float %1, %2
%23 = fptosi float %21 to i32
%24 = fptosi float %22 to i32
%25 = and i32 %23, 255
%26 = and i32 %24, 255
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [256 x i32], [256 x i32]* @__const.perlin2D.perm, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = add i32 %29, %25
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [256 x i32], [256 x i32]* @__const.perlin2D.perm, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = and i32 %33, 7
%35 = add nuw nsw i32 %25, 1
%36 = add i32 %29, %35
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds [256 x i32], [256 x i32]* @__const.perlin2D.perm, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = and i32 %39, 7
%41 = add nuw nsw i32 %26, 1
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds [256 x i32], [256 x i32]* @__const.perlin2D.perm, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = add i32 %44, %25
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds [256 x i32], [256 x i32]* @__const.perlin2D.perm, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = and i32 %48, 7
%50 = add i32 %44, %35
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds [256 x i32], [256 x i32]* @__const.perlin2D.perm, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = and i32 %53, 7
%55 = sitofp i32 %23 to float
%56 = fsub float %21, %55
%57 = zext i32 %34 to i64
%58 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 %57, i64 0
%59 = load float, float* %58
%60 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 %57, i64 1
%61 = load float, float* %60
%62 = add nsw i32 %23, 1
%63 = sitofp i32 %62 to float
%64 = fsub float %21, %63
%65 = zext i32 %40 to i64
%66 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 %65, i64 0
%67 = load float, float* %66
%68 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 %65, i64 1
%69 = load float, float* %68
%70 = add nsw i32 %24, 1
%71 = insertelement <2 x i32> poison, i32 %70, i64 0
%72 = insertelement <2 x i32> %71, i32 %24, i64 1
%73 = sitofp <2 x i32> %72 to <2 x float>
%74 = insertelement <2 x float> poison, float %22, i64 0
%75 = shufflevector <2 x float> %74, <2 x float> poison, <2 x i32> zeroinitializer
%76 = fsub <2 x float> %75, %73
%77 = zext i32 %49 to i64
%78 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 %77, i64 0
%79 = load float, float* %78
%80 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 %77, i64 1
%81 = load float, float* %80
%82 = insertelement <2 x float> poison, float %81, i64 0
%83 = insertelement <2 x float> %82, float %61, i64 1
%84 = fmul <2 x float> %76, %83
%85 = insertelement <2 x float> poison, float %79, i64 0
%86 = insertelement <2 x float> %85, float %59, i64 1
%87 = insertelement <2 x float> poison, float %56, i64 0
%88 = shufflevector <2 x float> %87, <2 x float> poison, <2 x i32> zeroinitializer
%89 = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %86, <2 x float> %88, <2 x float> %84)
%90 = zext i32 %54 to i64
%91 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 %90, i64 0
%92 = load float, float* %91
%93 = getelementptr inbounds [8 x [2 x float]], [8 x [2 x float]]* %4, i64 0, i64 %90, i64 1
%94 = load float, float* %93
%95 = insertelement <2 x float> poison, float %94, i64 0
%96 = insertelement <2 x float> %95, float %69, i64 1
%97 = fmul <2 x float> %76, %96
%98 = insertelement <2 x float> poison, float %92, i64 0
%99 = insertelement <2 x float> %98, float %67, i64 1
%100 = insertelement <2 x float> poison, float %64, i64 0
%101 = shufflevector <2 x float> %100, <2 x float> poison, <2 x i32> zeroinitializer
%102 = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %99, <2 x float> %101, <2 x float> %97)
%103 = fmul float %56, 3.000000e+00
%104 = fmul float %56, -2.000000e+00
%105 = fmul float %56, %104
%106 = fmul float %56, %105
%107 = tail call float @llvm.fmuladd.f32(float %103, float %56, float %106)
%108 = fsub <2 x float> %102, %89
%109 = insertelement <2 x float> poison, float %107, i64 0
%110 = shufflevector <2 x float> %109, <2 x float> poison, <2 x i32> zeroinitializer
%111 = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %110, <2 x float> %108, <2 x float> %89)
%112 = extractelement <2 x float> %76, i64 1
%113 = fmul float %112, 3.000000e+00
%114 = fmul float %112, -2.000000e+00
%115 = fmul float %112, %114
%116 = fmul float %112, %115
%117 = tail call float @llvm.fmuladd.f32(float %113, float %112, float %116)
%118 = extractelement <2 x float> %111, i64 0
%119 = extractelement <2 x float> %111, i64 1
%120 = fsub float %118, %119
%121 = tail call float @llvm.fmuladd.f32(float %117, float %120, float %119)
%122 = fpext float %121 to double
%123 = fadd double %122, 1.000000e+00
%124 = fmul double %123, 5.000000e-01
%125 = fptrunc double %124 to float
ret float %125
}