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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int recv_socket(int, char *, int, int);
int /*<<< orphan*/ stderr;
int recv_full(int sock, char *buff, int rsize) {
  int received = 0, r;
  while (received < rsize) {
    r = recv_socket(sock, buff + received, rsize - received, 20);
    if (r <= 0) {
      fprintf(stderr, "Client break in recv_full\n");
      break;
    }
    received += r;
  }
  return (received == rsize) ? 0 : 1;
}


x86 assembly (clang, -O0):
<recv_full>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1198 <recv_full+0x78>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x18(%rbp),%edx
mov    $0x14,%ecx
call   1040 <recv_socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     118a <recv_full+0x6a>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1198 <recv_full+0x78>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1139 <recv_full+0x19>
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%esi
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_full>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
test   %edx,%edx
jle    1164 <recv_full+0x44>
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebp,%rax
lea    (%r14,%rax,1),%rsi
mov    %ebx,%edx
sub    %eax,%edx
mov    %r15d,%edi
mov    $0x14,%ecx
call   1040 <recv_socket@plt>
test   %eax,%eax
jle    1168 <recv_full+0x48>
add    %eax,%ebp
cmp    %ebx,%ebp
jl     1140 <recv_full+0x20>
jmp    117d <recv_full+0x5d>
xor    %ebp,%ebp
jmp    117d <recv_full+0x5d>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
cmp    %ebx,%ebp
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Client break in recv_full\0A\00"
define i32 @recv_full(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %28, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %32
13: ; preds = %9
%14 = load i32, i32* %4
%15 = load i8*, i8** %5
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = sub nsw i32 %19, %20
%22 = call i32 @recv_socket(i32 %14, i8* %18, i32 %21, i32 20)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp sle i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %13
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %32
28: ; preds = %13
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = add nsw i32 %30, %29
store i32 %31, i32* %7
br label %9
32: ; preds = %25, %9
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = icmp eq i32 %33, %34
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 0, i32 1
ret i32 %37
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Client break in recv_full\0A\00"
define i32 @recv_full(i32 %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %7, label %18
5: ; preds = %7
%6 = icmp slt i32 %14, %2
br i1 %6, label %7, label %18
7: ; preds = %3, %5
%8 = phi i32 [ %14, %5 ], [ 0, %3 ]
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = sub nsw i32 %2, %8
%12 = tail call i32 @recv_socket(i32 %0, i8* %10, i32 %11, i32 20)
%13 = icmp slt i32 %12, 1
%14 = add nsw i32 %12, %8
br i1 %13, label %15, label %5
15: ; preds = %7
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %5, %3, %15
%19 = phi i32 [ %8, %15 ], [ 0, %3 ], [ %14, %5 ]
%20 = icmp ne i32 %19, %2
%21 = zext i1 %20 to i32
ret i32 %21
}