#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(int);
int /*<<< orphan*/ longjmp(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int setjmp(int /*<<< orphan*/);
int main(int argc, char **argv) {
  jmp_buf env;
  int r;
  volatile int x = 0x67895432;
  r = setjmp(env);
  if (r) {
    if (x != 0x67895432)
      exit(1);
    if (r == 2)
      goto again;
    goto finish;
  }
  longjmp(env, 2);
again:
  longjmp(env, 0);
  printf("fail\n");
  exit(1);
finish:
  printf("ok\n");
  exit(0);
}


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)
movl   $0x67895432,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <setjmp@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     119e <main+0x5e>
mov    -0x1c(%rbp),%eax
cmp    $0x67895432,%eax
je     118a <main+0x4a>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x2,-0x18(%rbp)
jne    1199 <main+0x59>
jmp    11ab <main+0x6b>
jmp    11b5 <main+0x75>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   1050 <longjmp@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <longjmp@plt>
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0x67895432,0x4(%rsp)
67
call   1040 <setjmp@plt>
test   %eax,%eax
jne    115c <main+0x1c>
mov    $0x2,%esi
call   1050 <longjmp@plt>
mov    0x4(%rsp),%ecx
cmp    $0x67895432,%ecx
jne    1174 <main+0x34>
cmp    $0x2,%eax
jne    117e <main+0x3e>
xor    %esi,%esi
call   1050 <longjmp@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"ok\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store volatile i32 1737053234, i32* %8
%9 = load i32, i32* %6
%10 = call i32 @setjmp(i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %2
%14 = load volatile i32, i32* %8
%15 = icmp ne i32 %14, 1737053234
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %13
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %22
21: ; preds = %18
br label %26
22: ; preds = %18
br label %29
23: ; preds = %2
%24 = load i32, i32* %6
%25 = call i32 @longjmp(i32 %24, i32 2)
unreachable
26: ; preds = %21
%27 = load i32, i32* %6
%28 = call i32 @longjmp(i32 %27, i32 0)
unreachable
29: ; preds = %22
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@str = [3 x i8] c"ok\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store volatile i32 1737053234, i32* %3
%5 = call i32 @setjmp(i32 undef)
%6 = icmp eq i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = load volatile i32, i32* %3
%9 = icmp eq i32 %8, 1737053234
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %7
%13 = icmp eq i32 %5, 2
br i1 %13, label %16, label %18
14: ; preds = %2
%15 = call i32 @longjmp(i32 undef, i32 2)
unreachable
16: ; preds = %12
%17 = call i32 @longjmp(i32 undef, i32 0)
unreachable
18: ; preds = %12
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%20 = call i32 @exit(i32 0)
unreachable
}