void test_branch_protected_scope() {
  int i = 0;
L1:
  ++i;
  int x[24];
#pragma omp parallel
#pragma omp single
  {
    if (i == 5)
      goto L1;
    else if (i == 6)
      return;
    else if (i == 7)
      goto L2;
    else if (i == 8) {
    L2:
      x[i]++;
    }
  }
  if (x[0] == 0)
    goto L2;
  else if (x[1] == 1)
    goto L1;
}


x86 assembly (clang, -O0):
<test_branch_protected_scope>:
push   %rbp
mov    %rsp,%rbp
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x5,-0x4(%rbp)
jne    1123 <test_branch_protected_scope+0x23>
jmp    110b <test_branch_protected_scope+0xb>
cmpl   $0x6,-0x4(%rbp)
jne    1132 <test_branch_protected_scope+0x32>
jmp    1191 <test_branch_protected_scope+0x91>
cmpl   $0x7,-0x4(%rbp)
jne    1141 <test_branch_protected_scope+0x41>
jmp    1150 <test_branch_protected_scope+0x50>
cmpl   $0x8,-0x4(%rbp)
jne    115f <test_branch_protected_scope+0x5f>
jmp    1150 <test_branch_protected_scope+0x50>
movslq -0x4(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x70(%rbp,%rax,4)
jmp    1164 <test_branch_protected_scope+0x64>
jmp    1169 <test_branch_protected_scope+0x69>
jmp    116e <test_branch_protected_scope+0x6e>
cmpl   $0x0,-0x70(%rbp)
jne    117d <test_branch_protected_scope+0x7d>
jmp    1150 <test_branch_protected_scope+0x50>
cmpl   $0x1,-0x6c(%rbp)
jne    118c <test_branch_protected_scope+0x8c>
jmp    110b <test_branch_protected_scope+0xb>
jmp    1191 <test_branch_protected_scope+0x91>
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_branch_protected_scope>:
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%edx
mov    $0x5,%eax
cmp    $0x4,%edx
je     1110 <test_branch_protected_scope+0x10>
cmp    $0x5,%edx
je     1168 <test_branch_protected_scope+0x68>
lea    0x1(%rdx),%eax
and    $0xfffffffe,%edx
cmp    $0x6,%edx
je     113c <test_branch_protected_scope+0x3c>
mov    $0x1,%edx
test   %ecx,%ecx
je     113c <test_branch_protected_scope+0x3c>
cmp    $0x1,%edx
je     1110 <test_branch_protected_scope+0x10>
jmp    1168 <test_branch_protected_scope+0x68>
movslq %eax,%rdx
mov    -0x68(%rsp,%rdx,4),%esi
add    $0x1,%esi
cs nopw 0x0(%rax,%rax,1)
mov    %esi,-0x68(%rsp,%rdx,4)
mov    -0x68(%rsp),%ecx
add    $0x1,%esi
test   %ecx,%ecx
je     1150 <test_branch_protected_scope+0x50>
mov    -0x64(%rsp),%edx
cmp    $0x1,%edx
je     1110 <test_branch_protected_scope+0x10>
ret

LLVM IR (-O0):
define void @test_branch_protected_scope() {
%1 = alloca i32
%2 = alloca [24 x i32]
store i32 0, i32* %1
br label %3
3: ; preds = %39, %8, %0
%4 = load i32, i32* %1
%5 = add nsw i32 %4, 1
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 5
br i1 %7, label %8, label %9
8: ; preds = %3
br label %3
9: ; preds = %3
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 6
br i1 %11, label %12, label %13
12: ; preds = %9
br label %41
13: ; preds = %9
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 7
br i1 %15, label %16, label %17
16: ; preds = %13
br label %21
17: ; preds = %13
%18 = load i32, i32* %1
%19 = icmp eq i32 %18, 8
br i1 %19, label %20, label %27
20: ; preds = %17
br label %21
21: ; preds = %34, %20, %16
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [24 x i32], [24 x i32]* %2, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = add nsw i32 %25, 1
store i32 %26, i32* %24
br label %27
27: ; preds = %21, %17
br label %28
28: ; preds = %27
br label %29
29: ; preds = %28
br label %30
30: ; preds = %29
%31 = getelementptr inbounds [24 x i32], [24 x i32]* %2, i64 0, i64 0
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
br label %21
35: ; preds = %30
%36 = getelementptr inbounds [24 x i32], [24 x i32]* %2, i64 0, i64 1
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %40
39: ; preds = %35
br label %3
40: ; preds = %35
br label %41
41: ; preds = %12, %40
ret void
}

LLVM IR (-O2):
define void @test_branch_protected_scope() {
%1 = alloca [24 x i32]
%2 = getelementptr inbounds [24 x i32], [24 x i32]* %1, i64 0, i64 0
%3 = getelementptr inbounds [24 x i32], [24 x i32]* %1, i64 0, i64 1
br label %4
4: ; preds = %26, %0
%5 = phi i32 [ %28, %26 ], [ undef, %0 ]
%6 = phi i32 [ %10, %26 ], [ 0, %0 ]
br label %7
7: ; preds = %4, %7
%8 = phi i32 [ 5, %7 ], [ %6, %4 ]
switch i32 %8, label %9 [
i32 4, label %7
i32 5, label %30
]
9: ; preds = %7
%10 = add nsw i32 %8, 1
%11 = and i32 %8, -2
%12 = icmp eq i32 %11, 6
%13 = icmp eq i32 %5, 0
%14 = select i1 %12, i1 true, i1 %13
br i1 %14, label %15, label %26
15: ; preds = %9
%16 = sext i32 %10 to i64
%17 = getelementptr inbounds [24 x i32], [24 x i32]* %1, i64 0, i64 %16
%18 = load i32, i32* %17
br label %19
19: ; preds = %15, %19
%20 = phi i32 [ %18, %15 ], [ %21, %19 ]
%21 = add nsw i32 %20, 1
store i32 %21, i32* %17
%22 = load i32, i32* %2
%23 = icmp eq i32 %22, 0
br i1 %23, label %19, label %24
24: ; preds = %19
%25 = load i32, i32* %3
br label %26
26: ; preds = %24, %9
%27 = phi i32 [ %25, %24 ], [ 1, %9 ]
%28 = phi i32 [ %22, %24 ], [ %5, %9 ]
%29 = icmp eq i32 %27, 1
br i1 %29, label %4, label %30
30: ; preds = %26, %7
ret void
}