#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*/ exit(int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int write(int, char *, int);
int copy(int inputFileDesc, int outputFileDesc) {
  char buffer[512];
  int sizeRead;
  while (sizeRead = read(inputFileDesc, buffer, 512)) {
    int writeVal;
    if (writeVal = write(outputFileDesc, buffer, sizeRead) != sizeRead) {
      perror("Error");
      exit(writeVal);
    }
  }
}


x86 assembly (clang, -O0):
<copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1040 <read@plt>
mov    %eax,-0x214(%rbp)
cmp    $0x0,%eax
je     11c9 <copy+0x89>
mov    -0xc(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    -0x214(%rbp),%edx
call   1030 <write@plt>
cmp    -0x214(%rbp),%eax
setne  %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x218(%rbp)
test   $0x1,%al
jne    11ad <copy+0x6d>
jmp    11c4 <copy+0x84>
lea    0xe4c(%rip),%rdi
call   1050 <perror@plt>
mov    -0x218(%rbp),%edi
call   1060 <exit@plt>
jmp    1151 <copy+0x11>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x200,%edx
call   1040 <read@plt>
test   %eax,%eax
je     119c <copy+0x5c>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
je     1160 <copy+0x20>
lea    0xe73(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Error\00"
define i32 @copy(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
br label %9
9: ; preds = %26, %2
%10 = load i32, i32* %4
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 512)
store i32 %12, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %9
%15 = load i32, i32* %5
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%17 = load i32, i32* %7
%18 = call i32 @write(i32 %15, i8* %16, i32 %17)
%19 = load i32, i32* %7
%20 = icmp ne i32 %18, %19
%21 = zext i1 %20 to i32
store i32 %21, i32* %8
br i1 %20, label %22, label %26
22: ; preds = %14
%23 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* %8
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %14
br label %9
27: ; preds = %9
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [6 x i8] c"Error\00"
define i32 @copy(i32 %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %8, %2
%6 = call i32 @read(i32 %0, i8* %4, i32 512)
%7 = icmp eq i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = call i32 @write(i32 %1, i8* %4, i32 %6)
%10 = icmp eq i32 %9, %6
br i1 %10, label %5, label %11
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5
ret i32 undef
}