#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 timespec {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ bail(char *);
int /*<<< orphan*/ printf(char *, double);
void compute_flops(double task_length) {
  int ret;
  int i;
  double a = 0.0;
  double b = 1.0;
  double c;
  struct timespec tim;
  if ((int)task_length < 0)
    bail("task_length must be > 0");
  printf("floating point operations : %f\n", task_length);
  for (i = 0; i < task_length; i++) {
    c = a + b;
    a = b;
    b = c;
  }
  return;
}


x86 assembly (clang, -O0):
<compute_flops>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xec3(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x8(%rbp),%eax
cmp    $0x0,%eax
jge    115c <compute_flops+0x3c>
lea    0xeb1(%rip),%rdi
call   1040 <bail@plt>
movsd  -0x8(%rbp),%xmm0
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b9 <compute_flops+0x99>
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1174 <compute_flops+0x54>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_flops>:
cvttsd2si %xmm0,%eax
test   %eax,%eax
js     1134 <compute_flops+0x14>
lea    0xee9(%rip),%rdi
jmp    1030 <printf@plt>
push   %rax
lea    0xec4(%rip),%rdi
movsd  %xmm0,(%rsp)
call   1040 <bail@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
lea    0xec2(%rip),%rdi
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.timespec = type { i32 }
@.str = [24 x i8] c"task_length must be > 0\00"
@.str.1 = [32 x i8] c"floating point operations : %f\0A\00"
define void @compute_flops(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca %struct.timespec
store double %0, double* %2
store double 0.000000e+00, double* %5
store double 1.000000e+00, double* %6
%9 = load double, double* %2
%10 = fptosi double %9 to i32
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @bail(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = load double, double* %2
%16 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), double %15)
store i32 0, i32* %4
br label %17
17: ; preds = %28, %14
%18 = load i32, i32* %4
%19 = sitofp i32 %18 to double
%20 = load double, double* %2
%21 = fcmp olt double %19, %20
br i1 %21, label %22, label %31
22: ; preds = %17
%23 = load double, double* %5
%24 = load double, double* %6
%25 = fadd double %23, %24
store double %25, double* %7
%26 = load double, double* %6
store double %26, double* %5
%27 = load double, double* %7
store double %27, double* %6
br label %28
28: ; preds = %22
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %17
31: ; preds = %17
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"task_length must be > 0\00"
@.str.1 = [32 x i8] c"floating point operations : %f\0A\00"
define void @compute_flops(double %0) {
%2 = fptosi double %0 to i32
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @bail(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), double %0)
ret void
}