#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 */
int EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *fps, *fpd;
  int ch;
  if (argc < 3) {
    fprintf(stderr, "Usage:%s <srcfile> <destfile>\n", argv[0]);
    exit(1);
  }
  fps = fopen(argv[1], "r");
  if (fps == NULL) {
    perror("fopen()");
    exit(1);
  }
  fpd = fopen(argv[2], "w");
  if (fpd == NULL) {
    fclose(fps);
    perror("fopen()");
    exit(1);
  }
  while ((ch = fgetc(fps)) != EOF)
    fputc(ch, fpd);
  fclose(fpd);
  fclose(fps);
  exit(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)
jge    11b6 <main+0x46>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ef <main+0x7f>
lea    0xe41(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe2b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1231 <main+0xc1>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdff(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1236 <main+0xc6>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%eax
je     1262 <main+0xf2>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <fputc@plt>
jmp    1236 <main+0xc6>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     119f <main+0x2f>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe70(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x8(%rbx),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d4 <main+0x64>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe67(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11ea <main+0x7a>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xe46(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2dec(%rip),%r15
cmp    (%r15),%eax
je     1227 <main+0xb7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    1210 <main+0xa0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Usage:%s <srcfile> <destfile>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"fopen()\00"
@.str.3 = [2 x i8] c"w\00"
@EOF = global i32 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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %18
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 ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %18
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %7
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %40
35: ; preds = %28
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
%38 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %28
br label %41
41: ; preds = %46, %40
%42 = load i32*, i32** %6
%43 = call i32 @fgetc(i32* %42)
store i32 %43, i32* %8
%44 = load i32, i32* @EOF
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = load i32, i32* %8
%48 = load i32*, i32** %7
%49 = call i32 @fputc(i32 %47, i32* %48)
br label %41
50: ; preds = %41
%51 = load i32*, i32** %7
%52 = call i32 @fclose(i32* %51)
%53 = load i32*, i32** %6
%54 = call i32 @fclose(i32* %53)
%55 = call i32 @exit(i32 0)
unreachable
}

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