#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_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
void fix_fds(void) {
  int fd0 = open("/dev/null", O_RDWR);
  int fd1 = open("/dev/null", O_RDWR);
  int fd2 = open("/dev/null", O_RDWR);
  if (fd0 > 2)
    close(fd0);
  if (fd1 > 2)
    close(fd1);
  if (fd2 > 2)
    close(fd2);
}


x86 assembly (clang, -O0):
<fix_fds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%esi
lea    0xec8(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x4(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
lea    0xeb0(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0x4(%rbp)
jle    1182 <fix_fds+0x62>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x2,-0x8(%rbp)
jle    1194 <fix_fds+0x74>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x2,-0xc(%rbp)
jle    11a6 <fix_fds+0x86>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fix_fds>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2eba(%rip),%r15
mov    (%r15),%esi
lea    0xec8(%rip),%r14
mov    %r14,%rdi
call   1040 <open@plt>
mov    %eax,%ebx
mov    (%r15),%esi
mov    %r14,%rdi
call   1040 <open@plt>
mov    %eax,%ebp
mov    (%r15),%esi
mov    %r14,%rdi
call   1040 <open@plt>
mov    %eax,%r14d
cmp    $0x3,%ebx
jge    117f <fix_fds+0x5f>
cmp    $0x3,%ebp
jge    118b <fix_fds+0x6b>
cmp    $0x3,%r14d
jl     1198 <fix_fds+0x78>
mov    %r14d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <close@plt>
mov    %ebx,%edi
call   1030 <close@plt>
cmp    $0x3,%ebp
jl     1167 <fix_fds+0x47>
mov    %ebp,%edi
call   1030 <close@plt>
cmp    $0x3,%r14d
jge    116d <fix_fds+0x4d>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
define void @fix_fds() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* %1
%14 = call i32 @close(i32 %13)
br label %15
15: ; preds = %12, %0
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 2
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %2
%20 = call i32 @close(i32 %19)
br label %21
21: ; preds = %18, %15
%22 = load i32, i32* %3
%23 = icmp sgt i32 %22, 2
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %24, %21
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
define void @fix_fds() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp sgt i32 %2, 2
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @close(i32 %2)
br label %10
10: ; preds = %8, %0
%11 = icmp sgt i32 %4, 2
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 @close(i32 %4)
br label %14
14: ; preds = %12, %10
%15 = icmp sgt i32 %6, 2
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = tail call i32 @close(i32 %6)
br label %18
18: ; preds = %16, %14
ret void
}