#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*/ STDIN_FILENO;
scalar_t__ bu_handle_version(int, char **);
int cat_fd(int /*<<< orphan*/);
int cat_file(char *);
scalar_t__ has_arg(int, char **, char *);
int /*<<< orphan*/ puts(char *);
int main(int argc, char **argv) {
  if (has_arg(argc, argv, "-h") || has_arg(argc, argv, "--help")) {
    puts("Usage: cat [-u] FILE...");
    puts("");
    puts("Concatenate and print the specified file(s).");
    puts("");
    puts("FILE    The file(s) to print.");
    return 1;
  }
  if (bu_handle_version(argc, argv)) {
    return 0;
  }
  if (argc < 2) {
    return cat_fd(STDIN_FILENO);
  }
  for (int i = 1; i < argc; i++) {
    int ret = cat_file(argv[i]);
    if (ret != 0) {
      return ret;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe8c(%rip),%rdx
call   1050 <has_arg@plt>
cmp    $0x0,%rax
jne    11a0 <main+0x50>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe72(%rip),%rdx
call   1050 <has_arg@plt>
cmp    $0x0,%rax
je     11e8 <main+0x98>
lea    0xe63(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9b(%rip),%rdi
call   1040 <puts@plt>
lea    0xe63(%rip),%rdi
call   1040 <puts@plt>
lea    0xe83(%rip),%rdi
call   1040 <puts@plt>
lea    0xe78(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1280 <main+0x130>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <bu_handle_version@plt>
cmp    $0x0,%rax
je     120a <main+0xba>
movl   $0x0,-0x4(%rbp)
jmp    1280 <main+0x130>
cmpl   $0x2,-0x8(%rbp)
jge    122a <main+0xda>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1030 <cat_fd@plt>
mov    %eax,-0x4(%rbp)
jmp    1280 <main+0x130>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1279 <main+0x129>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <cat_file@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1266 <main+0x116>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1280 <main+0x130>
jmp    126b <main+0x11b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1231 <main+0xe1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe8d(%rip),%rdx
call   1060 <has_arg@plt>
test   %rax,%rax
jne    1193 <main+0x33>
lea    0xe7f(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <has_arg@plt>
test   %rax,%rax
je     11df <main+0x7f>
lea    0xe70(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe72(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe89(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <bu_handle_version@plt>
xor    %r14d,%r14d
test   %rax,%rax
jne    11d1 <main+0x71>
cmp    $0x2,%ebp
jge    120e <main+0xae>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <cat_fd@plt>
mov    %ebp,%r15d
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx,%rbp,8),%rdi
call   1070 <cat_file@plt>
test   %eax,%eax
jne    1238 <main+0xd8>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1220 <main+0xc0>
jmp    11d1 <main+0x71>
mov    %eax,%r14d
jmp    11d1 <main+0x71>

LLVM IR (-O0):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [24 x i8] c"Usage: cat [-u] FILE...\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [45 x i8] c"Concatenate and print the specified file(s).\00"
@.str.5 = [30 x i8] c"FILE The file(s) to print.\00"
@STDIN_FILENO = 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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i64 @has_arg(i32 %8, i8** %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i64 @has_arg(i32 %13, i8** %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %12, %2
%18 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @puts(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %56
23: ; preds = %12
%24 = load i32, i32* %4
%25 = load i8**, i8*** %5
%26 = call i64 @bu_handle_version(i32 %24, i8** %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 0, i32* %3
br label %56
29: ; preds = %23
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 2
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* @STDIN_FILENO
%34 = call i32 @cat_fd(i32 %33)
store i32 %34, i32* %3
br label %56
35: ; preds = %29
store i32 1, i32* %6
br label %36
36: ; preds = %52, %35
%37 = load i32, i32* %6
%38 = load i32, i32* %4
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %55
40: ; preds = %36
%41 = load i8**, i8*** %5
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @cat_file(i8* %45)
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %40
%50 = load i32, i32* %7
store i32 %50, i32* %3
br label %56
51: ; preds = %40
br label %52
52: ; preds = %51
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %36
55: ; preds = %36
store i32 0, i32* %3
br label %56
56: ; preds = %55, %49, %32, %28, %17
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [24 x i8] c"Usage: cat [-u] FILE...\00"
@.str.4 = [45 x i8] c"Concatenate and print the specified file(s).\00"
@.str.5 = [30 x i8] c"FILE The file(s) to print.\00"
@STDIN_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i64 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5, %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @putchar(i32 10)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%12 = tail call i32 @putchar(i32 10)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %33
14: ; preds = %5
%15 = tail call i64 @bu_handle_version(i32 %0, i8** %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %33
17: ; preds = %14
%18 = icmp slt i32 %0, 2
br i1 %18, label %21, label %19
19: ; preds = %17
%20 = zext i32 %0 to i64
br label %26
21: ; preds = %17
%22 = load i32, i32* @STDIN_FILENO
%23 = tail call i32 @cat_fd(i32 %22)
br label %33
24: ; preds = %26
%25 = icmp eq i64 %32, %20
br i1 %25, label %33, label %26
26: ; preds = %19, %24
%27 = phi i64 [ 1, %19 ], [ %32, %24 ]
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = load i8*, i8** %28
%30 = tail call i32 @cat_file(i8* %29)
%31 = icmp eq i32 %30, 0
%32 = add nuw nsw i64 %27, 1
br i1 %31, label %24, label %33
33: ; preds = %24, %26, %14, %21, %8
%34 = phi i32 [ 1, %8 ], [ %23, %21 ], [ 0, %14 ], [ 0, %24 ], [ %30, %26 ]
ret i32 %34
}