#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 tv_sec;
  int tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_PROCESS_CPUTIME_ID;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ spread4(int);
int main() {
  struct timespec start, end;
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
  for (int i = 0; i < 10000; i++) {
    for (int j = 0; j < 10000; j++) {
      spread4(1);
      spread4(22);
      spread4(133);
      spread4(221);
    }
  }
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end);
  double elapsed =
      end.tv_sec - start.tv_sec + (end.tv_nsec - start.tv_nsec) * 1e-9;
  printf("%.6f \n", elapsed);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2710,-0x1c(%rbp)
jge    11c2 <main+0x92>
movl   $0x0,-0x20(%rbp)
cmpl   $0x2710,-0x20(%rbp)
jge    11af <main+0x7f>
mov    $0x1,%edi
call   1050 <spread4@plt>
mov    $0x16,%edi
call   1050 <spread4@plt>
mov    $0x85,%edi
call   1050 <spread4@plt>
mov    $0xdd,%edi
call   1050 <spread4@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116c <main+0x3c>
jmp    11b4 <main+0x84>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1158 <main+0x28>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x18(%rbp),%eax
sub    -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm1
mov    -0x14(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe10(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ea9(%rip),%r14
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
xor    %ebp,%ebp
xchg   %ax,%ax
mov    $0x2710,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
call   1050 <spread4@plt>
mov    $0x16,%edi
call   1050 <spread4@plt>
mov    $0x85,%edi
call   1050 <spread4@plt>
mov    $0xdd,%edi
call   1050 <spread4@plt>
add    $0xffffffff,%ebx
jne    1160 <main+0x30>
add    $0x1,%ebp
cmp    $0x2710,%ebp
jne    1150 <main+0x20>
mov    (%r14),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
sub    0x8(%rsp),%eax
cvtsi2sd %eax,%xmm1
sub    0xc(%rsp),%ecx
cvtsi2sd %ecx,%xmm0
mulsd  0xe3e(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0xe3b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@.str = [7 x i8] c"%.6f \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store i32 0, i32* %1
%7 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%8 = call i32 @clock_gettime(i32 %7, %struct.timespec* %2)
store i32 0, i32* %4
br label %9
9: ; preds = %25, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 10000
br i1 %11, label %12, label %28
12: ; preds = %9
store i32 0, i32* %5
br label %13
13: ; preds = %21, %12
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 10000
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = call i32 @spread4(i32 1)
%18 = call i32 @spread4(i32 22)
%19 = call i32 @spread4(i32 133)
%20 = call i32 @spread4(i32 221)
br label %21
21: ; preds = %16
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %13
24: ; preds = %13
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %9
28: ; preds = %9
%29 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%30 = call i32 @clock_gettime(i32 %29, %struct.timespec* %3)
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%34 = load i32, i32* %33
%35 = sub nsw i32 %32, %34
%36 = sitofp i32 %35 to double
%37 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%40 = load i32, i32* %39
%41 = sub nsw i32 %38, %40
%42 = sitofp i32 %41 to double
%43 = call double @llvm.fmuladd.f64(double %42, double 1.000000e-09, double %36)
store double %43, double* %6
%44 = load double, double* %6
%45 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %44)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@.str = [7 x i8] c"%.6f \0A\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %1 to i8*
%4 = bitcast %struct.timespec* %2 to i8*
%5 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %1)
br label %7
7: ; preds = %0, %26
%8 = phi i32 [ 0, %0 ], [ %27, %26 ]
br label %29
9: ; preds = %26
%10 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%11 = call i32 @clock_gettime(i32 %10, %struct.timespec* %2)
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%15 = load i32, i32* %14
%16 = sub nsw i32 %13, %15
%17 = sitofp i32 %16 to double
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%21 = load i32, i32* %20
%22 = sub nsw i32 %19, %21
%23 = sitofp i32 %22 to double
%24 = call double @llvm.fmuladd.f64(double %23, double 1.000000e-09, double %17)
%25 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %24)
ret i32 0
26: ; preds = %29
%27 = add nuw nsw i32 %8, 1
%28 = icmp eq i32 %27, 10000
br i1 %28, label %9, label %7
29: ; preds = %7, %29
%30 = phi i32 [ 0, %7 ], [ %35, %29 ]
%31 = call i32 @spread4(i32 1)
%32 = call i32 @spread4(i32 22)
%33 = call i32 @spread4(i32 133)
%34 = call i32 @spread4(i32 221)
%35 = add nuw nsw i32 %30, 1
%36 = icmp eq i32 %35, 10000
br i1 %36, label %26, label %29
}