#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 b_compareRange(unsigned int *, unsigned int const *, int /*<<< orphan*/,
                   int /*<<< orphan*/, int);
int b_findMsb(unsigned int *, int);
unsigned int b_multiplierRange(unsigned int *, unsigned int const *, int, int);
int /*<<< orphan*/ b_multiplyDigitsByDigit(unsigned int const *, unsigned int *,
                                           int, int, unsigned int);
int /*<<< orphan*/ b_resetDigits(unsigned int *, int);
int /*<<< orphan*/ b_subtractDigits(unsigned int *, unsigned int *,
                                    unsigned int *, int, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(unsigned int *);
int /*<<< orphan*/ memcpy(unsigned int *, unsigned int const *, int);
void b_divider(const unsigned *ns, const unsigned *ds, unsigned *qs,
               unsigned *rs, int n, int d) {
  unsigned *es = (unsigned *)calloc(sizeof(unsigned), d + 1);
  memcpy(rs, ns, n * sizeof(unsigned));
  unsigned *fs = (unsigned *)calloc(sizeof(unsigned), d + 1);
  int size = d, rmsb = 0, qidx = 0;
  while (rmsb + d - 1 < n) {
    int cmp = b_compareRange(rs + rmsb, ds, 0, 0, size);
    if (rmsb >= n - d && cmp < 0)
      break;
    if (cmp < 0) {
      size = d + 1;
      qs[qidx++] = 0;
    }
    unsigned p = b_multiplierRange(rs + rmsb, ds, size, d);
    qs[qidx++] = p;
    b_multiplyDigitsByDigit(ds, fs, d, size, p);
    b_subtractDigits(rs + rmsb, fs, es, size, size);
    memcpy(rs + rmsb, es, size * sizeof(unsigned));
    rmsb = b_findMsb(rs, n);
    size = d;
    b_resetDigits(es, d + 1);
    b_resetDigits(fs, d + 1);
  }
  free(es);
  free(fs);
}


x86 assembly (clang, -O0):
<b_divider>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x28(%rbp),%esi
add    $0x1,%esi
mov    $0x4,%edi
call   1070 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1080 <memcpy@plt>
mov    -0x28(%rbp),%esi
add    $0x1,%esi
mov    $0x4,%edi
call   1070 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x40(%rbp),%eax
add    -0x28(%rbp),%eax
sub    $0x1,%eax
cmp    -0x24(%rbp),%eax
jge    1351 <b_divider+0x1c1>
mov    -0x20(%rbp),%rdi
movslq -0x40(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x3c(%rbp),%r8d
xor    %ecx,%ecx
mov    %ecx,%edx
call   1090 <b_compareRange@plt>
mov    %eax,-0x48(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    -0x28(%rbp),%ecx
cmp    %ecx,%eax
jl     1258 <b_divider+0xc8>
cmpl   $0x0,-0x48(%rbp)
jge    1258 <b_divider+0xc8>
jmp    1351 <b_divider+0x1c1>
cmpl   $0x0,-0x48(%rbp)
jge    1284 <b_divider+0xf4>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x44(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x44(%rbp)
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rdi
movslq -0x40(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x3c(%rbp),%edx
mov    -0x28(%rbp),%ecx
call   1060 <b_multiplierRange@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    -0x44(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x44(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x4c(%rbp),%r8d
call   1050 <b_multiplyDigitsByDigit@plt>
mov    -0x20(%rbp),%rdi
movslq -0x40(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
call   1040 <b_subtractDigits@plt>
mov    -0x20(%rbp),%rdi
movslq -0x40(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
movslq -0x3c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1080 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   10a0 <b_findMsb@plt>
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
add    $0x1,%esi
call   10b0 <b_resetDigits@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%esi
add    $0x1,%esi
call   10b0 <b_resetDigits@plt>
jmp    1203 <b_divider+0x73>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b_divider>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9d,%ebx
mov    %r8d,%ebp
mov    %rcx,%r15
mov    %rdx,0x10(%rsp)
mov    %rsi,0x30(%rsp)
mov    %rdi,%r14
lea    0x1(%rbx),%r12d
mov    $0x4,%edi
mov    %r12d,%esi
call   1070 <calloc@plt>
mov    %rax,0x20(%rsp)
lea    0x0(,%rbp,4),%edx
mov    %r15,0x28(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <memcpy@plt>
mov    $0x4,%edi
mov    %r12d,%esi
call   1070 <calloc@plt>
mov    %rax,0x18(%rsp)
mov    %rbp,0x40(%rsp)
mov    %ebp,%eax
sub    %ebx,%eax
mov    %eax,0xc(%rsp)
jge    1224 <b_divider+0x94>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
xor    %ebp,%ebp
xor    %r13d,%r13d
mov    %r12d,0x8(%rsp)
mov    %rbx,0x38(%rsp)
jmp    12f6 <b_divider+0x166>
nopl   0x0(%rax,%rax,1)
movslq %r13d,%rax
add    $0x1,%r13d
mov    0x10(%rsp),%r15
movl   $0x0,(%r15,%rax,4)
mov    %r12d,%ebp
mov    %r14,%rdi
mov    0x30(%rsp),%r12
mov    %r12,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1060 <b_multiplierRange@plt>
movslq %r13d,%rcx
add    $0x1,%r13d
mov    %eax,(%r15,%rcx,4)
mov    %r12,%rdi
mov    0x18(%rsp),%r15
mov    %r15,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
call   1050 <b_multiplyDigitsByDigit@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    0x20(%rsp),%rbx
mov    %rbx,%rdx
mov    %ebp,%ecx
mov    %ebp,%r8d
call   1040 <b_subtractDigits@plt>
shl    $0x2,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1080 <memcpy@plt>
mov    0x28(%rsp),%rdi
mov    0x40(%rsp),%r14
mov    %r14d,%esi
call   10a0 <b_findMsb@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    0x8(%rsp),%r12d
mov    %r12d,%esi
call   10b0 <b_resetDigits@plt>
mov    %r15,%rdi
mov    %r12d,%esi
call   10b0 <b_resetDigits@plt>
mov    %ebp,%eax
mov    0x38(%rsp),%rbx
add    %ebx,%eax
cmp    %r14d,%eax
jg     1202 <b_divider+0x72>
movslq %ebp,%rbp
mov    0x28(%rsp),%rax
lea    (%rax,%rbp,4),%r14
mov    %r14,%rdi
mov    0x30(%rsp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %ebx,%r8d
call   1090 <b_compareRange@plt>
cmp    0xc(%rsp),%ebp
jl     1324 <b_divider+0x194>
test   %eax,%eax
js     1202 <b_divider+0x72>
test   %eax,%eax
js     1240 <b_divider+0xb0>
mov    %ebx,%ebp
mov    0x10(%rsp),%r15
jmp    1257 <b_divider+0xc7>

LLVM IR (-O0):
define void @b_divider(i32* %0, i32* %1, i32* %2, i32* %3, i32 %4, i32 %5) {
%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
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%20 = load i32, i32* %12
%21 = add nsw i32 %20, 1
%22 = call i64 @calloc(i32 4, i32 %21)
%23 = inttoptr i64 %22 to i32*
store i32* %23, i32** %13
%24 = load i32*, i32** %10
%25 = load i32*, i32** %7
%26 = load i32, i32* %11
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 4
%29 = trunc i64 %28 to i32
%30 = call i32 @memcpy(i32* %24, i32* %25, i32 %29)
%31 = load i32, i32* %12
%32 = add nsw i32 %31, 1
%33 = call i64 @calloc(i32 4, i32 %32)
%34 = inttoptr i64 %33 to i32*
store i32* %34, i32** %14
%35 = load i32, i32* %12
store i32 %35, i32* %15
store i32 0, i32* %16
store i32 0, i32* %17
br label %36
36: ; preds = %71, %6
%37 = load i32, i32* %16
%38 = load i32, i32* %12
%39 = add nsw i32 %37, %38
%40 = sub nsw i32 %39, 1
%41 = load i32, i32* %11
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %123
43: ; preds = %36
%44 = load i32*, i32** %10
%45 = load i32, i32* %16
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32*, i32** %8
%49 = load i32, i32* %15
%50 = call i32 @b_compareRange(i32* %47, i32* %48, i32 0, i32 0, i32 %49)
store i32 %50, i32* %18
%51 = load i32, i32* %16
%52 = load i32, i32* %11
%53 = load i32, i32* %12
%54 = sub nsw i32 %52, %53
%55 = icmp sge i32 %51, %54
br i1 %55, label %56, label %60
56: ; preds = %43
%57 = load i32, i32* %18
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %56
br label %123
60: ; preds = %56, %43
%61 = load i32, i32* %18
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %71
63: ; preds = %60
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %15
%66 = load i32*, i32** %9
%67 = load i32, i32* %17
%68 = add nsw i32 %67, 1
store i32 %68, i32* %17
%69 = sext i32 %67 to i64
%70 = getelementptr inbounds i32, i32* %66, i64 %69
store i32 0, i32* %70
br label %71
71: ; preds = %63, %60
%72 = load i32*, i32** %10
%73 = load i32, i32* %16
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %72, i64 %74
%76 = load i32*, i32** %8
%77 = load i32, i32* %15
%78 = load i32, i32* %12
%79 = call i32 @b_multiplierRange(i32* %75, i32* %76, i32 %77, i32 %78)
store i32 %79, i32* %19
%80 = load i32, i32* %19
%81 = load i32*, i32** %9
%82 = load i32, i32* %17
%83 = add nsw i32 %82, 1
store i32 %83, i32* %17
%84 = sext i32 %82 to i64
%85 = getelementptr inbounds i32, i32* %81, i64 %84
store i32 %80, i32* %85
%86 = load i32*, i32** %8
%87 = load i32*, i32** %14
%88 = load i32, i32* %12
%89 = load i32, i32* %15
%90 = load i32, i32* %19
%91 = call i32 @b_multiplyDigitsByDigit(i32* %86, i32* %87, i32 %88, i32 %89, i32 %90)
%92 = load i32*, i32** %10
%93 = load i32, i32* %16
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i32, i32* %92, i64 %94
%96 = load i32*, i32** %14
%97 = load i32*, i32** %13
%98 = load i32, i32* %15
%99 = load i32, i32* %15
%100 = call i32 @b_subtractDigits(i32* %95, i32* %96, i32* %97, i32 %98, i32 %99)
%101 = load i32*, i32** %10
%102 = load i32, i32* %16
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i32, i32* %101, i64 %103
%105 = load i32*, i32** %13
%106 = load i32, i32* %15
%107 = sext i32 %106 to i64
%108 = mul i64 %107, 4
%109 = trunc i64 %108 to i32
%110 = call i32 @memcpy(i32* %104, i32* %105, i32 %109)
%111 = load i32*, i32** %10
%112 = load i32, i32* %11
%113 = call i32 @b_findMsb(i32* %111, i32 %112)
store i32 %113, i32* %16
%114 = load i32, i32* %12
store i32 %114, i32* %15
%115 = load i32*, i32** %13
%116 = load i32, i32* %12
%117 = add nsw i32 %116, 1
%118 = call i32 @b_resetDigits(i32* %115, i32 %117)
%119 = load i32*, i32** %14
%120 = load i32, i32* %12
%121 = add nsw i32 %120, 1
%122 = call i32 @b_resetDigits(i32* %119, i32 %121)
br label %36
123: ; preds = %59, %36
%124 = load i32*, i32** %13
%125 = call i32 @free(i32* %124)
%126 = load i32*, i32** %14
%127 = call i32 @free(i32* %126)
ret void
}

LLVM IR (-O2):
define void @b_divider(i32* %0, i32* %1, i32* nocapture writeonly %2, i32* %3, i32 %4, i32 %5) {
%7 = add nsw i32 %5, 1
%8 = tail call i64 @calloc(i32 4, i32 %7)
%9 = inttoptr i64 %8 to i32*
%10 = shl i32 %4, 2
%11 = tail call i32 @memcpy(i32* %3, i32* %0, i32 %10)
%12 = tail call i64 @calloc(i32 4, i32 %7)
%13 = inttoptr i64 %12 to i32*
%14 = icmp slt i32 %4, %5
br i1 %14, label %47, label %15
15: ; preds = %6
%16 = sub nsw i32 %4, %5
br label %17
17: ; preds = %15, %31
%18 = phi i32 [ 0, %15 ], [ %42, %31 ]
%19 = phi i32 [ 0, %15 ], [ %35, %31 ]
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i32, i32* %3, i64 %20
%22 = tail call i32 @b_compareRange(i32* %21, i32* %1, i32 0, i32 0, i32 %5)
%23 = icmp sge i32 %18, %16
%24 = icmp slt i32 %22, 0
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %47, label %26
26: ; preds = %17
br i1 %24, label %27, label %31
27: ; preds = %26
%28 = add nsw i32 %19, 1
%29 = sext i32 %19 to i64
%30 = getelementptr inbounds i32, i32* %2, i64 %29
store i32 0, i32* %30
br label %31
31: ; preds = %26, %27
%32 = phi i32 [ %28, %27 ], [ %19, %26 ]
%33 = phi i32 [ %7, %27 ], [ %5, %26 ]
%34 = tail call i32 @b_multiplierRange(i32* %21, i32* %1, i32 %33, i32 %5)
%35 = add nsw i32 %32, 1
%36 = sext i32 %32 to i64
%37 = getelementptr inbounds i32, i32* %2, i64 %36
store i32 %34, i32* %37
%38 = tail call i32 @b_multiplyDigitsByDigit(i32* %1, i32* %13, i32 %5, i32 %33, i32 %34)
%39 = tail call i32 @b_subtractDigits(i32* %21, i32* %13, i32* %9, i32 %33, i32 %33)
%40 = shl i32 %33, 2
%41 = tail call i32 @memcpy(i32* %21, i32* %9, i32 %40)
%42 = tail call i32 @b_findMsb(i32* %3, i32 %4)
%43 = tail call i32 @b_resetDigits(i32* %9, i32 %7)
%44 = tail call i32 @b_resetDigits(i32* %13, i32 %7)
%45 = add nsw i32 %42, %5
%46 = icmp sgt i32 %45, %4
br i1 %46, label %47, label %17
47: ; preds = %31, %17, %6
%48 = tail call i32 @free(i32* %9)
%49 = tail call i32 @free(i32* %13)
ret void
}