#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, double *, int);
unsigned read_double(int socket, double *number) {
  ssize_t rvalue = read(socket, number, sizeof(*number));
  if (rvalue == 0) {
    if (true) {
      printf("DEBUG: ");
      puts("read_double - no process has the pipe open for writing");
    };
  } else if (rvalue == -1) {
    perror("read_double - Failed to read double");
    exit(EXIT_FAILURE);
  }
  return rvalue;
}


x86 assembly (clang, -O0):
<read_double>:
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    $0x8,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    119a <read_double+0x4a>
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
jmp    11c3 <read_double+0x73>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11be <read_double+0x6e>
lea    0xe94(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11c3 <read_double+0x73>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_double>:
push   %rbx
mov    $0x8,%edx
call   1050 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1180 <read_double+0x30>
cmp    $0xffffffff,%ebx
jne    1198 <read_double+0x48>
lea    0xed2(%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 = [55 x i8] c"read_double - no process has the pipe open for writing\00"
@.str.2 = [36 x i8] c"read_double - Failed to read double\00"
@EXIT_FAILURE = global i32 0
define i32 @read_double(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca i32
store i32 %0, i32* %3
store double* %1, double** %4
%6 = load i32, i32* %3
%7 = load double*, double** %4
%8 = call i32 @read(i32 %6, double* %7, i32 8)
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 ([55 x i8], [55 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 ([36 x i8], [36 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 = [55 x i8] c"read_double - no process has the pipe open for writing\00"
@.str.2 = [36 x i8] c"read_double - Failed to read double\00"
@EXIT_FAILURE = global i32 0
define i32 @read_double(i32 %0, double* nocapture %1) {
%3 = tail call i32 @read(i32 %0, double* %1, i32 8)
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 ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
br label %11
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 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
}