#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(int, void *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void recebe_mesmo(int socket, char *buffer, int tamanho) {
  int recebidos = 0;
  while (recebidos != tamanho) {
    recebidos = recv(socket, (void *)buffer, tamanho, 0);
    if (recebidos < tamanho) {
      fprintf(stdout, "received less...\n");
      buffer += recebidos;
      tamanho -= recebidos;
      recebidos = 0;
    }
  }
}


x86 assembly (clang, -O0):
<recebe_mesmo>:
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
je     11a2 <recebe_mesmo+0x82>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119d <recebe_mesmo+0x7d>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    1139 <recebe_mesmo+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recebe_mesmo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     1190 <recebe_mesmo+0x70>
mov    %edx,%r13d
mov    %rsi,%r12
mov    %edi,%r15d
lea    0xec1(%rip),%r14
jmp    1170 <recebe_mesmo+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
call   1040 <fprintf@plt>
movslq %ebx,%rax
add    %rax,%r12
xor    %ebx,%ebx
mov    %ebp,%r13d
cmp    %ebp,%ebx
je     1190 <recebe_mesmo+0x70>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %r13d,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebx
mov    %r13d,%ebp
sub    %eax,%ebp
jg     1150 <recebe_mesmo+0x30>
mov    %r13d,%ebp
cmp    %ebp,%ebx
jne    1170 <recebe_mesmo+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stdout = global i32 0
@.str = [18 x i8] c"received less...\0A\00"
define void @recebe_mesmo(i32 %0, i8* %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %21, label %5
5: ; preds = %3, %16
%6 = phi i32 [ %18, %16 ], [ %2, %3 ]
%7 = phi i8* [ %17, %16 ], [ %1, %3 ]
%8 = tail call i32 @recv(i32 %0, i8* %7, i32 %6, i32 0)
%9 = icmp sgt i32 %6, %8
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = load i32, i32* @stdout
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%13 = sext i32 %8 to i64
%14 = getelementptr inbounds i8, i8* %7, i64 %13
%15 = sub nsw i32 %6, %8
br label %16
16: ; preds = %10, %5
%17 = phi i8* [ %14, %10 ], [ %7, %5 ]
%18 = phi i32 [ %15, %10 ], [ %6, %5 ]
%19 = phi i32 [ 0, %10 ], [ %8, %5 ]
%20 = icmp eq i32 %19, %18
br i1 %20, label %21, label %5
21: ; preds = %16, %3
ret void
}