#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 u) {
  int n = 0;
  char buf[BUFSIZ];
  if (u != 1)
    u = BUFSIZ;
  while ((n = read(source, buf, u)) > 0)
    write(STDOUT_FILENO, buf, n);
}


x86 assembly (clang, -O0):
<concatenate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     1177 <concatenate+0x57>
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    117c <concatenate+0x5c>
mov    -0x28(%rbp),%rsi
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jle    11b1 <concatenate+0x91>
mov    -0x28(%rbp),%rsi
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
jmp    117c <concatenate+0x5c>
mov    -0x18(%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    %esi,%r15d
mov    %edi,%r14d
mov    0x2ea0(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
cmp    $0x1,%esi
cmovne %eax,%r15d
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1190 <concatenate+0x70>
mov    0x2e85(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     1170 <concatenate+0x50>
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, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%8 = load i32, i32* @BUFSIZ
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %6
%11 = alloca i8, i64 %9
store i64 %9, i64* %7
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* @BUFSIZ
store i32 %15, i32* %4
br label %16
16: ; preds = %14, %2
br label %17
17: ; preds = %22, %16
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = call i32 @read(i32 %18, i8* %11, i32 %19)
store i32 %20, i32* %5
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @STDOUT_FILENO
%24 = load i32, i32* %5
%25 = call i32 @write(i32 %23, i8* %11, i32 %24)
br label %17
26: ; preds = %17
%27 = load i8*, i8** %6
ret void
}

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