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

/* Variables and functions */
int /*<<< orphan*/ compute(int);
int /*<<< orphan*/ exit(int);
scalar_t__ getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, double);
int read(int, double *, int);
void child(int fd) {
  double val;
  printf("Child: My PID is %ld. Receiving a double value from the parent.\n",
         (long)getpid());
  if (read(fd, &val, sizeof(val)) != sizeof(val)) {
    perror("child: read from pipe");
    exit(1);
  }
  printf("Child: received value %f from the pipe. Will now compute.\n", val);
  compute(1000);
  exit(7);
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
cvtsi2sd %rax,%xmm0
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1050 <read@plt>
cltq
cmp    $0x8,%rax
je     11b6 <child+0x56>
lea    0xe9a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3e8,%edi
call   1080 <compute@plt>
mov    $0x7,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<child>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
cvtsi2sd %rax,%xmm0
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1050 <read@plt>
cmp    $0x8,%eax
jne    11bb <child+0x5b>
movsd  0x8(%rsp),%xmm0
lea    0xeb5(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3e8,%edi
call   1080 <compute@plt>
mov    $0x7,%edi
call   1070 <exit@plt>
lea    0xe7f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [65 x i8] c"Child: My PID is %ld. Receiving a double value from the parent.\0A\00"
@.str.1 = [22 x i8] c"child: read from pipe\00"
@.str.2 = [59 x i8] c"Child: received value %f from the pipe. Will now compute.\0A\00"
define void @child(i32 %0) {
%2 = alloca i32
%3 = alloca double
store i32 %0, i32* %2
%4 = call i64 (...) @getpid()
%5 = sitofp i64 %4 to double
%6 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), double %5)
%7 = load i32, i32* %2
%8 = call i32 @read(i32 %7, double* %3, i32 8)
%9 = sext i32 %8 to i64
%10 = icmp ne i64 %9, 8
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = load double, double* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), double %15)
%17 = call i32 @compute(i32 1000)
%18 = call i32 @exit(i32 7)
unreachable
}

LLVM IR (-O2):
@.str = [65 x i8] c"Child: My PID is %ld. Receiving a double value from the parent.\0A\00"
@.str.1 = [22 x i8] c"child: read from pipe\00"
@.str.2 = [59 x i8] c"Child: received value %f from the pipe. Will now compute.\0A\00"
define void @child(i32 %0) {
%2 = alloca double
%3 = bitcast double* %2 to i8*
%4 = tail call i64 (...) @getpid()
%5 = sitofp i64 %4 to double
%6 = tail call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), double %5)
%7 = call i32 @read(i32 %0, double* %2, i32 8)
%8 = icmp eq i32 %7, 8
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = load double, double* %2
%14 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), double %13)
%15 = tail call i32 @compute(i32 1000)
%16 = tail call i32 @exit(i32 7)
unreachable
}