#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 uint64_t;
typedef int uint32_t;
typedef int uint16_t;
typedef int int32_t;

/* Variables and functions */
uint32_t softfloat_estimateSqrt32(unsigned int expA, uint32_t a) {
  static const uint16_t sqrtOddAdjustments[] = {
      0x0004, 0x0022, 0x005D, 0x00B1, 0x011D, 0x019F, 0x0236, 0x02E0,
      0x039C, 0x0468, 0x0545, 0x0631, 0x072B, 0x0832, 0x0946, 0x0A67};
  static const uint16_t sqrtEvenAdjustments[] = {
      0x0A2D, 0x08AF, 0x075A, 0x0629, 0x051A, 0x0429, 0x0356, 0x029E,
      0x0200, 0x0179, 0x0109, 0x00AF, 0x0068, 0x0034, 0x0012, 0x0002};
  int index;
  uint32_t z;
  union {
    uint32_t ui;
    int32_t i;
  } u32;
  index = (a >> 27) & 15;
  if (expA & 1) {
    z = 0x4000 + (a >> 17) - sqrtOddAdjustments[index];
    z = ((a / z) << 14) + (z << 15);
    a >>= 1;
  } else {
    z = 0x8000 + (a >> 17) - sqrtEvenAdjustments[index];
    z = a / z + z;
    z = (0x20000 <= z) ? 0xFFFF8000 : z << 15;
    if (z <= a) {
      u32.ui = a;
      return u32.i >> 1;
    }
  }
  return (uint32_t)(((uint64_t)a << 31) / z) + (z >> 1);
}


