#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_cswap(int, void *, int, void *, int);
int /*<<< orphan*/ printf(char *);
float rand_float();
double tic();
double benchmark(int iterations, int len) {
  double elapsed;
  float x[len * 2];
  float y[len * 2];
  double t;
  int i;
  for (i = 0; i < len; i++) {
    x[i] = (rand_float() * 10000.0f) - 5000.0f;
    x[i + 1] = (rand_float() * 10000.0f) - 5000.0f;
    y[i] = 0.0f;
    y[i + 1] = 0.0f;
  }
  t = tic();
  for (i = 0; i < iterations; i++) {
    c_cswap(len, (void *)x, 1, (void *)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
add    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%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
add    %eax,%eax
lea    0xf(,%rax,4),%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    1238 <benchmark+0xf8>
mov    $0x0,%al
call   1030 <rand_float@plt>
mov    -0x48(%rbp),%rax
movss  0xe41(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe39(%rip),%xmm1
addss  %xmm1,%xmm0
movslq -0x34(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    $0x0,%al
call   1030 <rand_float@plt>
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%rax
movss  0xe11(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe09(%rip),%xmm1
addss  %xmm1,%xmm0
mov    -0x34(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
movss  %xmm0,(%rcx,%rdx,4)
movslq -0x34(%rbp),%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a0 <benchmark+0x60>
mov    $0x0,%al
call   1050 <tic@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12b0 <benchmark+0x170>
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    $0x1,%r8d
mov    %r8d,%edx
call   1060 <c_cswap@plt>
mov    -0x40(%rbp),%rax
movss  (%rax),%xmm0
ucomiss (%rax),%xmm0
jne    128c <benchmark+0x14c>
jp     128c <benchmark+0x14c>
jmp    129d <benchmark+0x15d>
lea    0xd75(%rip),%rdi
call   1040 <printf@plt>
jmp    12b0 <benchmark+0x170>
jmp    12a2 <benchmark+0x162>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    124b <benchmark+0x10b>
mov    $0x0,%al
call   1050 <tic@plt>
mov    -0x40(%rbp),%rax
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movss  (%rax),%xmm0
ucomiss (%rax),%xmm0
jne    12dd <benchmark+0x19d>
jp     12dd <benchmark+0x19d>
jmp    12e9 <benchmark+0x1a9>
lea    0xd24(%rip),%rdi
call   1040 <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
lea    (%rsi,%rsi,1),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsi,-0x30(%rbp)
test   %esi,%esi
jle    11e7 <benchmark+0xa7>
mov    -0x30(%rbp),%r13d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <rand_float@plt>
movss  0xe61(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe59(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,(%r12,%r14,4)
xor    %eax,%eax
call   1040 <rand_float@plt>
mulss  0xe3c(%rip),%xmm0
addss  0xe38(%rip),%xmm0
movss  %xmm0,0x4(%r12,%r14,4)
movq   $0x0,(%r15,%r14,4)
lea    0x1(%r14),%rax
mov    %rax,%r14
cmp    %rax,%r13
jne    1190 <benchmark+0x50>
xor    %eax,%eax
call   1050 <tic@plt>
movsd  %xmm0,-0x38(%rbp)
test   %ebx,%ebx
mov    -0x30(%rbp),%r14
jle    1236 <benchmark+0xf6>
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
mov    $0x1,%r8d
call   1060 <c_cswap@plt>
movss  (%r15),%xmm0
ucomiss %xmm0,%xmm0
jp     122a <benchmark+0xea>
add    $0xffffffff,%ebx
jne    1200 <benchmark+0xc0>
jmp    1236 <benchmark+0xf6>
lea    0xdd7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <tic@plt>
movss  (%r15),%xmm1
ucomiss %xmm1,%xmm1
jp     125b <benchmark+0x11b>
subsd  -0x38(%rbp),%xmm0
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda6(%rip),%rdi
movsd  %xmm0,-0x30(%rbp)
call   1030 <puts@plt>
movsd  -0x30(%rbp),%xmm0
jmp    1247 <benchmark+0x107>

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 = mul nsw i32 %11, 2
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca float, i64 %13
store i64 %13, i64* %7
%16 = load i32, i32* %4
%17 = mul nsw i32 %16, 2
%18 = zext i32 %17 to i64
%19 = alloca float, i64 %18
store i64 %18, i64* %8
store i32 0, i32* %10
br label %20
20: ; preds = %43, %2
%21 = load i32, i32* %10
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %46
24: ; preds = %20
%25 = call float (...) @rand_float()
%26 = call float @llvm.fmuladd.f32(float %25, float 1.000000e+04, float -5.000000e+03)
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds float, float* %15, i64 %28
store float %26, float* %29
%30 = call float (...) @rand_float()
%31 = call float @llvm.fmuladd.f32(float %30, float 1.000000e+04, float -5.000000e+03)
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds float, float* %15, i64 %34
store float %31, float* %35
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds float, float* %19, i64 %37
store float 0.000000e+00, float* %38
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds float, float* %19, i64 %41
store float 0.000000e+00, float* %42
br label %43
43: ; preds = %24
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %20
46: ; preds = %20
%47 = call double (...) @tic()
store double %47, double* %9
store i32 0, i32* %10
br label %48
48: ; preds = %65, %46
%49 = load i32, i32* %10
%50 = load i32, i32* %3
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %68
52: ; preds = %48
%53 = load i32, i32* %4
%54 = bitcast float* %15 to i8*
%55 = bitcast float* %19 to i8*
%56 = call i32 @c_cswap(i32 %53, i8* %54, i32 1, i8* %55, i32 1)
%57 = getelementptr inbounds float, float* %19, i64 0
%58 = load float, float* %57
%59 = getelementptr inbounds float, float* %19, i64 0
%60 = load float, float* %59
%61 = fcmp une float %58, %60
br i1 %61, label %62, label %64
62: ; preds = %52
%63 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %68
64: ; preds = %52
br label %65
65: ; preds = %64
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
br label %48
68: ; preds = %62, %48
%69 = call double (...) @tic()
%70 = load double, double* %9
%71 = fsub double %69, %70
store double %71, double* %5
%72 = getelementptr inbounds float, float* %19, i64 0
%73 = load float, float* %72
%74 = getelementptr inbounds float, float* %19, i64 0
%75 = load float, float* %74
%76 = fcmp une float %73, %75
br i1 %76, label %77, label %79
77: ; preds = %68
%78 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %79
79: ; preds = %77, %68
%80 = load double, double* %5
%81 = load i8*, i8** %6
ret double %80
}

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