#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*/ payload;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int ntohl(int);
int /*<<< orphan*/ perror(char *);
int read(int, int *, int);
void readData4(int socketfd, void *data) {
  int payload = -1;
  int *payload_pointer = &payload;
  int byte_read = read(socketfd, payload_pointer, sizeof(payload));
  if (byte_read < 0) {
    perror("Error reading from socket");
    exit(2);
  }
  *((int *)data) = ntohl(payload);
  return;
}


x86 assembly (clang, -O0):
<readData4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    -0x14(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1192 <readData4+0x52>
lea    0xe7d(%rip),%rdi
call   1040 <perror@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%edi
call   1060 <ntohl@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readData4>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1030 <read@plt>
test   %eax,%eax
js     1174 <readData4+0x34>
mov    0xc(%rsp),%edi
call   1060 <ntohl@plt>
mov    %eax,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
mov    $0x2,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Error reading from socket\00"
define void @readData4(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 -1, i32* %5
store i32* %5, i32** %6
%8 = load i32, i32* %3
%9 = load i32*, i32** %6
%10 = call i32 @read(i32 %8, i32* %9, i32 4)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 2)
unreachable
16: ; preds = %2
%17 = load i32, i32* %5
%18 = call i32 @ntohl(i32 %17)
%19 = load i8*, i8** %4
%20 = bitcast i8* %19 to i32*
store i32 %18, i32* %20
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"Error reading from socket\00"
define void @readData4(i32 %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%5 = call i32 @read(i32 %0, i32* %3, i32 4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 2)
unreachable
10: ; preds = %2
%11 = load i32, i32* %3
%12 = tail call i32 @ntohl(i32 %11)
%13 = bitcast i8* %1 to i32*
store i32 %12, i32* %13
ret void
}