#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 */
typedef int /*<<< orphan*/ jmp_buf;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ longjmp(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int setjmp(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  do {
    jmp_buf env;
    switch (setjmp(env)) {
    case 0:
      while (1) {
        {
          printf("In TRY statement\n");
          longjmp(env, (3));
          printf("not reachable\n");
        }
        break;
      case (1): {
        printf("FOO exception caught\n");
      } break;
      case (2): {
        printf("BAR exception caught\n");
      } break;
      case (3): {
        printf("GOO exception caught\n");
      } break;
      }
    default: {
      printf("Finally \n");
    }
    }
  } while (0);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <setjmp@plt>
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     11d2 <main+0x92>
mov    -0x20(%rbp),%rax
lea    0xe88(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    1186 <main+0x46>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x3,%esi
call   1050 <longjmp@plt>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
jmp    11cd <main+0x8d>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
jmp    11cd <main+0x8d>
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
jmp    11d2 <main+0x92>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
jmp    11e3 <main+0xa3>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
call   1040 <setjmp@plt>
cmp    $0x3,%eax
ja     118f <main+0x4f>
lea    0xef1(%rip),%rdi
mov    %eax,%eax
lea    0xea5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%esi
call   1050 <longjmp@plt>
lea    0xead(%rip),%rdi
jmp    118a <main+0x4a>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"In TRY statement\0A\00"
@.str.1 = [22 x i8] c"FOO exception caught\0A\00"
@.str.2 = [22 x i8] c"BAR exception caught\0A\00"
@.str.3 = [22 x i8] c"GOO exception caught\0A\00"
@.str.4 = [10 x i8] c"Finally \0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %7
7: ; preds = %2
%8 = load i32, i32* %6
%9 = call i32 @setjmp(i32 %8)
switch i32 %9, label %22 [
i32 0, label %10
i32 1, label %15
i32 2, label %17
i32 3, label %19
]
10: ; preds = %7
br label %11
11: ; preds = %10
%12 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %6
%14 = call i32 @longjmp(i32 %13, i32 3)
unreachable
15: ; preds = %7
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %21
17: ; preds = %7
%18 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %21
19: ; preds = %7
%20 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %17, %15
br label %22
22: ; preds = %7, %21
%23 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %24
24: ; preds = %22
br label %25
25: ; preds = %24
%26 = load i32, i32* @EXIT_SUCCESS
%27 = call i32 @exit(i32 %26)
unreachable
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@str = [21 x i8] c"GOO exception caught\00"
@str.5 = [9 x i8] c"Finally \00"
@str.6 = [21 x i8] c"BAR exception caught\00"
@str.7 = [21 x i8] c"FOO exception caught\00"
@str.8 = [17 x i8] c"In TRY statement\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = call i32 @setjmp(i32 undef)
switch i32 %3, label %12 [
i32 0, label %4
i32 1, label %9
i32 2, label %7
i32 3, label %8
]
4: ; preds = %2
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%6 = call i32 @longjmp(i32 undef, i32 3)
unreachable
7: ; preds = %2
br label %9
8: ; preds = %2
br label %9
9: ; preds = %2, %8, %7
%10 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0), %7 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0), %8 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0), %2 ]
%11 = call i32 @puts(i8* dereferenceable(1) %10)
br label %12
12: ; preds = %9, %2
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.5, i64 0, i64 0))
%14 = load i32, i32* @EXIT_SUCCESS
%15 = call i32 @exit(i32 %14)
unreachable
}