#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
char *calloc(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int open(char *, int, int);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  if (2 > argc) {
    fprintf(stderr, "catm requires 2 or more arguments\n");
    exit(EXIT_FAILURE);
  }
  int output = open(argv[1], 577, 384);
  if (-1 == output) {
    fprintf(stderr, "The file: %s is not a valid output file name\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  int i;
  int bytes;
  char *buffer = calloc(2, sizeof(char));
  int input;
  for (i = 2; i <= argc; i = i + 1) {
    input = open(argv[i], 0, 0);
    if (-1 == input) {
      fprintf(stderr, "The file: %s is not a valid input file name\n", argv[i]);
      exit(EXIT_FAILURE);
    }
  keep:
    bytes = read(input, buffer, 1);
    write(output, buffer, bytes);
    if (1 == bytes)
      goto keep;
  }
  free(buffer);
  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)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jle    11b9 <main+0x49>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x241,%esi
mov    $0x180,%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    120e <main+0x9e>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    $0x2,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     12d9 <main+0x169>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <open@plt>
mov    %eax,-0x2c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x2c(%rbp),%eax
jne    128b <main+0x11b>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1290 <main+0x120>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <write@plt>
mov    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jne    12c6 <main+0x156>
jmp    1290 <main+0x120>
jmp    12cb <main+0x15b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1228 <main+0xb8>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2ce7(%rip),%rax
mov    (%rax),%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    %rdi,(%rsp)
cmp    $0x1,%edi
jle    126d <main+0xfd>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
mov    $0x241,%esi
mov    $0x180,%edx
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1286 <main+0x116>
mov    %eax,%r12d
mov    $0x2,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    (%rsp),%rax
add    $0x1,%eax
mov    %rax,(%rsp)
mov    $0x2,%r14d
nopl   (%rax)
mov    %rbp,%r15
mov    0x0(%rbp,%r14,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
je     1241 <main+0xd1>
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,%ebp
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0x1,%ebp
je     11f0 <main+0x80>
add    $0x1,%r14
cmp    (%rsp),%r14
mov    %r15,%rbp
jne    11d0 <main+0x60>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14d,%eax
mov    0x2d95(%rip),%rcx
mov    (%rcx),%edi
mov    (%r15,%rax,8),%rdx
lea    0xdf9(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    125f <main+0xef>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xd89(%rip),%rsi
jmp    1258 <main+0xe8>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"catm requires 2 or more arguments\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [46 x i8] c"The file: %s is not a valid output file name\0A\00"
@.str.2 = [45 x i8] c"The file: %s is not a valid input file name\0A\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
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sgt i32 2, %11
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @open(i8* %21, i32 577, i32 384)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 -1, %23
br i1 %24, label %25, label %33
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %18
%34 = call i8* @calloc(i32 2, i32 1)
store i8* %34, i8** %9
store i32 2, i32* %7
br label %35
35: ; preds = %71, %33
%36 = load i32, i32* %7
%37 = load i32, i32* %4
%38 = icmp sle i32 %36, %37
br i1 %38, label %39, label %74
39: ; preds = %35
%40 = load i8**, i8*** %5
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @open(i8* %44, i32 0, i32 0)
store i32 %45, i32* %10
%46 = load i32, i32* %10
%47 = icmp eq i32 -1, %46
br i1 %47, label %48, label %58
48: ; preds = %39
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %54)
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %39
br label %59
59: ; preds = %69, %58
%60 = load i32, i32* %10
%61 = load i8*, i8** %9
%62 = call i32 @read(i32 %60, i8* %61, i32 1)
store i32 %62, i32* %8
%63 = load i32, i32* %6
%64 = load i8*, i8** %9
%65 = load i32, i32* %8
%66 = call i32 @write(i32 %63, i8* %64, i32 %65)
%67 = load i32, i32* %8
%68 = icmp eq i32 1, %67
br i1 %68, label %69, label %70
69: ; preds = %59
br label %59
70: ; preds = %59
br label %71
71: ; preds = %70
%72 = load i32, i32* %7
%73 = add nsw i32 %72, 1
store i32 %73, i32* %7
br label %35
74: ; preds = %35
%75 = load i8*, i8** %9
%76 = call i32 @free(i8* %75)
%77 = load i32, i32* @EXIT_SUCCESS
ret i32 %77
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"catm requires 2 or more arguments\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [46 x i8] c"The file: %s is not a valid output file name\0A\00"
@.str.2 = [45 x i8] c"The file: %s is not a valid input file name\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @open(i8* %11, i32 577, i32 384)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %10
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %9
%21 = tail call dereferenceable_or_null(2) i8* @calloc(i32 2, i32 1)
%22 = add nuw i32 %0, 1
%23 = zext i32 %22 to i64
br label %24
24: ; preds = %20, %42
%25 = phi i64 [ 2, %20 ], [ %43, %42 ]
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
%28 = tail call i32 @open(i8* %27, i32 0, i32 0)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %38
30: ; preds = %24
%31 = and i64 %25, 4294967295
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %32
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = tail call i32 @exit(i32 %36)
unreachable
38: ; preds = %24, %38
%39 = tail call i32 @read(i32 %28, i8* %21, i32 1)
%40 = tail call i32 @write(i32 %12, i8* %21, i32 %39)
%41 = icmp eq i32 %39, 1
br i1 %41, label %38, label %42
42: ; preds = %38
%43 = add nuw nsw i64 %25, 1
%44 = icmp eq i64 %43, %23
br i1 %44, label %45, label %24
45: ; preds = %42
%46 = tail call i32 @free(i8* %21)
%47 = load i32, i32* @EXIT_SUCCESS
ret i32 %47
}