#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 */
int abs(unsigned long);
scalar_t__ cdiv64_64(unsigned long long, unsigned long long);
int fls64(unsigned long long);
unsigned long qroot(unsigned long long a) {
  unsigned long x, x1;
  x = 1u << (fls64(a) >> 2);
  do {
    unsigned long long x3 = x;
    x1 = x;
    x3 *= x;
    x3 *= x;
    x = (3 * x + (unsigned long)cdiv64_64(a, x3)) / 4;
  } while (abs(x1 - x) > 1);
  return x;
}


x86 assembly (clang, -O0):
<qroot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fls64@plt>
mov    %eax,%ecx
sar    $0x2,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%eax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
imul   $0x3,-0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <cdiv64_64@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
shr    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
sub    -0x10(%rbp),%rdi
call   1040 <abs@plt>
cmp    $0x1,%eax
jg     1157 <qroot+0x27>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qroot>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <fls64@plt>
shr    $0x2,%eax
mov    $0x1,%ebx
mov    %eax,%ecx
shl    %cl,%ebx
nopl   0x0(%rax)
mov    %rbx,%r15
mov    %rbx,%rsi
imul   %rbx,%rsi
imul   %rbx,%rsi
lea    (%rbx,%rbx,2),%r12
mov    %r14,%rdi
call   1030 <cdiv64_64@plt>
mov    %rax,%rbx
add    %r12,%rbx
shr    $0x2,%rbx
sub    %rbx,%r15
mov    %r15,%rdi
call   1040 <abs@plt>
cmp    $0x1,%eax
jg     1150 <qroot+0x20>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @qroot(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %2
%6 = load i64, i64* %2
%7 = call i32 @fls64(i64 %6)
%8 = ashr i32 %7, 2
%9 = shl i32 1, %8
%10 = zext i32 %9 to i64
store i64 %10, i64* %3
br label %11
11: ; preds = %27, %1
%12 = load i64, i64* %3
store i64 %12, i64* %5
%13 = load i64, i64* %3
store i64 %13, i64* %4
%14 = load i64, i64* %3
%15 = load i64, i64* %5
%16 = mul i64 %15, %14
store i64 %16, i64* %5
%17 = load i64, i64* %3
%18 = load i64, i64* %5
%19 = mul i64 %18, %17
store i64 %19, i64* %5
%20 = load i64, i64* %3
%21 = mul i64 3, %20
%22 = load i64, i64* %2
%23 = load i64, i64* %5
%24 = call i64 @cdiv64_64(i64 %22, i64 %23)
%25 = add i64 %21, %24
%26 = udiv i64 %25, 4
store i64 %26, i64* %3
br label %27
27: ; preds = %11
%28 = load i64, i64* %4
%29 = load i64, i64* %3
%30 = sub i64 %28, %29
%31 = call i32 @abs(i64 %30)
%32 = icmp sgt i32 %31, 1
br i1 %32, label %11, label %33
33: ; preds = %27
%34 = load i64, i64* %3
ret i64 %34
}

LLVM IR (-O2):
define i64 @qroot(i64 %0) {
%2 = tail call i32 @fls64(i64 %0)
%3 = ashr i32 %2, 2
%4 = shl nuw i32 1, %3
%5 = zext i32 %4 to i64
br label %6
6: ; preds = %6, %1
%7 = phi i64 [ %5, %1 ], [ %13, %6 ]
%8 = mul i64 %7, %7
%9 = mul i64 %8, %7
%10 = mul nuw i64 %7, 3
%11 = tail call i64 @cdiv64_64(i64 %0, i64 %9)
%12 = add i64 %10, %11
%13 = lshr i64 %12, 2
%14 = sub nsw i64 %7, %13
%15 = tail call i32 @abs(i64 %14)
%16 = icmp sgt i32 %15, 1
br i1 %16, label %6, label %17
17: ; preds = %6
ret i64 %13
}