#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__ bigfunc(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int ic, i, n = 7;
  ic = 0;
#pragma omp parallel for shared(ic, n) private(i)
  for (i = 0; i < n; i++) {
    int TID = 0;
#pragma omp atomic
    ic += bigfunc(TID);
  }
  printf("Counter = %d\n", ic);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x7,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    117a <main+0x5a>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <bigfunc@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <main+0x24>
mov    -0x8(%rbp),%esi
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %edi,%edi
call   1040 <bigfunc@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1040 <bigfunc@plt>
add    %eax,%ebx
xor    %edi,%edi
call   1040 <bigfunc@plt>
add    %eax,%ebx
xor    %edi,%edi
call   1040 <bigfunc@plt>
add    %eax,%ebx
xor    %edi,%edi
call   1040 <bigfunc@plt>
add    %eax,%ebx
xor    %edi,%edi
call   1040 <bigfunc@plt>
add    %eax,%ebx
xor    %edi,%edi
call   1040 <bigfunc@plt>
add    %eax,%ebx
lea    0xe98(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Counter = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 7, i32* %4
store i32 0, i32* %2
store i32 0, i32* %3
br label %6
6: ; preds = %17, %0
%7 = load i32, i32* %3
%8 = load i32, i32* %4
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %20
10: ; preds = %6
store i32 0, i32* %5
%11 = load i32, i32* %5
%12 = call i64 @bigfunc(i32 %11)
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = add nsw i64 %14, %12
%16 = trunc i64 %15 to i32
store i32 %16, i32* %2
br label %17
17: ; preds = %10
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %6
20: ; preds = %6
%21 = load i32, i32* %2
%22 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"Counter = %d\0A\00"
define i32 @main() {
%1 = tail call i64 @bigfunc(i32 0)
%2 = trunc i64 %1 to i32
%3 = tail call i64 @bigfunc(i32 0)
%4 = trunc i64 %3 to i32
%5 = add i32 %2, %4
%6 = tail call i64 @bigfunc(i32 0)
%7 = trunc i64 %6 to i32
%8 = add i32 %5, %7
%9 = tail call i64 @bigfunc(i32 0)
%10 = trunc i64 %9 to i32
%11 = add i32 %8, %10
%12 = tail call i64 @bigfunc(i32 0)
%13 = trunc i64 %12 to i32
%14 = add i32 %11, %13
%15 = tail call i64 @bigfunc(i32 0)
%16 = trunc i64 %15 to i32
%17 = add i32 %14, %16
%18 = tail call i64 @bigfunc(i32 0)
%19 = trunc i64 %18 to i32
%20 = add i32 %17, %19
%21 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %20)
ret i32 0
}