#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*/ buf;
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 mutt_copy_stream(FILE *fin, FILE *fout) {
  size_t l;
  char buf[1024];
  while ((l = fread(buf, 1, sizeof(buf), fin)) > 0) {
    if (fwrite(buf, 1, l, fout) != l)
      return (-1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<mutt_copy_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jbe    118f <mutt_copy_stream+0x6f>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
cmp    -0x20(%rbp),%rax
je     118a <mutt_copy_stream+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <mutt_copy_stream+0x76>
jmp    1133 <mutt_copy_stream+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mutt_copy_stream>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     117c <mutt_copy_stream+0x5c>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1040 <fwrite@plt>
cmp    %rbx,%rax
je     1140 <mutt_copy_stream+0x20>
mov    $0xffffffff,%eax
jmp    117e <mutt_copy_stream+0x5e>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @mutt_copy_stream(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 = %8, %2
%6 = call i64 @fread(i8* %4, i32 1, i32 1024, 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 ], [ 0, %5 ]
ret i32 %12
}