#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ do_rnd_read(int, char *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ write(int, char *, scalar_t__);
int do_recvfile(int infd, int outfd) {
  ssize_t r;
  do {
    char buf[16384];
    r = do_rnd_read(infd, buf, sizeof(buf));
    if (r > 0) {
      if (write(outfd, buf, r) != r)
        break;
    } else if (r < 0) {
      perror("read");
    }
  } while (r > 0);
  return (int)r;
}


x86 assembly (clang, -O0):
<do_recvfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4010,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x4010(%rbp),%rsi
mov    $0x4000,%edx
call   1030 <do_rnd_read@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    118b <do_recvfile+0x5b>
mov    -0x8(%rbp),%edi
lea    -0x4010(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <write@plt>
cmp    -0x10(%rbp),%rax
je     1186 <do_recvfile+0x56>
jmp    11b7 <do_recvfile+0x87>
jmp    11a7 <do_recvfile+0x77>
cmpq   $0x0,-0x10(%rbp)
jge    11a2 <do_recvfile+0x72>
lea    0xe63(%rip),%rdi
call   1050 <perror@plt>
jmp    11a7 <do_recvfile+0x77>
jmp    11ac <do_recvfile+0x7c>
cmpq   $0x0,-0x10(%rbp)
jg     1141 <do_recvfile+0x11>
mov    -0x10(%rbp),%rax
add    $0x4010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_recvfile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x4008,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
mov    %rsp,%rsi
mov    $0x4000,%edx
call   1030 <do_rnd_read@plt>
mov    %rax,%rbx
test   %rax,%rax
jle    118b <do_recvfile+0x5b>
mov    %rsp,%rbp
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1040 <write@plt>
cmp    %rbx,%rax
jne    1190 <do_recvfile+0x60>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x4000,%edx
call   1030 <do_rnd_read@plt>
mov    %rax,%rbx
test   %rax,%rax
jg     1160 <do_recvfile+0x30>
test   %rbx,%rbx
js     11a0 <do_recvfile+0x70>
mov    %ebx,%eax
add    $0x4008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe59(%rip),%rdi
call   1050 <perror@plt>
jmp    1190 <do_recvfile+0x60>

LLVM IR (-O0):
@.str = [5 x i8] c"read\00"
define i32 @do_recvfile(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca [16384 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %7
7: ; preds = %29, %2
%8 = load i32, i32* %3
%9 = getelementptr inbounds [16384 x i8], [16384 x i8]* %6, i64 0, i64 0
%10 = call i64 @do_rnd_read(i32 %8, i8* %9, i32 16384)
store i64 %10, i64* %5
%11 = load i64, i64* %5
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %7
%14 = load i32, i32* %4
%15 = getelementptr inbounds [16384 x i8], [16384 x i8]* %6, i64 0, i64 0
%16 = load i64, i64* %5
%17 = call i64 @write(i32 %14, i8* %15, i64 %16)
%18 = load i64, i64* %5
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %13
br label %32
21: ; preds = %13
br label %28
22: ; preds = %7
%23 = load i64, i64* %5
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
br label %28
28: ; preds = %27, %21
br label %29
29: ; preds = %28
%30 = load i64, i64* %5
%31 = icmp sgt i64 %30, 0
br i1 %31, label %7, label %32
32: ; preds = %29, %20
%33 = load i64, i64* %5
%34 = trunc i64 %33 to i32
ret i32 %34
}

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
define i32 @do_recvfile(i32 %0, i32 %1) {
%3 = alloca [16384 x i8]
%4 = getelementptr inbounds [16384 x i8], [16384 x i8]* %3, i64 0, i64 0
%5 = call i64 @do_rnd_read(i32 %0, i8* %4, i32 16384)
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2, %17
%8 = phi i64 [ %18, %17 ], [ %5, %2 ]
%9 = call i64 @write(i32 %1, i8* %4, i64 %8)
%10 = icmp eq i64 %9, %8
br i1 %10, label %17, label %20
11: ; preds = %17, %2
%12 = phi i64 [ %5, %2 ], [ %18, %17 ]
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
br label %20
17: ; preds = %7
%18 = call i64 @do_rnd_read(i32 %0, i8* %4, i32 16384)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %7, label %11
20: ; preds = %7, %16
%21 = phi i64 [ %12, %16 ], [ %8, %7 ]
%22 = trunc i64 %21 to i32
ret i32 %22
}