#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 */
int cos(int);
float rastrigin(float x, float y) {
  float f;
  float p1, p2, p3;
  int i, j;
  int d = 2;
  float pi = 3.14159265359;
  p1 = 10 * d;
  p2 = x * x + y * y;
  p3 = 10 * (cos(2 * pi * x) + cos(2 * pi * y));
  f = p1 + p2 - p3;
  return f;
}


x86 assembly (clang, -O0):
<rastrigin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movl   $0x2,-0x24(%rbp)
movss  0xed3(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
imul   $0xa,-0x24(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x4(%rbp),%xmm2
movss  -0x8(%rbp),%xmm1
mulss  -0x8(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xe94(%rip),%xmm0
mulss  -0x28(%rbp),%xmm0
mulss  -0x4(%rbp),%xmm0
cvttss2si %xmm0,%edi
call   1030 <cos@plt>
mov    %eax,-0x2c(%rbp)
movss  0xe76(%rip),%xmm0
mulss  -0x28(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
cvttss2si %xmm0,%edi
call   1030 <cos@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
imul   $0xa,%eax,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
subss  -0x18(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rastrigin>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm1,0x8(%rsp)
movaps %xmm1,%xmm3
mulss  %xmm1,%xmm3
movaps %xmm0,%xmm2
mulss  %xmm0,%xmm2
addss  %xmm3,%xmm2
movss  %xmm2,0xc(%rsp)
mulss  0xec5(%rip),%xmm0
cvttss2si %xmm0,%edi
call   1030 <cos@plt>
mov    %eax,%ebx
movss  0x8(%rsp),%xmm0
mulss  0xeac(%rip),%xmm0
cvttss2si %xmm0,%edi
call   1030 <cos@plt>
add    %ebx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
movss  0xc(%rsp),%xmm0
addss  0xe8b(%rip),%xmm0
subss  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define float @rastrigin(float %0, float %1) {
%3 = alloca float
%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 float
store float %0, float* %3
store float %1, float* %4
store i32 2, i32* %11
store float 0x400921FB60000000, float* %12
%13 = load i32, i32* %11
%14 = mul nsw i32 10, %13
%15 = sitofp i32 %14 to float
store float %15, float* %6
%16 = load float, float* %3
%17 = load float, float* %3
%18 = load float, float* %4
%19 = load float, float* %4
%20 = fmul float %18, %19
%21 = call float @llvm.fmuladd.f32(float %16, float %17, float %20)
store float %21, float* %7
%22 = load float, float* %12
%23 = fmul float 2.000000e+00, %22
%24 = load float, float* %3
%25 = fmul float %23, %24
%26 = fptosi float %25 to i32
%27 = call i32 @cos(i32 %26)
%28 = load float, float* %12
%29 = fmul float 2.000000e+00, %28
%30 = load float, float* %4
%31 = fmul float %29, %30
%32 = fptosi float %31 to i32
%33 = call i32 @cos(i32 %32)
%34 = add nsw i32 %27, %33
%35 = mul nsw i32 10, %34
%36 = sitofp i32 %35 to float
store float %36, float* %8
%37 = load float, float* %6
%38 = load float, float* %7
%39 = fadd float %37, %38
%40 = load float, float* %8
%41 = fsub float %39, %40
store float %41, float* %5
%42 = load float, float* %5
ret float %42
}

LLVM IR (-O2):
define float @rastrigin(float %0, float %1) {
%3 = fmul float %1, %1
%4 = tail call float @llvm.fmuladd.f32(float %0, float %0, float %3)
%5 = fmul float %0, 0x401921FB60000000
%6 = fptosi float %5 to i32
%7 = tail call i32 @cos(i32 %6)
%8 = fmul float %1, 0x401921FB60000000
%9 = fptosi float %8 to i32
%10 = tail call i32 @cos(i32 %9)
%11 = add nsw i32 %10, %7
%12 = mul nsw i32 %11, 10
%13 = sitofp i32 %12 to float
%14 = fadd float %4, 2.000000e+01
%15 = fsub float %14, %13
ret float %15
}