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

/* Variables and functions */
int /*<<< orphan*/ ConvertToDouble(unsigned char *, double *);
int read(int, unsigned char *, int);
int ConvertReadDouble(int fp, double *val) {
  unsigned char tmp[8];
  int s = 0, o = 0, l = 8;
  while (o < 8) {
    s = read(fp, tmp + o, l);
    o = o + s;
    l = l - s;
    if (s == 0)
      return -1;
    if (s == -1)
      return -1;
  }
  ConvertToDouble(tmp, val);
  return 0;
}


x86 assembly (clang, -O0):
<ConvertReadDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x8,-0x24(%rbp)
cmpl   $0x8,-0x20(%rbp)
jge    11aa <ConvertReadDouble+0x8a>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    118f <ConvertReadDouble+0x6f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <ConvertReadDouble+0x9e>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11a5 <ConvertReadDouble+0x85>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <ConvertReadDouble+0x9e>
jmp    1144 <ConvertReadDouble+0x24>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <ConvertToDouble@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ConvertReadDouble>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    $0x8,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x7,%ebp
jg     116c <ConvertReadDouble+0x4c>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rsi
mov    %r15d,%edi
mov    %ebx,%edx
call   1040 <read@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     1179 <ConvertReadDouble+0x59>
sub    %ecx,%ebx
add    %ecx,%ebp
cmp    $0xffffffff,%ecx
jne    1140 <ConvertReadDouble+0x20>
jmp    1179 <ConvertReadDouble+0x59>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1030 <ConvertToDouble@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ConvertReadDouble(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double*
%6 = alloca [8 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store double* %1, double** %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 8, i32* %9
br label %10
10: ; preds = %34, %2
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 8
br i1 %12, label %13, label %35
13: ; preds = %10
%14 = load i32, i32* %4
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i32, i32* %9
%20 = call i32 @read(i32 %14, i8* %18, i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %8
%22 = load i32, i32* %7
%23 = add nsw i32 %21, %22
store i32 %23, i32* %8
%24 = load i32, i32* %9
%25 = load i32, i32* %7
%26 = sub nsw i32 %24, %25
store i32 %26, i32* %9
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %13
store i32 -1, i32* %3
br label %39
30: ; preds = %13
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 -1, i32* %3
br label %39
34: ; preds = %30
br label %10
35: ; preds = %10
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%37 = load double*, double** %5
%38 = call i32 @ConvertToDouble(i8* %36, double* %37)
store i32 0, i32* %3
br label %39
39: ; preds = %35, %33, %29
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
define i32 @ConvertReadDouble(i32 %0, double* %1) {
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %14, %2
%6 = phi i32 [ 0, %2 ], [ %16, %14 ]
%7 = phi i32 [ 8, %2 ], [ %15, %14 ]
%8 = icmp slt i32 %6, 8
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = sext i32 %6 to i64
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %10
%12 = call i32 @read(i32 %0, i8* %11, i32 %7)
%13 = icmp eq i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %9
%15 = sub nsw i32 %7, %12
%16 = add nsw i32 %12, %6
%17 = icmp eq i32 %12, -1
br i1 %17, label %20, label %5
18: ; preds = %5
%19 = call i32 @ConvertToDouble(i8* %4, double* %1)
br label %20
20: ; preds = %14, %9, %18
%21 = phi i32 [ 0, %18 ], [ -1, %9 ], [ -1, %14 ]
ret i32 %21
}