#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 /*<<< orphan*/ c_daxpy(int, double, double *, int, double *, int);
int /*<<< orphan*/ printf(char *);
double rand_double();
double tic();
double benchmark(int iterations, int len) {
  double elapsed;
  double x[len];
  double y[len];
  double t;
  int i;
  for (i = 0; i < len; i++) {
    x[i] = (rand_double() * 200.0) - 100.0;
    y[i] = (rand_double() * 200.0) - 100.0;
  }
  t = tic();
  for (i = 0; i < iterations; i++) {
    c_daxpy(len, 5.0, x, 1, y, 1);
    if (y[0] != y[0]) {
      printf("should not return NaN\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (y[0] != y[0]) {
    printf("should not return NaN\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120e <benchmark+0xce>
mov    $0x0,%al
call   1050 <rand_double@plt>
mov    -0x48(%rbp),%rax
movsd  0xe4d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe49(%rip),%xmm1
addsd  %xmm1,%xmm0
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    $0x0,%al
call   1050 <rand_double@plt>
mov    -0x40(%rbp),%rax
movsd  0xe21(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe1d(%rip),%xmm1
addsd  %xmm1,%xmm0
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    119c <benchmark+0x5c>
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    128f <benchmark+0x14f>
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%edi
movsd  0xdc0(%rip),%xmm0
mov    $0x1,%r8d
mov    %r8d,%edx
call   1060 <c_daxpy@plt>
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd (%rax),%xmm0
jne    126b <benchmark+0x12b>
jp     126b <benchmark+0x12b>
jmp    127c <benchmark+0x13c>
lea    0xda6(%rip),%rdi
call   1030 <printf@plt>
jmp    128f <benchmark+0x14f>
jmp    1281 <benchmark+0x141>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1221 <benchmark+0xe1>
mov    $0x0,%al
call   1040 <tic@plt>
mov    -0x40(%rbp),%rax
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  (%rax),%xmm0
ucomisd (%rax),%xmm0
jne    12bd <benchmark+0x17d>
jp     12bd <benchmark+0x17d>
jmp    12c9 <benchmark+0x189>
lea    0xd54(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    %esi,%r13d
mov    %rsp,%r12
lea    0xf(,%r13,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    %esi,-0x30(%rbp)
test   %esi,%esi
jle    11cb <benchmark+0x8b>
xor    %r14d,%r14d
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <rand_double@plt>
movsd  0xe71(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe6d(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r12,%r14,8)
xor    %eax,%eax
call   1050 <rand_double@plt>
mulsd  0xe4c(%rip),%xmm0
addsd  0xe4c(%rip),%xmm0
movsd  %xmm0,(%r15,%r14,8)
add    $0x1,%r14
cmp    %r14,%r13
jne    1180 <benchmark+0x40>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,-0x38(%rbp)
test   %ebx,%ebx
mov    -0x30(%rbp),%r14d
jle    121f <benchmark+0xdf>
nop
mov    %r14d,%edi
movsd  0xe25(%rip),%xmm0
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
mov    $0x1,%r8d
call   1060 <c_daxpy@plt>
movsd  (%r15),%xmm0
ucomisd %xmm0,%xmm0
jp     1213 <benchmark+0xd3>
add    $0xffffffff,%ebx
jne    11e0 <benchmark+0xa0>
jmp    121f <benchmark+0xdf>
lea    0xdfe(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  (%r15),%xmm1
ucomisd %xmm1,%xmm1
jp     1245 <benchmark+0x105>
subsd  -0x38(%rbp),%xmm0
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdcc(%rip),%rdi
movsd  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movsd  -0x30(%rbp),%xmm0
jmp    1231 <benchmark+0xf1>

LLVM IR (-O0):
@.str = [23 x i8] c"should not return NaN\0A\00"
define double @benchmark(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca double
%10 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%11 = load i32, i32* %4
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca double, i64 %12
store i64 %12, i64* %7
%15 = load i32, i32* %4
%16 = zext i32 %15 to i64
%17 = alloca double, i64 %16
store i64 %16, i64* %8
store i32 0, i32* %10
br label %18
18: ; preds = %33, %2
%19 = load i32, i32* %10
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %36
22: ; preds = %18
%23 = call double (...) @rand_double()
%24 = call double @llvm.fmuladd.f64(double %23, double 2.000000e+02, double -1.000000e+02)
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %14, i64 %26
store double %24, double* %27
%28 = call double (...) @rand_double()
%29 = call double @llvm.fmuladd.f64(double %28, double 2.000000e+02, double -1.000000e+02)
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %17, i64 %31
store double %29, double* %32
br label %33
33: ; preds = %22
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
br label %18
36: ; preds = %18
%37 = call double (...) @tic()
store double %37, double* %9
store i32 0, i32* %10
br label %38
38: ; preds = %53, %36
%39 = load i32, i32* %10
%40 = load i32, i32* %3
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %56
42: ; preds = %38
%43 = load i32, i32* %4
%44 = call i32 @c_daxpy(i32 %43, double 5.000000e+00, double* %14, i32 1, double* %17, i32 1)
%45 = getelementptr inbounds double, double* %17, i64 0
%46 = load double, double* %45
%47 = getelementptr inbounds double, double* %17, i64 0
%48 = load double, double* %47
%49 = fcmp une double %46, %48
br i1 %49, label %50, label %52
50: ; preds = %42
%51 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %56
52: ; preds = %42
br label %53
53: ; preds = %52
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %38
56: ; preds = %50, %38
%57 = call double (...) @tic()
%58 = load double, double* %9
%59 = fsub double %57, %58
store double %59, double* %5
%60 = getelementptr inbounds double, double* %17, i64 0
%61 = load double, double* %60
%62 = getelementptr inbounds double, double* %17, i64 0
%63 = load double, double* %62
%64 = fcmp une double %61, %63
br i1 %64, label %65, label %67
65: ; preds = %56
%66 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %67
67: ; preds = %65, %56
%68 = load double, double* %5
%69 = load i8*, i8** %6
ret double %68
}

LLVM IR (-O2):
@str.1 = [22 x i8] c"should not return NaN\00"
define double @benchmark(i32 %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = alloca double, i64 %3
%5 = alloca double, i64 %3
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %17
7: ; preds = %2, %7
%8 = phi i64 [ %15, %7 ], [ 0, %2 ]
%9 = tail call double (...) @rand_double()
%10 = tail call double @llvm.fmuladd.f64(double %9, double 2.000000e+02, double -1.000000e+02)
%11 = getelementptr inbounds double, double* %4, i64 %8
store double %10, double* %11
%12 = tail call double (...) @rand_double()
%13 = tail call double @llvm.fmuladd.f64(double %12, double 2.000000e+02, double -1.000000e+02)
%14 = getelementptr inbounds double, double* %5, i64 %8
store double %13, double* %14
%15 = add nuw nsw i64 %8, 1
%16 = icmp eq i64 %15, %3
br i1 %16, label %17, label %7
17: ; preds = %7, %2
%18 = tail call double (...) @tic()
%19 = icmp sgt i32 %0, 0
br i1 %19, label %22, label %30
20: ; preds = %22
%21 = icmp eq i32 %27, %0
br i1 %21, label %30, label %22
22: ; preds = %17, %20
%23 = phi i32 [ %27, %20 ], [ 0, %17 ]
%24 = call i32 @c_daxpy(i32 %1, double 5.000000e+00, double* %4, i32 1, double* %5, i32 1)
%25 = load double, double* %5
%26 = fcmp uno double %25, 0.000000e+00
%27 = add nuw nsw i32 %23, 1
br i1 %26, label %28, label %20
28: ; preds = %22
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
br label %30
30: ; preds = %20, %17, %28
%31 = call double (...) @tic()
%32 = load double, double* %5
%33 = fcmp uno double %32, 0.000000e+00
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
%37 = fsub double %31, %18
ret double %37
}