#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*/ b_addDigits(unsigned int *, unsigned int const *,
                               unsigned int *, int, int, int);
int b_compareDigits(unsigned int const *, unsigned int *, int, int);
int b_compareRange(unsigned int const *, unsigned int const *,
                   int /*<<< orphan*/, int /*<<< orphan*/, int);
int b_findMsb(unsigned int *, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(unsigned int *);
int /*<<< orphan*/ memcpy(unsigned int *, unsigned int *, int);
unsigned b_multiplierRange(const unsigned *lrg, const unsigned *sml,
                           int lrg_size, int sml_size) {
  int cmp = b_compareRange(lrg, sml, 0, 0, sml_size);
  if (!cmp)
    return 1u;
  unsigned p = 0;
  int buf_size = lrg_size + 1;
  unsigned *buf = (unsigned *)calloc(sizeof(unsigned), buf_size);
  unsigned *acc = (unsigned *)calloc(sizeof(unsigned), buf_size);
  while (p < 10) {
    int idx0 = b_findMsb(acc, buf_size);
    cmp = acc[0] ? b_compareDigits(lrg, acc, lrg_size, buf_size)
                 : b_compareDigits(lrg, acc + idx0, lrg_size, buf_size - idx0);
    if (cmp < 0)
      break;
    b_addDigits(buf, sml, acc, buf_size, sml_size, buf_size);
    p++;
    memcpy(buf, acc, sizeof(unsigned) * (buf_size));
  }
  free(buf);
  free(acc);
  return p - 1;
}


x86 assembly (clang, -O0):
<b_multiplierRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%r8d
xor    %ecx,%ecx
mov    %ecx,%edx
call   1080 <b_compareRange@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11b4 <b_multiplierRange+0x44>
movl   $0x1,-0x4(%rbp)
jmp    12bc <b_multiplierRange+0x14c>
movl   $0x0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
mov    $0x4,%edi
call   1040 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%esi
mov    $0x4,%edi
call   1040 <calloc@plt>
mov    %rax,-0x40(%rbp)
cmpl   $0xa,-0x28(%rbp)
jae    12a1 <b_multiplierRange+0x131>
mov    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1090 <b_findMsb@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rax
cmpl   $0x0,(%rax)
je     1227 <b_multiplierRange+0xb7>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x2c(%rbp),%ecx
call   1070 <b_compareDigits@plt>
mov    %eax,-0x48(%rbp)
jmp    124b <b_multiplierRange+0xdb>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
movslq -0x44(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
mov    -0x2c(%rbp),%ecx
sub    -0x44(%rbp),%ecx
call   1070 <b_compareDigits@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1260 <b_multiplierRange+0xf0>
jmp    12a1 <b_multiplierRange+0x131>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
call   1050 <b_addDigits@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
jmp    11e6 <b_multiplierRange+0x76>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b_multiplierRange>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r8d
mov    %edx,%r13d
xor    %ebx,%ebx
mov    %rdi,0x8(%rsp)
mov    %rsi,0x10(%rsp)
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r8d,0x4(%rsp)
call   1080 <b_compareRange@plt>
test   %eax,%eax
je     1277 <b_multiplierRange+0x107>
lea    0x1(%r13),%r14d
mov    $0x4,%edi
mov    %r14d,%esi
call   1040 <calloc@plt>
mov    %rax,%rbp
mov    $0x4,%edi
mov    %r14d,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
lea    0x4(,%r13,4),%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14d,%esi
call   1090 <b_findMsb@plt>
cmpl   $0x0,(%r15)
je     1210 <b_multiplierRange+0xa0>
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %r13d,%edx
mov    %r14d,%ecx
jmp    1223 <b_multiplierRange+0xb3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cltq
lea    (%r15,%rax,4),%rsi
mov    %r14d,%ecx
sub    %eax,%ecx
mov    0x8(%rsp),%rdi
mov    %r13d,%edx
call   1070 <b_compareDigits@plt>
test   %eax,%eax
js     1262 <b_multiplierRange+0xf2>
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    0x4(%rsp),%r8d
mov    %r14d,%r9d
call   1050 <b_addDigits@plt>
add    $0x1,%ebx
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1060 <memcpy@plt>
cmp    $0xa,%ebx
jne    11e0 <b_multiplierRange+0x70>
mov    $0xa,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0xffffffff,%ebx
jmp    127c <b_multiplierRange+0x10c>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @b_multiplierRange(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%16 = load i32*, i32** %6
%17 = load i32*, i32** %7
%18 = load i32, i32* %9
%19 = call i32 @b_compareRange(i32* %16, i32* %17, i32 0, i32 0, i32 %18)
store i32 %19, i32* %10
%20 = load i32, i32* %10
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %4
store i32 1, i32* %5
br label %89
23: ; preds = %4
store i32 0, i32* %11
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %12
%26 = load i32, i32* %12
%27 = call i64 @calloc(i32 4, i32 %26)
%28 = inttoptr i64 %27 to i32*
store i32* %28, i32** %13
%29 = load i32, i32* %12
%30 = call i64 @calloc(i32 4, i32 %29)
%31 = inttoptr i64 %30 to i32*
store i32* %31, i32** %14
br label %32
32: ; preds = %65, %23
%33 = load i32, i32* %11
%34 = icmp ult i32 %33, 10
br i1 %34, label %35, label %82
35: ; preds = %32
%36 = load i32*, i32** %14
%37 = load i32, i32* %12
%38 = call i32 @b_findMsb(i32* %36, i32 %37)
store i32 %38, i32* %15
%39 = load i32*, i32** %14
%40 = getelementptr inbounds i32, i32* %39, i64 0
%41 = load i32, i32* %40
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %35
%44 = load i32*, i32** %6
%45 = load i32*, i32** %14
%46 = load i32, i32* %8
%47 = load i32, i32* %12
%48 = call i32 @b_compareDigits(i32* %44, i32* %45, i32 %46, i32 %47)
br label %60
49: ; preds = %35
%50 = load i32*, i32** %6
%51 = load i32*, i32** %14
%52 = load i32, i32* %15
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = load i32, i32* %8
%56 = load i32, i32* %12
%57 = load i32, i32* %15
%58 = sub nsw i32 %56, %57
%59 = call i32 @b_compareDigits(i32* %50, i32* %54, i32 %55, i32 %58)
br label %60
60: ; preds = %49, %43
%61 = phi i32 [ %48, %43 ], [ %59, %49 ]
store i32 %61, i32* %10
%62 = load i32, i32* %10
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %60
br label %82
65: ; preds = %60
%66 = load i32*, i32** %13
%67 = load i32*, i32** %7
%68 = load i32*, i32** %14
%69 = load i32, i32* %12
%70 = load i32, i32* %9
%71 = load i32, i32* %12
%72 = call i32 @b_addDigits(i32* %66, i32* %67, i32* %68, i32 %69, i32 %70, i32 %71)
%73 = load i32, i32* %11
%74 = add i32 %73, 1
store i32 %74, i32* %11
%75 = load i32*, i32** %13
%76 = load i32*, i32** %14
%77 = load i32, i32* %12
%78 = sext i32 %77 to i64
%79 = mul i64 4, %78
%80 = trunc i64 %79 to i32
%81 = call i32 @memcpy(i32* %75, i32* %76, i32 %80)
br label %32
82: ; preds = %64, %32
%83 = load i32*, i32** %13
%84 = call i32 @free(i32* %83)
%85 = load i32*, i32** %14
%86 = call i32 @free(i32* %85)
%87 = load i32, i32* %11
%88 = sub i32 %87, 1
store i32 %88, i32* %5
br label %89
89: ; preds = %82, %22
%90 = load i32, i32* %5
ret i32 %90
}

LLVM IR (-O2):
define i32 @b_multiplierRange(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = tail call i32 @b_compareRange(i32* %0, i32* %1, i32 0, i32 0, i32 %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %39, label %7
7: ; preds = %4
%8 = add nsw i32 %2, 1
%9 = tail call i64 @calloc(i32 4, i32 %8)
%10 = inttoptr i64 %9 to i32*
%11 = tail call i64 @calloc(i32 4, i32 %8)
%12 = inttoptr i64 %11 to i32*
%13 = shl i32 %8, 2
br label %14
14: ; preds = %7, %29
%15 = phi i32 [ 0, %7 ], [ %31, %29 ]
%16 = tail call i32 @b_findMsb(i32* %12, i32 %8)
%17 = load i32, i32* %12
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = tail call i32 @b_compareDigits(i32* %0, i32* %12, i32 %2, i32 %8)
br label %26
21: ; preds = %14
%22 = sext i32 %16 to i64
%23 = getelementptr inbounds i32, i32* %12, i64 %22
%24 = sub nsw i32 %8, %16
%25 = tail call i32 @b_compareDigits(i32* %0, i32* %23, i32 %2, i32 %24)
br label %26
26: ; preds = %21, %19
%27 = phi i32 [ %20, %19 ], [ %25, %21 ]
%28 = icmp slt i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = tail call i32 @b_addDigits(i32* %10, i32* %1, i32* %12, i32 %8, i32 %3, i32 %8)
%31 = add nuw nsw i32 %15, 1
%32 = tail call i32 @memcpy(i32* %10, i32* %12, i32 %13)
%33 = icmp eq i32 %31, 10
br i1 %33, label %34, label %14
34: ; preds = %26, %29
%35 = phi i32 [ %15, %26 ], [ 10, %29 ]
%36 = tail call i32 @free(i32* %10)
%37 = tail call i32 @free(i32* %12)
%38 = add nsw i32 %35, -1
br label %39
39: ; preds = %4, %34
%40 = phi i32 [ %38, %34 ], [ 1, %4 ]
ret i32 %40
}