#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 ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("No specified files!\n");
    return 1;
  }
  FILE *in = fopen(argv[1], "rb");
  FILE *out = fopen(argv[2], "ab");
  if (!in || !out) {
    printf("File open failed!\n");
    return 2;
  }
  int size = ftell(out);
  char ch;
  while ((ch = fgetc(in)) != EOF)
    fputc(ch, out);
  fwrite(&size, 1, 4, out);
  fclose(out);
  fclose(in);
  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     11a8 <main+0x38>
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1277 <main+0x107>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe49(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ee <main+0x7e>
cmpq   $0x0,-0x20(%rbp)
jne    1206 <main+0x96>
lea    0xe26(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1277 <main+0x107>
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x25(%rbp)
movsbl %al,%eax
mov    0x2dc0(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1247 <main+0xd7>
mov    -0x25(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    1212 <main+0xa2>
mov    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1090 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%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   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    1223 <main+0xb3>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe60(%rip),%rsi
call   1080 <fopen@plt>
test   %r14,%r14
je     1236 <main+0xc6>
mov    %rax,%rbx
test   %rax,%rax
je     1236 <main+0xc6>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2e10(%rip),%r15
cmp    (%r15),%al
je     11f8 <main+0x88>
nopl   (%rax)
movsbl %al,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%al
jne    11e0 <main+0x70>
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1247 <main+0xd7>
lea    0xdee(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1247 <main+0xd7>
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"No specified files!\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"ab\00"
@.str.3 = [19 x i8] c"File open failed!\0A\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 i32
%9 = alloca i8
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 %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %51
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 ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %7
%23 = load i32*, i32** %6
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %14
%26 = load i32*, i32** %7
%27 = icmp ne i32* %26, null
br i1 %27, label %30, label %28
28: ; preds = %25, %14
%29 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %51
30: ; preds = %25
%31 = load i32*, i32** %7
%32 = call i32 @ftell(i32* %31)
store i32 %32, i32* %8
br label %33
33: ; preds = %40, %30
%34 = load i32*, i32** %6
%35 = call signext i8 @fgetc(i32* %34)
store i8 %35, i8* %9
%36 = sext i8 %35 to i32
%37 = load i8, i8* @EOF
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %36, %38
br i1 %39, label %40, label %44
40: ; preds = %33
%41 = load i8, i8* %9
%42 = load i32*, i32** %7
%43 = call i32 @fputc(i8 signext %41, i32* %42)
br label %33
44: ; preds = %33
%45 = load i32*, i32** %7
%46 = call i32 @fwrite(i32* %8, i32 1, i32 4, i32* %45)
%47 = load i32*, i32** %7
%48 = call i32 @fclose(i32* %47)
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
store i32 0, i32* %3
br label %51
51: ; preds = %44, %28, %12
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"ab\00"
@EOF = global i8 0
@str = [18 x i8] c"File open failed!\00"
@str.4 = [20 x i8] c"No specified files!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 3
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
br label %35
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 ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp ne i32* %10, null
%15 = icmp ne i32* %13, null
%16 = and i1 %14, %15
br i1 %16, label %19, label %17
17: ; preds = %7
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %35
19: ; preds = %7
%20 = bitcast i32* %3 to i8*
%21 = tail call i32 @ftell(i32* %13)
store i32 %21, i32* %3
%22 = tail call signext i8 @fgetc(i32* %10)
%23 = load i8, i8* @EOF
%24 = icmp eq i8 %22, %23
br i1 %24, label %31, label %25
25: ; preds = %19, %25
%26 = phi i8 [ %28, %25 ], [ %22, %19 ]
%27 = tail call i32 @fputc(i8 signext %26, i32* %13)
%28 = tail call signext i8 @fgetc(i32* %10)
%29 = load i8, i8* @EOF
%30 = icmp eq i8 %28, %29
br i1 %30, label %31, label %25
31: ; preds = %25, %19
%32 = call i32 @fwrite(i32* %3, i32 1, i32 4, i32* %13)
%33 = tail call i32 @fclose(i32* %13)
%34 = tail call i32 @fclose(i32* %10)
br label %35
35: ; preds = %17, %31, %5
%36 = phi i32 [ 1, %5 ], [ 0, %31 ], [ 2, %17 ]
ret i32 %36
}