#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*/ LOG_ERR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int redirect_io(void) {
  if (freopen("/dev/null", "r", stdin) == NULL) {
    syslog(LOG_ERR, "failed to redirect stdin, code %d (%s)", errno,
           strerror(errno));
    return 0;
  }
  if (freopen("/dev/null", "w", stdout) == NULL) {
    syslog(LOG_ERR, "failed to redirect stdout, code %d (%s)", errno,
           strerror(errno));
    return 0;
  }
  if (freopen("/dev/null", "w", stderr) == NULL) {
    syslog(LOG_ERR, "failed to redirect stderr, code %d (%s)", errno,
           strerror(errno));
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<redirect_io>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edx
lea    0xeb8(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1030 <freopen@plt>
cmp    $0x0,%rax
jne    11a4 <redirect_io+0x74>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%edx
mov    %eax,%ecx
lea    0xe79(%rip),%rsi
call   1040 <syslog@plt>
movl   $0x0,-0x4(%rbp)
jmp    1283 <redirect_io+0x153>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
lea    0xe4c(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1030 <freopen@plt>
cmp    $0x0,%rax
jne    1210 <redirect_io+0xe0>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%edx
mov    %eax,%ecx
lea    0xe36(%rip),%rsi
call   1040 <syslog@plt>
movl   $0x0,-0x4(%rbp)
jmp    1283 <redirect_io+0x153>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
lea    0xde0(%rip),%rdi
lea    0xe0c(%rip),%rsi
call   1030 <freopen@plt>
cmp    $0x0,%rax
jne    127c <redirect_io+0x14c>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    %eax,%ecx
lea    0xdf2(%rip),%rsi
call   1040 <syslog@plt>
movl   $0x0,-0x4(%rbp)
jmp    1283 <redirect_io+0x153>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redirect_io>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rax
mov    (%rax),%edx
lea    0xebd(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1030 <freopen@plt>
test   %rax,%rax
je     11c0 <redirect_io+0x90>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
lea    0xe9c(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1030 <freopen@plt>
test   %rax,%rax
je     11e2 <redirect_io+0xb2>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
lea    0xe7b(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1030 <freopen@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    120f <redirect_io+0xdf>
mov    0x2e13(%rip),%rax
mov    (%rax),%ebx
mov    0x2e22(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1050 <strerror@plt>
lea    0xe9f(%rip),%rsi
jmp    1202 <redirect_io+0xd2>
mov    0x2df1(%rip),%rax
mov    (%rax),%ebx
mov    0x2e00(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1050 <strerror@plt>
lea    0xe2c(%rip),%rsi
jmp    1202 <redirect_io+0xd2>
mov    0x2dcf(%rip),%rax
mov    (%rax),%ebx
mov    0x2dde(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1050 <strerror@plt>
lea    0xe33(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <syslog@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@LOG_ERR = global i32 0
@.str.2 = [39 x i8] c"failed to redirect stdin, code %d (%s)\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.4 = [40 x i8] c"failed to redirect stdout, code %d (%s)\00"
@stderr = global i32 0
@.str.5 = [40 x i8] c"failed to redirect stderr, code %d (%s)\00"
define i32 @redirect_io() {
%1 = alloca i32
%2 = load i32, i32* @stdin
%3 = call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = load i32, i32* @LOG_ERR
%7 = load i32, i32* @errno
%8 = load i32, i32* @errno
%9 = call i32 @strerror(i32 %8)
%10 = call i32 @syslog(i32 %6, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %7, i32 %9)
store i32 0, i32* %1
br label %32
11: ; preds = %0
%12 = load i32, i32* @stdout
%13 = call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i32, i32* @LOG_ERR
%17 = load i32, i32* @errno
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call i32 @syslog(i32 %16, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %17, i32 %19)
store i32 0, i32* %1
br label %32
21: ; preds = %11
%22 = load i32, i32* @stderr
%23 = call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i32, i32* @LOG_ERR
%27 = load i32, i32* @errno
%28 = load i32, i32* @errno
%29 = call i32 @strerror(i32 %28)
%30 = call i32 @syslog(i32 %26, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %27, i32 %29)
store i32 0, i32* %1
br label %32
31: ; preds = %21
store i32 1, i32* %1
br label %32
32: ; preds = %31, %25, %15, %5
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@LOG_ERR = global i32 0
@.str.2 = [39 x i8] c"failed to redirect stdin, code %d (%s)\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.4 = [40 x i8] c"failed to redirect stdout, code %d (%s)\00"
@stderr = global i32 0
@.str.5 = [40 x i8] c"failed to redirect stderr, code %d (%s)\00"
define i32 @redirect_io() {
%1 = load i32, i32* @stdin
%2 = tail call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %9
4: ; preds = %0
%5 = load i32, i32* @LOG_ERR
%6 = load i32, i32* @errno
%7 = tail call i32 @strerror(i32 %6)
%8 = tail call i32 @syslog(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 %7)
br label %27
9: ; preds = %0
%10 = load i32, i32* @stdout
%11 = tail call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32, i32* @LOG_ERR
%15 = load i32, i32* @errno
%16 = tail call i32 @strerror(i32 %15)
%17 = tail call i32 @syslog(i32 %14, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %15, i32 %16)
br label %27
18: ; preds = %9
%19 = load i32, i32* @stderr
%20 = tail call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i32, i32* @LOG_ERR
%24 = load i32, i32* @errno
%25 = tail call i32 @strerror(i32 %24)
%26 = tail call i32 @syslog(i32 %23, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %24, i32 %25)
br label %27
27: ; preds = %18, %22, %13, %4
%28 = phi i32 [ 0, %4 ], [ 0, %13 ], [ 0, %22 ], [ 1, %18 ]
ret i32 %28
}