#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 veryBad = 0;
#pragma omp parallel firstprivate(i)
  {
    int rank = omp_get_thread_num();
    int size = omp_get_num_threads();
    i = i + rank;
#pragma omp critical
    {
      v[rank] = rank;
      veryBad += rank;
      printf("veryBad = %d (from rank %d)\n", veryBad, rank);
      printf("i=%d\n", i);
    }
  }
  printf("veryBad = %d\n", veryBad);
  exit(0);
  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)
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,-0x24(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe1c(%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,%r14
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
movslq %ebp,%rbx
add    $0x6,%ebp
mov    %ebx,(%r14,%rbx,4)
lea    0xe5f(%rip),%rdi
mov    %ebx,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe60(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"veryBad = %d (from rank %d)\0A\00"
@.str.1 = [6 x i8] c"i=%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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 20, i32* %6
%12 = load i32, i32* %6
%13 = call i32 @omp_set_num_threads(i32 %12)
store i32 6, i32* %7
%14 = load i32, i32* %6
%15 = call i64 @calloc(i32 %14, i32 4)
%16 = inttoptr i64 %15 to i32*
store i32* %16, i32** %8
store i32 0, i32* %9
%17 = call i32 (...) @omp_get_thread_num()
store i32 %17, i32* %10
%18 = call i32 (...) @omp_get_num_threads()
store i32 %18, i32* %11
%19 = load i32, i32* %7
%20 = load i32, i32* %10
%21 = add nsw i32 %19, %20
store i32 %21, i32* %7
%22 = load i32, i32* %10
%23 = load i32*, i32** %8
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
store i32 %22, i32* %26
%27 = load i32, i32* %10
%28 = load i32, i32* %9
%29 = add nsw i32 %28, %27
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = load i32, i32* %10
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %31)
%33 = load i32, i32* %7
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %9
%36 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [29 x i8] c"veryBad = %d (from rank %d)\0A\00"
@.str.1 = [6 x i8] c"i=%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 = add nsw i32 %6, 6
%9 = sext i32 %6 to i64
%10 = getelementptr inbounds i32, i32* %5, i64 %9
store i32 %6, i32* %10
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %6)
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%14 = tail call i32 @exit(i32 0)
unreachable
}