#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__ EACCES;
scalar_t__ ENXIO;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(void) {
  int exitcode, fd;
  fd = open("/dev/puffs", O_RDWR);
  if (fd != -1) {
    printf("yes\n");
    close(fd);
    exitcode = EXIT_SUCCESS;
  } else {
    if (errno == ENXIO) {
      printf("enxio\n");
      exitcode = EXIT_SUCCESS;
    } else if (errno == EACCES) {
      printf("eacces\n");
      exitcode = EXIT_SUCCESS;
    } else {
      printf("failed\n");
      exitcode = EXIT_FAILURE;
    }
  }
  return exitcode;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     1186 <main+0x56>
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1216 <main+0xe6>
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
jne    11bd <main+0x8d>
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1211 <main+0xe1>
mov    0x2e0c(%rip),%rax
mov    (%rax),%rax
mov    0x2e12(%rip),%rcx
cmp    (%rcx),%rax
jne    11f4 <main+0xc4>
lea    0xe39(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    120c <main+0xdc>
lea    0xe24(%rip),%rdi
call   1030 <printf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    1211 <main+0xe1>
jmp    1216 <main+0xe6>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
lea    0xebf(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1169 <main+0x39>
mov    %eax,%ebx
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2e51(%rip),%rax
jmp    11bc <main+0x8c>
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
jne    1188 <main+0x58>
lea    0xe93(%rip),%rdi
jmp    119b <main+0x6b>
mov    0x2e51(%rip),%rcx
cmp    (%rcx),%rax
jne    11a9 <main+0x79>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e11(%rip),%rax
jmp    11bc <main+0x8c>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/puffs\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"yes\0A\00"
@EXIT_SUCCESS = global i32 0
@errno = global i64 0
@ENXIO = global i64 0
@.str.2 = [7 x i8] c"enxio\0A\00"
@EACCES = global i64 0
@.str.3 = [8 x i8] c"eacces\0A\00"
@.str.4 = [8 x i8] c"failed\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* %3
%11 = call i32 @close(i32 %10)
%12 = load i32, i32* @EXIT_SUCCESS
store i32 %12, i32* %2
br label %32
13: ; preds = %0
%14 = load i64, i64* @errno
%15 = load i64, i64* @ENXIO
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_SUCCESS
store i32 %19, i32* %2
br label %31
20: ; preds = %13
%21 = load i64, i64* @errno
%22 = load i64, i64* @EACCES
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* @EXIT_SUCCESS
store i32 %26, i32* %2
br label %30
27: ; preds = %20
%28 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %2
br label %30
30: ; preds = %27, %24
br label %31
31: ; preds = %30, %17
br label %32
32: ; preds = %31, %8
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/puffs\00"
@O_RDWR = global i32 0
@EXIT_SUCCESS = global i32 0
@errno = global i64 0
@ENXIO = global i64 0
@EACCES = global i64 0
@EXIT_FAILURE = global i32 0
@str = [7 x i8] c"failed\00"
@str.5 = [7 x i8] c"eacces\00"
@str.6 = [6 x i8] c"enxio\00"
@str.7 = [4 x i8] c"yes\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.7, i64 0, i64 0))
%6 = tail call i32 @close(i32 %2)
br label %20
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = load i64, i64* @ENXIO
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.6, i64 0, i64 0))
br label %20
13: ; preds = %7
%14 = load i64, i64* @EACCES
%15 = icmp eq i64 %8, %14
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.5, i64 0, i64 0))
br label %20
18: ; preds = %13
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %11, %18, %16, %4
%21 = phi i32* [ @EXIT_SUCCESS, %4 ], [ @EXIT_SUCCESS, %11 ], [ @EXIT_SUCCESS, %16 ], [ @EXIT_FAILURE, %18 ]
%22 = load i32, i32* %21
ret i32 %22
}