#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int omp_get_num_threads();
int omp_get_thread_num();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char **argv) {
  int threadCount = 20;
  omp_set_num_threads(threadCount);
  int i = 6;
  int *v = (int *)calloc(threadCount, sizeof(int));
  int badness, veryBad = 0;
#pragma omp parallel reduction(+ : veryBad)
  {
    int rank = omp_get_thread_num();
    int size = omp_get_num_threads();
    int foo = veryBad;
    if ((rank + 1) % 2 == 0)
      printf("hello world from rank %d/%d\n", rank, size);
    v[rank] = rank;
    badness = rank;
    veryBad = foo + rank;
  }
  int n;
  for (n = 0; n < threadCount; ++n) {
    printf("v[%d]=%d\n", n, v[n]);
  }
  printf("veryBad = %d\n", veryBad);
  exit(0);
  return 0;
}


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   $0x14,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <omp_set_num_threads@plt>
movl   $0x6,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11e9 <main+0x89>
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x34(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1243 <main+0xe3>
mov    -0x38(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    120d <main+0xad>
mov    -0x28(%rbp),%esi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x14,%edi
call   1070 <omp_set_num_threads@plt>
mov    $0x14,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
test   $0x1,%r14b
je     11aa <main+0x4a>
lea    0xe62(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movslq %r14d,%rax
mov    %r14d,(%rbx,%rax,4)
mov    (%rbx),%edx
lea    0xe63(%rip),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx),%edx
mov    %rbp,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%edx
mov    %rbp,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rbx),%edx
mov    %rbp,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%edx
mov    %rbp,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rbx),%edx
mov    %rbp,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%edx
mov    %rbp,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rbx),%edx
mov    %rbp,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rbx),%edx
mov    %rbp,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x24(%rbx),%edx
mov    %rbp,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x28(%rbx),%edx
mov    %rbp,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2c(%rbx),%edx
mov    %rbp,%rdi
mov    $0xb,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x30(%rbx),%edx
mov    %rbp,%rdi
mov    $0xc,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x34(%rbx),%edx
mov    %rbp,%rdi
mov    $0xd,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x38(%rbx),%edx
mov    %rbp,%rdi
mov    $0xe,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x3c(%rbx),%edx
mov    %rbp,%rdi
mov    $0xf,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x40(%rbx),%edx
mov    %rbp,%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x44(%rbx),%edx
mov    %rbp,%rdi
mov    $0x11,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x48(%rbx),%edx
mov    %rbp,%rdi
mov    $0x12,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4c(%rbx),%edx
mov    %rbp,%rdi
mov    $0x13,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd04(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"hello world from rank %d/%d\0A\00"
@.str.1 = [10 x i8] c"v[%d]=%d\0A\00"
@.str.2 = [14 x i8] c"veryBad = %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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 20, i32* %6
%15 = load i32, i32* %6
%16 = call i32 @omp_set_num_threads(i32 %15)
store i32 6, i32* %7
%17 = load i32, i32* %6
%18 = call i64 @calloc(i32 %17, i32 4)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %8
store i32 0, i32* %10
%20 = call i32 (...) @omp_get_thread_num()
store i32 %20, i32* %11
%21 = call i32 (...) @omp_get_num_threads()
store i32 %21, i32* %12
%22 = load i32, i32* %10
store i32 %22, i32* %13
%23 = load i32, i32* %11
%24 = add nsw i32 %23, 1
%25 = srem i32 %24, 2
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %2
%28 = load i32, i32* %11
%29 = load i32, i32* %12
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %29)
br label %31
31: ; preds = %27, %2
%32 = load i32, i32* %11
%33 = load i32*, i32** %8
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 %32, i32* %36
%37 = load i32, i32* %11
store i32 %37, i32* %9
%38 = load i32, i32* %13
%39 = load i32, i32* %11
%40 = add nsw i32 %38, %39
store i32 %40, i32* %10
store i32 0, i32* %14
br label %41
41: ; preds = %53, %31
%42 = load i32, i32* %14
%43 = load i32, i32* %6
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %56
45: ; preds = %41
%46 = load i32, i32* %14
%47 = load i32*, i32** %8
%48 = load i32, i32* %14
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load i32, i32* %50
%52 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %46, i32 %51)
br label %53
53: ; preds = %45
%54 = load i32, i32* %14
%55 = add nsw i32 %54, 1
store i32 %55, i32* %14
br label %41
56: ; preds = %41
%57 = load i32, i32* %10
%58 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %57)
%59 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [29 x i8] c"hello world from rank %d/%d\0A\00"
@.str.1 = [10 x i8] c"v[%d]=%d\0A\00"
@.str.2 = [14 x i8] c"veryBad = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @omp_set_num_threads(i32 20)
%4 = tail call i64 @calloc(i32 20, i32 4)
%5 = inttoptr i64 %4 to i32*
%6 = tail call i32 (...) @omp_get_thread_num()
%7 = tail call i32 (...) @omp_get_num_threads()
%8 = and i32 %6, 1
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
br label %12
12: ; preds = %10, %2
%13 = sext i32 %6 to i64
%14 = getelementptr inbounds i32, i32* %5, i64 %13
store i32 %6, i32* %14
%15 = load i32, i32* %5
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %15)
%17 = getelementptr inbounds i32, i32* %5, i64 1
%18 = load i32, i32* %17
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %18)
%20 = getelementptr inbounds i32, i32* %5, i64 2
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %21)
%23 = getelementptr inbounds i32, i32* %5, i64 3
%24 = load i32, i32* %23
%25 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 %24)
%26 = getelementptr inbounds i32, i32* %5, i64 4
%27 = load i32, i32* %26
%28 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 %27)
%29 = getelementptr inbounds i32, i32* %5, i64 5
%30 = load i32, i32* %29
%31 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 %30)
%32 = getelementptr inbounds i32, i32* %5, i64 6
%33 = load i32, i32* %32
%34 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 6, i32 %33)
%35 = getelementptr inbounds i32, i32* %5, i64 7
%36 = load i32, i32* %35
%37 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 7, i32 %36)
%38 = getelementptr inbounds i32, i32* %5, i64 8
%39 = load i32, i32* %38
%40 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 8, i32 %39)
%41 = getelementptr inbounds i32, i32* %5, i64 9
%42 = load i32, i32* %41
%43 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9, i32 %42)
%44 = getelementptr inbounds i32, i32* %5, i64 10
%45 = load i32, i32* %44
%46 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 10, i32 %45)
%47 = getelementptr inbounds i32, i32* %5, i64 11
%48 = load i32, i32* %47
%49 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 11, i32 %48)
%50 = getelementptr inbounds i32, i32* %5, i64 12
%51 = load i32, i32* %50
%52 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 12, i32 %51)
%53 = getelementptr inbounds i32, i32* %5, i64 13
%54 = load i32, i32* %53
%55 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 13, i32 %54)
%56 = getelementptr inbounds i32, i32* %5, i64 14
%57 = load i32, i32* %56
%58 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 14, i32 %57)
%59 = getelementptr inbounds i32, i32* %5, i64 15
%60 = load i32, i32* %59
%61 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 15, i32 %60)
%62 = getelementptr inbounds i32, i32* %5, i64 16
%63 = load i32, i32* %62
%64 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 16, i32 %63)
%65 = getelementptr inbounds i32, i32* %5, i64 17
%66 = load i32, i32* %65
%67 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 17, i32 %66)
%68 = getelementptr inbounds i32, i32* %5, i64 18
%69 = load i32, i32* %68
%70 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 18, i32 %69)
%71 = getelementptr inbounds i32, i32* %5, i64 19
%72 = load i32, i32* %71
%73 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 19, i32 %72)
%74 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%75 = tail call i32 @exit(i32 0)
unreachable
}