#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*/ abort();
int /*<<< orphan*/ foo(int, char *);
int main() {
  int i;
  char j[128];
#pragma omp parallel
  {
#pragma omp for
    for (i = 0; i < 128; i++)
      j[i] = 0;
#pragma omp for ordered schedule(dynamic, 1)
    for (i = 0; i < 128; i++) {
#pragma omp atomic
      j[i]++;
#pragma omp ordered threads
      {
        int t;
#pragma omp atomic read
        t = j[i];
        if (t != 1)
          abort();
        if (i > 1) {
#pragma omp atomic read
          t = j[i - 1];
          if (t == 0)
            abort();
        }
        if (i < 127) {
#pragma omp atomic read
          t = j[i + 1];
          if (t == 2)
            abort();
        }
      }
#pragma omp atomic
      j[i]++;
    }
#pragma omp for ordered schedule(static, 1)
    for (i = 0; i < 128; i++)
      foo(i, j);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x80,-0x8(%rbp)
jge    1160 <main+0x40>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1139 <main+0x19>
movl   $0x0,-0x8(%rbp)
cmpl   $0x80,-0x8(%rbp)
jge    1244 <main+0x124>
movslq -0x8(%rbp),%rax
mov    -0x90(%rbp,%rax,1),%cl
add    $0x1,%cl
mov    %cl,-0x90(%rbp,%rax,1)
movslq -0x8(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
mov    %eax,-0x94(%rbp)
cmpl   $0x1,-0x94(%rbp)
je     11af <main+0x8f>
mov    $0x0,%al
call   1030 <abort@plt>
cmpl   $0x1,-0x8(%rbp)
jle    11e8 <main+0xc8>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x90(%rbp,%rax,1),%eax
ff
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
jne    11e3 <main+0xc3>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11e8 <main+0xc8>
cmpl   $0x7f,-0x8(%rbp)
jge    1221 <main+0x101>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x90(%rbp,%rax,1),%eax
ff
mov    %eax,-0x94(%rbp)
cmpl   $0x2,-0x94(%rbp)
jne    121c <main+0xfc>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1221 <main+0x101>
movslq -0x8(%rbp),%rax
mov    -0x90(%rbp,%rax,1),%cl
add    $0x1,%cl
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1167 <main+0x47>
movl   $0x0,-0x8(%rbp)
cmpl   $0x80,-0x8(%rbp)
jge    1275 <main+0x155>
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   1040 <foo@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    124b <main+0x12b>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x88,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movw   $0x202,(%rsp)
movb   $0x1,0x2(%rsp)
xor    %eax,%eax
jmp    118f <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x2,0x2(%rsp,%rax,1)
cmp    $0x7d,%rax
je     11b0 <main+0x90>
movzbl 0x3(%rsp,%rax,1),%ecx
lea    0x1(%rcx),%edx
mov    %dl,0x3(%rsp,%rax,1)
add    $0x1,%rax
test   %cl,%cl
jne    11e2 <main+0xc2>
lea    0x1(%rax),%ecx
cmpb   $0x0,(%rsp,%rcx,1)
je     11e2 <main+0xc2>
lea    0x2(%rax),%rcx
cmp    $0x7e,%rcx
ja     1170 <main+0x50>
cmpb   $0x2,0x3(%rsp,%rax,1)
je     11e2 <main+0xc2>
movb   $0x2,0x2(%rsp,%rax,1)
jmp    117b <main+0x5b>
xor    %ebx,%ebx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <foo@plt>
add    $0x1,%ebx
cmp    $0x80,%ebx
jne    11c0 <main+0xa0>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %12, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 128
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %8
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
br label %5
15: ; preds = %5
store i32 0, i32* %2
br label %16
16: ; preds = %70, %15
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 128
br i1 %18, label %19, label %73
19: ; preds = %16
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = add i8 %23, 1
store i8 %24, i8* %22
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %34
32: ; preds = %19
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %19
%35 = load i32, i32* %2
%36 = icmp sgt i32 %35, 1
br i1 %36, label %37, label %49
37: ; preds = %34
%38 = load i32, i32* %2
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
store i32 %43, i32* %4
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %37
%47 = call i32 (...) @abort()
unreachable
48: ; preds = %37
br label %49
49: ; preds = %48, %34
%50 = load i32, i32* %2
%51 = icmp slt i32 %50, 127
br i1 %51, label %52, label %64
52: ; preds = %49
%53 = load i32, i32* %2
%54 = add nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
store i32 %58, i32* %4
%59 = load i32, i32* %4
%60 = icmp eq i32 %59, 2
br i1 %60, label %61, label %63
61: ; preds = %52
%62 = call i32 (...) @abort()
unreachable
63: ; preds = %52
br label %64
64: ; preds = %63, %49
%65 = load i32, i32* %2
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %66
%68 = load i8, i8* %67
%69 = add i8 %68, 1
store i8 %69, i8* %67
br label %70
70: ; preds = %64
%71 = load i32, i32* %2
%72 = add nsw i32 %71, 1
store i32 %72, i32* %2
br label %16
73: ; preds = %16
store i32 0, i32* %2
br label %74
74: ; preds = %81, %73
%75 = load i32, i32* %2
%76 = icmp slt i32 %75, 128
br i1 %76, label %77, label %84
77: ; preds = %74
%78 = load i32, i32* %2
%79 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%80 = call i32 @foo(i32 %78, i8* %79)
br label %81
81: ; preds = %77
%82 = load i32, i32* %2
%83 = add nsw i32 %82, 1
store i32 %83, i32* %2
br label %74
84: ; preds = %74
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
store i8 2, i8* %3
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 1
store i8 2, i8* %4
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 2
store i8 1, i8* %5
br label %8
6: ; preds = %30
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %0, %30
%9 = phi i8* [ %5, %0 ], [ %33, %30 ]
%10 = phi i64 [ 2, %0 ], [ %20, %30 ]
%11 = add nuw i64 %10, 4294967295
%12 = and i64 %11, 4294967295
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = tail call i32 (...) @abort()
unreachable
18: ; preds = %8
%19 = icmp ult i64 %10, 127
%20 = add nuw nsw i64 %10, 1
br i1 %19, label %21, label %28
21: ; preds = %18
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %20
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 2
br i1 %24, label %26, label %25
25: ; preds = %21
store i8 2, i8* %9
br label %30
26: ; preds = %21
%27 = tail call i32 (...) @abort()
unreachable
28: ; preds = %18
store i8 2, i8* %9
%29 = icmp eq i64 %20, 128
br i1 %29, label %36, label %30
30: ; preds = %25, %28
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %20
%32 = load i8, i8* %31
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %20
%34 = add i8 %32, 1
store i8 %34, i8* %33
%35 = icmp eq i8 %32, 0
br i1 %35, label %8, label %6
36: ; preds = %28, %36
%37 = phi i32 [ %39, %36 ], [ 0, %28 ]
%38 = call i32 @foo(i32 %37, i8* %3)
%39 = add nuw nsw i32 %37, 1
%40 = icmp eq i32 %39, 128
br i1 %40, label %41, label %36
41: ; preds = %36
ret i32 0
}