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

/* Variables and functions */
size_t fread(char *, int, int, int /*<<< orphan*/ *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
size_t fcopy(FILE *outstream, FILE *instream) {
  size_t n, count = 0;
  char temp[1024];
  while ((n = fread(temp, 1, sizeof(temp), instream))) {
    size_t m = fwrite(temp, 1, n, outstream);
    count += m;
    if (m == 0)
      break;
  }
  return count;
}


x86 assembly (clang, -O0):
<fcopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11aa <fcopy+0x8a>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    11a5 <fcopy+0x85>
jmp    11aa <fcopy+0x8a>
jmp    113b <fcopy+0x1b>
mov    -0x20(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcopy>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
mov    %rsp,%r12
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     1175 <fcopy+0x55>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r15,%rcx
call   1040 <fwrite@plt>
add    %rax,%rbx
test   %rax,%rax
jne    1140 <fcopy+0x20>
mov    %rbx,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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