#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[], char *envp[]) {
  char c;
  int ret = 0;
  FILE *in, *out;
  if (argc != 3) {
    fprintf(stderr, "Invalid arguments!\n");
    return -1;
  }
  in = fopen(argv[1], "r");
  if (!in) {
    fprintf(stderr, "cat: can't open %s\n", argv[1]);
    return -1;
  }
  out = fopen(argv[2], "w");
  if (!out) {
    fprintf(stderr, "cat: can't open %s\n", argv[2]);
    fclose(in);
    return -1;
  }
  while (fscanf(in, "%c", &c) != EOF)
    fprintf(out, "%c", c);
  fclose(in);
  fclose(out);
  return ret;
}


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)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118f <main+0x4f>
mov    0x2e66(%rip),%rax
movslq (%rax),%rdi
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1292 <main+0x152>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe76(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11de <main+0x9e>
mov    0x2e1f(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1292 <main+0x152>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1236 <main+0xf6>
mov    0x2dd0(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1292 <main+0x152>
jmp    123b <main+0xfb>
mov    -0x28(%rbp),%rdi
lea    0xde6(%rip),%rsi
lea    -0x19(%rbp),%rdx
call   1040 <fscanf@plt>
mov    0x2d92(%rip),%rcx
cmp    (%rcx),%rax
je     127a <main+0x13a>
mov    -0x30(%rbp),%rdi
movsbl -0x19(%rbp),%edx
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    123b <main+0xfb>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    1215 <main+0xb5>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1237 <main+0xd7>
mov    %rax,%r14
mov    0x10(%r15),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1255 <main+0xf5>
mov    %rax,%rbx
lea    0xe74(%rip),%rsi
lea    0xf(%rsp),%rdx
mov    %r14,%rdi
call   1040 <fscanf@plt>
mov    0x2e1c(%rip),%r13
cmp    0x0(%r13),%rax
je     1201 <main+0xa1>
lea    0xe53(%rip),%r15
lea    0xf(%rsp),%r12
xchg   %ax,%ax
movsbl 0xf(%rsp),%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
cmp    0x0(%r13),%rax
jne    11e0 <main+0x80>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    127e <main+0x11e>
mov    0x2dbc(%rip),%rax
movslq (%rax),%rcx
lea    0xdda(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
jmp    1279 <main+0x119>
mov    0x2d9a(%rip),%rax
movslq (%rax),%rdi
mov    0x8(%r15),%rdx
lea    0xdca(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1279 <main+0x119>
mov    0x2d7c(%rip),%rax
movslq (%rax),%rdi
mov    0x10(%r15),%rdx
lea    0xdac(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"Invalid arguments!\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"cat: can't open %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%c\00"
@EOF = global i64 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 0, i32* %9
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %68
19: ; preds = %3
%20 = load i8**, i8*** %6
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %10
%24 = load i32*, i32** %10
%25 = icmp ne i32* %24, null
br i1 %25, label %34, label %26
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i32*
%30 = load i8**, i8*** %6
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 -1, i32* %4
br label %68
34: ; preds = %19
%35 = load i8**, i8*** %6
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %38, i32** %11
%39 = load i32*, i32** %11
%40 = icmp ne i32* %39, null
br i1 %40, label %51, label %41
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = sext i32 %42 to i64
%44 = inttoptr i64 %43 to i32*
%45 = load i8**, i8*** %6
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = load i32*, i32** %10
%50 = call i32 @fclose(i32* %49)
store i32 -1, i32* %4
br label %68
51: ; preds = %34
br label %52
52: ; preds = %57, %51
%53 = load i32*, i32** %10
%54 = call i64 @fscanf(i32* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%55 = load i64, i64* @EOF
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %62
57: ; preds = %52
%58 = load i32*, i32** %11
%59 = load i8, i8* %8
%60 = sext i8 %59 to i32
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %60)
br label %52
62: ; preds = %52
%63 = load i32*, i32** %10
%64 = call i32 @fclose(i32* %63)
%65 = load i32*, i32** %11
%66 = call i32 @fclose(i32* %65)
%67 = load i32, i32* %9
store i32 %67, i32* %4
br label %68
68: ; preds = %62, %41, %26, %14
%69 = load i32, i32* %4
ret i32 %69
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"Invalid arguments!\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"cat: can't open %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%c\00"
@EOF = global i64 0
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = alloca i8
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 19, i64 1, i32* %9)
br label %48
11: ; preds = %3
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i32*
%20 = load i8*, i8** %12
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %48
22: ; preds = %11
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %31, label %27
27: ; preds = %22
%28 = call i64 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%29 = load i64, i64* @EOF
%30 = icmp eq i64 %28, %29
br i1 %30, label %45, label %38
31: ; preds = %22
%32 = load i32, i32* @stderr
%33 = sext i32 %32 to i64
%34 = inttoptr i64 %33 to i32*
%35 = load i8*, i8** %23
%36 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = tail call i32 @fclose(i32* %14)
br label %48
38: ; preds = %27, %38
%39 = load i8, i8* %4
%40 = sext i8 %39 to i32
%41 = call i32 @fputc(i32 %40, i32* %25)
%42 = call i64 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%43 = load i64, i64* @EOF
%44 = icmp eq i64 %42, %43
br i1 %44, label %45, label %38
45: ; preds = %38, %27
%46 = call i32 @fclose(i32* %14)
%47 = call i32 @fclose(i32* %25)
br label %48
48: ; preds = %45, %31, %16, %6
%49 = phi i32 [ -1, %6 ], [ 0, %45 ], [ -1, %31 ], [ -1, %16 ]
ret i32 %49
}