#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 */
typedef int /*<<< orphan*/ quotient;
typedef int /*<<< orphan*/ b;
typedef int /*<<< orphan*/ a;

/* Variables and functions */
int /*<<< orphan*/ bzero(unsigned char *, int);
int compare(unsigned char *, int, unsigned char *, int);
int deduct(unsigned char *, int, unsigned char *, int);
int get_highbit(unsigned char *, int);
int /*<<< orphan*/ printf(char *, ...);
int shiftleft(unsigned char *, int);
int shiftright(unsigned char *, int);
int division(unsigned char *dividend, int a_len, unsigned char *divisor,
             int b_len) {
  int i, j = 0, comp, number = 0, b_shift_len = b_len, quo_len = 0,
         quo_total_len;
  int a_highbit, b_highbit;
  unsigned char a[20], b[20], quotient[20];
  bzero(quotient, sizeof(quotient));
  bzero(a, sizeof(a));
  bzero(b, sizeof(b));
  for (i = 20 - 1; i >= 20 - 1 - a_len; i--)
    a[i] = dividend[i];
  for (i = 20 - 1; i >= 20 - 1 - b_len; i--)
    b[i] = divisor[i];
  if ((b[20 - 1] == 0) && (b_len == 0)) {
    printf("Please don't let divisor = 0\n");
    return 1;
  }
  comp = compare(a, a_len, b, b_len);
  switch (comp) {
  case 1:
    printf("quotient is 0\n");
    printf("reminder: \n");
    for (i = 20 - 1, j = 0; i >= 20 - 1 - a_len; i--, j++)
      printf("+ %d * 256^%d\n", a[i], j);
    return 1;
  case 3:
    printf("quotient is 1\n");
    printf("remainder is 0\n");
    return 1;
  }
  a_highbit = get_highbit(a, a_len);
  b_highbit = get_highbit(b, b_len);
  if (a_len - b_len >= 2) {
    number = (a_len - b_len - 1) << 3;
    number += a_highbit - b_highbit + 8;
  } else if (a_len - b_len)
    number = a_highbit - b_highbit + 8;
  else
    number = a_highbit - b_highbit;
  for (i = 0; i < number; i++)
    b_shift_len = shiftleft(b, b_shift_len);
  quo_total_len = ((a_len - b_len) << 3) + a_highbit - b_highbit;
  for (i = 0; i <= quo_total_len; i++) {
    quo_len = shiftleft(quotient, quo_len);
    comp = compare(a, a_len, b, b_shift_len);
    switch (comp) {
    case 1:
      break;
    case 2:
    case 3:
      quotient[20 - 1] |= 0x1;
      a_len = deduct(a, a_len, b, b_shift_len);
      break;
    }
    b_shift_len = shiftright(b, b_shift_len);
  }
  printf("\n\n");
  printf("quotient:  ");
  for (i = 20 - 1, j = 0; i >= 20 - 1 - quo_len; i--, j++)
    printf("+ %d *256^%d", quotient[i], j);
  printf("\n");
  printf("reminder:  ");
  for (i = 20 - 1, j = 0; i >= 20 - 1 - a_len; i--, j++)
    printf("+ %d *256^%d", a[i], j);
  printf("\n");
  return 1;
}


