#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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  FILE *inf, *outf;
  int c, d;
  if (argc != 3) {
    printf("Usage: %s input output\n", argv[0]);
    return 1;
  }
  inf = fopen(argv[1], "r");
  if (!inf) {
    perror("Cannot open input");
    return 2;
  }
  outf = fopen(argv[2], "w");
  if (!inf) {
    perror("Cannot write output");
    return 3;
  }
  while (EOF != (c = fgetc(inf))) {
    d = fgetc(inf);
    fputc(d, outf);
    fputc(c, outf);
  }
  fclose(inf);
  fclose(outf);
  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     119f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1281 <main+0x121>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11da <main+0x7a>
lea    0xe51(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1281 <main+0x121>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe43(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1215 <main+0xb5>
lea    0xe2a(%rip),%rdi
call   1080 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    1281 <main+0x121>
jmp    121a <main+0xba>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
mov    %ecx,-0x24(%rbp)
cmp    %ecx,%eax
je     1268 <main+0x108>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <fputc@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <fputc@plt>
jmp    121a <main+0xba>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <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   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1201 <main+0xa1>
mov    0x8(%rbx),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1224 <main+0xc4>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r13
mov    0x2e3b(%rip),%r15
mov    (%r15),%r12d
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    %eax,%r12d
je     11ed <main+0x8d>
mov    %eax,%ebp
nop
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
mov    (%r15),%ebx
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
cmp    %eax,%ebx
jne    11c0 <main+0x60>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1215 <main+0xb5>
mov    (%rbx),%rsi
lea    0xdf5(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdef(%rip),%rdi
call   1080 <perror@plt>
mov    $0x2,%eax
jmp    1215 <main+0xb5>

LLVM IR (-O0):
@.str = [24 x i8] c"Usage: %s input output\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"Cannot open input\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [20 x i8] c"Cannot write output\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
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %55
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 = load i32*, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %26, label %24
24: ; preds = %17
%25 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %55
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 = load i32*, i32** %6
%32 = icmp ne i32* %31, null
br i1 %32, label %35, label %33
33: ; preds = %26
%34 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i32 3, i32* %3
br label %55
35: ; preds = %26
br label %36
36: ; preds = %41, %35
%37 = load i32, i32* @EOF
%38 = load i32*, i32** %6
%39 = call i32 @fgetc(i32* %38)
store i32 %39, i32* %8
%40 = icmp ne i32 %37, %39
br i1 %40, label %41, label %50
41: ; preds = %36
%42 = load i32*, i32** %6
%43 = call i32 @fgetc(i32* %42)
store i32 %43, i32* %9
%44 = load i32, i32* %9
%45 = load i32*, i32** %7
%46 = call i32 @fputc(i32 %44, i32* %45)
%47 = load i32, i32* %8
%48 = load i32*, i32** %7
%49 = call i32 @fputc(i32 %47, i32* %48)
br label %36
50: ; preds = %36
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
store i32 0, i32* %3
br label %55
55: ; preds = %50, %33, %24, %12
%56 = load i32, i32* %3
ret i32 %56
}

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