#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 uint8_t;
typedef float uint32_t;
typedef int /*<<< orphan*/ bytes;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fread(char *, int, int, int /*<<< orphan*/ *);
int read_fixed32(FILE *fp, float *ptr) {
  char bytes[4];
  uint8_t b1, b2, b3, b4;
  uint32_t r1, r2;
  if (fread(bytes, sizeof(bytes), 1, fp) != 1) {
    return 1;
  }
  b1 = bytes[0];
  b2 = bytes[1];
  b3 = bytes[2];
  b4 = bytes[3];
  r1 = (b1 << 8) | b2;
  r2 = (b3 << 8) | b4;
  if (r2 == 0) {
    *ptr = r1;
  } else {
    *ptr = b1 + (b2 / 65536.0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_fixed32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     114c <read_fixed32+0x3c>
movl   $0x1,-0x4(%rbp)
jmp    11e2 <read_fixed32+0xd2>
movsbl -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
movsbl -0x1b(%rbp),%eax
mov    %eax,-0x24(%rbp)
movsbl -0x1a(%rbp),%eax
mov    %eax,-0x28(%rbp)
movsbl -0x19(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x8,%eax
or     -0x24(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%eax
shl    $0x8,%eax
or     -0x2c(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11b5 <read_fixed32+0xa5>
jp     11b5 <read_fixed32+0xa5>
movss  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
jmp    11db <read_fixed32+0xcb>
cvtsi2sdl -0x20(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
movsd  0xe39(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_fixed32>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rcx
lea    0x4(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    117e <read_fixed32+0x6e>
movsbl 0x4(%rsp),%eax
movsbl 0x5(%rsp),%ecx
movsbl 0x6(%rsp),%edx
movsbl 0x7(%rsp),%esi
shl    $0x8,%edx
or     %esi,%edx
je     116f <read_fixed32+0x5f>
cvtsi2sd %eax,%xmm0
cvtsi2sd %ecx,%xmm1
mulsd  0xe9e(%rip),%xmm1
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
jmp    1178 <read_fixed32+0x68>
shl    $0x8,%eax
or     %ecx,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,(%rbx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_fixed32(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
%10 = alloca i32
%11 = alloca float
%12 = alloca float
store i32* %0, i32** %4
store float* %1, float** %5
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = call i32 @fread(i8* %13, i32 4, i32 1, i32* %14)
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 1, i32* %3
br label %56
18: ; preds = %2
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
store i32 %21, i32* %7
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
store i32 %24, i32* %8
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
store i32 %27, i32* %9
%28 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
store i32 %30, i32* %10
%31 = load i32, i32* %7
%32 = shl i32 %31, 8
%33 = load i32, i32* %8
%34 = or i32 %32, %33
%35 = sitofp i32 %34 to float
store float %35, float* %11
%36 = load i32, i32* %9
%37 = shl i32 %36, 8
%38 = load i32, i32* %10
%39 = or i32 %37, %38
%40 = sitofp i32 %39 to float
store float %40, float* %12
%41 = load float, float* %12
%42 = fcmp oeq float %41, 0.000000e+00
br i1 %42, label %43, label %46
43: ; preds = %18
%44 = load float, float* %11
%45 = load float*, float** %5
store float %44, float* %45
br label %55
46: ; preds = %18
%47 = load i32, i32* %7
%48 = sitofp i32 %47 to double
%49 = load i32, i32* %8
%50 = sitofp i32 %49 to double
%51 = fdiv double %50, 6.553600e+04
%52 = fadd double %48, %51
%53 = fptrunc double %52 to float
%54 = load float*, float** %5
store float %53, float* %54
br label %55
55: ; preds = %46, %43
store i32 0, i32* %3
br label %56
56: ; preds = %55, %17
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
define i32 @read_fixed32(i32* nocapture %0, float* nocapture writeonly %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = call i32 @fread(i8* %4, i32 4, i32 1, i32* %0)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %34
7: ; preds = %2
%8 = load i8, i8* %4
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%10 = load i8, i8* %9
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = shl nsw i32 %13, 8
%18 = or i32 %17, %16
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %7
%21 = sext i8 %10 to i32
%22 = sext i8 %8 to i32
%23 = shl nsw i32 %22, 8
%24 = or i32 %23, %21
%25 = sitofp i32 %24 to float
br label %32
26: ; preds = %7
%27 = sitofp i8 %8 to double
%28 = sitofp i8 %10 to double
%29 = fmul double %28, 0x3EF0000000000000
%30 = fadd double %29, %27
%31 = fptrunc double %30 to float
br label %32
32: ; preds = %26, %20
%33 = phi float [ %31, %26 ], [ %25, %20 ]
store float %33, float* %1
br label %34
34: ; preds = %2, %32
%35 = phi i32 [ 0, %32 ], [ 1, %2 ]
ret i32 %35
}