#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*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int main(int argv, char *argc[]) {
  if (argv != 3) {
    printf("please input param");
    return 1;
  }
  FILE *fi = fopen(argc[1], "r");
  if (fi == NULL) {
    printf("open file error");
    return 1;
  }
  FILE *fo = fopen(argc[2], "w");
  if (fo == NULL) {
    printf("open file error");
    return 1;
  }
  char c;
  while ((c = fgetc(fi)) != EOF) {
    putchar(c);
    fputc(c, fo);
  }
  fclose(fo);
  fclose(fi);
  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     1198 <main+0x38>
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126a <main+0x10a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d3 <main+0x73>
lea    0xe51(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126a <main+0x10a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe41(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120e <main+0xae>
lea    0xe16(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126a <main+0x10a>
jmp    1213 <main+0xb3>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2dbf(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1251 <main+0xf1>
movsbl -0x21(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x21(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
jmp    1213 <main+0xb3>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11f5 <main+0x95>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xea3(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fe <main+0x9e>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe8d(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fe <main+0x9e>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    0x2e36(%rip),%r15
cmp    (%r15),%al
je     11e1 <main+0x81>
nopw   0x0(%rax,%rax,1)
movsbl %al,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    (%r15),%al
jne    11c0 <main+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    120f <main+0xaf>
lea    0xe04(%rip),%rdi
jmp    1205 <main+0xa5>
lea    0xe0e(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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