#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 */
typedef int uint32_t;
struct nyan {
  float f;
  int ui;
};

/* Variables and functions */
float fabsf(float);
float kernel_cos(float a, int flag) {
  float a2 = a * a;
  float answer;
  union nyan {
    float f;
    uint32_t ui;
  } c3, c2, c1;
  c3.ui = 0xbab38106;
  c2.ui = 0x3d2aa789;
  c1.ui = 0xbf000000;
  answer = c3.f * a2;
  answer += c2.f;
  answer *= a2;
  answer += c1.f;
  answer *= a2;
  answer += 1.0f;
  if (flag == 0) {
    return fabsf(answer);
  } else {
    return -fabsf(answer);
  }
}


x86 assembly (clang, -O0):
<kernel_cos>:
push   %rbp
mov    %rsp,%rbp
movss  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0xbab38106,-0x18(%rbp)
movl   $0x3d2aa789,-0x20(%rbp)
movl   $0xbf000000,-0x28(%rbp)
movss  -0x18(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x20(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x28(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xe7d(%rip),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11b1 <kernel_cos+0xb1>
movss  -0x14(%rbp),%xmm0
movaps 0xe6d(%rip),%xmm1
pand   %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11d3 <kernel_cos+0xd3>
movss  -0x14(%rbp),%xmm0
movaps 0xe53(%rip),%xmm1
pand   %xmm1,%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_cos>:
movaps %xmm0,%xmm1
mulss  %xmm0,%xmm1
movss  0xef1(%rip),%xmm0
mulss  %xmm1,%xmm0
addss  0xee9(%rip),%xmm0
mulss  %xmm1,%xmm0
addss  0xee1(%rip),%xmm0
mulss  %xmm1,%xmm0
addss  0xed9(%rip),%xmm0
test   %edi,%edi
je     113f <kernel_cos+0x3f>
orps   0xee2(%rip),%xmm0
ret
andps  0xeca(%rip),%xmm0
ret

LLVM IR (-O0):
%union.nyan = type { float }
define float @kernel_cos(float %0, i32 %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca i32
%6 = alloca float
%7 = alloca float
%8 = alloca %union.nyan
%9 = alloca %union.nyan
%10 = alloca %union.nyan
store float %0, float* %4
store i32 %1, i32* %5
%11 = load float, float* %4
%12 = load float, float* %4
%13 = fmul float %11, %12
store float %13, float* %6
%14 = bitcast %union.nyan* %8 to i32*
store i32 -1162641146, i32* %14
%15 = bitcast %union.nyan* %9 to i32*
store i32 1026205577, i32* %15
%16 = bitcast %union.nyan* %10 to i32*
store i32 -1090519040, i32* %16
%17 = bitcast %union.nyan* %8 to float*
%18 = load float, float* %17
%19 = load float, float* %6
%20 = fmul float %18, %19
store float %20, float* %7
%21 = bitcast %union.nyan* %9 to float*
%22 = load float, float* %21
%23 = load float, float* %7
%24 = fadd float %23, %22
store float %24, float* %7
%25 = load float, float* %6
%26 = load float, float* %7
%27 = fmul float %26, %25
store float %27, float* %7
%28 = bitcast %union.nyan* %10 to float*
%29 = load float, float* %28
%30 = load float, float* %7
%31 = fadd float %30, %29
store float %31, float* %7
%32 = load float, float* %6
%33 = load float, float* %7
%34 = fmul float %33, %32
store float %34, float* %7
%35 = load float, float* %7
%36 = fadd float %35, 1.000000e+00
store float %36, float* %7
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %2
%40 = load float, float* %7
%41 = call float @llvm.fabs.f32(float %40)
store float %41, float* %3
br label %46
42: ; preds = %2
%43 = load float, float* %7
%44 = call float @llvm.fabs.f32(float %43)
%45 = fneg float %44
store float %45, float* %3
br label %46
46: ; preds = %42, %39
%47 = load float, float* %3
ret float %47
}

LLVM IR (-O2):
define float @kernel_cos(float %0, i32 %1) {
%3 = fmul float %0, %0
%4 = fmul float %3, 0x3F567020C0000000
%5 = fsub float 0x3FA554F120000000, %4
%6 = fmul float %3, %5
%7 = fadd float %6, -5.000000e-01
%8 = fmul float %3, %7
%9 = fadd float %8, 1.000000e+00
%10 = icmp eq i32 %1, 0
%11 = tail call float @llvm.fabs.f32(float %9)
%12 = fneg float %11
%13 = select i1 %10, float %11, float %12
ret float %13
}