#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*/ foo(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int setjmp(int /*<<< orphan*/);
int main() {
  int i = 37;
  while (i--) {
    jmp_buf buf;
    int ret;
    if ((ret = setjmp(buf)) != 0) {
      printf("Return from longjmp: %d\n", ret);
    } else {
      foo(buf, i);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x25,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1192 <main+0x62>
mov    -0xc(%rbp),%edi
call   1050 <setjmp@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     1182 <main+0x52>
mov    -0x10(%rbp),%esi
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
jmp    118d <main+0x5d>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <foo@plt>
jmp    1146 <main+0x16>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x24,%ebp
lea    0xec1(%rip),%rbx
jmp    115c <main+0x2c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%esi
call   1040 <foo@plt>
add    $0xffffffff,%ebp
jae    1174 <main+0x44>
call   1050 <setjmp@plt>
test   %eax,%eax
je     1150 <main+0x20>
mov    %eax,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0xffffffff,%ebp
jb     115c <main+0x2c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Return from longjmp: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 37, i32* %2
br label %5
5: ; preds = %20, %0
%6 = load i32, i32* %2
%7 = add nsw i32 %6, -1
store i32 %7, i32* %2
%8 = icmp ne i32 %6, 0
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = load i32, i32* %3
%11 = call i32 @setjmp(i32 %10)
store i32 %11, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* %4
%15 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %20
16: ; preds = %9
%17 = load i32, i32* %3
%18 = load i32, i32* %2
%19 = call i32 @foo(i32 %17, i32 %18)
br label %20
20: ; preds = %16, %13
br label %5
21: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Return from longjmp: %d\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %9
%2 = phi i32 [ 36, %0 ], [ %10, %9 ]
%3 = call i32 @setjmp(i32 undef)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %9
7: ; preds = %1
%8 = call i32 @foo(i32 undef, i32 %2)
br label %9
9: ; preds = %7, %5
%10 = add nsw i32 %2, -1
%11 = icmp eq i32 %2, 0
br i1 %11, label %12, label %1
12: ; preds = %9
ret i32 0
}