#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int ifd, ofd;
  char ofile[16] = "/dev/null";
  char ifile[32];
  char buf[32];
  if (argc != 2) {
    printf("usage, %s file, will send contents of file 2 /dev/null\n", argv[0]);
    exit(-1);
  }
  strcpy(ifile, argv[1]);
  if ((ofd = open(ofile, O_RDWR)) < 0) {
    printf("error opening %s\n", ofile);
    exit(-1);
  }
  if ((ifd = open(ifile, O_RDONLY)) < 0) {
    printf("error opening %s\n", ifile);
    exit(-1);
  }
  read(ifd, buf, sizeof(buf) - 1);
  write(ofd, buf, sizeof(buf) - 1);
  printf("copied contents of %s to a safer place... (%s)\n", ifile, ofile);
  close(ifd);
  close(ofd);
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe73(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c5 <main+0x55>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1210 <main+0xa0>
lea    -0x30(%rbp),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    -0x50(%rbp),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    124a <main+0xda>
lea    -0x50(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x1f,%edx
call   1070 <read@plt>
mov    -0x18(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x1f,%edx
call   1040 <write@plt>
lea    -0x50(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
movaps 0xe81(%rip),%xmm0
movaps %xmm0,(%rsp)
cmp    $0x2,%edi
jne    11b7 <main+0x47>
mov    0x8(%rsi),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1080 <open@plt>
test   %eax,%eax
jns    11c3 <main+0x53>
lea    0xe96(%rip),%rdi
mov    %rsp,%rsi
jmp    11e8 <main+0x78>
mov    (%rsi),%rsi
lea    0xe4f(%rip),%rdi
jmp    11e8 <main+0x78>
mov    %eax,%ebx
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1080 <open@plt>
test   %eax,%eax
jns    11f9 <main+0x89>
lea    0xe65(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    %eax,%ebp
lea    0x30(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x1f,%edx
call   1070 <read@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1f,%edx
call   1040 <write@plt>
lea    0xe35(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.main.ofile = [16 x i8] c"/dev/null\00\00\00\00\00\00\00"
@.str = [56 x i8] c"usage, %s file, will send contents of file 2 /dev/null\0A\00"
@O_RDWR = global i32 0
@.str.1 = [18 x i8] c"error opening %s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [48 x i8] c"copied contents of %s to a safer place... (%s)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [16 x i8]
%9 = alloca [32 x i8]
%10 = alloca [32 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [16 x i8]* %8 to i8*
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strcpy(i8* %21, i8* %24)
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%27 = load i32, i32* @O_RDWR
%28 = call i32 @open(i8* %26, i32 %27)
store i32 %28, i32* %7
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %20
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%32 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %20
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%36 = load i32, i32* @O_RDONLY
%37 = call i32 @open(i8* %35, i32 %36)
store i32 %37, i32* %6
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%41 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 -1)
unreachable
43: ; preds = %34
%44 = load i32, i32* %6
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%46 = call i32 @read(i32 %44, i8* %45, i32 31)
%47 = load i32, i32* %7
%48 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%49 = call i32 @write(i32 %47, i8* %48, i32 31)
%50 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%52 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %50, i8* %51)
%53 = load i32, i32* %6
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* %7
%56 = call i32 @close(i32 %55)
%57 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@__const.main.ofile = [16 x i8] c"/dev/null\00\00\00\00\00\00\00"
@.str = [56 x i8] c"usage, %s file, will send contents of file 2 /dev/null\0A\00"
@O_RDWR = global i32 0
@.str.1 = [18 x i8] c"error opening %s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [48 x i8] c"copied contents of %s to a safer place... (%s)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 2
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strcpy(i8* %7, i8* %16)
%18 = load i32, i32* @O_RDWR
%19 = call i32 @open(i8* %6, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %14
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %7, i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %24
%32 = call i32 @read(i32 %26, i8* %8, i32 31)
%33 = call i32 @write(i32 %19, i8* %8, i32 31)
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %6)
%35 = call i32 @close(i32 %26)
%36 = call i32 @close(i32 %19)
%37 = call i32 @exit(i32 1)
unreachable
}