#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 cook_MULSHIFT32(int, int);
int InvRootR(int r) {
  int i, xn, t;
  xn = (cook_MULSHIFT32(r, 0xc0000000) << 2) + 0x60000000;
  for (i = 0; i < 4; i++) {
    t = cook_MULSHIFT32(xn, xn);
    t = 0x0c000000 - (cook_MULSHIFT32(r, t) << 2);
    xn = cook_MULSHIFT32(xn, t) << (6 - 1);
  }
  if (xn >> 30)
    xn = (1 << 30) - 1;
  return xn;
}


x86 assembly (clang, -O0):
<InvRootR>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0xc0000000,%esi
call   1030 <cook_MULSHIFT32@plt>
shl    $0x2,%eax
add    $0x60000000,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    118b <InvRootR+0x7b>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <cook_MULSHIFT32@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <cook_MULSHIFT32@plt>
mov    %eax,%ecx
shl    $0x2,%ecx
mov    $0xc000000,%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <cook_MULSHIFT32@plt>
shl    $0x5,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113a <InvRootR+0x2a>
mov    -0xc(%rbp),%eax
sar    $0x1e,%eax
cmp    $0x0,%eax
je     11a1 <InvRootR+0x91>
movl   $0x3fffffff,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InvRootR>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0xc0000000,%esi
call   1030 <cook_MULSHIFT32@plt>
lea    0x60000000(,%rax,4),%ebp
mov    %ebp,%edi
mov    %ebp,%esi
call   1030 <cook_MULSHIFT32@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <cook_MULSHIFT32@plt>
shl    $0x2,%eax
mov    $0xc000000,%r14d
mov    $0xc000000,%esi
sub    %eax,%esi
mov    %ebp,%edi
call   1030 <cook_MULSHIFT32@plt>
mov    %eax,%ebp
shl    $0x5,%ebp
mov    %ebp,%edi
mov    %ebp,%esi
call   1030 <cook_MULSHIFT32@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <cook_MULSHIFT32@plt>
shl    $0x2,%eax
mov    $0xc000000,%esi
sub    %eax,%esi
mov    %ebp,%edi
call   1030 <cook_MULSHIFT32@plt>
mov    %eax,%ebp
shl    $0x5,%ebp
mov    %ebp,%edi
mov    %ebp,%esi
call   1030 <cook_MULSHIFT32@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <cook_MULSHIFT32@plt>
shl    $0x2,%eax
mov    $0xc000000,%esi
sub    %eax,%esi
mov    %ebp,%edi
call   1030 <cook_MULSHIFT32@plt>
mov    %eax,%ebp
shl    $0x5,%ebp
mov    %ebp,%edi
mov    %ebp,%esi
call   1030 <cook_MULSHIFT32@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <cook_MULSHIFT32@plt>
shl    $0x2,%eax
sub    %eax,%r14d
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <cook_MULSHIFT32@plt>
shl    $0x5,%eax
cmp    $0x3fffffff,%eax
mov    $0x3fffffff,%ecx
cmovae %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @InvRootR(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @cook_MULSHIFT32(i32 %6, i32 -1073741824)
%8 = shl i32 %7, 2
%9 = add nsw i32 %8, 1610612736
store i32 %9, i32* %4
store i32 0, i32* %3
br label %10
10: ; preds = %26, %1
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = load i32, i32* %4
%15 = load i32, i32* %4
%16 = call i32 @cook_MULSHIFT32(i32 %14, i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %2
%18 = load i32, i32* %5
%19 = call i32 @cook_MULSHIFT32(i32 %17, i32 %18)
%20 = shl i32 %19, 2
%21 = sub nsw i32 201326592, %20
store i32 %21, i32* %5
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = call i32 @cook_MULSHIFT32(i32 %22, i32 %23)
%25 = shl i32 %24, 5
store i32 %25, i32* %4
br label %26
26: ; preds = %13
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %10
29: ; preds = %10
%30 = load i32, i32* %4
%31 = ashr i32 %30, 30
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 1073741823, i32* %4
br label %34
34: ; preds = %33, %29
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @InvRootR(i32 %0) {
%2 = tail call i32 @cook_MULSHIFT32(i32 %0, i32 -1073741824)
%3 = shl i32 %2, 2
%4 = add nsw i32 %3, 1610612736
%5 = tail call i32 @cook_MULSHIFT32(i32 %4, i32 %4)
%6 = tail call i32 @cook_MULSHIFT32(i32 %0, i32 %5)
%7 = mul i32 %6, -4
%8 = add i32 %7, 201326592
%9 = tail call i32 @cook_MULSHIFT32(i32 %4, i32 %8)
%10 = shl i32 %9, 5
%11 = tail call i32 @cook_MULSHIFT32(i32 %10, i32 %10)
%12 = tail call i32 @cook_MULSHIFT32(i32 %0, i32 %11)
%13 = mul i32 %12, -4
%14 = add i32 %13, 201326592
%15 = tail call i32 @cook_MULSHIFT32(i32 %10, i32 %14)
%16 = shl i32 %15, 5
%17 = tail call i32 @cook_MULSHIFT32(i32 %16, i32 %16)
%18 = tail call i32 @cook_MULSHIFT32(i32 %0, i32 %17)
%19 = mul i32 %18, -4
%20 = add i32 %19, 201326592
%21 = tail call i32 @cook_MULSHIFT32(i32 %16, i32 %20)
%22 = shl i32 %21, 5
%23 = tail call i32 @cook_MULSHIFT32(i32 %22, i32 %22)
%24 = tail call i32 @cook_MULSHIFT32(i32 %0, i32 %23)
%25 = mul i32 %24, -4
%26 = add i32 %25, 201326592
%27 = tail call i32 @cook_MULSHIFT32(i32 %22, i32 %26)
%28 = shl i32 %27, 5
%29 = icmp ult i32 %28, 1073741823
%30 = select i1 %29, i32 %28, i32 1073741823
ret i32 %30
}