#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 BUFSIZ;
int read(int, char *, int);
int write(int, char *, int);
void filecopy(int inf, int outf) {
  void error(char *, ...);
  char buf[BUFSIZ];
  int n;
  while ((n = read(inf, buf, BUFSIZ)) > 0)
    if (write(outf, buf, n) != n)
      error("cat: write error on file");
}


x86 assembly (clang, -O0):
<filecopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x4(%rbp),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11b6 <filecopy+0x86>
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
cmp    -0x1c(%rbp),%eax
je     11b1 <filecopy+0x81>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <error@plt>
jmp    116a <filecopy+0x3a>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filecopy>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
mov    0x2e95(%rip),%r12
mov    (%r12),%edx
mov    %rsp,%r13
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %r13,%rsi
call   1040 <read@plt>
test   %eax,%eax
jle    11b6 <filecopy+0x86>
mov    %eax,%ebx
jmp    1195 <filecopy+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%edx
mov    %r15d,%edi
mov    %r13,%rsi
call   1040 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    11b6 <filecopy+0x86>
mov    %r14d,%edi
mov    %r13,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
je     1180 <filecopy+0x50>
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1050 <error@plt>
jmp    1180 <filecopy+0x50>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [25 x i8] c"cat: write error on file\00"
define void @filecopy(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* @BUFSIZ
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
br label %12
12: ; preds = %24, %2
%13 = load i32, i32* %3
%14 = load i32, i32* @BUFSIZ
%15 = call i32 @read(i32 %13, i8* %11, i32 %14)
store i32 %15, i32* %7
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = load i32, i32* %4
%19 = load i32, i32* %7
%20 = call i32 @write(i32 %18, i8* %11, i32 %19)
%21 = load i32, i32* %7
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %17
br label %24
24: ; preds = %23, %17
br label %12
25: ; preds = %12
%26 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [25 x i8] c"cat: write error on file\00"
define void @filecopy(i32 %0, i32 %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @read(i32 %0, i8* %5, i32 %3)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %2, %13
%9 = phi i32 [ %15, %13 ], [ %6, %2 ]
%10 = call i32 @write(i32 %1, i8* %5, i32 %9)
%11 = icmp eq i32 %10, %9
br i1 %11, label %13, label %12
12: ; preds = %8
tail call void (i8*, ...) @error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %12, %8
%14 = load i32, i32* @BUFSIZ
%15 = call i32 @read(i32 %0, i8* %5, i32 %14)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %8, label %17
17: ; preds = %13, %2
ret void
}