#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 O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *, int /*<<< orphan*/);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int open(char *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void redir_to_dev_null() {
  int fd = open("/dev/null", O_WRONLY | O_TRUNC);
  if (fd == -1) {
    die("unable to open /dev/null (%s)", strerror(errno));
  }
  dup2(fd, STDOUT_FILENO);
  dup2(fd, STDERR_FILENO);
  close(fd);
}


x86 assembly (clang, -O0):
<redir_to_dev_null>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    119f <redir_to_dev_null+0x4f>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%esi
lea    0xe70(%rip),%rdi
call   1060 <die@plt>
mov    -0x4(%rbp),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x4(%rbp),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redir_to_dev_null>:
push   %rbx
mov    0x2e60(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe96(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1192 <redir_to_dev_null+0x42>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe7f(%rip),%rdi
mov    %eax,%esi
call   1060 <die@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <dup2@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <dup2@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1040 <close@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [30 x i8] c"unable to open /dev/null (%s)\00"
@errno = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define void @redir_to_dev_null() {
%1 = alloca i32
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_TRUNC
%4 = or i32 %2, %3
%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* %1
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = call i32 @strerror(i32 %9)
%11 = call i32 @die(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8, %0
%13 = load i32, i32* %1
%14 = load i32, i32* @STDOUT_FILENO
%15 = call i32 @dup2(i32 %13, i32 %14)
%16 = load i32, i32* %1
%17 = load i32, i32* @STDERR_FILENO
%18 = call i32 @dup2(i32 %16, i32 %17)
%19 = load i32, i32* %1
%20 = call i32 @close(i32 %19)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [30 x i8] c"unable to open /dev/null (%s)\00"
@errno = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define void @redir_to_dev_null() {
%1 = load i32, i32* @O_WRONLY
%2 = load i32, i32* @O_TRUNC
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @die(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %6, %0
%11 = load i32, i32* @STDOUT_FILENO
%12 = tail call i32 @dup2(i32 %4, i32 %11)
%13 = load i32, i32* @STDERR_FILENO
%14 = tail call i32 @dup2(i32 %4, i32 %13)
%15 = tail call i32 @close(i32 %4)
ret void
}