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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int read(int, int *, int);
unsigned read_int(int socket, int *integer) {
  ssize_t rvalue = read(socket, integer, sizeof(*integer));
  if (rvalue == 0) {
    if (true) {
      printf("DEBUG: ");
      puts("read_int - no process has the pipe open for writing");
    };
  } else if (rvalue == -1) {
    perror("read_int - Failed to read int");
    exit(EXIT_FAILURE);
  }
  return rvalue;
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    119a <read_int+0x4a>
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
jmp    11c3 <read_int+0x73>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11be <read_int+0x6e>
lea    0xe91(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11c3 <read_int+0x73>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rbx
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1180 <read_int+0x30>
cmp    $0xffffffff,%ebx
jne    1198 <read_int+0x48>
lea    0xecf(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"DEBUG: \00"
@.str.1 = [52 x i8] c"read_int - no process has the pipe open for writing\00"
@.str.2 = [30 x i8] c"read_int - Failed to read int\00"
@EXIT_FAILURE = global i32 0
define i32 @read_int(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%6 = load i32, i32* %3
%7 = load i32*, i32** %4
%8 = call i32 @read(i32 %6, i32* %7, i32 4)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @puts(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %22
14: ; preds = %2
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %14
br label %22
22: ; preds = %21, %11
%23 = load i32, i32* %5
ret i32 %23
}

LLVM IR (-O2):
@.str = [8 x i8] c"DEBUG: \00"
@.str.1 = [52 x i8] c"read_int - no process has the pipe open for writing\00"
@.str.2 = [30 x i8] c"read_int - Failed to read int\00"
@EXIT_FAILURE = global i32 0
define i32 @read_int(i32 %0, i32* nocapture %1) {
%3 = tail call i32 @read(i32 %0, i32* %1, i32 4)
switch i32 %3, label %11 [
i32 0, label %4
i32 -1, label %7
]
4: ; preds = %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %11
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2, %4
ret i32 %3
}