#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*/ perror(char *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int recv_msg(int t, int min_size, char *buf, int bufsize) {
  int bytes_recv = 0;
  while (bytes_recv < min_size)
    if ((bytes_recv += recv(t, buf + bytes_recv, bufsize, 0)) < 0) {
      perror("recv");
      return -1;
    }
  return bytes_recv;
}


x86 assembly (clang, -O0):
<recv_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1193 <recv_msg+0x73>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    118e <recv_msg+0x6e>
lea    0xe83(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <recv_msg+0x79>
jmp    113c <recv_msg+0x1c>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_msg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebp
mov    %edi,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %ebp,%ebx
jge    116d <recv_msg+0x4d>
mov    %ebx,%esi
add    %r15,%rsi
mov    %r12d,%edi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
add    %ebx,%eax
mov    %eax,%ebx
jns    1140 <recv_msg+0x20>
lea    0xe9d(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"recv\00"
define i32 @recv_msg(i32 %0, i32 %1, i8* %2, i32 %3) {
br label %5
5: ; preds = %8, %4
%6 = phi i32 [ 0, %4 ], [ %13, %8 ]
%7 = icmp slt i32 %6, %1
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = zext i32 %6 to i64
%10 = getelementptr inbounds i8, i8* %2, i64 %9
%11 = tail call i64 @recv(i32 %0, i8* %10, i32 %3, i32 0)
%12 = trunc i64 %11 to i32
%13 = add i32 %6, %12
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %5
15: ; preds = %8
%16 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %5, %15
%18 = phi i32 [ -1, %15 ], [ %6, %5 ]
ret i32 %18
}