#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fib(int, int);
int getopt(int, char **, char *);
double omp_get_wtime();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, ...);
int strtol(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  int fib_start = 30;
  int fib_cutoff = 20;
  int num_threads = 4;
  int opt;
  while ((opt = getopt(argc, argv, "c:hn:t:")) != -1) {
    switch (opt) {
    case 'c':
      fib_cutoff = strtol(optarg, NULL, 10);
      break;
    case 'n':
      fib_start = strtol(optarg, NULL, 10);
      break;
    case 't':
      num_threads = strtol(optarg, NULL, 10);
      break;
    case 'h':
    default:
      printf("usage: %s -c fib_cutoff -n fib_start -t num_threads\n", argv[0]);
      exit(EXIT_SUCCESS);
    }
  }
  double t;
  double t1;
  for (int nth = 1; nth <= num_threads; nth++) {
    omp_set_num_threads(nth);
#pragma omp parallel
    {
#pragma omp single
      {
        t = omp_get_wtime();
        fib(fib_start, fib_cutoff);
        t = omp_get_wtime() - t;
        if (nth == 1) {
          t1 = t;
        }
        printf("%d %d %lf %lf\n", fib_cutoff, nth, t1 / t, t1 / t / nth);
      }
    }
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1e,-0x14(%rbp)
movl   $0x14,-0x18(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe9f(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     126d <main+0xfd>
mov    -0x20(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x11,%eax
ja     1245 <main+0xd5>
mov    -0x40(%rbp),%rax
lea    0xe26(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x18(%rbp)
jmp    1268 <main+0xf8>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x14(%rbp)
jmp    1268 <main+0xf8>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x1c(%rbp)
jmp    1268 <main+0xf8>
jmp    1245 <main+0xd5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    119b <main+0x2b>
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1303 <main+0x193>
mov    -0x34(%rbp),%edi
call   1060 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1070 <fib@plt>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x1,-0x34(%rbp)
jne    12c4 <main+0x154>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x34(%rbp),%edx
movsd  -0x30(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
divsd  -0x28(%rbp),%xmm1
cvtsi2sdl -0x34(%rbp),%xmm2
divsd  %xmm2,%xmm1
lea    0xd97(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1274 <main+0x104>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
mov    $0x1e,%r12d
mov    $0x4,%eax
mov    %rax,0x8(%rsp)
mov    $0x14,%r15d
lea    0xe60(%rip),%r13
mov    0x2e51(%rip),%r14
jmp    11c2 <main+0x52>
nopl   0x0(%rax)
mov    (%r14),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%r12d
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1080 <getopt@plt>
cmp    $0x6e,%eax
je     11b0 <main+0x40>
cmp    $0x63,%eax
je     11f4 <main+0x84>
cmp    $0x74,%eax
jne    1208 <main+0x98>
mov    (%r14),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,0x8(%rsp)
jmp    11c2 <main+0x52>
mov    (%r14),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%r15d
jmp    11c2 <main+0x52>
cmp    $0xffffffff,%eax
jne    12ba <main+0x14a>
mov    0x8(%rsp),%rbp
test   %ebp,%ebp
jle    12cc <main+0x15c>
neg    %ebp
mov    $0x1,%ebx
lea    0xe11(%rip),%r14
jmp    127a <main+0x10a>
xchg   %ax,%ax
movsd  %xmm2,0x8(%rsp)
divsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movapd %xmm2,%xmm1
divsd  %xmm0,%xmm1
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
movapd %xmm2,%xmm0
mov    $0x2,%al
call   1040 <printf@plt>
lea    (%rbx,%rbp,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
cmp    $0x1,%eax
je     12cc <main+0x15c>
mov    %ebx,%edi
call   1060 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r12d,%edi
mov    %r15d,%esi
call   1070 <fib@plt>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
subsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm2
cmp    $0x1,%ebx
je     1230 <main+0xc0>
movsd  0x10(%rsp),%xmm2
jmp    1230 <main+0xc0>
mov    0x0(%rbp),%rsi
lea    0xd43(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"c:hn:t:\00"
@optarg = global i32 0
@.str.1 = [53 x i8] c"usage: %s -c fib_cutoff -n fib_start -t num_threads\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [15 x i8] c"%d %d %lf %lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 30, i32* %6
store i32 20, i32* %7
store i32 4, i32* %8
br label %13
13: ; preds = %37, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %9
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %38
18: ; preds = %13
%19 = load i32, i32* %9
switch i32 %19, label %30 [
i32 99, label %20
i32 110, label %23
i32 116, label %26
i32 104, label %29
]
20: ; preds = %18
%21 = load i32, i32* @optarg
%22 = call i32 @strtol(i32 %21, i32* null, i32 10)
store i32 %22, i32* %7
br label %37
23: ; preds = %18
%24 = load i32, i32* @optarg
%25 = call i32 @strtol(i32 %24, i32* null, i32 10)
store i32 %25, i32* %6
br label %37
26: ; preds = %18
%27 = load i32, i32* @optarg
%28 = call i32 @strtol(i32 %27, i32* null, i32 10)
store i32 %28, i32* %8
br label %37
29: ; preds = %18
br label %30
30: ; preds = %18, %29
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_SUCCESS
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %26, %23, %20
br label %13
38: ; preds = %13
store i32 1, i32* %12
br label %39
39: ; preds = %70, %38
%40 = load i32, i32* %12
%41 = load i32, i32* %8
%42 = icmp sle i32 %40, %41
br i1 %42, label %43, label %73
43: ; preds = %39
%44 = load i32, i32* %12
%45 = call i32 @omp_set_num_threads(i32 %44)
%46 = call double (...) @omp_get_wtime()
store double %46, double* %10
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = call i32 @fib(i32 %47, i32 %48)
%50 = call double (...) @omp_get_wtime()
%51 = load double, double* %10
%52 = fsub double %50, %51
store double %52, double* %10
%53 = load i32, i32* %12
%54 = icmp eq i32 %53, 1
br i1 %54, label %55, label %57
55: ; preds = %43
%56 = load double, double* %10
store double %56, double* %11
br label %57
57: ; preds = %55, %43
%58 = load i32, i32* %7
%59 = load i32, i32* %12
%60 = load double, double* %11
%61 = load double, double* %10
%62 = fdiv double %60, %61
%63 = load double, double* %11
%64 = load double, double* %10
%65 = fdiv double %63, %64
%66 = load i32, i32* %12
%67 = sitofp i32 %66 to double
%68 = fdiv double %65, %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %58, i32 %59, double %62, double %68)
br label %70
70: ; preds = %57
%71 = load i32, i32* %12
%72 = add nsw i32 %71, 1
store i32 %72, i32* %12
br label %39
73: ; preds = %39
%74 = load i32, i32* @EXIT_SUCCESS
%75 = call i32 @exit(i32 %74)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"c:hn:t:\00"
@optarg = global i32 0
@.str.1 = [53 x i8] c"usage: %s -c fib_cutoff -n fib_start -t num_threads\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [15 x i8] c"%d %d %lf %lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %15, %2
%4 = phi i32 [ %17, %15 ], [ 20, %2 ]
%5 = phi i32 [ %8, %15 ], [ 4, %2 ]
%6 = phi i32 [ %11, %15 ], [ 30, %2 ]
br label %7
7: ; preds = %3, %21
%8 = phi i32 [ %5, %3 ], [ %23, %21 ]
%9 = phi i32 [ %6, %3 ], [ %11, %21 ]
br label %10
10: ; preds = %7, %18
%11 = phi i32 [ %20, %18 ], [ %9, %7 ]
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
switch i32 %12, label %24 [
i32 -1, label %13
i32 99, label %15
i32 110, label %18
i32 116, label %21
]
13: ; preds = %10
%14 = icmp slt i32 %8, 1
br i1 %14, label %29, label %32
15: ; preds = %10
%16 = load i32, i32* @optarg
%17 = tail call i32 @strtol(i32 %16, i32* null, i32 10)
br label %3
18: ; preds = %10
%19 = load i32, i32* @optarg
%20 = tail call i32 @strtol(i32 %19, i32* null, i32 10)
br label %10
21: ; preds = %10
%22 = load i32, i32* @optarg
%23 = tail call i32 @strtol(i32 %22, i32* null, i32 10)
br label %7
24: ; preds = %10
%25 = load i8*, i8** %1
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_SUCCESS
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %32, %13
%30 = load i32, i32* @EXIT_SUCCESS
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %13, %32
%33 = phi i32 [ %46, %32 ], [ 1, %13 ]
%34 = phi double [ %41, %32 ], [ undef, %13 ]
%35 = tail call i32 @omp_set_num_threads(i32 %33)
%36 = tail call double (...) @omp_get_wtime()
%37 = tail call i32 @fib(i32 %11, i32 %4)
%38 = tail call double (...) @omp_get_wtime()
%39 = fsub double %38, %36
%40 = icmp eq i32 %33, 1
%41 = select i1 %40, double %39, double %34
%42 = fdiv double %41, %39
%43 = sitofp i32 %33 to double
%44 = fdiv double %42, %43
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %33, double %42, double %44)
%46 = add nuw i32 %33, 1
%47 = icmp eq i32 %33, %8
br i1 %47, label %29, label %32
}