#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  FILE *fi, *fo;
  int i;
  if (argc != 3) {
    printf("E: Need 2 filenames as arguments.\n");
    return EXIT_FAILURE;
  }
  if ((fi = fopen(argv[1], "r")) == NULL) {
    perror("E: Can not open input file");
    return EXIT_FAILURE;
  }
  if ((fo = fopen(argv[2], "w")) == NULL) {
    perror("E: Can not open output file");
    return EXIT_FAILURE;
  }
  for (;;) {
    i = getc(fi);
    if (ferror(fi)) {
      perror("E: Error reading input file");
      exit(EXIT_FAILURE);
    } else if (feof(fi)) {
      break;
    } else {
      putc(i, fo);
    }
  }
  if (fclose(fi)) {
    perror("E: Can not close input file");
    exit(EXIT_FAILURE);
  }
  if (fclose(fo)) {
    perror("E: Can not close output file");
    exit(EXIT_FAILURE);
  }
  return EXIT_SUCCESS;
}


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     11cd <main+0x3d>
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    131d <main+0x18d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe47(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    120c <main+0x7c>
lea    0xe2f(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    131d <main+0x18d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe25(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    124b <main+0xbb>
lea    0xe0d(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    131d <main+0x18d>
jmp    1250 <main+0xc0>
mov    -0x18(%rbp),%rdi
call   10b0 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1289 <main+0xf9>
lea    0xde8(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     12a1 <main+0x111>
jmp    12b7 <main+0x127>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <putc@plt>
jmp    12b2 <main+0x122>
jmp    1250 <main+0xc0>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     12e4 <main+0x154>
lea    0xda9(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1311 <main+0x181>
lea    0xd98(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2cc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    1200 <main+0x70>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe59(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     123d <main+0xad>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1246 <main+0xb6>
mov    %rax,%r14
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    125b <main+0xcb>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    1215 <main+0x85>
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <putc@plt>
jmp    11d0 <main+0x40>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dcd(%rip),%rax
jmp    1236 <main+0xa6>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
jne    1275 <main+0xe5>
mov    %r14,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
jne    127e <main+0xee>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdbe(%rip),%rdi
jmp    124d <main+0xbd>
lea    0xdd2(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d87(%rip),%rax
jmp    1236 <main+0xa6>
lea    0xdd9(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xddb(%rip),%rdi
jmp    1262 <main+0xd2>
lea    0xdee(%rip),%rdi
jmp    1262 <main+0xd2>

LLVM IR (-O0):
@.str = [35 x i8] c"E: Need 2 filenames as arguments.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"E: Can not open input file\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [28 x i8] c"E: Can not open output file\00"
@.str.5 = [28 x i8] c"E: Error reading input file\00"
@.str.6 = [28 x i8] c"E: Can not close input file\00"
@.str.7 = [29 x i8] c"E: Can not close output file\00"
@EXIT_SUCCESS = 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 ne i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %72
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %3
br label %72
23: ; preds = %14
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %27, i32** %7
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %3
br label %72
32: ; preds = %23
br label %33
33: ; preds = %53, %32
%34 = load i32*, i32** %6
%35 = call i32 @getc(i32* %34)
store i32 %35, i32* %8
%36 = load i32*, i32** %6
%37 = call i64 @ferror(i32* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %33
%40 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %33
%44 = load i32*, i32** %6
%45 = call i64 @feof(i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %43
br label %54
48: ; preds = %43
%49 = load i32, i32* %8
%50 = load i32*, i32** %7
%51 = call i32 @putc(i32 %49, i32* %50)
br label %52
52: ; preds = %48
br label %53
53: ; preds = %52
br label %33
54: ; preds = %47
%55 = load i32*, i32** %6
%56 = call i64 @fclose(i32* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %54
%59 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %54
%63 = load i32*, i32** %7
%64 = call i64 @fclose(i32* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %62
%67 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%68 = load i32, i32* @EXIT_FAILURE
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %62
%71 = load i32, i32* @EXIT_SUCCESS
store i32 %71, i32* %3
br label %72
72: ; preds = %70, %29, %20, %11
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"E: Can not open input file\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [28 x i8] c"E: Can not open output file\00"
@.str.5 = [28 x i8] c"E: Error reading input file\00"
@.str.6 = [28 x i8] c"E: Can not close input file\00"
@.str.7 = [29 x i8] c"E: Can not close output file\00"
@EXIT_SUCCESS = global i32 0
@str = [34 x i8] c"E: Need 2 filenames as arguments.\00"
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 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %51
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 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %51
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 i32 @getc(i32* %9)
%20 = tail call i64 @ferror(i32* %9)
%21 = icmp eq i64 %20, 0
br i1 %21, label %28, label %24
22: ; preds = %13
%23 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %51
24: ; preds = %32, %18
%25 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %18, %32
%29 = phi i32 [ %34, %32 ], [ %19, %18 ]
%30 = tail call i64 @feof(i32* %9)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = tail call i32 @putc(i32 %29, i32* %16)
%34 = tail call i32 @getc(i32* %9)
%35 = tail call i64 @ferror(i32* %9)
%36 = icmp eq i64 %35, 0
br i1 %36, label %28, label %24
37: ; preds = %28
%38 = tail call i64 @fclose(i32* %9)
%39 = icmp eq i64 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %37
%41 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = tail call i32 @exit(i32 %42)
unreachable
44: ; preds = %37
%45 = tail call i64 @fclose(i32* %16)
%46 = icmp eq i64 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %44
%48 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = tail call i32 @exit(i32 %49)
unreachable
51: ; preds = %44, %22, %11, %4
%52 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %11 ], [ @EXIT_FAILURE, %22 ], [ @EXIT_SUCCESS, %44 ]
%53 = load i32, i32* %52
ret i32 %53
}