#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 scalar_t__ uint32_t;

/* Variables and functions */
float INFINITY;
scalar_t__ UINT32_C(int);
float copysign(float, float);
scalar_t__ fabs(float);
scalar_t__ float_as_uint(float);
float fmul_native(float, float);
float fsub_native(float, float);
scalar_t__ scalbn(float, int);
float uint_as_float(scalar_t__);
float finv_soft(float a) {
  if (a == 0)
    return copysign(INFINITY, a);
  if (fabs(a) >= scalbn(1.0f, 127))
    return copysign(0.0f, a);
  uint32_t bin = float_as_uint(a);
  float x = uint_as_float(UINT32_C(0x7f000000) - bin);
  x = fmul_native(x, fsub_native(2.0f, fmul_native(a, x)));
  x = fmul_native(x, fsub_native(2.0f, fmul_native(a, x)));
  x = fmul_native(x, fsub_native(2.0f, fmul_native(a, x)));
  return x;
}


x86 assembly (clang, -O0):
<finv_soft>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11c3 <finv_soft+0x43>
jp     11c3 <finv_soft+0x43>
mov    0x2e3d(%rip),%rax
movss  (%rax),%xmm0
movss  -0x8(%rbp),%xmm1
call   1080 <copysign@plt>
movss  %xmm0,-0x4(%rbp)
jmp    12ee <finv_soft+0x16e>
movss  -0x8(%rbp),%xmm0
call   1050 <fabs@plt>
mov    %rax,-0x20(%rbp)
movss  0xe27(%rip),%xmm0
mov    $0x7f,%edi
call   1060 <scalbn@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jl     120a <finv_soft+0x8a>
movss  -0x8(%rbp),%xmm1
xorps  %xmm0,%xmm0
call   1080 <copysign@plt>
movss  %xmm0,-0x4(%rbp)
jmp    12ee <finv_soft+0x16e>
movss  -0x8(%rbp),%xmm0
call   1040 <float_as_uint@plt>
mov    %rax,-0x10(%rbp)
mov    $0x7f000000,%edi
call   1090 <UINT32_C@plt>
mov    %rax,%rdi
sub    -0x10(%rbp),%rdi
call   1070 <uint_as_float@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
call   10a0 <fmul_native@plt>
movaps %xmm0,%xmm1
movss  0xdad(%rip),%xmm0
call   1030 <fsub_native@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
call   10a0 <fmul_native@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
call   10a0 <fmul_native@plt>
movaps %xmm0,%xmm1
movss  0xd72(%rip),%xmm0
call   1030 <fsub_native@plt>
movaps %xmm0,%xmm1
movss  -0x28(%rbp),%xmm0
call   10a0 <fmul_native@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
call   10a0 <fmul_native@plt>
movaps %xmm0,%xmm1
movss  0xd37(%rip),%xmm0
call   1030 <fsub_native@plt>
movaps %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
call   10a0 <fmul_native@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finv_soft>:
push   %rbx
sub    $0x10,%rsp
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jne    11a2 <finv_soft+0x22>
jp     11a2 <finv_soft+0x22>
mov    0x2e4f(%rip),%rax
movss  (%rax),%xmm0
jmp    1295 <finv_soft+0x115>
movss  %xmm1,0xc(%rsp)
movaps %xmm1,%xmm0
call   1050 <fabs@plt>
mov    %rax,%rbx
movss  0xe45(%rip),%xmm0
mov    $0x7f,%edi
call   1060 <scalbn@plt>
cmp    %rax,%rbx
jge    128c <finv_soft+0x10c>
movss  0xc(%rsp),%xmm0
call   1040 <float_as_uint@plt>
mov    %rax,%rbx
mov    $0x7f000000,%edi
call   1090 <UINT32_C@plt>
sub    %rbx,%rax
mov    %rax,%rdi
call   1070 <uint_as_float@plt>
movaps %xmm0,%xmm1
movss  %xmm0,0x8(%rsp)
movss  0xc(%rsp),%xmm0
call   10a0 <fmul_native@plt>
movaps %xmm0,%xmm1
movss  0xdf4(%rip),%xmm0
call   1030 <fsub_native@plt>
movaps %xmm0,%xmm1
movss  0x8(%rsp),%xmm0
call   10a0 <fmul_native@plt>
movaps %xmm0,%xmm1
movss  %xmm0,0x8(%rsp)
movss  0xc(%rsp),%xmm0
call   10a0 <fmul_native@plt>
movaps %xmm0,%xmm1
movss  0xdc2(%rip),%xmm0
call   1030 <fsub_native@plt>
movaps %xmm0,%xmm1
movss  0x8(%rsp),%xmm0
call   10a0 <fmul_native@plt>
movaps %xmm0,%xmm1
movss  %xmm0,0x8(%rsp)
movss  0xc(%rsp),%xmm0
call   10a0 <fmul_native@plt>
movaps %xmm0,%xmm1
movss  0xd90(%rip),%xmm0
call   1030 <fsub_native@plt>
movaps %xmm0,%xmm1
movss  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
jmp    10a0 <fmul_native@plt>
xorps  %xmm0,%xmm0
movss  0xc(%rsp),%xmm1
add    $0x10,%rsp
pop    %rbx
jmp    1080 <copysign@plt>

