#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 */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ is_open(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(void) {
  int fd1, fd2;
  fd1 = open("/etc/passwd", O_RDONLY);
  if (is_open(fd1)) {
    printf("fd1 is open\n");
  } else {
    printf("fd1 is closed\n");
  }
  close(fd1);
  if (is_open(fd1)) {
    printf("fd1 is open\n");
  } else {
    printf("fd1 is closed\n");
  }
  fd2 = open("/etc/passwd", O_RDONLY);
  if (is_open(fd1)) {
    printf("fd2 is open\n");
  } else {
    printf("fd2 is closed\n");
  }
  close(fd2);
  if (is_open(fd1)) {
    printf("fd2 is open\n");
  } else {
    printf("fd2 is closed\n");
  }
  fd2 = open("/etc/passwd", O_RDONLY);
  if (is_open(fd1)) {
    printf("fd2 is open\n");
  } else {
    printf("fd2 is closed\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <is_open@plt>
cmp    $0x0,%rax
je     118a <main+0x4a>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
jmp    1196 <main+0x56>
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <is_open@plt>
cmp    $0x0,%rax
je     11c1 <main+0x81>
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
jmp    11cd <main+0x8d>
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    0xe23(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <is_open@plt>
cmp    $0x0,%rax
je     1208 <main+0xc8>
lea    0xe2a(%rip),%rdi
call   1030 <printf@plt>
jmp    1214 <main+0xd4>
lea    0xe26(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <is_open@plt>
cmp    $0x0,%rax
je     123f <main+0xff>
lea    0xdf3(%rip),%rdi
call   1030 <printf@plt>
jmp    124b <main+0x10b>
lea    0xdef(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
lea    0xda5(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <is_open@plt>
cmp    $0x0,%rax
je     1286 <main+0x146>
lea    0xdac(%rip),%rdi
call   1030 <printf@plt>
jmp    1292 <main+0x152>
lea    0xda8(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e96(%rip),%r12
mov    (%r12),%esi
lea    0xea3(%rip),%r14
mov    %r14,%rdi
call   1060 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <is_open@plt>
test   %rax,%rax
lea    0xe94(%rip),%r15
lea    0xeb5(%rip),%rbx
mov    %rbx,%rdi
cmove  %r15,%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1050 <is_open@plt>
test   %rax,%rax
cmove  %r15,%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    (%r12),%esi
mov    %r14,%rdi
call   1060 <open@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1050 <is_open@plt>
test   %rax,%rax
lea    0xe52(%rip),%r13
lea    0xe59(%rip),%rbx
mov    %rbx,%rdi
cmove  %r13,%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1050 <is_open@plt>
test   %rax,%rax
mov    %rbx,%rdi
cmove  %r13,%rdi
call   1030 <puts@plt>
mov    (%r12),%esi
mov    %r14,%rdi
call   1060 <open@plt>
mov    %ebp,%edi
call   1050 <is_open@plt>
test   %rax,%rax
cmove  %r13,%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/etc/passwd\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"fd1 is open\0A\00"
@.str.2 = [15 x i8] c"fd1 is closed\0A\00"
@.str.3 = [13 x i8] c"fd2 is open\0A\00"
@.str.4 = [15 x i8] c"fd2 is closed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = call i64 @is_open(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
%14 = load i32, i32* %2
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %2
%17 = call i64 @is_open(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %23
21: ; preds = %13
%22 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %24)
store i32 %25, i32* %3
%26 = load i32, i32* %2
%27 = call i64 @is_open(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %33
31: ; preds = %23
%32 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
%34 = load i32, i32* %3
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* %2
%37 = call i64 @is_open(i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %43
41: ; preds = %33
%42 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %41, %39
%44 = load i32, i32* @O_RDONLY
%45 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %44)
store i32 %45, i32* %3
%46 = load i32, i32* %2
%47 = call i64 @is_open(i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %53
51: ; preds = %43
%52 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %49
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str = [12 x i8] c"/etc/passwd\00"
@O_RDONLY = global i32 0
@str.5 = [14 x i8] c"fd1 is closed\00"
@str.8 = [14 x i8] c"fd2 is closed\00"
@str.11 = [12 x i8] c"fd2 is open\00"
@str.13 = [12 x i8] c"fd1 is open\00"
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i64 @is_open(i32 %2)
%4 = icmp eq i64 %3, 0
%5 = select i1 %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0)
%6 = tail call i32 @puts(i8* dereferenceable(1) %5)
%7 = tail call i32 @close(i32 %2)
%8 = tail call i64 @is_open(i32 %2)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0)
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = tail call i64 @is_open(i32 %2)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0)
%17 = tail call i32 @puts(i8* dereferenceable(1) %16)
%18 = tail call i32 @close(i32 %13)
%19 = tail call i64 @is_open(i32 %2)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0)
%22 = tail call i32 @puts(i8* dereferenceable(1) %21)
%23 = load i32, i32* @O_RDONLY
%24 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = tail call i64 @is_open(i32 %2)
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0)
%28 = tail call i32 @puts(i8* dereferenceable(1) %27)
ret i32 0
}