#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*/ ConvertToFloat(unsigned char *, float *);
int read(int, unsigned char *, int);
int ConvertReadFloat(int fp, float *val) {
  unsigned char tmp[4];
  int s = 0, o = 0, l = 4;
  while (o < 4) {
    s = read(fp, tmp + o, l);
    o = o + s;
    l = l - s;
    if (s == 0)
      return -1;
    if (s == -1)
      return -1;
  }
  ConvertToFloat(tmp, val);
  return 0;
}


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

x86 assembly (clang, -O2):
<ConvertReadFloat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    $0x4,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x3,%ebp
jg     1170 <ConvertReadFloat+0x50>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x4,%rsi
mov    %r15d,%edi
mov    %ebx,%edx
call   1040 <read@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     117f <ConvertReadFloat+0x5f>
sub    %ecx,%ebx
add    %ecx,%ebp
cmp    $0xffffffff,%ecx
jne    1140 <ConvertReadFloat+0x20>
jmp    117f <ConvertReadFloat+0x5f>
lea    0x4(%rsp),%rdi
mov    %r14,%rsi
call   1030 <ConvertToFloat@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ConvertReadFloat(i32 %0, float* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca float*
%6 = alloca [4 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store float* %1, float** %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 4, i32* %9
br label %10
10: ; preds = %34, %2
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %35
13: ; preds = %10
%14 = load i32, i32* %4
%15 = getelementptr inbounds [4 x i8], [4 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 [4 x i8], [4 x i8]* %6, i64 0, i64 0
%37 = load float*, float** %5
%38 = call i32 @ConvertToFloat(i8* %36, float* %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 @ConvertReadFloat(i32 %0, float* %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %14, %2
%6 = phi i32 [ 0, %2 ], [ %16, %14 ]
%7 = phi i32 [ 4, %2 ], [ %15, %14 ]
%8 = icmp slt i32 %6, 4
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = sext i32 %6 to i64
%11 = getelementptr inbounds [4 x i8], [4 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 @ConvertToFloat(i8* %4, float* %1)
br label %20
20: ; preds = %14, %9, %18
%21 = phi i32 [ 0, %18 ], [ -1, %9 ], [ -1, %14 ]
ret i32 %21
}