x86 assembly (clang, -O0):
<division>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    -0xa0(%rbp),%rdi
mov    $0x14,%esi
call   1070 <bzero@plt>
lea    -0x60(%rbp),%rdi
mov    $0x14,%esi
call   1070 <bzero@plt>
lea    -0x80(%rbp),%rdi
mov    $0x14,%esi
call   1070 <bzero@plt>
movl   $0x13,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x13,%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jl     120c <division+0x9c>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x60(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    11d8 <division+0x68>
movl   $0x13,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x13,%ecx
sub    -0x24(%rbp),%ecx
cmp    %ecx,%eax
jl     1247 <division+0xd7>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    1213 <division+0xa3>
movzbl -0x6d(%rbp),%eax
cmp    $0x0,%eax
jne    1278 <division+0x108>
cmpl   $0x0,-0x24(%rbp)
jne    1278 <division+0x108>
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15c0 <division+0x450>
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%ecx
lea    -0x60(%rbp),%rdi
lea    -0x80(%rbp),%rdx
call   1080 <compare@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0xa4(%rbp)
sub    $0x1,%eax
je     12b9 <division+0x149>
jmp    12a5 <division+0x135>
mov    -0xa4(%rbp),%eax
sub    $0x3,%eax
je     1333 <division+0x1c3>
jmp    135b <division+0x1eb>
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x13,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x13,%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jl     1327 <division+0x1b7>
movslq -0x28(%rbp),%rax
movzbl -0x60(%rbp,%rax,1),%esi
mov    -0x2c(%rbp),%edx
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12e3 <division+0x173>
movl   $0x1,-0x4(%rbp)
jmp    15c0 <division+0x450>
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15c0 <division+0x450>
lea    -0x60(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <get_highbit@plt>
mov    %eax,-0x44(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <get_highbit@plt>
mov    %eax,-0x48(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x24(%rbp),%eax
cmp    $0x2,%eax
jl     13ab <division+0x23b>
mov    -0x14(%rbp),%eax
sub    -0x24(%rbp),%eax
sub    $0x1,%eax
shl    $0x3,%eax
mov    %eax,-0x34(%rbp)
mov    -0x44(%rbp),%eax
sub    -0x48(%rbp),%eax
add    $0x8,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    13d9 <division+0x269>
mov    -0x14(%rbp),%eax
sub    -0x24(%rbp),%eax
cmp    $0x0,%eax
je     13cb <division+0x25b>
mov    -0x44(%rbp),%eax
sub    -0x48(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x34(%rbp)
jmp    13d4 <division+0x264>
mov    -0x44(%rbp),%eax
sub    -0x48(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    13d9 <division+0x269>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1409 <division+0x299>
lea    -0x80(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1090 <shiftleft@plt>
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    13e0 <division+0x270>
mov    -0x14(%rbp),%eax
sub    -0x24(%rbp),%eax
shl    $0x3,%eax
add    -0x44(%rbp),%eax
sub    -0x48(%rbp),%eax
mov    %eax,-0x40(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x40(%rbp),%eax
jg     14cc <division+0x35c>
mov    -0x3c(%rbp),%esi
lea    -0xa0(%rbp),%rdi
call   1090 <shiftleft@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%ecx
lea    -0x60(%rbp),%rdi
lea    -0x80(%rbp),%rdx
call   1080 <compare@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0xa8(%rbp)
sub    $0x1,%eax
je     1484 <division+0x314>
jmp    146d <division+0x2fd>
mov    -0xa8(%rbp),%eax
add    $0xfffffffe,%eax
sub    $0x2,%eax
jb     1489 <division+0x319>
jmp    14af <division+0x33f>
jmp    14af <division+0x33f>
movzbl -0x8d(%rbp),%eax
or     $0x1,%eax
mov    %al,-0x8d(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x80(%rbp),%rdx
mov    -0x38(%rbp),%ecx
call   1030 <deduct@plt>
mov    %eax,-0x14(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1060 <shiftright@plt>
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1422 <division+0x2b2>
lea    0xb94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xb89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x13,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x13,%ecx
sub    -0x3c(%rbp),%ecx
cmp    %ecx,%eax
jl     153d <division+0x3cd>
movslq -0x28(%rbp),%rax
movzbl -0xa0(%rbp,%rax,1),%esi
ff
mov    -0x2c(%rbp),%edx
lea    0xb57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    14f6 <division+0x386>
lea    0xb24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xb31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x13,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x13,%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jl     15ab <division+0x43b>
movslq -0x28(%rbp),%rax
movzbl -0x60(%rbp,%rax,1),%esi
mov    -0x2c(%rbp),%edx
lea    0xae9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1567 <division+0x3f7>
lea    0xab6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<division>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%rbp
lea    0x50(%rsp),%rdi
mov    $0x14,%esi
call   10a0 <bzero@plt>
lea    0x30(%rsp),%rdi
mov    $0x14,%esi
call   10a0 <bzero@plt>
lea    0x10(%rsp),%rdi
mov    $0x14,%esi
call   10a0 <bzero@plt>
test   %r15d,%r15d
js     120e <division+0x6e>
mov    %r15d,%edx
mov    $0x13,%eax
sub    %rdx,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x30,%rdi
add    %rax,%rbp
add    $0x1,%rdx
mov    %rbp,%rsi
call   1080 <memcpy@plt>
test   %r12d,%r12d
js     1252 <division+0xb2>
mov    %r12d,%edx
mov    $0x13,%eax
sub    %rdx,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
add    %rax,%rbx
add    $0x1,%rdx
mov    %rbx,%rsi
call   1080 <memcpy@plt>
test   %r12d,%r12d
jne    1252 <division+0xb2>
cmpb   $0x0,0x23(%rsp)
jne    1252 <division+0xb2>
lea    0xe22(%rip),%rdi
call   1040 <puts@plt>
jmp    14a5 <division+0x305>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rdx
mov    %r15d,%esi
mov    %r12d,%ecx
call   10b0 <compare@plt>
cmp    $0x3,%eax
je     12d0 <division+0x130>
cmp    $0x1,%eax
jne    12ed <division+0x14d>
lea    0xdd9(%rip),%rdi
call   1040 <puts@plt>
lea    0xddb(%rip),%rdi
call   1040 <puts@plt>
test   %r15d,%r15d
js     14a5 <division+0x305>
lea    0x43(%rsp),%rbx
add    $0x1,%r15d
lea    0xd5e(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx),%esi
mov    %r14,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%ebp
add    $0xffffffffffffffff,%rbx
cmp    %ebp,%r15d
jne    12b0 <division+0x110>
jmp    14a5 <division+0x305>
lea    0xd5d(%rip),%rdi
call   1040 <puts@plt>
lea    0xd5f(%rip),%rdi
call   1040 <puts@plt>
jmp    14a5 <division+0x305>
lea    0x30(%rsp),%rdi
mov    %r15d,%esi
call   1060 <get_highbit@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%rdi
mov    %r12d,%esi
call   1060 <get_highbit@plt>
mov    %r15d,%r14d
sub    %r12d,%r14d
cmp    $0x2,%r14d
mov    %rbx,0x48(%rsp)
jl     1320 <division+0x180>
lea    (%rbx,%r14,8),%r13d
jmp    132b <division+0x18b>
lea    0x8(%rbx),%r13d
test   %r14d,%r14d
cmove  %ebx,%r13d
mov    %eax,0xc(%rsp)
sub    %eax,%r13d
mov    %r12d,%ebp
test   %r13d,%r13d
jle    1362 <division+0x1c2>
lea    0x10(%rsp),%rbx
mov    %r12d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %ebp,%esi
call   10c0 <shiftleft@plt>
mov    %eax,%ebp
add    $0xffffffff,%r13d
jne    1350 <division+0x1b0>
mov    0x48(%rsp),%rcx
lea    (%rcx,%r14,8),%eax
mov    0xc(%rsp),%edx
cmp    %edx,%eax
js     13f4 <division+0x254>
mov    %edx,%eax
lea    (%rcx,%r15,8),%r14d
sub    %edx,%r14d
shl    $0x3,%r12d
sub    %r12d,%r14d
add    $0x1,%r14d
xor    %r12d,%r12d
lea    0x30(%rsp),%rbx
lea    0x10(%rsp),%r13
jmp    13b2 <division+0x212>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %ebp,%esi
call   1090 <shiftright@plt>
mov    %eax,%ebp
add    $0xffffffff,%r14d
je     13f7 <division+0x257>
lea    0x50(%rsp),%rdi
mov    %r12d,%esi
call   10c0 <shiftleft@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r13,%rdx
mov    %ebp,%ecx
call   10b0 <compare@plt>
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    13a0 <division+0x200>
orb    $0x1,0x63(%rsp)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r13,%rdx
mov    %ebp,%ecx
call   1050 <deduct@plt>
mov    %eax,%r15d
jmp    13a0 <division+0x200>
xor    %r12d,%r12d
lea    0xc0f(%rip),%rdi
call   1040 <puts@plt>
lea    0xc05(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
test   %r12d,%r12d
js     144b <division+0x2ab>
lea    0x63(%rsp),%rbx
add    $0x1,%r12d
lea    0xbf5(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%esi
mov    %r14,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%ebp
add    $0xffffffffffffffff,%rbx
cmp    %ebp,%r12d
jne    1430 <division+0x290>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xbcc(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
test   %r15d,%r15d
js     149b <division+0x2fb>
lea    0x43(%rsp),%rbx
add    $0x1,%r15d
lea    0xba3(%rip),%r14
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl (%rbx),%esi
mov    %r14,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%ebp
add    $0xffffffffffffffff,%rbx
cmp    %ebp,%r15d
jne    1480 <division+0x2e0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Please don't let divisor = 0\0A\00"
@.str.1 = [15 x i8] c"quotient is 0\0A\00"
@.str.2 = [12 x i8] c"reminder: \0A\00"
@.str.3 = [15 x i8] c"+ %d * 256^%d\0A\00"
@.str.4 = [15 x i8] c"quotient is 1\0A\00"
@.str.5 = [16 x i8] c"remainder is 0\0A\00"
@.str.6 = [3 x i8] c"\0A\0A\00"
@.str.7 = [12 x i8] c"quotient: \00"
@.str.8 = [13 x i8] c"+ %d *256^%d\00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [12 x i8] c"reminder: \00"
define i32 @division(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%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 [20 x i8]
%20 = alloca [20 x i8]
%21 = alloca [20 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 0, i32* %11
store i32 0, i32* %13
%22 = load i32, i32* %9
store i32 %22, i32* %14
store i32 0, i32* %15
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %21, i64 0, i64 0
%24 = call i32 @bzero(i8* %23, i32 20)
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %19, i64 0, i64 0
%26 = call i32 @bzero(i8* %25, i32 20)
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %20, i64 0, i64 0
%28 = call i32 @bzero(i8* %27, i32 20)
store i32 19, i32* %10
br label %29
29: ; preds = %43, %4
%30 = load i32, i32* %10
%31 = load i32, i32* %7
%32 = sub nsw i32 19, %31
%33 = icmp sge i32 %30, %32
br i1 %33, label %34, label %46
34: ; preds = %29
%35 = load i8*, i8** %6
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %19, i64 0, i64 %41
store i8 %39, i8* %42
br label %43
43: ; preds = %34
%44 = load i32, i32* %10
%45 = add nsw i32 %44, -1
store i32 %45, i32* %10
br label %29
46: ; preds = %29
store i32 19, i32* %10
br label %47
47: ; preds = %61, %46
%48 = load i32, i32* %10
%49 = load i32, i32* %9
%50 = sub nsw i32 19, %49
%51 = icmp sge i32 %48, %50
br i1 %51, label %52, label %64
52: ; preds = %47
%53 = load i8*, i8** %8
%54 = load i32, i32* %10
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [20 x i8], [20 x i8]* %20, i64 0, i64 %59
store i8 %57, i8* %60
br label %61
61: ; preds = %52
%62 = load i32, i32* %10
%63 = add nsw i32 %62, -1
store i32 %63, i32* %10
br label %47
64: ; preds = %47
%65 = getelementptr inbounds [20 x i8], [20 x i8]* %20, i64 0, i64 19
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %74
69: ; preds = %64
%70 = load i32, i32* %9
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %242
74: ; preds = %69, %64
%75 = getelementptr inbounds [20 x i8], [20 x i8]* %19, i64 0, i64 0
%76 = load i32, i32* %7
%77 = getelementptr inbounds [20 x i8], [20 x i8]* %20, i64 0, i64 0
%78 = load i32, i32* %9
%79 = call i32 @compare(i8* %75, i32 %76, i8* %77, i32 %78)
store i32 %79, i32* %12
%80 = load i32, i32* %12
switch i32 %80, label %106 [
i32 1, label %81
i32 3, label %103
]
81: ; preds = %74
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 19, i32* %10
store i32 0, i32* %11
br label %84
84: ; preds = %97, %81
%85 = load i32, i32* %10
%86 = load i32, i32* %7
%87 = sub nsw i32 19, %86
%88 = icmp sge i32 %85, %87
br i1 %88, label %89, label %102
89: ; preds = %84
%90 = load i32, i32* %10
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [20 x i8], [20 x i8]* %19, i64 0, i64 %91
%93 = load i8, i8* %92
%94 = zext i8 %93 to i32
%95 = load i32, i32* %11
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %94, i32 %95)
br label %97
97: ; preds = %89
%98 = load i32, i32* %10
%99 = add nsw i32 %98, -1
store i32 %99, i32* %10
%100 = load i32, i32* %11
%101 = add nsw i32 %100, 1
store i32 %101, i32* %11
br label %84
102: ; preds = %84
store i32 1, i32* %5
br label %242
103: ; preds = %74
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %5
br label %242
106: ; preds = %74
%107 = getelementptr inbounds [20 x i8], [20 x i8]* %19, i64 0, i64 0
%108 = load i32, i32* %7
%109 = call i32 @get_highbit(i8* %107, i32 %108)
store i32 %109, i32* %17
%110 = getelementptr inbounds [20 x i8], [20 x i8]* %20, i64 0, i64 0
%111 = load i32, i32* %9
%112 = call i32 @get_highbit(i8* %110, i32 %111)
store i32 %112, i32* %18
%113 = load i32, i32* %7
%114 = load i32, i32* %9
%115 = sub nsw i32 %113, %114
%116 = icmp sge i32 %115, 2
br i1 %116, label %117, label %129
117: ; preds = %106
%118 = load i32, i32* %7
%119 = load i32, i32* %9
%120 = sub nsw i32 %118, %119
%121 = sub nsw i32 %120, 1
%122 = shl i32 %121, 3
store i32 %122, i32* %13
%123 = load i32, i32* %17
%124 = load i32, i32* %18
%125 = sub nsw i32 %123, %124
%126 = add nsw i32 %125, 8
%127 = load i32, i32* %13
%128 = add nsw i32 %127, %126
store i32 %128, i32* %13
br label %144
129: ; preds = %106
%130 = load i32, i32* %7
%131 = load i32, i32* %9
%132 = sub nsw i32 %130, %131
%133 = icmp ne i32 %132, 0
br i1 %133, label %134, label %139
134: ; preds = %129
%135 = load i32, i32* %17
%136 = load i32, i32* %18
%137 = sub nsw i32 %135, %136
%138 = add nsw i32 %137, 8
store i32 %138, i32* %13
br label %143
139: ; preds = %129
%140 = load i32, i32* %17
%141 = load i32, i32* %18
%142 = sub nsw i32 %140, %141
store i32 %142, i32* %13
br label %143
143: ; preds = %139, %134
br label %144
144: ; preds = %143, %117
store i32 0, i32* %10
br label %145
145: ; preds = %153, %144
%146 = load i32, i32* %10
%147 = load i32, i32* %13
%148 = icmp slt i32 %146, %147
br i1 %148, label %149, label %156
149: ; preds = %145
%150 = getelementptr inbounds [20 x i8], [20 x i8]* %20, i64 0, i64 0
%151 = load i32, i32* %14
%152 = call i32 @shiftleft(i8* %150, i32 %151)
store i32 %152, i32* %14
br label %153
153: ; preds = %149
%154 = load i32, i32* %10
%155 = add nsw i32 %154, 1
store i32 %155, i32* %10
br label %145
156: ; preds = %145
%157 = load i32, i32* %7
%158 = load i32, i32* %9
%159 = sub nsw i32 %157, %158
%160 = shl i32 %159, 3
%161 = load i32, i32* %17
%162 = add nsw i32 %160, %161
%163 = load i32, i32* %18
%164 = sub nsw i32 %162, %163
store i32 %164, i32* %16
store i32 0, i32* %10
br label %165
165: ; preds = %195, %156
%166 = load i32, i32* %10
%167 = load i32, i32* %16
%168 = icmp sle i32 %166, %167
br i1 %168, label %169, label %198
169: ; preds = %165
%170 = getelementptr inbounds [20 x i8], [20 x i8]* %21, i64 0, i64 0
%171 = load i32, i32* %15
%172 = call i32 @shiftleft(i8* %170, i32 %171)
store i32 %172, i32* %15
%173 = getelementptr inbounds [20 x i8], [20 x i8]* %19, i64 0, i64 0
%174 = load i32, i32* %7
%175 = getelementptr inbounds [20 x i8], [20 x i8]* %20, i64 0, i64 0
%176 = load i32, i32* %14
%177 = call i32 @compare(i8* %173, i32 %174, i8* %175, i32 %176)
store i32 %177, i32* %12
%178 = load i32, i32* %12
switch i32 %178, label %191 [
i32 1, label %179
i32 2, label %180
i32 3, label %180
]
179: ; preds = %169
br label %191
180: ; preds = %169, %169
%181 = getelementptr inbounds [20 x i8], [20 x i8]* %21, i64 0, i64 19
%182 = load i8, i8* %181
%183 = zext i8 %182 to i32
%184 = or i32 %183, 1
%185 = trunc i32 %184 to i8
store i8 %185, i8* %181
%186 = getelementptr inbounds [20 x i8], [20 x i8]* %19, i64 0, i64 0
%187 = load i32, i32* %7
%188 = getelementptr inbounds [20 x i8], [20 x i8]* %20, i64 0, i64 0
%189 = load i32, i32* %14
%190 = call i32 @deduct(i8* %186, i32 %187, i8* %188, i32 %189)
store i32 %190, i32* %7
br label %191
191: ; preds = %169, %180, %179
%192 = getelementptr inbounds [20 x i8], [20 x i8]* %20, i64 0, i64 0
%193 = load i32, i32* %14
%194 = call i32 @shiftright(i8* %192, i32 %193)
store i32 %194, i32* %14
br label %195
195: ; preds = %191
%196 = load i32, i32* %10
%197 = add nsw i32 %196, 1
store i32 %197, i32* %10
br label %165
198: ; preds = %165
%199 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%200 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
store i32 19, i32* %10
store i32 0, i32* %11
br label %201
201: ; preds = %214, %198
%202 = load i32, i32* %10
%203 = load i32, i32* %15
%204 = sub nsw i32 19, %203
%205 = icmp sge i32 %202, %204
br i1 %205, label %206, label %219
206: ; preds = %201
%207 = load i32, i32* %10
%208 = sext i32 %207 to i64
%209 = getelementptr inbounds [20 x i8], [20 x i8]* %21, i64 0, i64 %208
%210 = load i8, i8* %209
%211 = zext i8 %210 to i32
%212 = load i32, i32* %11
%213 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %211, i32 %212)
br label %214
214: ; preds = %206
%215 = load i32, i32* %10
%216 = add nsw i32 %215, -1
store i32 %216, i32* %10
%217 = load i32, i32* %11
%218 = add nsw i32 %217, 1
store i32 %218, i32* %11
br label %201
219: ; preds = %201
%220 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%221 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
store i32 19, i32* %10
store i32 0, i32* %11
br label %222
222: ; preds = %235, %219
%223 = load i32, i32* %10
%224 = load i32, i32* %7
%225 = sub nsw i32 19, %224
%226 = icmp sge i32 %223, %225
br i1 %226, label %227, label %240
227: ; preds = %222
%228 = load i32, i32* %10
%229 = sext i32 %228 to i64
%230 = getelementptr inbounds [20 x i8], [20 x i8]* %19, i64 0, i64 %229
%231 = load i8, i8* %230
%232 = zext i8 %231 to i32
%233 = load i32, i32* %11
%234 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %232, i32 %233)
br label %235
235: ; preds = %227
%236 = load i32, i32* %10
%237 = add nsw i32 %236, -1
store i32 %237, i32* %10
%238 = load i32, i32* %11
%239 = add nsw i32 %238, 1
store i32 %239, i32* %11
br label %222
240: ; preds = %222
%241 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %5
br label %242
242: ; preds = %240, %103, %102, %72
%243 = load i32, i32* %5
ret i32 %243
}

LLVM IR (-O2):
@.str.3 = [15 x i8] c"+ %d * 256^%d\0A\00"
@.str.7 = [12 x i8] c"quotient: \00"
@.str.8 = [13 x i8] c"+ %d *256^%d\00"
@.str.10 = [12 x i8] c"reminder: \00"
@str = [14 x i8] c"quotient is 1\00"
@str.11 = [15 x i8] c"remainder is 0\00"
@str.12 = [14 x i8] c"quotient is 0\00"
@str.13 = [11 x i8] c"reminder: \00"
@str.14 = [2 x i8] c"\0A\00"
@str.15 = [29 x i8] c"Please don't let divisor = 0\00"
define i32 @division(i8* nocapture %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = alloca [20 x i8]
%6 = alloca [20 x i8]
%7 = alloca [20 x i8]
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%11 = call i32 @bzero(i8* %10, i32 20)
%12 = call i32 @bzero(i8* %8, i32 20)
%13 = call i32 @bzero(i8* %9, i32 20)
%14 = icmp slt i32 %1, 0
br i1 %14, label %21, label %15
15: ; preds = %4
%16 = zext i32 %1 to i64
%17 = sub nsw i64 19, %16
%18 = getelementptr [20 x i8], [20 x i8]* %5, i64 0, i64 %17
%19 = getelementptr i8, i8* %0, i64 %17
%20 = add nuw nsw i64 %16, 1
br label %21
21: ; preds = %15, %4
%22 = icmp slt i32 %3, 0
br i1 %22, label %36, label %23
23: ; preds = %21
%24 = zext i32 %3 to i64
%25 = sub nsw i64 19, %24
%26 = getelementptr [20 x i8], [20 x i8]* %6, i64 0, i64 %25
%27 = getelementptr i8, i8* %2, i64 %25
%28 = add nuw nsw i64 %24, 1
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 19
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
%32 = icmp eq i32 %3, 0
%33 = and i1 %32, %31
br i1 %33, label %34, label %36
34: ; preds = %23
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.15, i64 0, i64 0))
br label %140
36: ; preds = %21, %23
%37 = call i32 @compare(i8* %8, i32 %1, i8* %9, i32 %3)
switch i32 %37, label %54 [
i32 1, label %38
i32 3, label %51
]
38: ; preds = %36
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.12, i64 0, i64 0))
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.13, i64 0, i64 0))
br i1 %14, label %140, label %41
41: ; preds = %38, %41
%42 = phi i64 [ %48, %41 ], [ 19, %38 ]
%43 = phi i32 [ %49, %41 ], [ 0, %38 ]
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %42
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %43)
%48 = add nsw i64 %42, -1
%49 = add nuw i32 %43, 1
%50 = icmp eq i32 %43, %1
br i1 %50, label %140, label %41
51: ; preds = %36
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.11, i64 0, i64 0))
br label %140
54: ; preds = %36
%55 = call i32 @get_highbit(i8* %8, i32 %1)
%56 = call i32 @get_highbit(i8* %9, i32 %3)
%57 = sub nsw i32 %1, %3
%58 = icmp sgt i32 %57, 1
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = shl i32 %57, 3
%61 = add i32 %55, %60
br label %66
62: ; preds = %54
%63 = icmp eq i32 %57, 0
%64 = add i32 %55, 8
%65 = select i1 %63, i32 %55, i32 %64
br label %66
66: ; preds = %62, %59
%67 = phi i32 [ %61, %59 ], [ %65, %62 ]
%68 = sub i32 %67, %56
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %76
70: ; preds = %66, %70
%71 = phi i32 [ %74, %70 ], [ 0, %66 ]
%72 = phi i32 [ %73, %70 ], [ %3, %66 ]
%73 = call i32 @shiftleft(i8* %9, i32 %72)
%74 = add nuw nsw i32 %71, 1
%75 = icmp eq i32 %74, %68
br i1 %75, label %76, label %70
76: ; preds = %70, %66
%77 = phi i32 [ %3, %66 ], [ %73, %70 ]
%78 = shl i32 %57, 3
%79 = add nsw i32 %55, %78
%80 = sub i32 %79, %56
%81 = icmp slt i32 %80, 0
br i1 %81, label %108, label %82
82: ; preds = %76
%83 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 19
%84 = shl i32 %1, 3
%85 = add i32 %55, %84
%86 = add i32 %85, 1
%87 = sub i32 %86, %56
%88 = mul i32 %3, -8
%89 = add i32 %88, %87
br label %90
90: ; preds = %82, %103
%91 = phi i32 [ %1, %82 ], [ %104, %103 ]
%92 = phi i32 [ 0, %82 ], [ %106, %103 ]
%93 = phi i32 [ 0, %82 ], [ %95, %103 ]
%94 = phi i32 [ %77, %82 ], [ %105, %103 ]
%95 = call i32 @shiftleft(i8* %10, i32 %93)
%96 = call i32 @compare(i8* %8, i32 %91, i8* %9, i32 %94)
%97 = and i32 %96, -2
%98 = icmp eq i32 %97, 2
br i1 %98, label %99, label %103
99: ; preds = %90
%100 = load i8, i8* %83
%101 = or i8 %100, 1
store i8 %101, i8* %83
%102 = call i32 @deduct(i8* %8, i32 %91, i8* %9, i32 %94)
br label %103
103: ; preds = %90, %99
%104 = phi i32 [ %91, %90 ], [ %102, %99 ]
%105 = call i32 @shiftright(i8* %9, i32 %94)
%106 = add nuw i32 %92, 1
%107 = icmp eq i32 %106, %89
br i1 %107, label %108, label %90
108: ; preds = %103, %76
%109 = phi i32 [ 0, %76 ], [ %95, %103 ]
%110 = phi i32 [ %1, %76 ], [ %104, %103 ]
%111 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.14, i64 0, i64 0))
%112 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%113 = icmp slt i32 %109, 0
br i1 %113, label %124, label %114
114: ; preds = %108, %114
%115 = phi i64 [ %121, %114 ], [ 19, %108 ]
%116 = phi i32 [ %122, %114 ], [ 0, %108 ]
%117 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 %115
%118 = load i8, i8* %117
%119 = zext i8 %118 to i32
%120 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %119, i32 %116)
%121 = add nsw i64 %115, -1
%122 = add nuw i32 %116, 1
%123 = icmp eq i32 %116, %109
br i1 %123, label %124, label %114
124: ; preds = %114, %108
%125 = call i32 @putchar(i32 10)
%126 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%127 = icmp slt i32 %110, 0
br i1 %127, label %138, label %128
128: ; preds = %124, %128
%129 = phi i64 [ %135, %128 ], [ 19, %124 ]
%130 = phi i32 [ %136, %128 ], [ 0, %124 ]
%131 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %129
%132 = load i8, i8* %131
%133 = zext i8 %132 to i32
%134 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i32 %133, i32 %130)
%135 = add nsw i64 %129, -1
%136 = add nuw i32 %130, 1
%137 = icmp eq i32 %130, %110
br i1 %137, label %138, label %128
138: ; preds = %128, %124
%139 = call i32 @putchar(i32 10)
br label %140
140: ; preds = %41, %38, %138, %51, %34
ret i32 1
}