#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 */
struct rusage {
  int dummy;
};

/* Variables and functions */
float M_PI;
int /*<<< orphan*/ RUSAGE_SELF;
float atan2(float, float);
float cosf(float);
int /*<<< orphan*/ getrusage(int /*<<< orphan*/, struct rusage *);
float sinf(float);
void benchmark_mybench(struct rusage *_start, struct rusage *_finish,
                       unsigned long int *_num_iterations) {
  unsigned int i;
  float x, y, theta;
  getrusage(RUSAGE_SELF, _start);
  for (i = 0; i < (*_num_iterations); i++) {
    x = cosf(M_PI / 2.0f);
    y = sinf(M_PI / 2.0f);
    theta = atan2(y, x);
  }
  getrusage(RUSAGE_SELF, _finish);
}


x86 assembly (clang, -O0):
<benchmark_mybench>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1060 <getrusage@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jae    11e1 <benchmark_mybench+0xa1>
mov    0x2e64(%rip),%rax
movss  (%rax),%xmm0
movss  0xe70(%rip),%xmm1
divss  %xmm1,%xmm0
call   1050 <cosf@plt>
movss  %xmm0,-0x20(%rbp)
mov    0x2e43(%rip),%rax
movss  (%rax),%xmm0
movss  0xe4f(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <sinf@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
call   1040 <atan2@plt>
movss  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116d <benchmark_mybench+0x2d>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1060 <getrusage@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark_mybench>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rsi
mov    0x2e7c(%rip),%r15
mov    (%r15),%edi
call   1060 <getrusage@plt>
cmpq   $0x0,(%r12)
je     11c2 <benchmark_mybench+0x82>
mov    $0x1,%ebp
mov    0x2e71(%rip),%rbx
nopw   0x0(%rax,%rax,1)
movss  (%rbx),%xmm0
movss  0xe74(%rip),%xmm1
mulss  %xmm1,%xmm0
call   1050 <cosf@plt>
movss  %xmm0,0xc(%rsp)
movss  (%rbx),%xmm0
mulss  0xe59(%rip),%xmm0
call   1030 <sinf@plt>
movss  0xc(%rsp),%xmm1
call   1040 <atan2@plt>
mov    %ebp,%eax
add    $0x1,%ebp
cmp    %rax,(%r12)
ja     1180 <benchmark_mybench+0x40>
mov    (%r15),%edi
mov    %r14,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <getrusage@plt>

LLVM IR (-O0):
%struct.rusage = type { i32 }
@RUSAGE_SELF = global i32 0
@M_PI = global float 0.000000e+00
define void @benchmark_mybench(%struct.rusage* %0, %struct.rusage* %1, i64* %2) {
%4 = alloca %struct.rusage*
%5 = alloca %struct.rusage*
%6 = alloca i64*
%7 = alloca i32
%8 = alloca float
%9 = alloca float
%10 = alloca float
store %struct.rusage* %0, %struct.rusage** %4
store %struct.rusage* %1, %struct.rusage** %5
store i64* %2, i64** %6
%11 = load i32, i32* @RUSAGE_SELF
%12 = load %struct.rusage*, %struct.rusage** %4
%13 = call i32 @getrusage(i32 %11, %struct.rusage* %12)
store i32 0, i32* %7
br label %14
14: ; preds = %30, %3
%15 = load i32, i32* %7
%16 = zext i32 %15 to i64
%17 = load i64*, i64** %6
%18 = load i64, i64* %17
%19 = icmp ult i64 %16, %18
br i1 %19, label %20, label %33
20: ; preds = %14
%21 = load float, float* @M_PI
%22 = fdiv float %21, 2.000000e+00
%23 = call float @cosf(float %22)
store float %23, float* %8
%24 = load float, float* @M_PI
%25 = fdiv float %24, 2.000000e+00
%26 = call float @sinf(float %25)
store float %26, float* %9
%27 = load float, float* %9
%28 = load float, float* %8
%29 = call float @atan2(float %27, float %28)
store float %29, float* %10
br label %30
30: ; preds = %20
%31 = load i32, i32* %7
%32 = add i32 %31, 1
store i32 %32, i32* %7
br label %14
33: ; preds = %14
%34 = load i32, i32* @RUSAGE_SELF
%35 = load %struct.rusage*, %struct.rusage** %5
%36 = call i32 @getrusage(i32 %34, %struct.rusage* %35)
ret void
}

LLVM IR (-O2):
%struct.rusage = type { i32 }
@RUSAGE_SELF = global i32 0
@M_PI = global float 0.000000e+00
define void @benchmark_mybench(%struct.rusage* %0, %struct.rusage* %1, i64* nocapture %2) {
%4 = load i32, i32* @RUSAGE_SELF
%5 = tail call i32 @getrusage(i32 %4, %struct.rusage* %0)
%6 = load i64, i64* %2
%7 = icmp eq i64 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %3, %8
%9 = phi i32 [ %17, %8 ], [ 0, %3 ]
%10 = load float, float* @M_PI
%11 = fmul float %10, 5.000000e-01
%12 = tail call float @cosf(float %11)
%13 = load float, float* @M_PI
%14 = fmul float %13, 5.000000e-01
%15 = tail call float @sinf(float %14)
%16 = tail call float @atan2(float %15, float %12)
%17 = add i32 %9, 1
%18 = zext i32 %17 to i64
%19 = load i64, i64* %2
%20 = icmp ugt i64 %19, %18
br i1 %20, label %8, label %21
21: ; preds = %8, %3
%22 = load i32, i32* @RUSAGE_SELF
%23 = tail call i32 @getrusage(i32 %22, %struct.rusage* %1)
ret void
}