LLVM IR (-O0):
@INFINITY = global float 0.000000e+00
define float @finv_soft(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca i64
%5 = alloca float
store float %0, float* %3
%6 = load float, float* %3
%7 = fcmp oeq float %6, 0.000000e+00
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load float, float* @INFINITY
%10 = load float, float* %3
%11 = call float @copysign(float %9, float %10)
store float %11, float* %2
br label %46
12: ; preds = %1
%13 = load float, float* %3
%14 = call i64 @fabs(float %13)
%15 = call i64 @scalbn(float 1.000000e+00, i32 127)
%16 = icmp sge i64 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load float, float* %3
%19 = call float @copysign(float 0.000000e+00, float %18)
store float %19, float* %2
br label %46
20: ; preds = %12
%21 = load float, float* %3
%22 = call i64 @float_as_uint(float %21)
store i64 %22, i64* %4
%23 = call i64 @UINT32_C(i32 2130706432)
%24 = load i64, i64* %4
%25 = sub nsw i64 %23, %24
%26 = call float @uint_as_float(i64 %25)
store float %26, float* %5
%27 = load float, float* %5
%28 = load float, float* %3
%29 = load float, float* %5
%30 = call float @fmul_native(float %28, float %29)
%31 = call float @fsub_native(float 2.000000e+00, float %30)
%32 = call float @fmul_native(float %27, float %31)
store float %32, float* %5
%33 = load float, float* %5
%34 = load float, float* %3
%35 = load float, float* %5
%36 = call float @fmul_native(float %34, float %35)
%37 = call float @fsub_native(float 2.000000e+00, float %36)
%38 = call float @fmul_native(float %33, float %37)
store float %38, float* %5
%39 = load float, float* %5
%40 = load float, float* %3
%41 = load float, float* %5
%42 = call float @fmul_native(float %40, float %41)
%43 = call float @fsub_native(float 2.000000e+00, float %42)
%44 = call float @fmul_native(float %39, float %43)
store float %44, float* %5
%45 = load float, float* %5
store float %45, float* %2
br label %46
46: ; preds = %20, %17, %8
%47 = load float, float* %2
ret float %47
}

LLVM IR (-O2):
@INFINITY = global float 0.000000e+00
define float @finv_soft(float %0) {
%2 = fcmp oeq float %0, 0.000000e+00
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load float, float* @INFINITY
%5 = tail call float @copysign(float %4, float %0)
br label %26
6: ; preds = %1
%7 = tail call i64 @fabs(float %0)
%8 = tail call i64 @scalbn(float 1.000000e+00, i32 127)
%9 = icmp slt i64 %7, %8
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call float @copysign(float 0.000000e+00, float %0)
br label %26
12: ; preds = %6
%13 = tail call i64 @float_as_uint(float %0)
%14 = tail call i64 @UINT32_C(i32 2130706432)
%15 = sub nsw i64 %14, %13
%16 = tail call float @uint_as_float(i64 %15)
%17 = tail call float @fmul_native(float %0, float %16)
%18 = tail call float @fsub_native(float 2.000000e+00, float %17)
%19 = tail call float @fmul_native(float %16, float %18)
%20 = tail call float @fmul_native(float %0, float %19)
%21 = tail call float @fsub_native(float 2.000000e+00, float %20)
%22 = tail call float @fmul_native(float %19, float %21)
%23 = tail call float @fmul_native(float %0, float %22)
%24 = tail call float @fsub_native(float 2.000000e+00, float %23)
%25 = tail call float @fmul_native(float %22, float %24)
br label %26
26: ; preds = %12, %10, %3
%27 = phi float [ %5, %3 ], [ %11, %10 ], [ %25, %12 ]
ret float %27
}