#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 /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, double, int);
int main(int argc, char **argv) {
  int N, nthreads;
  int i;
  double sum = 0;
  if (argc > 1) {
    N = atoi(argv[1]);
    nthreads = atoi(argv[2]);
  } else {
    N = 10;
    nthreads = 10;
  }
  omp_set_num_threads(nthreads);
#pragma omp parallel for reduction(+ : sum)
  for (i = 1; i < N; i++) {
    sum += 1.0 / i;
  }
  printf("Sum of harmonical series 1/n = %.4lf for N = %d\n", sum, N);
  return 0;
}


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,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    117d <main+0x4d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    118b <main+0x5b>
movl   $0xa,-0x14(%rbp)
movl   $0xa,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <omp_set_num_threads@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11cf <main+0x9f>
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xe4d(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119a <main+0x6a>
movsd  -0x28(%rbp),%xmm0
mov    -0x14(%rbp),%esi
lea    0xe2a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    1167 <main+0x37>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,%edi
call   1040 <omp_set_num_threads@plt>
xorpd  %xmm0,%xmm0
cmp    $0x2,%r14d
jge    1177 <main+0x47>
jmp    1210 <main+0xe0>
mov    $0xa,%r14d
mov    $0xa,%edi
call   1040 <omp_set_num_threads@plt>
lea    -0x1(%r14),%eax
cmp    $0x2,%r14d
jne    1196 <main+0x66>
movsd  0xe77(%rip),%xmm1
xorpd  %xmm0,%xmm0
test   $0x1,%al
jne    1200 <main+0xd0>
jmp    1210 <main+0xe0>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
neg    %ecx
mov    $0x1,%edx
movsd  0xe56(%rip),%xmm1
xorpd  %xmm0,%xmm0
movsd  0xe52(%rip),%xmm2
movapd %xmm1,%xmm3
nopw   0x0(%rax,%rax,1)
movapd %xmm1,%xmm4
divsd  %xmm3,%xmm4
addsd  %xmm0,%xmm4
lea    0x1(%rdx),%esi
xorps  %xmm5,%xmm5
cvtsi2sd %esi,%xmm5
movapd %xmm1,%xmm0
divsd  %xmm5,%xmm0
addsd  %xmm4,%xmm0
addsd  %xmm2,%xmm3
mov    %edx,%esi
add    $0x2,%edx
add    %ecx,%esi
add    $0x2,%esi
cmp    $0x1,%esi
jne    11c0 <main+0x90>
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
test   $0x1,%al
je     1210 <main+0xe0>
movsd  0xdf8(%rip),%xmm2
divsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
lea    0xdf9(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Sum of harmonical series 1/n = %.4lf for N = %d\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 double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %9
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %7
br label %22
21: ; preds = %2
store i32 10, i32* %6
store i32 10, i32* %7
br label %22
22: ; preds = %21, %12
%23 = load i32, i32* %7
%24 = call i32 @omp_set_num_threads(i32 %23)
store i32 1, i32* %8
br label %25
25: ; preds = %35, %22
%26 = load i32, i32* %8
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = load i32, i32* %8
%31 = sitofp i32 %30 to double
%32 = fdiv double 1.000000e+00, %31
%33 = load double, double* %9
%34 = fadd double %33, %32
store double %34, double* %9
br label %35
35: ; preds = %29
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %25
38: ; preds = %25
%39 = load double, double* %9
%40 = load i32, i32* %6
%41 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), double %39, i32 %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [49 x i8] c"Sum of harmonical series 1/n = %.4lf for N = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @omp_set_num_threads(i32 10)
br label %15
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = tail call i32 @omp_set_num_threads(i32 %12)
%14 = icmp sgt i32 %9, 1
br i1 %14, label %15, label %46
15: ; preds = %4, %6
%16 = phi i32 [ 10, %4 ], [ %9, %6 ]
%17 = add i32 %16, -1
%18 = and i32 %17, 1
%19 = icmp eq i32 %16, 2
br i1 %19, label %38, label %20
20: ; preds = %15
%21 = and i32 %17, -2
br label %22
22: ; preds = %22, %20
%23 = phi double [ 0.000000e+00, %20 ], [ %32, %22 ]
%24 = phi i32 [ 1, %20 ], [ %33, %22 ]
%25 = phi i32 [ 0, %20 ], [ %34, %22 ]
%26 = sitofp i32 %24 to double
%27 = fdiv double 1.000000e+00, %26
%28 = fadd double %23, %27
%29 = add nuw nsw i32 %24, 1
%30 = sitofp i32 %29 to double
%31 = fdiv double 1.000000e+00, %30
%32 = fadd double %28, %31
%33 = add nuw nsw i32 %24, 2
%34 = add i32 %25, 2
%35 = icmp eq i32 %34, %21
br i1 %35, label %36, label %22
36: ; preds = %22
%37 = sitofp i32 %33 to double
br label %38
38: ; preds = %36, %15
%39 = phi double [ undef, %15 ], [ %32, %36 ]
%40 = phi double [ 0.000000e+00, %15 ], [ %32, %36 ]
%41 = phi double [ 1.000000e+00, %15 ], [ %37, %36 ]
%42 = icmp eq i32 %18, 0
br i1 %42, label %46, label %43
43: ; preds = %38
%44 = fdiv double 1.000000e+00, %41
%45 = fadd double %40, %44
br label %46
46: ; preds = %43, %38, %6
%47 = phi i32 [ %9, %6 ], [ %16, %38 ], [ %16, %43 ]
%48 = phi double [ 0.000000e+00, %6 ], [ %39, %38 ], [ %45, %43 ]
%49 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), double %48, i32 %47)
ret i32 0
}