#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*/ FILE;

/* Variables and functions */
int BUFSIZ;
size_t fread_unlocked(char **, size_t, int, int /*<<< orphan*/ *);
size_t fwrite_unlocked(char **, size_t, size_t, int /*<<< orphan*/ *);
size_t fsend_unlocked(FILE *in, FILE *out, size_t size) {
  size_t ret = 0, read, write;
  char buf[size][BUFSIZ];
  do {
    read = fread_unlocked(buf, size, BUFSIZ, in);
    write = fwrite_unlocked(buf, size, read, out);
    ret += write;
  } while (read && write == read);
  return ret;
}


x86 assembly (clang, -O0):
<fsend_unlocked>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rcx,%rsi
imul   %rax,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x40(%rbp)
mov    %rax,-0x48(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rcx
call   1030 <fread_unlocked@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
call   1040 <fwrite_unlocked@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x51(%rbp)
je     11d5 <fsend_unlocked+0xb5>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
sete   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    1174 <fsend_unlocked+0x54>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsend_unlocked>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%rcx
mov    0x2ea2(%rip),%rax
mov    (%rax),%edx
mov    %rdx,%rax
imul   %r12,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rcx,-0x30(%rbp)
call   1030 <fread_unlocked@plt>
mov    %rax,%r14
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
mov    %rbx,%r15
mov    %rbx,%rcx
call   1040 <fwrite_unlocked@plt>
mov    %rax,%rbx
test   %r14,%r14
je     11c9 <fsend_unlocked+0xa9>
cmp    %r14,%rbx
jne    11c9 <fsend_unlocked+0xa9>
nopl   0x0(%rax,%rax,1)
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    %r12,%rsi
mov    -0x30(%rbp),%rcx
call   1030 <fread_unlocked@plt>
mov    %rax,%r14
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
mov    %r15,%rcx
call   1040 <fwrite_unlocked@plt>
add    %rax,%rbx
test   %r14,%r14
je     11c9 <fsend_unlocked+0xa9>
cmp    %r14,%rax
je     1190 <fsend_unlocked+0x70>
mov    %rbx,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
define i64 @fsend_unlocked(i32* %0, i32* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
store i64 %2, i64* %6
store i64 0, i64* %7
%13 = load i64, i64* %6
%14 = load i32, i32* @BUFSIZ
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %10
%17 = mul nuw i64 %13, %15
%18 = alloca i8, i64 %17
store i64 %13, i64* %11
store i64 %15, i64* %12
br label %19
19: ; preds = %40, %3
%20 = bitcast i8* %18 to i8**
%21 = load i64, i64* %6
%22 = load i32, i32* @BUFSIZ
%23 = load i32*, i32** %4
%24 = call i64 @fread_unlocked(i8** %20, i64 %21, i32 %22, i32* %23)
store i64 %24, i64* %8
%25 = bitcast i8* %18 to i8**
%26 = load i64, i64* %6
%27 = load i64, i64* %8
%28 = load i32*, i32** %5
%29 = call i64 @fwrite_unlocked(i8** %25, i64 %26, i64 %27, i32* %28)
store i64 %29, i64* %9
%30 = load i64, i64* %9
%31 = load i64, i64* %7
%32 = add i64 %31, %30
store i64 %32, i64* %7
br label %33
33: ; preds = %19
%34 = load i64, i64* %8
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i64, i64* %9
%38 = load i64, i64* %8
%39 = icmp eq i64 %37, %38
br label %40
40: ; preds = %36, %33
%41 = phi i1 [ false, %33 ], [ %39, %36 ]
br i1 %41, label %19, label %42
42: ; preds = %40
%43 = load i64, i64* %7
%44 = load i8*, i8** %10
ret i64 %43
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
define i64 @fsend_unlocked(i32* nocapture %0, i32* nocapture %1, i64 %2) {
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = mul nuw i64 %5, %2
%7 = alloca i8, i64 %6
%8 = bitcast i8* %7 to i8**
%9 = call i64 @fread_unlocked(i8** %8, i64 %2, i32 %4, i32* %0)
%10 = call i64 @fwrite_unlocked(i8** %8, i64 %2, i64 %9, i32* %1)
%11 = icmp ne i64 %9, 0
%12 = icmp eq i64 %10, %9
%13 = and i1 %11, %12
br i1 %13, label %14, label %23
14: ; preds = %3, %14
%15 = phi i64 [ %19, %14 ], [ %10, %3 ]
%16 = load i32, i32* @BUFSIZ
%17 = call i64 @fread_unlocked(i8** %8, i64 %2, i32 %16, i32* %0)
%18 = call i64 @fwrite_unlocked(i8** %8, i64 %2, i64 %17, i32* %1)
%19 = add i64 %18, %15
%20 = icmp ne i64 %17, 0
%21 = icmp eq i64 %18, %17
%22 = and i1 %20, %21
br i1 %22, label %14, label %23
23: ; preds = %14, %3
%24 = phi i64 [ %10, %3 ], [ %19, %14 ]
ret i64 %24
}