#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 fib_seq(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
long get_usecs();
int omp_get_thread_num();
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (argc > 5)
    fprintf(stderr,
            "Usage: %s num_iterations work_intensity num_loops randomize\n",
            argv[0]);
  int num_iter = 512;
  int work_int = 32;
  int num_loops = 1;
  int randomize = 0;
  if (argc > 1)
    num_iter = atoi(argv[1]);
  if (argc > 2)
    work_int = atoi(argv[2]);
  if (argc > 3)
    num_loops = atoi(argv[3]);
  if (argc > 4)
    randomize = 1;
  if (randomize)
    srand(time(NULL));
  ;
  fprintf(stderr, "Running %s %d %d %d %d ...\n", argv[0], num_iter, work_int,
          num_loops, randomize);
  long par_time_start = get_usecs();
  for (int j = 0; j < num_loops; j++) {
    int k = num_iter;
    if (randomize)
      k = (rand() % num_iter) + 1;
    fprintf(stderr, "Starting loop %d with %d iterations ...\n", j, k);
#pragma omp parallel for schedule(dynamic)
    for (int i = 0; i < k; i++) {
      int result = fib_seq(work_int);
      fprintf(stderr, "iteration %d thread %d result = %d\n", i,
              omp_get_thread_num(), result);
    }
  }
  long par_time_end = get_usecs();
  double par_time = (double)(par_time_end - par_time_start) / 1000000;
  fprintf(stderr, "Execution time = %f s\n", par_time);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
