#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*/ EXIT_FAILURE;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "Usage: %s file_in file_out\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  char c;
  int in = open(argv[1], O_RDONLY);
  int out = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);
  while (read(in, &c, 1) == 1)
    write(out, &c, 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119a <main+0x4a>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    0x2dd3(%rip),%rax
or     (%rax),%esi
mov    0x2e1a(%rip),%rax
or     (%rax),%esi
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
mov    0x2de8(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    1224 <main+0xd4>
mov    -0x1c(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    11f4 <main+0xa4>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    120f <main+0xbf>
mov    0x8(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%r14d
mov    0x10(%rbp),%rdi
mov    0x2e72(%rip),%rax
mov    0x2e13(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e58(%rip),%rax
or     (%rax),%esi
mov    0x2e0f(%rip),%rax
mov    0x2e28(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebp
lea    0xf(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    1204 <main+0xb4>
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
je     11e0 <main+0x90>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xddd(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s file_in file_out\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 (i8*, i32, ...) @open(i8* %22, i32 %23)
store i32 %24, i32* %7
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_CREAT
%29 = load i32, i32* @O_WRONLY
%30 = or i32 %28, %29
%31 = load i32, i32* @O_TRUNC
%32 = or i32 %30, %31
%33 = load i32, i32* @S_IRUSR
%34 = load i32, i32* @S_IWUSR
%35 = or i32 %33, %34
%36 = call i32 (i8*, i32, ...) @open(i8* %27, i32 %32, i32 %35)
store i32 %36, i32* %8
br label %37
37: ; preds = %41, %19
%38 = load i32, i32* %7
%39 = call i32 @read(i32 %38, i8* %6, i32 1)
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %8
%43 = call i32 @write(i32 %42, i8* %6, i32 1)
br label %37
44: ; preds = %37
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s file_in file_out\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, 3
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 (i8*, i32, ...) @open(i8* %13, i32 %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_CREAT
%19 = load i32, i32* @O_WRONLY
%20 = or i32 %19, %18
%21 = load i32, i32* @O_TRUNC
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IRUSR
%24 = load i32, i32* @S_IWUSR
%25 = or i32 %24, %23
%26 = tail call i32 (i8*, i32, ...) @open(i8* %17, i32 %22, i32 %25)
%27 = call i32 @read(i32 %15, i8* %3, i32 1)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %33
29: ; preds = %11, %29
%30 = call i32 @write(i32 %26, i8* %3, i32 1)
%31 = call i32 @read(i32 %15, i8* %3, i32 1)
%32 = icmp eq i32 %31, 1
br i1 %32, label %29, label %33
33: ; preds = %29, %11
ret i32 0
}