#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_FAILURE;
int EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
scalar_t__ fib(int);
int /*<<< orphan*/ printf(char *, double);
int rand();
int main(int argc, char *argv[]) {
  double sum = 0.0;
  int i, n, max;
  if (argc != 3)
    errx(EXIT_FAILURE, "expecting n and max");
  n = atoi(argv[1]);
  max = atoi(argv[2]);
#pragma omp parallel for private(i) schedule(dynamic, 1)
  for (i = 0; i < n; i++) {
#pragma omp atomic
    sum += fib(rand() % max);
  }
  printf("sum = %lf\n", sum);
  return EXIT_SUCCESS;
}


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)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118d <main+0x3d>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1030 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11ef <main+0x9f>
mov    $0x0,%al
call   1070 <rand@plt>
cltd
idivl  -0x24(%rbp)
mov    %edx,%edi
call   1050 <fib@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b4 <main+0x64>
movsd  -0x18(%rbp),%xmm0
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x3,%edi
je     1170 <main+0x20>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1030 <errx@plt>
mov    0x8(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
call   1060 <atoi@plt>
test   %ebx,%ebx
jle    11c8 <main+0x78>
mov    %eax,%ebp
xorps  %xmm0,%xmm0
nopl   (%rax)
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
cltd
idiv   %ebp
mov    %edx,%edi
call   1050 <fib@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0xffffffff,%ebx
jne    1190 <main+0x40>
jmp    11cb <main+0x7b>
xorps  %xmm0,%xmm0
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [20 x i8] c"expecting n and max\00"
@.str.1 = [11 x i8] c"sum = %lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %6
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @errx(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %12, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %8
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %9
store i32 0, i32* %7
br label %24
24: ; preds = %36, %15
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %39
28: ; preds = %24
%29 = call i32 (...) @rand()
%30 = load i32, i32* %9
%31 = srem i32 %29, %30
%32 = call i64 @fib(i32 %31)
%33 = sitofp i64 %32 to double
%34 = load double, double* %6
%35 = fadd double %34, %33
store double %35, double* %6
br label %36
36: ; preds = %28
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %24
39: ; preds = %24
%40 = load double, double* %6
%41 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %40)
%42 = load i32, i32* @EXIT_SUCCESS
ret i32 %42
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [20 x i8] c"expecting n and max\00"
@.str.1 = [11 x i8] c"sum = %lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @errx(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %4, %2
%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 = icmp sgt i32 %10, 0
br i1 %14, label %15, label %25
15: ; preds = %7, %15
%16 = phi double [ %22, %15 ], [ 0.000000e+00, %7 ]
%17 = phi i32 [ %23, %15 ], [ 0, %7 ]
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, %13
%20 = tail call i64 @fib(i32 %19)
%21 = sitofp i64 %20 to double
%22 = fadd double %16, %21
%23 = add nuw nsw i32 %17, 1
%24 = icmp eq i32 %23, %10
br i1 %24, label %25, label %15
25: ; preds = %15, %7
%26 = phi double [ 0.000000e+00, %7 ], [ %22, %15 ]
%27 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %26)
%28 = load i32, i32* @EXIT_SUCCESS
ret i32 %28
}