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

/* Variables and functions */
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int const getbytes(char *, int const);
scalar_t__ malloc(int const);
int /*<<< orphan*/ stderr;
int getf64(long double *data) {
  double d = 0;
  const int size = sizeof(d);
  char *buf = (char *)malloc(size);
  char *byte;
  if (getbytes(buf, size) < size) {
    fputs("error reading data\n", stderr);
    free(buf);
    return 0;
  }
  *data = *((double *)buf);
  free(buf);
  return size;
}


x86 assembly (clang, -O0):
<getf64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x8,-0x1c(%rbp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x8,%esi
call   1040 <getbytes@plt>
cmp    $0x8,%eax
jge    11aa <getf64+0x6a>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <getf64+0x86>
mov    -0x28(%rbp),%rax
fldl   (%rax)
mov    -0x10(%rbp),%rax
fstpt  (%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x8,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getf64>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x8,%ebp
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x8,%esi
call   1040 <getbytes@plt>
cmp    $0x7,%eax
jg     1184 <getf64+0x44>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1050 <fputs@plt>
xor    %ebp,%ebp
jmp    1189 <getf64+0x49>
fldl   (%rbx)
fstpt  (%r14)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"error reading data\0A\00"
@stderr = global i32 0
define i32 @getf64(x86_fp80* %0) {
%2 = alloca i32
%3 = alloca x86_fp80*
%4 = alloca double
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store x86_fp80* %0, x86_fp80** %3
store double 0.000000e+00, double* %4
store i32 8, i32* %5
%8 = call i64 @malloc(i32 8)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @getbytes(i8* %10, i32 8)
%12 = icmp slt i32 %11, 8
br i1 %12, label %13, label %18
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i8*, i8** %6
%17 = call i32 @free(i8* %16)
store i32 0, i32* %2
br label %26
18: ; preds = %1
%19 = load i8*, i8** %6
%20 = bitcast i8* %19 to double*
%21 = load double, double* %20
%22 = fpext double %21 to x86_fp80
%23 = load x86_fp80*, x86_fp80** %3
store x86_fp80 %22, x86_fp80* %23
%24 = load i8*, i8** %6
%25 = call i32 @free(i8* %24)
store i32 8, i32* %2
br label %26
26: ; preds = %18, %13
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [20 x i8] c"error reading data\0A\00"
@stderr = global i32 0
define i32 @getf64(x86_fp80* nocapture writeonly %0) {
%2 = tail call i64 @malloc(i32 8)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @getbytes(i8* %3, i32 8)
%5 = icmp slt i32 %4, 8
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %13
9: ; preds = %1
%10 = inttoptr i64 %2 to double*
%11 = load double, double* %10
%12 = fpext double %11 to x86_fp80
store x86_fp80 %12, x86_fp80* %0
br label %13
13: ; preds = %9, %6
%14 = phi i32 [ 0, %6 ], [ 8, %9 ]
%15 = tail call i32 @free(i8* %3)
ret i32 %14
}