#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, int, double, double);
double sqrt(int);
void gettime(void) {
  int i, nthreads;
  clock_t clock_timer;
  double wall_timer;
  double c[1000000];
  for (nthreads = 1; nthreads <= 8; ++nthreads) {
    clock_timer = clock();
    wall_timer = omp_get_wtime();
#pragma omp parallel for private(i) num_threads(nthreads)
    for (i = 0; i < 1000000; i++)
      c[i] = sqrt(i * 4 + i * 2 + i);
    printf("threads: %d %f %f\n", nthreads,
           (double)(clock() - clock_timer) / CLOCKS_PER_SEC,
           omp_get_wtime() - wall_timer);
  }
}


x86 assembly (clang, -O0):
<gettime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7a1230,%rsp
movl   $0x1,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jg     121b <gettime+0xdb>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0xf4240,-0x4(%rbp)
jge    11b8 <gettime+0x78>
mov    -0x4(%rbp),%edi
shl    $0x2,%edi
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
add    %eax,%edi
add    -0x4(%rbp),%edi
call   1060 <sqrt@plt>
movslq -0x4(%rbp),%rax
movsd  %xmm0,-0x7a1220(%rbp,%rax,8)
85 ff
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    117a <gettime+0x3a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x7a122c(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e10(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x7a1228(%rbp)
ff
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
mov    -0x7a122c(%rbp),%esi
movaps %xmm0,%xmm1
movsd  -0x7a1228(%rbp),%xmm0
ff
subsd  -0x18(%rbp),%xmm1
lea    0xdf8(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1152 <gettime+0x12>
add    $0x7a1230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettime>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%ebp
mov    0x2e90(%rip),%r12
lea    0xea1(%rip),%r14
nop
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x31,%ebx
nopl   0x0(%rax)
lea    -0x31(%rbx),%edi
call   1060 <sqrt@plt>
lea    -0x2a(%rbx),%edi
call   1060 <sqrt@plt>
lea    -0x23(%rbx),%edi
call   1060 <sqrt@plt>
lea    -0x1c(%rbx),%edi
call   1060 <sqrt@plt>
lea    -0x15(%rbx),%edi
call   1060 <sqrt@plt>
lea    -0xe(%rbx),%edi
call   1060 <sqrt@plt>
lea    -0x7(%rbx),%edi
call   1060 <sqrt@plt>
mov    %ebx,%edi
call   1060 <sqrt@plt>
add    $0x38,%ebx
cmp    $0x6acff1,%ebx
jne    1180 <gettime+0x40>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r15,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r12),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movapd %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
mov    %r14,%rdi
mov    %ebp,%esi
movsd  (%rsp),%xmm0
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    $0x9,%ebp
jne    1160 <gettime+0x20>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"threads: %d %f %f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define void @gettime() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca double
%5 = alloca [1000000 x double]
store i32 1, i32* %2
br label %6
6: ; preds = %42, %0
%7 = load i32, i32* %2
%8 = icmp sle i32 %7, 8
br i1 %8, label %9, label %45
9: ; preds = %6
%10 = call i64 (...) @clock()
store i64 %10, i64* %3
%11 = call double (...) @omp_get_wtime()
store double %11, double* %4
store i32 0, i32* %1
br label %12
12: ; preds = %27, %9
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 1000000
br i1 %14, label %15, label %30
15: ; preds = %12
%16 = load i32, i32* %1
%17 = mul nsw i32 %16, 4
%18 = load i32, i32* %1
%19 = mul nsw i32 %18, 2
%20 = add nsw i32 %17, %19
%21 = load i32, i32* %1
%22 = add nsw i32 %20, %21
%23 = call double @sqrt(i32 %22)
%24 = load i32, i32* %1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1000000 x double], [1000000 x double]* %5, i64 0, i64 %25
store double %23, double* %26
br label %27
27: ; preds = %15
%28 = load i32, i32* %1
%29 = add nsw i32 %28, 1
store i32 %29, i32* %1
br label %12
30: ; preds = %12
%31 = load i32, i32* %2
%32 = call i64 (...) @clock()
%33 = load i64, i64* %3
%34 = sub nsw i64 %32, %33
%35 = sitofp i64 %34 to double
%36 = load double, double* @CLOCKS_PER_SEC
%37 = fdiv double %35, %36
%38 = call double (...) @omp_get_wtime()
%39 = load double, double* %4
%40 = fsub double %38, %39
%41 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %31, double %37, double %40)
br label %42
42: ; preds = %30
%43 = load i32, i32* %2
%44 = add nsw i32 %43, 1
store i32 %44, i32* %2
br label %6
45: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"threads: %d %f %f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define void @gettime() {
br label %1
1: ; preds = %0, %32
%2 = phi i32 [ 1, %0 ], [ %41, %32 ]
%3 = tail call i64 (...) @clock()
%4 = tail call double (...) @omp_get_wtime()
br label %5
5: ; preds = %5, %1
%6 = phi i32 [ 0, %1 ], [ %30, %5 ]
%7 = mul nuw nsw i32 %6, 7
%8 = tail call double @sqrt(i32 %7)
%9 = or i32 %6, 1
%10 = mul nuw nsw i32 %9, 7
%11 = tail call double @sqrt(i32 %10)
%12 = or i32 %6, 2
%13 = mul nuw nsw i32 %12, 7
%14 = tail call double @sqrt(i32 %13)
%15 = or i32 %6, 3
%16 = mul nuw nsw i32 %15, 7
%17 = tail call double @sqrt(i32 %16)
%18 = or i32 %6, 4
%19 = mul nuw nsw i32 %18, 7
%20 = tail call double @sqrt(i32 %19)
%21 = or i32 %6, 5
%22 = mul nuw nsw i32 %21, 7
%23 = tail call double @sqrt(i32 %22)
%24 = or i32 %6, 6
%25 = mul nuw nsw i32 %24, 7
%26 = tail call double @sqrt(i32 %25)
%27 = or i32 %6, 7
%28 = mul nuw nsw i32 %27, 7
%29 = tail call double @sqrt(i32 %28)
%30 = add nuw nsw i32 %6, 8
%31 = icmp eq i32 %30, 1000000
br i1 %31, label %32, label %5
32: ; preds = %5
%33 = tail call i64 (...) @clock()
%34 = sub nsw i64 %33, %3
%35 = sitofp i64 %34 to double
%36 = load double, double* @CLOCKS_PER_SEC
%37 = fdiv double %35, %36
%38 = tail call double (...) @omp_get_wtime()
%39 = fsub double %38, %4
%40 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %2, double %37, double %39)
%41 = add nuw nsw i32 %2, 1
%42 = icmp eq i32 %41, 9
br i1 %42, label %43, label %1
43: ; preds = %32
ret void
}