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

/* Variables and functions */
int /*<<< orphan*/ net_close_connection(int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ recv(int, void *, int, int /*<<< orphan*/);
ssize_t net_recieve_data(int socket, void *msg, int len) {
  ssize_t n_bytes = recv(socket, msg, len, 0);
  if (n_bytes < 0) {
    printf("%s \n", "Error, could not recieve data!");
    net_close_connection(socket);
    return -1;
  }
  if (n_bytes == 0) {
    printf("%s \n", "Error, socket is being blocked or connection to the "
                    "remote note failed!");
    net_close_connection(socket);
    return -1;
  }
  return n_bytes;
}


x86 assembly (clang, -O0):
<net_recieve_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    118a <net_recieve_data+0x5a>
lea    0xe97(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <net_close_connection@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11c5 <net_recieve_data+0x95>
cmpq   $0x0,-0x28(%rbp)
jne    11bd <net_recieve_data+0x8d>
lea    0xe64(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <net_close_connection@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11c5 <net_recieve_data+0x95>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_recieve_data>:
push   %rbx
mov    %edi,%ebx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
js     1143 <net_recieve_data+0x13>
je     114c <net_recieve_data+0x1c>
pop    %rbx
ret
lea    0xebb(%rip),%rsi
jmp    1153 <net_recieve_data+0x23>
lea    0xed1(%rip),%rsi
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <net_close_connection@plt>
mov    $0xffffffffffffffff,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s \0A\00"
@.str.1 = [31 x i8] c"Error, could not recieve data!\00"
@.str.2 = [72 x i8] c"Error, socket is being blocked or connection to the remote note failed!\00"
define i64 @net_recieve_data(i32 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = call i64 @recv(i32 %9, i8* %10, i32 %11, i32 0)
store i64 %12, i64* %8
%13 = load i64, i64* %8
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* %5
%18 = call i32 @net_close_connection(i32 %17)
store i64 -1, i64* %4
br label %28
19: ; preds = %3
%20 = load i64, i64* %8
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* %5
%25 = call i32 @net_close_connection(i32 %24)
store i64 -1, i64* %4
br label %28
26: ; preds = %19
%27 = load i64, i64* %8
store i64 %27, i64* %4
br label %28
28: ; preds = %26, %22, %15
%29 = load i64, i64* %4
ret i64 %29
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s \0A\00"
@.str.1 = [31 x i8] c"Error, could not recieve data!\00"
@.str.2 = [72 x i8] c"Error, socket is being blocked or connection to the remote note failed!\00"
define i64 @net_recieve_data(i32 %0, i8* %1, i32 %2) {
%4 = tail call i64 @recv(i32 %0, i8* %1, i32 %2, i32 0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = icmp eq i64 %4, 0
br i1 %7, label %8, label %12
8: ; preds = %6, %3
%9 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0), %6 ]
%10 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @net_close_connection(i32 %0)
br label %12
12: ; preds = %8, %6
%13 = phi i64 [ %4, %6 ], [ -1, %8 ]
ret i64 %13
}