x86 assembly (clang, -O0):
<softfloat_estimateSqrt32>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x1b,%eax
and    $0xf,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1164 <softfloat_estimateSqrt32+0x64>
mov    -0xc(%rbp),%eax
sar    $0x11,%eax
add    $0x4000,%eax
movslq -0x10(%rbp),%rdx
lea    0xec5(%rip),%rcx
sub    (%rcx,%rdx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
shl    $0xe,%eax
mov    -0x14(%rbp),%ecx
shl    $0xf,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11dc <softfloat_estimateSqrt32+0xdc>
mov    -0xc(%rbp),%eax
sar    $0x11,%eax
add    $0x8000,%eax
movslq -0x10(%rbp),%rdx
lea    0xec6(%rip),%rcx
sub    (%rcx,%rdx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x20000,%eax
cmp    -0x14(%rbp),%eax
jg     11a8 <softfloat_estimateSqrt32+0xa8>
mov    $0xffff8000,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b1 <softfloat_estimateSqrt32+0xb1>
mov    -0x14(%rbp),%eax
shl    $0xf,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11d7 <softfloat_estimateSqrt32+0xd7>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <softfloat_estimateSqrt32+0xf1>
jmp    11dc <softfloat_estimateSqrt32+0xdc>
mov    -0xc(%rbp),%eax
shl    $0x1f,%eax
cltd
idivl  -0x14(%rbp)
mov    -0x14(%rbp),%ecx
sar    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<softfloat_estimateSqrt32>:
mov    %esi,%eax
shr    $0x1b,%eax
and    $0xf,%eax
mov    %esi,%ecx
sar    $0x11,%ecx
mov    %eax,%eax
test   $0x1,%dil
jne    114e <softfloat_estimateSqrt32+0x4e>
lea    0xf24(%rip),%rdx
sub    (%rdx,%rax,4),%ecx
lea    0x8000(%rcx),%edi
mov    %esi,%eax
cltd
idiv   %edi
add    %ecx,%eax
add    $0x8000,%eax
mov    %eax,%edx
shl    $0xf,%edx
cmp    $0x20000,%eax
mov    $0xffff8000,%ecx
cmovl  %edx,%ecx
cmp    %esi,%ecx
jg     116d <softfloat_estimateSqrt32+0x6d>
sar    %esi
mov    %esi,%ecx
mov    %ecx,%eax
ret
lea    0xeab(%rip),%rdx
sub    (%rdx,%rax,4),%ecx
add    $0x4000,%ecx
mov    %esi,%eax
cltd
idiv   %ecx
shl    $0xe,%eax
shl    $0xf,%ecx
add    %eax,%ecx
sar    %esi
shl    $0x1f,%esi
mov    %esi,%eax
cltd
idiv   %ecx
sar    %ecx
add    %eax,%ecx
mov    %ecx,%eax
ret

LLVM IR (-O0):
%union.anon = type { i32 }
@softfloat_estimateSqrt32.sqrtOddAdjustments = internal constant [16 x i32] [i32 4, i32 34, i32 93, i32 177, i32 285, i32 415, i32 566, i32 736, i32 924, i32 1128, i32 1349, i32 1585, i32 1835, i32 2098, i32 2374, i32 2663]
@softfloat_estimateSqrt32.sqrtEvenAdjustments = internal constant [16 x i32] [i32 2605, i32 2223, i32 1882, i32 1577, i32 1306, i32 1065, i32 854, i32 670, i32 512, i32 377, i32 265, i32 175, i32 104, i32 52, i32 18, i32 2]
define i32 @softfloat_estimateSqrt32(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %union.anon
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
%10 = ashr i32 %9, 27
%11 = and i32 %10, 15
store i32 %11, i32* %6
%12 = load i32, i32* %4
%13 = and i32 %12, 1
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %2
%16 = load i32, i32* %5
%17 = ashr i32 %16, 17
%18 = add nsw i32 16384, %17
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [16 x i32], [16 x i32]* @softfloat_estimateSqrt32.sqrtOddAdjustments, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = sub nsw i32 %18, %22
store i32 %23, i32* %7
%24 = load i32, i32* %5
%25 = load i32, i32* %7
%26 = sdiv i32 %24, %25
%27 = shl i32 %26, 14
%28 = load i32, i32* %7
%29 = shl i32 %28, 15
%30 = add nsw i32 %27, %29
store i32 %30, i32* %7
%31 = load i32, i32* %5
%32 = ashr i32 %31, 1
store i32 %32, i32* %5
br label %65
33: ; preds = %2
%34 = load i32, i32* %5
%35 = ashr i32 %34, 17
%36 = add nsw i32 32768, %35
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [16 x i32], [16 x i32]* @softfloat_estimateSqrt32.sqrtEvenAdjustments, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = sub nsw i32 %36, %40
store i32 %41, i32* %7
%42 = load i32, i32* %5
%43 = load i32, i32* %7
%44 = sdiv i32 %42, %43
%45 = load i32, i32* %7
%46 = add nsw i32 %44, %45
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = icmp sle i32 131072, %47
br i1 %48, label %49, label %50
49: ; preds = %33
br label %53
50: ; preds = %33
%51 = load i32, i32* %7
%52 = shl i32 %51, 15
br label %53
53: ; preds = %50, %49
%54 = phi i32 [ -32768, %49 ], [ %52, %50 ]
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = load i32, i32* %5
%57 = icmp sle i32 %55, %56
br i1 %57, label %58, label %64
58: ; preds = %53
%59 = load i32, i32* %5
%60 = bitcast %union.anon* %8 to i32*
store i32 %59, i32* %60
%61 = bitcast %union.anon* %8 to i32*
%62 = load i32, i32* %61
%63 = ashr i32 %62, 1
store i32 %63, i32* %3
br label %73
64: ; preds = %53
br label %65
65: ; preds = %64, %15
%66 = load i32, i32* %5
%67 = shl i32 %66, 31
%68 = load i32, i32* %7
%69 = sdiv i32 %67, %68
%70 = load i32, i32* %7
%71 = ashr i32 %70, 1
%72 = add nsw i32 %69, %71
store i32 %72, i32* %3
br label %73
73: ; preds = %65, %58
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@softfloat_estimateSqrt32.sqrtOddAdjustments = internal unnamed_addr constant [16 x i32] [i32 4, i32 34, i32 93, i32 177, i32 285, i32 415, i32 566, i32 736, i32 924, i32 1128, i32 1349, i32 1585, i32 1835, i32 2098, i32 2374, i32 2663]
@softfloat_estimateSqrt32.sqrtEvenAdjustments = internal unnamed_addr constant [16 x i32] [i32 2605, i32 2223, i32 1882, i32 1577, i32 1306, i32 1065, i32 854, i32 670, i32 512, i32 377, i32 265, i32 175, i32 104, i32 52, i32 18, i32 2]
define i32 @softfloat_estimateSqrt32(i32 %0, i32 %1) {
%3 = lshr i32 %1, 27
%4 = and i32 %3, 15
%5 = and i32 %0, 1
%6 = icmp eq i32 %5, 0
%7 = ashr i32 %1, 17
br i1 %6, label %19, label %8
8: ; preds = %2
%9 = add nsw i32 %7, 16384
%10 = zext i32 %4 to i64
%11 = getelementptr inbounds [16 x i32], [16 x i32]* @softfloat_estimateSqrt32.sqrtOddAdjustments, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = sub i32 %9, %12
%14 = sdiv i32 %1, %13
%15 = shl i32 %14, 14
%16 = shl i32 %13, 15
%17 = add nsw i32 %15, %16
%18 = ashr i32 %1, 1
br label %33
19: ; preds = %2
%20 = add nsw i32 %7, 32768
%21 = zext i32 %4 to i64
%22 = getelementptr inbounds [16 x i32], [16 x i32]* @softfloat_estimateSqrt32.sqrtEvenAdjustments, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = sub i32 %20, %23
%25 = sdiv i32 %1, %24
%26 = add nsw i32 %25, %24
%27 = icmp sgt i32 %26, 131071
%28 = shl i32 %26, 15
%29 = select i1 %27, i32 -32768, i32 %28
%30 = icmp sgt i32 %29, %1
br i1 %30, label %33, label %31
31: ; preds = %19
%32 = ashr i32 %1, 1
br label %40
33: ; preds = %19, %8
%34 = phi i32 [ %18, %8 ], [ %1, %19 ]
%35 = phi i32 [ %17, %8 ], [ %29, %19 ]
%36 = shl i32 %34, 31
%37 = sdiv i32 %36, %35
%38 = ashr i32 %35, 1
%39 = add nsw i32 %37, %38
br label %40
40: ; preds = %33, %31
%41 = phi i32 [ %39, %33 ], [ %32, %31 ]
ret i32 %41
}