#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*/ errno;
int /*<<< orphan*/ fatal(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void reopen_all() {
  if (freopen("/dev/null", "r", stdin) == NULL ||
      freopen("/dev/null", "w", stdout) == NULL ||
      freopen("/dev/null", "w", stdout) == NULL)
    fatal("freopen: %s", strerror(errno));
}


x86 assembly (clang, -O0):
<reopen_all>:
push   %rbp
mov    %rsp,%rbp
mov    0x2ead(%rip),%rax
mov    (%rax),%edx
lea    0xebc(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1030 <freopen@plt>
cmp    $0x0,%rax
je     11a6 <reopen_all+0x76>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
lea    0xe96(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1030 <freopen@plt>
cmp    $0x0,%rax
je     11a6 <reopen_all+0x76>
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
lea    0xe70(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1030 <freopen@plt>
cmp    $0x0,%rax
jne    11c2 <reopen_all+0x92>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    %eax,%esi
lea    0xe51(%rip),%rdi
call   1050 <fatal@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<reopen_all>:
push   %rbx
mov    0x2eb0(%rip),%rax
mov    (%rax),%edx
lea    0xebf(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1030 <freopen@plt>
test   %rax,%rax
je     118f <reopen_all+0x5f>
mov    0x2e77(%rip),%rbx
mov    (%rbx),%edx
lea    0xe9e(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1030 <freopen@plt>
test   %rax,%rax
je     118f <reopen_all+0x5f>
mov    (%rbx),%edx
lea    0xe84(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1030 <freopen@plt>
test   %rax,%rax
je     118f <reopen_all+0x5f>
pop    %rbx
ret
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
lea    0xe6a(%rip),%rdi
mov    %eax,%esi
pop    %rbx
jmp    1050 <fatal@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.3 = [12 x i8] c"freopen: %s\00"
@errno = global i32 0
define void @reopen_all() {
%1 = load i32, i32* @stdin
%2 = 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 %12, label %4
4: ; preds = %0
%5 = load i32, i32* @stdout
%6 = 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.2, i64 0, i64 0), i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = load i32, i32* @stdout
%10 = 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.2, i64 0, i64 0), i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %8, %4, %0
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = call i32 @fatal(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %12, %8
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.3 = [12 x i8] c"freopen: %s\00"
@errno = global i32 0
define void @reopen_all() {
%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 %12, label %4
4: ; preds = %0
%5 = load i32, i32* @stdout
%6 = 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.2, i64 0, i64 0), i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = load i32, i32* @stdout
%10 = 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.2, i64 0, i64 0), i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %8, %4, %0
%13 = load i32, i32* @errno
%14 = tail call i32 @strerror(i32 %13)
%15 = tail call i32 @fatal(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %12, %8
ret void
}