#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*/ longjmp(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int setjmp(int /*<<< orphan*/);
void co2(jmp_buf *venvironment1, jmp_buf *venvironment2) {
  int VAR = 5;
  jmp_buf *const environment1 = venvironment1;
  jmp_buf *const environment2 = venvironment2;
  printf("In function co2 place 1\n");
  int ret = setjmp(*environment2);
  if (ret == 0) {
    longjmp(*environment1, 1);
  }
  printf("In function co2 place 2\n");
  ret = setjmp(*environment2);
  if (ret == 0) {
    longjmp(*environment1, 1);
  }
  printf("In function co2 place 3\n");
  longjmp(*environment1, 1);
}


x86 assembly (clang, -O0):
<co2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x5,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1040 <setjmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    118b <co2+0x5b>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1050 <longjmp@plt>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1040 <setjmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11bf <co2+0x8f>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1050 <longjmp@plt>
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1050 <longjmp@plt>

x86 assembly (clang, -O2):
<co2>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%edi
call   1040 <setjmp@plt>
test   %eax,%eax
je     1174 <co2+0x44>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%edi
call   1040 <setjmp@plt>
test   %eax,%eax
je     1174 <co2+0x44>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%edi
mov    $0x1,%esi
call   1050 <longjmp@plt>

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

LLVM IR (-O2):
@str = [24 x i8] c"In function co2 place 1\00"
@str.3 = [24 x i8] c"In function co2 place 2\00"
@str.4 = [24 x i8] c"In function co2 place 3\00"
define void @co2(i32* nocapture %0, i32* nocapture %1) {
%3 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%4 = load i32, i32* %1
%5 = call i32 @setjmp(i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* %0
%9 = call i32 @longjmp(i32 %8, i32 1)
unreachable
10: ; preds = %2
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.3, i64 0, i64 0))
%12 = load i32, i32* %1
%13 = call i32 @setjmp(i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* %0
%17 = call i32 @longjmp(i32 %16, i32 1)
unreachable
18: ; preds = %10
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.4, i64 0, i64 0))
%20 = load i32, i32* %0
%21 = call i32 @longjmp(i32 %20, i32 1)
unreachable
}