#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 /*<<< orphan*/ __rthal_do_div(unsigned long long *, unsigned int const);
void xnarch_init_llmulshft(const unsigned m_in, const unsigned d_in,
                           unsigned *m_out, unsigned *s_out) {
  unsigned long long mult;
  *s_out = 31;
  while (1) {
    mult = ((unsigned long long)m_in) << *s_out;
    __rthal_do_div(&(mult), (d_in));
    if (mult <= 0x7FFFFFFF)
      break;
    (*s_out)--;
  }
  *m_out = (unsigned)mult;
}


x86 assembly (clang, -O0):
<xnarch_init_llmulshft>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1f,(%rax)
mov    -0x4(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
shl    %cl,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   1030 <__rthal_do_div@plt>
cmpq   $0x7fffffff,-0x20(%rbp)
7f
ja     115f <xnarch_init_llmulshft+0x4f>
jmp    116f <xnarch_init_llmulshft+0x5f>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
jmp    1130 <xnarch_init_llmulshft+0x20>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xnarch_init_llmulshft>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %esi,%r12d
mov    %edi,%ebp
movl   $0x1f,(%rcx)
mov    %rbp,%rax
shl    $0x1f,%rax
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1030 <__rthal_do_div@plt>
mov    (%rsp),%rax
test   $0xffffffff80000000,%rax
je     1185 <xnarch_init_llmulshft+0x75>
mov    $0x80000000,%r13d
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rbx),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rbx)
mov    %rbp,%rax
shl    %cl,%rax
mov    %rax,(%rsp)
mov    %r15,%rdi
mov    %r12d,%esi
call   1030 <__rthal_do_div@plt>
mov    (%rsp),%rax
cmp    %r13,%rax
jae    1160 <xnarch_init_llmulshft+0x50>
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @xnarch_init_llmulshft(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%10 = load i32*, i32** %8
store i32 31, i32* %10
br label %11
11: ; preds = %4, %23
%12 = load i32, i32* %5
%13 = zext i32 %12 to i64
%14 = load i32*, i32** %8
%15 = load i32, i32* %14
%16 = zext i32 %15 to i64
%17 = shl i64 %13, %16
store i64 %17, i64* %9
%18 = load i32, i32* %6
%19 = call i32 @__rthal_do_div(i64* %9, i32 %18)
%20 = load i64, i64* %9
%21 = icmp ule i64 %20, 2147483647
br i1 %21, label %22, label %23
22: ; preds = %11
br label %27
23: ; preds = %11
%24 = load i32*, i32** %8
%25 = load i32, i32* %24
%26 = add i32 %25, -1
store i32 %26, i32* %24
br label %11
27: ; preds = %22
%28 = load i64, i64* %9
%29 = trunc i64 %28 to i32
%30 = load i32*, i32** %7
store i32 %29, i32* %30
ret void
}

LLVM IR (-O2):
define void @xnarch_init_llmulshft(i32 %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = zext i32 %0 to i64
store i32 31, i32* %3
%8 = shl nuw nsw i64 %7, 31
store i64 %8, i64* %5
%9 = call i32 @__rthal_do_div(i64* %5, i32 %1)
%10 = load i64, i64* %5
%11 = icmp ult i64 %10, 2147483648
br i1 %11, label %20, label %12
12: ; preds = %4, %12
%13 = load i32, i32* %3
%14 = add i32 %13, -1
store i32 %14, i32* %3
%15 = zext i32 %14 to i64
%16 = shl i64 %7, %15
store i64 %16, i64* %5
%17 = call i32 @__rthal_do_div(i64* %5, i32 %1)
%18 = load i64, i64* %5
%19 = icmp ult i64 %18, 2147483648
br i1 %19, label %20, label %12
20: ; preds = %12, %4
%21 = phi i64 [ %10, %4 ], [ %18, %12 ]
%22 = trunc i64 %21 to i32
store i32 %22, i32* %2
ret void
}