#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 int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int recv(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/);
uint32_t cbReadLong(int fd) {
  int n = 0;
  uint32_t return_val = 0;
  n = recv(fd, &return_val, sizeof(uint32_t), 0);
  if (n == 0) {
    printf("WARNING: n = 0 in readLong\n");
  }
  if (n < 0) {
    printf("WARNING: n < 0 in readLong\n");
  }
  return_val = ntohl(return_val);
  return return_val;
}


x86 assembly (clang, -O0):
<cbReadLong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1175 <cbReadLong+0x45>
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    118b <cbReadLong+0x5b>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <ntohl@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cbReadLong>:
push   %rax
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     1159 <cbReadLong+0x29>
jns    1165 <cbReadLong+0x35>
lea    0xea9(%rip),%rdi
jmp    1160 <cbReadLong+0x30>
lea    0xebb(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%edi
call   1050 <ntohl@plt>
pop    %rcx
ret

LLVM IR (-O0):
@.str = [28 x i8] c"WARNING: n = 0 in readLong\0A\00"
@.str.1 = [28 x i8] c"WARNING: n < 0 in readLong\0A\00"
define i32 @cbReadLong(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%5 = load i32, i32* %2
%6 = call i32 @recv(i32 %5, i32* %4, i32 4, i32 0)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = load i32, i32* %4
%18 = call i32 @ntohl(i32 %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
ret i32 %19
}

LLVM IR (-O2):
@str = [27 x i8] c"WARNING: n < 0 in readLong\00"
@str.2 = [27 x i8] c"WARNING: n = 0 in readLong\00"
define i32 @cbReadLong(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = call i32 @recv(i32 %0, i32* %2, i32 4, i32 0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = icmp slt i32 %4, 0
br i1 %7, label %8, label %11
8: ; preds = %6, %1
%9 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @str.2, i64 0, i64 0), %1 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0), %6 ]
%10 = call i32 @puts(i8* dereferenceable(1) %9)
br label %11
11: ; preds = %8, %6
%12 = load i32, i32* %2
%13 = call i32 @ntohl(i32 %12)
ret i32 %13
}