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

/* Variables and functions */
int od_rsqrt_norm(int);
int16_t od_sqrt_norm(int32_t x) {
  ;
  return (
      (((int32_t)(((x * od_rsqrt_norm(x)) + (1 << (15) >> 1)) >> (15)))) ^
      (((32767) ^
        (((int32_t)(((x * od_rsqrt_norm(x)) + (1 << (15) >> 1)) >> (15))))) &
       -((32767) <
         (((int32_t)(((x * od_rsqrt_norm(x)) + (1 << (15) >> 1)) >> (15)))))));
}


x86 assembly (clang, -O0):
<od_sqrt_norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <od_rsqrt_norm@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   %ecx,%eax
add    $0x4000,%eax
sar    $0xf,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <od_rsqrt_norm@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   %ecx,%eax
add    $0x4000,%eax
sar    $0xf,%eax
xor    $0x7fff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <od_rsqrt_norm@plt>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%ecx
mov    %eax,%edx
mov    -0x8(%rbp),%eax
imul   %edx,%esi
add    $0x4000,%esi
sar    $0xf,%esi
mov    $0x7fff,%edx
cmp    %esi,%edx
setl   %dl
and    $0x1,%dl
movzbl %dl,%esi
xor    %edx,%edx
sub    %esi,%edx
and    %edx,%ecx
xor    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<od_sqrt_norm>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
call   1030 <od_rsqrt_norm@plt>
mov    %eax,%ebx
imul   %r14d,%ebx
add    $0x4000,%ebx
sar    $0xf,%ebx
mov    %r14d,%edi
call   1030 <od_rsqrt_norm@plt>
mov    %eax,%ebp
imul   %r14d,%ebp
add    $0x4000,%ebp
sar    $0xf,%ebp
xor    $0x7fff,%ebp
mov    %r14d,%edi
call   1030 <od_rsqrt_norm@plt>
imul   %r14d,%eax
xor    %ecx,%ecx
cmp    $0x3fffc000,%eax
cmovge %ebp,%ecx
xor    %ebx,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @od_sqrt_norm(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @od_rsqrt_norm(i32 %4)
%6 = mul nsw i32 %3, %5
%7 = add nsw i32 %6, 16384
%8 = ashr i32 %7, 15
%9 = load i32, i32* %2
%10 = load i32, i32* %2
%11 = call i32 @od_rsqrt_norm(i32 %10)
%12 = mul nsw i32 %9, %11
%13 = add nsw i32 %12, 16384
%14 = ashr i32 %13, 15
%15 = xor i32 32767, %14
%16 = load i32, i32* %2
%17 = load i32, i32* %2
%18 = call i32 @od_rsqrt_norm(i32 %17)
%19 = mul nsw i32 %16, %18
%20 = add nsw i32 %19, 16384
%21 = ashr i32 %20, 15
%22 = icmp slt i32 32767, %21
%23 = zext i1 %22 to i32
%24 = sub nsw i32 0, %23
%25 = and i32 %15, %24
%26 = xor i32 %8, %25
ret i32 %26
}

LLVM IR (-O2):
define i32 @od_sqrt_norm(i32 %0) {
%2 = tail call i32 @od_rsqrt_norm(i32 %0)
%3 = mul nsw i32 %2, %0
%4 = add nsw i32 %3, 16384
%5 = ashr i32 %4, 15
%6 = tail call i32 @od_rsqrt_norm(i32 %0)
%7 = mul nsw i32 %6, %0
%8 = add nsw i32 %7, 16384
%9 = ashr i32 %8, 15
%10 = xor i32 %9, 32767
%11 = tail call i32 @od_rsqrt_norm(i32 %0)
%12 = mul nsw i32 %11, %0
%13 = icmp sgt i32 %12, 1073725439
%14 = select i1 %13, i32 %10, i32 0
%15 = xor i32 %14, %5
ret i32 %15
}