#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char **, int const);
int /*<<< orphan*/ write(int, ...);
void complex_cat(char *argv[]) {
  write(1, "COMPLEX\n\n", 9);
  int fd;
  const int BUFFER_SIZE = 1024;
  char file_buffer[BUFFER_SIZE];
  int num_bytes_read;
  fd = open(argv[1], O_RDONLY);
  num_bytes_read = -1;
  while (num_bytes_read != 0) {
    num_bytes_read = read(fd, &file_buffer, BUFFER_SIZE);
    write(1, &file_buffer, num_bytes_read);
  }
  close(fd);
  close(1);
}


x86 assembly (clang, -O0):
<complex_cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x1,%edi
lea    0xea5(%rip),%rsi
mov    $0x9,%edx
mov    $0x0,%al
call   1030 <write@plt>
movl   $0x400,-0x10(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d1 <complex_cat+0x91>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edx
mov    $0x1,%edi
lea    -0x420(%rbp),%rsi
mov    $0x0,%al
call   1030 <write@plt>
jmp    1195 <complex_cat+0x55>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<complex_cat>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
lea    0xeab(%rip),%rsi
mov    $0x1,%edi
mov    $0x9,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    0x8(%rbx),%rdi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%r14d
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,%ebp
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write@plt>
test   %ebp,%ebp
jne    1180 <complex_cat+0x40>
mov    %r14d,%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"COMPLEX\0A\0A\00"
@O_RDONLY = global i32 0
define void @complex_cat(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i8** %0, i8*** %2
%7 = call i32 (i32, ...) @write(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
store i32 1024, i32* %4
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %5
%9 = alloca i8, i64 1024
%10 = load i8**, i8*** %2
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %3
store i32 -1, i32* %6
br label %15
15: ; preds = %18, %1
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i32, i32* %3
%20 = bitcast i8* %9 to i8**
%21 = call i32 @read(i32 %19, i8** %20, i32 1024)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = call i32 (i32, ...) @write(i32 1, i8* %9, i32 %22)
br label %15
24: ; preds = %15
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
%27 = call i32 @close(i32 1)
%28 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"COMPLEX\0A\0A\00"
@O_RDONLY = global i32 0
define void @complex_cat(i8** nocapture %0) {
%2 = tail call i32 (i32, ...) @write(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %0, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = bitcast [1024 x i8]* %3 to i8**
br label %10
10: ; preds = %1, %10
%11 = call i32 @read(i32 %8, i8** %9, i32 1024)
%12 = call i32 (i32, ...) @write(i32 1, i8* %4, i32 %11)
%13 = icmp eq i32 %11, 0
br i1 %13, label %14, label %10
14: ; preds = %10
%15 = call i32 @close(i32 %8)
%16 = call i32 @close(i32 1)
ret void
}