void test_branch_protected_scope() {
  int i = 0;
L1:
  ++i;
  int x[24];
#pragma omp simd
  for (i = 0; i < 16; ++i) {
    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)
movl   $0x0,-0x4(%rbp)
cmpl   $0x10,-0x4(%rbp)
jge    1192 <test_branch_protected_scope+0x92>
cmpl   $0x5,-0x4(%rbp)
jne    1134 <test_branch_protected_scope+0x34>
jmp    110b <test_branch_protected_scope+0xb>
cmpl   $0x6,-0x4(%rbp)
jne    1143 <test_branch_protected_scope+0x43>
jmp    11b5 <test_branch_protected_scope+0xb5>
cmpl   $0x7,-0x4(%rbp)
jne    1152 <test_branch_protected_scope+0x52>
jmp    1161 <test_branch_protected_scope+0x61>
cmpl   $0x8,-0x4(%rbp)
jne    1170 <test_branch_protected_scope+0x70>
jmp    1161 <test_branch_protected_scope+0x61>
movslq -0x4(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x70(%rbp,%rax,4)
jmp    1175 <test_branch_protected_scope+0x75>
jmp    117a <test_branch_protected_scope+0x7a>
jmp    117f <test_branch_protected_scope+0x7f>
jmp    1184 <test_branch_protected_scope+0x84>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    111b <test_branch_protected_scope+0x1b>
cmpl   $0x0,-0x70(%rbp)
jne    11a1 <test_branch_protected_scope+0xa1>
jmp    1161 <test_branch_protected_scope+0x61>
cmpl   $0x1,-0x6c(%rbp)
jne    11b0 <test_branch_protected_scope+0xb0>
jmp    110b <test_branch_protected_scope+0xb>
jmp    11b5 <test_branch_protected_scope+0xb5>
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_branch_protected_scope>:
xor    %ecx,%ecx
jmp    1123 <test_branch_protected_scope+0x23>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpl   $0x0,-0x68(%rsp)
je     1143 <test_branch_protected_scope+0x43>
cmpl   $0x1,-0x64(%rsp)
mov    $0x0,%ecx
jne    1151 <test_branch_protected_scope+0x51>
mov    %rcx,%rax
cmp    $0xf,%rcx
ja     1110 <test_branch_protected_scope+0x10>
mov    $0x0,%ecx
cmp    $0x5,%eax
je     1123 <test_branch_protected_scope+0x23>
cmp    $0x6,%eax
je     1151 <test_branch_protected_scope+0x51>
lea    -0x7(%rax),%ecx
cmp    $0x1,%ecx
ja     1148 <test_branch_protected_scope+0x48>
addl   $0x1,-0x68(%rsp,%rax,4)
add    $0x1,%rax
mov    %rax,%rcx
jmp    1123 <test_branch_protected_scope+0x23>
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 = %47, %12, %0
%4 = load i32, i32* %1
%5 = add nsw i32 %4, 1
store i32 %5, i32* %1
store i32 0, i32* %1
br label %6
6: ; preds = %35, %3
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 16
br i1 %8, label %9, label %38
9: ; preds = %6
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 5
br i1 %11, label %12, label %13
12: ; preds = %9
br label %3
13: ; preds = %9
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 6
br i1 %15, label %16, label %17
16: ; preds = %13
br label %49
17: ; preds = %13
%18 = load i32, i32* %1
%19 = icmp eq i32 %18, 7
br i1 %19, label %20, label %21
20: ; preds = %17
br label %25
21: ; preds = %17
%22 = load i32, i32* %1
%23 = icmp eq i32 %22, 8
br i1 %23, label %24, label %31
24: ; preds = %21
br label %25
25: ; preds = %42, %24, %20
%26 = load i32, i32* %1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [24 x i32], [24 x i32]* %2, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = add nsw i32 %29, 1
store i32 %30, i32* %28
br label %31
31: ; preds = %25, %21
br label %32
32: ; preds = %31
br label %33
33: ; preds = %32
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
%36 = load i32, i32* %1
%37 = add nsw i32 %36, 1
store i32 %37, i32* %1
br label %6
38: ; preds = %6
%39 = getelementptr inbounds [24 x i32], [24 x i32]* %2, i64 0, i64 0
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %38
br label %25
43: ; preds = %38
%44 = getelementptr inbounds [24 x i32], [24 x i32]* %2, i64 0, i64 1
%45 = load i32, i32* %44
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %48
47: ; preds = %43
br label %3
48: ; preds = %43
br label %49
49: ; preds = %16, %48
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 = %19, %0
%5 = phi i64 [ 0, %0 ], [ %20, %19 ]
%6 = icmp ult i64 %5, 16
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = trunc i64 %5 to i32
switch i32 %8, label %9 [
i32 5, label %19
i32 6, label %27
]
9: ; preds = %7
%10 = trunc i64 %5 to i32
%11 = add nsw i32 %10, -7
%12 = icmp ult i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %21, %9
%14 = getelementptr inbounds [24 x i32], [24 x i32]* %1, i64 0, i64 %5
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
store i32 %16, i32* %14
br label %17
17: ; preds = %9, %13
%18 = add nuw i64 %5, 1
br label %19
19: ; preds = %17, %7, %24
%20 = phi i64 [ %18, %17 ], [ 0, %7 ], [ 0, %24 ]
br label %4
21: ; preds = %4
%22 = load i32, i32* %2
%23 = icmp eq i32 %22, 0
br i1 %23, label %13, label %24
24: ; preds = %21
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 1
br i1 %26, label %19, label %27
27: ; preds = %24, %7
ret void
}