#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 BUFSIZ;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
main(int argc, char *argv[]) {
  int f1, f2, n;
  char buf[BUFSIZ];
  if (argc < 2) {
    fprintf(stderr, "Usage:cat file [file2 ...]\n");
    exit(1);
  }
  while (--argc) {
    ++argv;
    if ((f1 = open(*argv, O_RDONLY, 0)) == -1) {
      fprintf(stderr, "error:can't open file %s", *argv);
    }
    while ((n = read(f1, buf, BUFSIZ)) > 0) {
      write(1, buf, n);
    }
    close(f1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11cd <main+0x6d>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11d2 <main+0x72>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     127a <main+0x11a>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1231 <main+0xd1>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1236 <main+0xd6>
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    0x2d8c(%rip),%rax
mov    (%rax),%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    126d <main+0x10d>
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1236 <main+0xd6>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    11d2 <main+0x72>
movl   $0x0,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e5b(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x2,%edi
jl     1221 <main+0xc1>
mov    %rsi,%r14
mov    %edi,%r15d
add    $0xffffffff,%r15d
nopl   (%rax)
mov    0x8(%r14),%rdi
add    $0x8,%r14
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    11ef <main+0x8f>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe49(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11ef <main+0x8f>
nopl   0x0(%rax)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%r12),%edx
mov    %r13d,%edi
mov    %rbx,%rsi
call   1050 <read@plt>
test   %eax,%eax
jg     11e0 <main+0x80>
mov    %r13d,%edi
call   1040 <close@plt>
add    $0xffffffff,%r15d
jne    11a0 <main+0x40>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"Usage:cat file [file2 ...]\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"error:can't open file %s\00"
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 i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %9
%14 = alloca i8, i64 %12
store i64 %12, i64* %10
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
br label %22
22: ; preds = %48, %21
%23 = load i32, i32* %4
%24 = add nsw i32 %23, -1
store i32 %24, i32* %4
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %51
26: ; preds = %22
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i32 1
store i8** %28, i8*** %5
%29 = load i8**, i8*** %5
%30 = load i8*, i8** %29
%31 = load i32, i32* @O_RDONLY
%32 = call i32 @open(i8* %30, i32 %31, i32 0)
store i32 %32, i32* %6
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %39
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %5
%37 = load i8*, i8** %36
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %34, %26
br label %40
40: ; preds = %45, %39
%41 = load i32, i32* %6
%42 = load i32, i32* @BUFSIZ
%43 = call i32 @read(i32 %41, i8* %14, i32 %42)
store i32 %43, i32* %8
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32, i32* %8
%47 = call i32 @write(i32 1, i8* %14, i32 %46)
br label %40
48: ; preds = %40
%49 = load i32, i32* %6
%50 = call i32 @close(i32 %49)
br label %22
51: ; preds = %22
store i32 0, i32* %3
%52 = load i8*, i8** %9
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"Usage:cat file [file2 ...]\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"error:can't open file %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp slt i32 %0, 2
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = add nsw i32 %0, -1
br label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7, %35
%14 = phi i32 [ %37, %35 ], [ %8, %7 ]
%15 = phi i8** [ %16, %35 ], [ %1, %7 ]
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = tail call i32 @open(i8* %17, i32 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %16
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %21, %13
%26 = load i32, i32* @BUFSIZ
%27 = call i32 @read(i32 %19, i8* %5, i32 %26)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %25, %29
%30 = phi i32 [ %33, %29 ], [ %27, %25 ]
%31 = call i32 @write(i32 1, i8* %5, i32 %30)
%32 = load i32, i32* @BUFSIZ
%33 = call i32 @read(i32 %19, i8* %5, i32 %32)
%34 = icmp sgt i32 %33, 0
br i1 %34, label %29, label %35
35: ; preds = %29, %25
%36 = tail call i32 @close(i32 %19)
%37 = add nsw i32 %14, -1
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %13
39: ; preds = %35
ret i32 0
}