#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__ int64_t;

/* Variables and functions */
int /*<<< orphan*/ _recv_from_socket(int, void *, scalar_t__);
int /*<<< orphan*/ assert(int);
void *socket_check_realloc(void *, scalar_t__, char *);
void *_recv_and_alloc(int s, void *data, int64_t length) {
  data = socket_check_realloc(data, length, "receive buffer");
  assert(data != NULL || length <= 0);
  _recv_from_socket(s, data, length);
  return data;
}


x86 assembly (clang, -O0):
<_recv_and_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xeae(%rip),%rdx
call   1030 <socket_check_realloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1,%al
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x19(%rbp)
jne    1176 <_recv_and_alloc+0x46>
cmpq   $0x0,-0x18(%rbp)
setle  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <_recv_from_socket@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_recv_and_alloc>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %edi,%r14d
lea    0xebf(%rip),%rdx
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1030 <socket_check_realloc@plt>
mov    %rax,%rbp
test   %rax,%rax
setne  %al
test   %rbx,%rbx
setle  %cl
or     %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1040 <_recv_from_socket@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"receive buffer\00"
define i8* @_recv_and_alloc(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%7 = load i8*, i8** %5
%8 = load i64, i64* %6
%9 = call i8* @socket_check_realloc(i8* %7, i64 %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i64, i64* %6
%14 = icmp sle i64 %13, 0
br label %15
15: ; preds = %12, %3
%16 = phi i1 [ true, %3 ], [ %14, %12 ]
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* %4
%20 = load i8*, i8** %5
%21 = load i64, i64* %6
%22 = call i32 @_recv_from_socket(i32 %19, i8* %20, i64 %21)
%23 = load i8*, i8** %5
ret i8* %23
}

LLVM IR (-O2):
@.str = [15 x i8] c"receive buffer\00"
define i8* @_recv_and_alloc(i32 %0, i8* %1, i64 %2) {
%4 = tail call i8* @socket_check_realloc(i8* %1, i64 %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i8* %4, null
%6 = icmp slt i64 %2, 1
%7 = or i1 %6, %5
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @_recv_from_socket(i32 %0, i8* %4, i64 %2)
ret i8* %4
}