#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 */
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
size_t fread(char *, int, int, int /*<<< orphan*/ *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int fcopy_knox(FILE *f1, FILE *f2) {
  char buffer[512];
  size_t n;
  while ((n = fread(buffer, sizeof(char), sizeof(buffer), f1)) > 0) {
    if (fwrite(buffer, sizeof(char), n, f2) != n)
      return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<fcopy_knox>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
mov    %rax,-0x228(%rbp)
cmp    $0x0,%rax
jbe    1198 <fcopy_knox+0x78>
lea    -0x220(%rbp),%rdi
mov    -0x228(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
cmp    -0x228(%rbp),%rax
je     1193 <fcopy_knox+0x73>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <fcopy_knox+0x7f>
jmp    1133 <fcopy_knox+0x13>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcopy_knox>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %rsp,%r12
mov    $0x1,%r14d
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     117b <fcopy_knox+0x5b>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r15,%rcx
call   1040 <fwrite@plt>
cmp    %rbx,%rax
je     1140 <fcopy_knox+0x20>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fcopy_knox(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [512 x i8]
%7 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
br label %8
8: ; preds = %21, %2
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%10 = load i32*, i32** %4
%11 = call i64 @fread(i8* %9, i32 1, i32 512, i32* %10)
store i64 %11, i64* %7
%12 = icmp ugt i64 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%15 = load i64, i64* %7
%16 = load i32*, i32** %5
%17 = call i64 @fwrite(i8* %14, i32 1, i64 %15, i32* %16)
%18 = load i64, i64* %7
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %13
store i32 -1, i32* %3
br label %23
21: ; preds = %13
br label %8
22: ; preds = %8
store i32 1, i32* %3
br label %23
23: ; preds = %22, %20
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @fcopy_knox(i32* nocapture %0, i32* nocapture %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 i64 @fread(i8* %4, i32 1, i32 512, i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = call i64 @fwrite(i8* %4, i32 1, i64 %6, i32* %1)
%10 = icmp eq i64 %9, %6
br i1 %10, label %5, label %11
11: ; preds = %5, %8
%12 = phi i32 [ -1, %8 ], [ 1, %5 ]
ret i32 %12
}