#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 */

/* Variables and functions */
scalar_t__ EPERM;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int main() {
  setbuf(stdout, NULL);
  printf("checkpoint1\n");
  if (open("./", O_RDONLY) == -1) {
    printf("checkpoint2\n");
    if (errno == EPERM) {
      printf("checkpoint3\n");
    } else {
      printf("fail1");
    }
  } else {
    printf("fail2");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <setbuf@plt>
lea    0xea8(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    0xea0(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
jne    11c3 <main+0x93>
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%rax
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%rax
jne    11b2 <main+0x82>
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
jmp    11be <main+0x8e>
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
jmp    11cf <main+0x9f>
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <setbuf@plt>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    0xe93(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1180 <main+0x40>
lea    0xe8b(%rip),%rdi
jmp    11b7 <main+0x77>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%rax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
jne    11b0 <main+0x70>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
jmp    11bc <main+0x7c>
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [13 x i8] c"checkpoint1\0A\00"
@.str.1 = [3 x i8] c"./\00"
@O_RDONLY = global i32 0
@.str.2 = [13 x i8] c"checkpoint2\0A\00"
@errno = global i64 0
@EPERM = global i64 0
@.str.3 = [13 x i8] c"checkpoint3\0A\00"
@.str.4 = [6 x i8] c"fail1\00"
@.str.5 = [6 x i8] c"fail2\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = load i32, i32* @stdout
%3 = call i32 @setbuf(i32 %2, i32* null)
%4 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %18
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%10 = load i64, i64* @errno
%11 = load i64, i64* @EPERM
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %17
15: ; preds = %8
%16 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
br label %20
18: ; preds = %0
%19 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %20
20: ; preds = %18, %17
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str.1 = [3 x i8] c"./\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@EPERM = global i64 0
@.str.4 = [6 x i8] c"fail1\00"
@.str.5 = [6 x i8] c"fail2\00"
@str = [12 x i8] c"checkpoint1\00"
@str.6 = [12 x i8] c"checkpoint2\00"
@str.7 = [12 x i8] c"checkpoint3\00"
define i32 @main() {
%1 = load i32, i32* @stdout
%2 = tail call i32 @setbuf(i32 %1, i32* null)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
%9 = load i64, i64* @errno
%10 = load i64, i64* @EPERM
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
br label %18
14: ; preds = %7
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %18
16: ; preds = %0
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %18
18: ; preds = %12, %14, %16
ret i32 0
}