#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*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  FILE *fin, *fout;
  char c;
  if (argc != 3) {
    printf("Usage: %s filein fileout\n", argv[0]);
    exit(0);
  }
  if ((fin = fopen(argv[1], "r")) == NULL) {
    perror("fopen filein");
    exit(0);
  }
  if ((fout = fopen(argv[2], "w")) == NULL) {
    perror("fopen fileout");
    exit(0);
  }
  while ((c = getc(fin)) != EOF)
    putc(c, fout);
  fclose(fin);
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11aa <main+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe61(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11df <main+0x6f>
lea    0xe49(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1214 <main+0xa4>
lea    0xe23(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    1219 <main+0xa9>
mov    -0x18(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2db9(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     124e <main+0xde>
mov    -0x21(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
jmp    1219 <main+0xa9>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1200 <main+0x90>
mov    0x8(%rbx),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1216 <main+0xa6>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     121f <main+0xaf>
mov    %rax,%rbx
mov    %r14,%rdi
call   1090 <getc@plt>
mov    0x2e24(%rip),%r15
cmp    (%r15),%al
je     11e8 <main+0x78>
nopl   0x0(%rax)
movsbl %al,%edi
mov    %rbx,%rsi
call   1050 <putc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
cmp    (%r15),%al
jne    11d0 <main+0x60>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%rbx),%rsi
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xdff(%rip),%rdi
jmp    1226 <main+0xb6>
lea    0xe05(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Usage: %s filein fileout\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"fopen filein\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [14 x i8] c"fopen fileout\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8
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 %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %17
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %30, i32** %7
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %26
br label %36
36: ; preds = %43, %35
%37 = load i32*, i32** %6
%38 = call signext i8 @getc(i32* %37)
store i8 %38, i8* %8
%39 = sext i8 %38 to i32
%40 = load i8, i8* @EOF
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %39, %41
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = load i8, i8* %8
%45 = load i32*, i32** %7
%46 = call i32 @putc(i8 signext %44, i32* %45)
br label %36
47: ; preds = %36
%48 = load i32*, i32** %6
%49 = call i32 @fclose(i32* %48)
%50 = load i32*, i32** %7
%51 = call i32 @fclose(i32* %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"Usage: %s filein fileout\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"fopen filein\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [14 x i8] c"fopen fileout\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %25, label %21
21: ; preds = %16
%22 = tail call signext i8 @getc(i32* %11)
%23 = load i8, i8* @EOF
%24 = icmp eq i8 %22, %23
br i1 %24, label %34, label %28
25: ; preds = %16
%26 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%27 = tail call i32 @exit(i32 0)
unreachable
28: ; preds = %21, %28
%29 = phi i8 [ %31, %28 ], [ %22, %21 ]
%30 = tail call i32 @putc(i8 signext %29, i32* %19)
%31 = tail call signext i8 @getc(i32* %11)
%32 = load i8, i8* @EOF
%33 = icmp eq i8 %31, %32
br i1 %33, label %34, label %28
34: ; preds = %28, %21
%35 = tail call i32 @fclose(i32* %11)
%36 = tail call i32 @fclose(i32* %19)
ret i32 0
}