#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int write(int, char *, int);
int copy(int in, int out) {
  int n;
  char tamp[1024];
  while ((n = read(in, tamp, 1024)) > 0) {
    if (write(out, tamp, n) != n)
      do {
        perror("write");
        return EXIT_FAILURE;
      } while (0);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jle    11a3 <copy+0x73>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <write@plt>
cmp    -0x10(%rbp),%eax
je     119e <copy+0x6e>
jmp    1181 <copy+0x51>
lea    0xe78(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11af <copy+0x7f>
jmp    1141 <copy+0x11>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
mov    %rsp,%r15
mov    0x2e8a(%rip),%r12
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1189 <copy+0x59>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
je     1150 <copy+0x20>
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e57(%rip),%r12
mov    (%r12),%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"write\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @copy(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %8, %2
%6 = call i32 @read(i32 %0, i8* %4, i32 1024)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %13
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))
br label %13
13: ; preds = %5, %11
%14 = phi i32* [ @EXIT_FAILURE, %11 ], [ @EXIT_SUCCESS, %5 ]
%15 = load i32, i32* %14
ret i32 %15
}