#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 /*<<< orphan*/ dup(int);
int /*<<< orphan*/ open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
void utilStandardIOSimpleRedirect(int to) {
  int i;
  for (i = 0; i < 3; ++i) {
    close(i);
    if (to >= 0)
      dup(to);
    else
      open("/dev/null", O_RDWR, 0);
  }
}


x86 assembly (clang, -O0):
<utilStandardIOSimpleRedirect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1195 <utilStandardIOSimpleRedirect+0x65>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x4(%rbp)
jl     116b <utilStandardIOSimpleRedirect+0x3b>
mov    -0x4(%rbp),%edi
call   1030 <dup@plt>
jmp    1182 <utilStandardIOSimpleRedirect+0x52>
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
xor    %edx,%edx
call   1050 <open@plt>
jmp    1187 <utilStandardIOSimpleRedirect+0x57>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1142 <utilStandardIOSimpleRedirect+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utilStandardIOSimpleRedirect>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %edi,%edi
call   1040 <close@plt>
test   %ebx,%ebx
js     1171 <utilStandardIOSimpleRedirect+0x41>
mov    %ebx,%edi
call   1030 <dup@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    %ebx,%edi
call   1030 <dup@plt>
mov    $0x2,%edi
call   1040 <close@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <dup@plt>
mov    0x2e70(%rip),%r14
mov    (%r14),%esi
lea    0xe7e(%rip),%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <open@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <open@plt>
mov    $0x2,%edi
call   1040 <close@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <open@plt>

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

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