#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*/ STDOUT_FILENO;
int read(int, char *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
void concatenate(int source) {
  int n = 0;
  char buf[BUFSIZ];
  while ((n = read(source, buf, BUFSIZ)) > 0)
    write(STDOUT_FILENO, buf, n);
}


x86 assembly (clang, -O0):
<concatenate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x4(%rbp),%edi
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
call   1040 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1199 <concatenate+0x79>
mov    -0x20(%rbp),%rsi
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
call   1030 <write@plt>
jmp    115e <concatenate+0x3e>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concatenate>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
mov    0x2ea3(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rsi
call   1040 <read@plt>
test   %eax,%eax
jle    1180 <concatenate+0x60>
mov    0x2e91(%rip),%r12
nop
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%r15),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <read@plt>
test   %eax,%eax
jg     1160 <concatenate+0x40>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@STDOUT_FILENO = global i32 0
define void @concatenate(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 %0, i32* %2
store i32 0, i32* %3
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %4
%9 = alloca i8, i64 %7
store i64 %7, i64* %5
br label %10
10: ; preds = %15, %1
%11 = load i32, i32* %2
%12 = load i32, i32* @BUFSIZ
%13 = call i32 @read(i32 %11, i8* %9, i32 %12)
store i32 %13, i32* %3
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* @STDOUT_FILENO
%17 = load i32, i32* %3
%18 = call i32 @write(i32 %16, i8* %9, i32 %17)
br label %10
19: ; preds = %10
%20 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@STDOUT_FILENO = global i32 0
define void @concatenate(i32 %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @read(i32 %0, i8* %4, i32 %2)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %1, %7
%8 = phi i32 [ %12, %7 ], [ %5, %1 ]
%9 = load i32, i32* @STDOUT_FILENO
%10 = call i32 @write(i32 %9, i8* %4, i32 %8)
%11 = load i32, i32* @BUFSIZ
%12 = call i32 @read(i32 %0, i8* %4, i32 %11)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %7, label %14
14: ; preds = %7, %1
ret void
}