#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*/ close(int);
int /*<<< orphan*/ free(void *);
void *malloc(int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int read(int, void *, int);
int /*<<< orphan*/ write(int, void *, int);
int main(int argc, char **argv) {
  int rfd = 4;
  int wfd = 5;
  int readBytes = 0;
  void *buffer;
  buffer = malloc(4096 * sizeof(char));
  memset(buffer, 0, 4096);
  while ((readBytes = read(rfd, buffer, 4096)) > 0) {
    write(wfd, buffer, readBytes);
  }
  close(rfd);
  close(wfd);
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
movl   $0x5,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11da <main+0x7a>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <write@plt>
jmp    11a9 <main+0x49>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
nopl   (%rax)
mov    $0x4,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    11a7 <main+0x47>
mov    $0x5,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    1180 <main+0x20>
mov    $0x4,%edi
call   1060 <close@plt>
mov    $0x5,%edi
call   1060 <close@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %6
store i32 5, i32* %7
store i32 0, i32* %8
%10 = call i8* @malloc(i32 4096)
store i8* %10, i8** %9
%11 = load i8*, i8** %9
%12 = call i32 @memset(i8* %11, i32 0, i32 4096)
br label %13
13: ; preds = %18, %2
%14 = load i32, i32* %6
%15 = load i8*, i8** %9
%16 = call i32 @read(i32 %14, i8* %15, i32 4096)
store i32 %16, i32* %8
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i32, i32* %7
%20 = load i8*, i8** %9
%21 = load i32, i32* %8
%22 = call i32 @write(i32 %19, i8* %20, i32 %21)
br label %13
23: ; preds = %13
%24 = load i32, i32* %6
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %7
%27 = call i32 @close(i32 %26)
%28 = load i8*, i8** %9
%29 = call i32 @free(i8* %28)
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%4 = tail call i32 @memset(i8* %3, i32 0, i32 4096)
%5 = tail call i32 @read(i32 4, i8* %3, i32 4096)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2, %7
%8 = phi i32 [ %10, %7 ], [ %5, %2 ]
%9 = tail call i32 @write(i32 5, i8* %3, i32 %8)
%10 = tail call i32 @read(i32 4, i8* %3, i32 4096)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %7, label %12
12: ; preds = %7, %2
%13 = tail call i32 @close(i32 4)
%14 = tail call i32 @close(i32 5)
%15 = tail call i32 @free(i8* %3)
ret i32 0
}