#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*/ memset(char *, int /*<<< orphan*/, int);
int read(int, char *, int);
scalar_t__ write(int, char *, int);
int copy(int in, int out) {
  int cpt;
  int buf_size = 2048;
  char buf[buf_size];
  memset(buf, 0, buf_size);
  while ((cpt = read(in, buf, buf_size)) >= 0) {
    if (write(out, buf, cpt) < 0)
      return 0;
    if (cpt == 0)
      break;
  }
  if (cpt < 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x800,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jl     11d0 <copy+0xa0>
mov    -0x38(%rbp),%rsi
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11bc <copy+0x8c>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11fb <copy+0xcb>
cmpl   $0x0,-0x10(%rbp)
jne    11cb <copy+0x9b>
jmp    11d0 <copy+0xa0>
jmp    1175 <copy+0x45>
cmpl   $0x0,-0x10(%rbp)
jge    11ed <copy+0xbd>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11fb <copy+0xcb>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
js     118c <copy+0x5c>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1193 <copy+0x63>
test   %ebp,%ebp
jne    1160 <copy+0x30>
not    %ebp
shr    $0x1f,%ebp
jmp    1195 <copy+0x65>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @copy(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 2048, i32* %7
%11 = load i32, i32* %7
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = load i32, i32* %7
%16 = call i32 @memset(i8* %14, i32 0, i32 %15)
br label %17
17: ; preds = %32, %2
%18 = load i32, i32* %4
%19 = load i32, i32* %7
%20 = call i32 @read(i32 %18, i8* %14, i32 %19)
store i32 %20, i32* %6
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %17
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = call i64 @write(i32 %23, i8* %14, i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 0, i32* %3
store i32 1, i32* %10
br label %38
28: ; preds = %22
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %28
br label %33
32: ; preds = %28
br label %17
33: ; preds = %31, %17
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 0, i32* %3
store i32 1, i32* %10
br label %38
37: ; preds = %33
store i32 1, i32* %3
store i32 1, i32* %10
br label %38
38: ; preds = %37, %36, %27
%39 = load i8*, i8** %8
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
define i32 @copy(i32 %0, i32 %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 2048)
br label %6
6: ; preds = %12, %2
%7 = call i32 @read(i32 %0, i8* %4, i32 2048)
%8 = icmp sgt i32 %7, -1
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = call i64 @write(i32 %1, i8* %4, i32 %7)
%11 = icmp slt i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = icmp eq i32 %7, 0
br i1 %13, label %14, label %6
14: ; preds = %12, %6
%15 = xor i32 %7, -1
%16 = lshr i32 %15, 31
br label %17
17: ; preds = %9, %14
%18 = phi i32 [ %16, %14 ], [ 0, %9 ]
ret i32 %18
}