#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 int int16_t;

/* Variables and functions */
scalar_t__ floor(float);
uint8_t findexp(float residual, uint8_t *nybble) {
  uint8_t exp = 0;
  while ((residual > 7.5f) || (residual < -8.5f)) {
    exp++;
    residual /= 2;
  }
  if (nybble)
    *nybble = ((((int16_t)floor(residual)) > (7))
                   ? (7)
                   : ((((int16_t)floor(residual)) < (-8))
                          ? (-8)
                          : ((int16_t)floor(residual))));
  return exp;
}


x86 assembly (clang, -O0):
<findexp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movss  -0x4(%rbp),%xmm0
mov    $0x1,%al
movss  0xec9(%rip),%xmm1
ucomiss %xmm1,%xmm0
mov    %al,-0x15(%rbp)
ja     1155 <findexp+0x45>
movss  0xeb9(%rip),%xmm0
ucomiss -0x4(%rbp),%xmm0
seta   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1165 <findexp+0x55>
jmp    1189 <findexp+0x79>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movss  -0x4(%rbp),%xmm0
movss  0xe8d(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1128 <findexp+0x18>
cmpq   $0x0,-0x10(%rbp)
je     11f0 <findexp+0xe0>
movss  -0x4(%rbp),%xmm0
call   1030 <floor@plt>
cmp    $0x7,%eax
jle    11b4 <findexp+0xa4>
mov    $0x7,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e7 <findexp+0xd7>
movss  -0x4(%rbp),%xmm0
call   1030 <floor@plt>
cmp    $0xfffffff8,%eax
jge    11d4 <findexp+0xc4>
mov    $0xfffffff8,%eax
mov    %eax,-0x20(%rbp)
jmp    11e1 <findexp+0xd1>
movss  -0x4(%rbp),%xmm0
call   1030 <floor@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findexp>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
ucomiss 0xee3(%rip),%xmm0
ja     112e <findexp+0x1e>
xor    %ebp,%ebp
movss  0xedb(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    1161 <findexp+0x51>
xor    %ebp,%ebp
movss  0xed0(%rip),%xmm3
movss  0xec0(%rip),%xmm1
movss  0xebc(%rip),%xmm2
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mulss  %xmm3,%xmm0
ucomiss %xmm1,%xmm0
ja     1150 <findexp+0x40>
ucomiss %xmm0,%xmm2
ja     1150 <findexp+0x40>
test   %rbx,%rbx
je     11a3 <findexp+0x93>
movss  %xmm0,0x4(%rsp)
call   1030 <floor@plt>
mov    %rax,%rcx
mov    $0x7,%eax
cmp    $0x7,%ecx
jg     11a1 <findexp+0x91>
movss  0x4(%rsp),%xmm0
call   1030 <floor@plt>
mov    %rax,%rcx
mov    $0xfffffff8,%eax
cmp    $0xfffffff8,%ecx
jl     11a1 <findexp+0x91>
movss  0x4(%rsp),%xmm0
call   1030 <floor@plt>
mov    %eax,(%rbx)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @findexp(float %0, i32* %1) {
%3 = alloca float
%4 = alloca i32*
%5 = alloca i32
store float %0, float* %3
store i32* %1, i32** %4
store i32 0, i32* %5
br label %6
6: ; preds = %14, %2
%7 = load float, float* %3
%8 = fcmp ogt float %7, 7.500000e+00
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load float, float* %3
%11 = fcmp olt float %10, -8.500000e+00
br label %12
12: ; preds = %9, %6
%13 = phi i1 [ true, %6 ], [ %11, %9 ]
br i1 %13, label %14, label %19
14: ; preds = %12
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
store i32 %16, i32* %5
%17 = load float, float* %3
%18 = fdiv float %17, 2.000000e+00
store float %18, float* %3
br label %6
19: ; preds = %12
%20 = load i32*, i32** %4
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %43
22: ; preds = %19
%23 = load float, float* %3
%24 = call i64 @floor(float %23)
%25 = trunc i64 %24 to i32
%26 = icmp sgt i32 %25, 7
br i1 %26, label %27, label %28
27: ; preds = %22
br label %40
28: ; preds = %22
%29 = load float, float* %3
%30 = call i64 @floor(float %29)
%31 = trunc i64 %30 to i32
%32 = icmp slt i32 %31, -8
br i1 %32, label %33, label %34
33: ; preds = %28
br label %38
34: ; preds = %28
%35 = load float, float* %3
%36 = call i64 @floor(float %35)
%37 = trunc i64 %36 to i32
br label %38
38: ; preds = %34, %33
%39 = phi i32 [ -8, %33 ], [ %37, %34 ]
br label %40
40: ; preds = %38, %27
%41 = phi i32 [ 7, %27 ], [ %39, %38 ]
%42 = load i32*, i32** %4
store i32 %41, i32* %42
br label %43
43: ; preds = %40, %19
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
define i32 @findexp(float %0, i32* writeonly %1) {
%3 = fcmp ogt float %0, 7.500000e+00
%4 = fcmp olt float %0, -8.500000e+00
%5 = or i1 %3, %4
br i1 %5, label %6, label %14
6: ; preds = %2, %6
%7 = phi i32 [ %9, %6 ], [ 0, %2 ]
%8 = phi float [ %10, %6 ], [ %0, %2 ]
%9 = add nuw nsw i32 %7, 1
%10 = fmul float %8, 5.000000e-01
%11 = fcmp ogt float %10, 7.500000e+00
%12 = fcmp olt float %10, -8.500000e+00
%13 = or i1 %11, %12
br i1 %13, label %6, label %14
14: ; preds = %6, %2
%15 = phi float [ %0, %2 ], [ %10, %6 ]
%16 = phi i32 [ 0, %2 ], [ %9, %6 ]
%17 = icmp eq i32* %1, null
br i1 %17, label %31, label %18
18: ; preds = %14
%19 = tail call i64 @floor(float %15)
%20 = trunc i64 %19 to i32
%21 = icmp sgt i32 %20, 7
br i1 %21, label %29, label %22
22: ; preds = %18
%23 = tail call i64 @floor(float %15)
%24 = trunc i64 %23 to i32
%25 = icmp slt i32 %24, -8
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = tail call i64 @floor(float %15)
%28 = trunc i64 %27 to i32
br label %29
29: ; preds = %26, %22, %18
%30 = phi i32 [ 7, %18 ], [ %28, %26 ], [ -8, %22 ]
store i32 %30, i32* %1
br label %31
31: ; preds = %29, %14
ret i32 %16
}