#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 read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void lowlevelcopy(int in, int out, int blockSize) {
  char buf[blockSize];
  int n;
  while ((n = read(in, buf, blockSize)) > 0)
    write(out, buf, n);
}


x86 assembly (clang, -O0):
<lowlevelcopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%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,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%edx
call   1040 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    1186 <lowlevelcopy+0x66>
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    -0x24(%rbp),%edx
call   1030 <write@plt>
jmp    1157 <lowlevelcopy+0x37>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lowlevelcopy>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %esi,%r14d
mov    %edi,%r15d
mov    %edx,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rsi
nopw   0x0(%rax,%rax,1)
call   1040 <read@plt>
test   %eax,%eax
jle    1171 <lowlevelcopy+0x51>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
jmp    1150 <lowlevelcopy+0x30>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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