jle    11be <main+0x3e>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x200,-0x14(%rbp)
movl   $0x20,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11f4 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    120e <main+0x8e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1228 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x8(%rbp)
jle    1239 <main+0xb9>
movl   $0x1,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1253 <main+0xd3>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x20(%rbp),%eax
lea    0xdcd(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1090 <get_usecs@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1350 <main+0x1d0>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     12c1 <main+0x141>
mov    $0x0,%al
call   10a0 <rand@plt>
cltd
idivl  -0x14(%rbp)
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    133d <main+0x1bd>
mov    -0x18(%rbp),%edi
call   1040 <fib_seq@plt>
mov    %eax,-0x38(%rbp)
mov    0x2cdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    -0x50(%rbp),%edi
mov    -0x4c(%rbp),%edx
mov    %eax,%ecx
mov    -0x38(%rbp),%r8d
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12e5 <main+0x165>
jmp    1342 <main+0x1c2>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1294 <main+0x114>
mov    $0x0,%al
call   1090 <get_usecs@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  0xc90(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
movsd  -0x48(%rbp),%xmm0
lea    0xd20(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r15
cmp    $0x6,%edi
jl     11f0 <main+0x70>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xe5f(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%r15),%rdi
call   1080 <atoi@plt>
mov    %eax,0x10(%rsp)
mov    0x10(%r15),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
mov    0x18(%r15),%rdi
call   1080 <atoi@plt>
mov    %eax,0x14(%rsp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x1,%al
mov    %eax,0xc(%rsp)
mov    $0x1,%eax
jmp    125a <main+0xda>
mov    %edi,%ebp
mov    $0x20,%ebx
movl   $0x1,0x14(%rsp)
cmp    $0x2,%edi
jl     1248 <main+0xc8>
mov    0x8(%r15),%rdi
call   1080 <atoi@plt>
mov    %eax,0x10(%rsp)
xor    %eax,%eax
cmp    $0x2,%ebp
je     1252 <main+0xd2>
mov    0x10(%r15),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
xor    %eax,%eax
cmp    $0x4,%ebp
jb     1252 <main+0xd2>
mov    0x18(%r15),%rdi
call   1080 <atoi@plt>
mov    %eax,0x14(%rsp)
xor    %eax,%eax
movl   $0x0,0xc(%rsp)
cmp    $0x4,%ebp
jne    11d5 <main+0x55>
jmp    125a <main+0xda>
movl   $0x200,0x10(%rsp)
xor    %eax,%eax
movl   $0x0,0xc(%rsp)
mov    0x2d7f(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%r15),%rdx
mov    %eax,(%rsp)
lea    0xdd4(%rip),%rsi
mov    0x10(%rsp),%ecx
mov    %ebx,%r8d
mov    0x14(%rsp),%r14d
mov    %r14d,%r9d
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1090 <get_usecs@plt>
mov    %rax,0x20(%rsp)
test   %r14d,%r14d
jle    1352 <main+0x1d2>
lea    0xde7(%rip),%r13
xor    %r14d,%r14d
mov    %ebx,0x1c(%rsp)
jmp    12c4 <main+0x144>
nopl   0x0(%rax)
mov    0x18(%rsp),%r14d
add    $0x1,%r14d
cmp    0x14(%rsp),%r14d
je     1352 <main+0x1d2>
mov    0x10(%rsp),%r12d
cmpb   $0x0,0xc(%rsp)
je     12e3 <main+0x163>
xor    %eax,%eax
call   10a0 <rand@plt>
cltd
idivl  0x10(%rsp)
mov    %edx,%r12d
add    $0x1,%r12d
mov    0x0(%rbp),%edi
lea    0xd74(%rip),%rsi
mov    %r14d,0x18(%rsp)
mov    %r14d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %r12d,%r12d
jle    12b0 <main+0x130>
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <fib_seq@plt>
mov    %r12d,%ebx
mov    %eax,%r12d
mov    0x0(%rbp),%r15d
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    %r14d,%edx
mov    %eax,%ecx
mov    %r12d,%r8d
mov    %ebx,%r12d
mov    0x1c(%rsp),%ebx
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%r14d
cmp    %r14d,%r12d
jne    1310 <main+0x190>
jmp    12b0 <main+0x130>
xor    %eax,%eax
call   1090 <get_usecs@plt>
sub    0x20(%rsp),%rax
cvtsi2sd %rax,%xmm0
divsd  0xc95(%rip),%xmm0
mov    0x0(%rbp),%edi
lea    0xd39(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [61 x i8] c"Usage: %s num_iterations work_intensity num_loops randomize\0A\00"
@.str.1 = [28 x i8] c"Running %s %d %d %d %d ...\0A\00"
@.str.2 = [41 x i8] c"Starting loop %d with %d iterations ...\0A\00"
@.str.3 = [36 x i8] c"iteration %d thread %d result = %d\0A\00"
@.str.4 = [23 x i8] c"Execution time = %f s\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 i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
%16 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 5
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %19, %2
store i32 512, i32* %6
store i32 32, i32* %7
store i32 1, i32* %8
store i32 0, i32* %9
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 1
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %6
br label %33
33: ; preds = %28, %25
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 2
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %7
br label %41
41: ; preds = %36, %33
%42 = load i32, i32* %4
%43 = icmp sgt i32 %42, 3
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 3
%47 = load i8*, i8** %46
%48 = call i32 @atoi(i8* %47)
store i32 %48, i32* %8
br label %49
49: ; preds = %44, %41
%50 = load i32, i32* %4
%51 = icmp sgt i32 %50, 4
br i1 %51, label %52, label %53
52: ; preds = %49
store i32 1, i32* %9
br label %53
53: ; preds = %52, %49
%54 = load i32, i32* %9
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = call i32 @time(i32* null)
%58 = call i32 @srand(i32 %57)
br label %59
59: ; preds = %56, %53
%60 = load i32, i32* @stderr
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 0
%63 = load i8*, i8** %62
%64 = load i32, i32* %6
%65 = load i32, i32* %7
%66 = load i32, i32* %8
%67 = load i32, i32* %9
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %63, i32 %64, i32 %65, i32 %66, i32 %67)
%69 = call i64 (...) @get_usecs()
store i64 %69, i64* %10
store i32 0, i32* %11
br label %70
70: ; preds = %104, %59
%71 = load i32, i32* %11
%72 = load i32, i32* %8
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %107
74: ; preds = %70
%75 = load i32, i32* %6
store i32 %75, i32* %12
%76 = load i32, i32* %9
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %83
78: ; preds = %74
%79 = call i32 (...) @rand()
%80 = load i32, i32* %6
%81 = srem i32 %79, %80
%82 = add nsw i32 %81, 1
store i32 %82, i32* %12
br label %83
83: ; preds = %78, %74
%84 = load i32, i32* @stderr
%85 = load i32, i32* %11
%86 = load i32, i32* %12
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %85, i32 %86)
store i32 0, i32* %13
br label %88
88: ; preds = %100, %83
%89 = load i32, i32* %13
%90 = load i32, i32* %12
%91 = icmp slt i32 %89, %90
br i1 %91, label %92, label %103
92: ; preds = %88
%93 = load i32, i32* %7
%94 = call i32 @fib_seq(i32 %93)
store i32 %94, i32* %14
%95 = load i32, i32* @stderr
%96 = load i32, i32* %13
%97 = call i32 (...) @omp_get_thread_num()
%98 = load i32, i32* %14
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %96, i32 %97, i32 %98)
br label %100
100: ; preds = %92
%101 = load i32, i32* %13
%102 = add nsw i32 %101, 1
store i32 %102, i32* %13
br label %88
103: ; preds = %88
br label %104
104: ; preds = %103
%105 = load i32, i32* %11
%106 = add nsw i32 %105, 1
store i32 %106, i32* %11
br label %70
107: ; preds = %70
%108 = call i64 (...) @get_usecs()
store i64 %108, i64* %15
%109 = load i64, i64* %15
%110 = load i64, i64* %10
%111 = sub nsw i64 %109, %110
%112 = sitofp i64 %111 to double
%113 = fdiv double %112, 1.000000e+06
store double %113, double* %16
%114 = load i32, i32* @stderr
%115 = load double, double* %16
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), double %115)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [61 x i8] c"Usage: %s num_iterations work_intensity num_loops randomize\0A\00"
@.str.1 = [28 x i8] c"Running %s %d %d %d %d ...\0A\00"
@.str.2 = [41 x i8] c"Starting loop %d with %d iterations ...\0A\00"
@.str.3 = [36 x i8] c"iteration %d thread %d result = %d\0A\00"
@.str.4 = [23 x i8] c"Execution time = %f s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 5
br i1 %3, label %4, label %17
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
br label %34
17: ; preds = %2
%18 = icmp sgt i32 %0, 1
br i1 %18, label %19, label %40
19: ; preds = %17
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = icmp eq i32 %0, 2
br i1 %23, label %40, label %24
24: ; preds = %19
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i32 @atoi(i8* %26)
%28 = icmp ugt i32 %0, 3
br i1 %28, label %29, label %40
29: ; preds = %24
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = tail call i32 @atoi(i8* %31)
%33 = icmp eq i32 %0, 4
br i1 %33, label %40, label %34
34: ; preds = %4, %29
%35 = phi i32 [ %16, %4 ], [ %32, %29 ]
%36 = phi i32 [ %10, %4 ], [ %22, %29 ]
%37 = phi i32 [ %13, %4 ], [ %27, %29 ]
%38 = tail call i32 @time(i32* null)
%39 = tail call i32 @srand(i32 %38)
br label %40
40: ; preds = %17, %19, %24, %34, %29
%41 = phi i32 [ 1, %34 ], [ 0, %29 ], [ 0, %24 ], [ 0, %19 ], [ 0, %17 ]
%42 = phi i1 [ true, %34 ], [ false, %29 ], [ false, %24 ], [ false, %19 ], [ false, %17 ]
%43 = phi i32 [ %35, %34 ], [ %32, %29 ], [ 1, %24 ], [ 1, %19 ], [ 1, %17 ]
%44 = phi i32 [ %36, %34 ], [ %22, %29 ], [ %22, %24 ], [ %22, %19 ], [ 512, %17 ]
%45 = phi i32 [ %37, %34 ], [ %27, %29 ], [ %27, %24 ], [ 32, %19 ], [ 32, %17 ]
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %1
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %47, i32 %44, i32 %45, i32 %43, i32 %41)
%49 = tail call i64 (...) @get_usecs()
%50 = icmp sgt i32 %43, 0
br i1 %50, label %58, label %51
51: ; preds = %69, %40
%52 = tail call i64 (...) @get_usecs()
%53 = sub nsw i64 %52, %49
%54 = sitofp i64 %53 to double
%55 = fdiv double %54, 1.000000e+06
%56 = load i32, i32* @stderr
%57 = tail call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), double %55)
ret i32 0
58: ; preds = %40, %69
%59 = phi i32 [ %70, %69 ], [ 0, %40 ]
br i1 %42, label %60, label %64
60: ; preds = %58
%61 = tail call i32 (...) @rand()
%62 = srem i32 %61, %44
%63 = add nsw i32 %62, 1
br label %64
64: ; preds = %60, %58
%65 = phi i32 [ %63, %60 ], [ %44, %58 ]
%66 = load i32, i32* @stderr
%67 = tail call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %59, i32 %65)
%68 = icmp sgt i32 %65, 0
br i1 %68, label %72, label %69
69: ; preds = %72, %64
%70 = add nuw nsw i32 %59, 1
%71 = icmp eq i32 %70, %43
br i1 %71, label %51, label %58
72: ; preds = %64, %72
%73 = phi i32 [ %78, %72 ], [ 0, %64 ]
%74 = tail call i32 @fib_seq(i32 %45)
%75 = load i32, i32* @stderr
%76 = tail call i32 (...) @omp_get_thread_num()
%77 = tail call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %73, i32 %76, i32 %74)
%78 = add nuw nsw i32 %73, 1
%79 = icmp eq i32 %78, %65
br i1 %79, label %69, label %72
}