#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);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int fd1 = open("/tmp/in1.txt", O_RDONLY);
  int fd2 = open("/tmp/in1.txt", O_RDONLY);
  int fd3 = open("/tmp/in1.txt", O_RDONLY);
  int fd4 = open("/tmp/in1.txt", O_RDONLY);
  int fd5 = open("/tmp/in1.txt", O_RDONLY);
  printf("Descriptors: %d %d %d %d %d\n", fd1, fd2, fd3, fd4, fd5);
  close(fd3);
  close(fd2);
  fd2 = open("/tmp/in1.txt", O_RDONLY);
  fd3 = open("/tmp/in1.txt", O_RDONLY);
  printf("Reopened fd2 and fd3\n");
  printf("Descriptors: %d %d %d %d %d\n", fd1, fd2, fd3, fd4, fd5);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
lea    0xe99(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe51(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
lea    0xe0a(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
lea    0xdf2(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%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),%r14
mov    (%r14),%esi
lea    0xea4(%rip),%r12
mov    %r12,%rdi
call   1060 <open@plt>
mov    %eax,%ebx
mov    %eax,0x4(%rsp)
mov    (%r14),%esi
mov    %r12,%rdi
call   1060 <open@plt>
mov    %eax,%ebp
mov    (%r14),%esi
mov    %r12,%rdi
call   1060 <open@plt>
mov    %eax,%r13d
mov    (%r14),%esi
mov    %r12,%rdi
call   1060 <open@plt>
mov    %eax,%r15d
mov    (%r14),%esi
mov    %r12,%rdi
call   1060 <open@plt>
mov    %eax,(%rsp)
lea    0xe65(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r13d,%ecx
mov    %r15d,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13d,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    (%r14),%esi
mov    %r12,%rdi
call   1060 <open@plt>
mov    %eax,%ebp
mov    (%r14),%esi
mov    %r12,%rdi
call   1060 <open@plt>
mov    %eax,%ebx
lea    0xe3e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe15(%rip),%rdi
mov    0x4(%rsp),%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r15d,%r8d
mov    (%rsp),%r9d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/tmp/in1.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [29 x i8] c"Descriptors: %d %d %d %d %d\0A\00"
@.str.2 = [22 x i8] c"Reopened fd2 and fd3\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18, i32 %19, i32 %20, i32 %21)
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %27)
store i32 %28, i32* %3
%29 = load i32, i32* @O_RDONLY
%30 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %29)
store i32 %30, i32* %4
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* %2
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = load i32, i32* %5
%36 = load i32, i32* %6
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %33, i32 %34, i32 %35, i32 %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/tmp/in1.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [29 x i8] c"Descriptors: %d %d %d %d %d\0A\00"
@str = [21 x i8] c"Reopened fd2 and fd3\00"
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %4, i32 %6, i32 %8, i32 %10)
%12 = tail call i32 @close(i32 %6)
%13 = tail call i32 @close(i32 %4)
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %15, i32 %17, i32 %8, i32 %10)
ret i32 0
}