#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 atoi(char *);
int /*<<< orphan*/ cuda_kernel_exec(int);
double gettimeofday_sec();
int /*<<< orphan*/ printf(char *, double);
int main(int argc, char *argv[]) {
  double t1, t2;
  int n = 100;
  if (argc > 1) {
    n = atoi(argv[1]);
  }
  printf("n: %d\n", n);
  t1 = gettimeofday_sec();
  cuda_kernel_exec(n);
  t2 = gettimeofday_sec();
  printf("elapsed: %f sec.\n", t2 - t1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x64,-0x24(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1177 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x24(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <gettimeofday_sec@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <cuda_kernel_exec@plt>
mov    $0x0,%al
call   1040 <gettimeofday_sec@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x64,%ebx
cmp    $0x2,%edi
jl     115a <main+0x1a>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
cvtsi2sd %ebx,%xmm0
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <gettimeofday_sec@plt>
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
call   1060 <cuda_kernel_exec@plt>
xor    %eax,%eax
call   1040 <gettimeofday_sec@plt>
subsd  0x8(%rsp),%xmm0
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"n: %d\0A\00"
@.str.1 = [18 x i8] c"elapsed: %f sec.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 100, i32* %8
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %8
br label %16
16: ; preds = %11, %2
%17 = load i32, i32* %8
%18 = sitofp i32 %17 to double
%19 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %18)
%20 = call double (...) @gettimeofday_sec()
store double %20, double* %6
%21 = load i32, i32* %8
%22 = call i32 @cuda_kernel_exec(i32 %21)
%23 = call double (...) @gettimeofday_sec()
store double %23, double* %7
%24 = load double, double* %7
%25 = load double, double* %6
%26 = fsub double %24, %25
%27 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"n: %d\0A\00"
@.str.1 = [18 x i8] c"elapsed: %f sec.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %4, %2
%9 = phi i32 [ %7, %4 ], [ 100, %2 ]
%10 = sitofp i32 %9 to double
%11 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %10)
%12 = tail call double (...) @gettimeofday_sec()
%13 = tail call i32 @cuda_kernel_exec(i32 %9)
%14 = tail call double (...) @gettimeofday_sec()
%15 = fsub double %14, %12
%16 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double %15)
ret i32 0
}