#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 */
double sqrt(double);
void mp_invisqrt_init(int n, int radix, int in, int out[]) {
  void mp_unexp_d2mp(int n, int radix, double din, short int out[]);
  int outexp;
  double dout;
  out[0] = 1;
  outexp = 0;
  dout = sqrt((double)1 / in);
  while (dout < 1) {
    dout *= radix;
    outexp--;
  }
  out[1] = outexp;
  mp_unexp_d2mp(n, radix, dout, (short int *)&out[2]);
}


x86 assembly (clang, -O0):
<mp_invisqrt_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x0,-0x1c(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xead(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  0xe97(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1191 <mp_invisqrt_init+0x71>
cvtsi2sdl -0x8(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1161 <mp_invisqrt_init+0x41>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rdx
add    $0x8,%rdx
call   1030 <mp_unexp_d2mp@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_invisqrt_init>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%rbx
mov    %esi,%ebp
mov    %edi,%r14d
movl   $0x1,(%rcx)
cvtsi2sd %edx,%xmm1
movsd  0xec2(%rip),%xmm2
movapd %xmm2,%xmm0
divsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1156 <mp_invisqrt_init+0x36>
sqrtsd %xmm0,%xmm0
jmp    1163 <mp_invisqrt_init+0x43>
call   1040 <sqrt@plt>
movsd  0xe9d(%rip),%xmm2
xor    %eax,%eax
ucomisd %xmm0,%xmm2
jbe    118d <mp_invisqrt_init+0x6d>
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mulsd  %xmm1,%xmm0
add    $0xffffffff,%eax
ucomisd %xmm0,%xmm2
ja     1180 <mp_invisqrt_init+0x60>
mov    %eax,0x4(%rbx)
add    $0x8,%rbx
mov    %r14d,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <mp_unexp_d2mp@plt>

LLVM IR (-O0):
define void @mp_invisqrt_init(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%11 = load i32*, i32** %8
%12 = getelementptr inbounds i32, i32* %11, i64 0
store i32 1, i32* %12
store i32 0, i32* %9
%13 = load i32, i32* %7
%14 = sitofp i32 %13 to double
%15 = fdiv double 1.000000e+00, %14
%16 = call double @sqrt(double %15)
store double %16, double* %10
br label %17
17: ; preds = %20, %4
%18 = load double, double* %10
%19 = fcmp olt double %18, 1.000000e+00
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %6
%22 = sitofp i32 %21 to double
%23 = load double, double* %10
%24 = fmul double %23, %22
store double %24, double* %10
%25 = load i32, i32* %9
%26 = add nsw i32 %25, -1
store i32 %26, i32* %9
br label %17
27: ; preds = %17
%28 = load i32, i32* %9
%29 = load i32*, i32** %8
%30 = getelementptr inbounds i32, i32* %29, i64 1
store i32 %28, i32* %30
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = load double, double* %10
%34 = load i32*, i32** %8
%35 = getelementptr inbounds i32, i32* %34, i64 2
%36 = bitcast i32* %35 to i16*
ret void
}

LLVM IR (-O2):
define void @mp_invisqrt_init(i32 %0, i32 %1, i32 %2, i32* %3) {
store i32 1, i32* %3
%5 = sitofp i32 %2 to double
%6 = fdiv double 1.000000e+00, %5
%7 = tail call double @sqrt(double %6)
%8 = fcmp olt double %7, 1.000000e+00
br i1 %8, label %9, label %17
9: ; preds = %4
%10 = sitofp i32 %1 to double
br label %11
11: ; preds = %9, %11
%12 = phi double [ %7, %9 ], [ %14, %11 ]
%13 = phi i32 [ 0, %9 ], [ %15, %11 ]
%14 = fmul double %12, %10
%15 = add nsw i32 %13, -1
%16 = fcmp olt double %14, 1.000000e+00
br i1 %16, label %11, label %17
17: ; preds = %11, %4
%18 = phi i32 [ 0, %4 ], [ %15, %11 ]
%19 = phi double [ %7, %4 ], [ %14, %11 ]
%20 = getelementptr inbounds i32, i32* %3, i64 1
store i32 %18, i32* %20
%21 = getelementptr inbounds i32, i32* %3, i64 2
%22 = bitcast i32* %21 to i16*
tail call void @mp_unexp_d2mp(i32 %0, i32 %1, double %19, i16* %22)
ret void
}