#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*/ bufcon_putc(char *, unsigned int);
char *bufcon_putui(char *buffer, unsigned int num) {
  unsigned int divisor;
  unsigned int current;
  unsigned int remainder;
  unsigned int found;
  current = num;
  divisor = 1000000000;
  found = 0;
  while (divisor > 0) {
    remainder = current % divisor;
    current = current / divisor;
    if (current != 0)
      found = 1;
    if (found != 0)
      bufcon_putc(buffer, current + '0');
    divisor = divisor / 10;
    current = remainder;
  }
  if (found == 0)
    bufcon_putc(buffer, current + '0');
  return buffer;
}


x86 assembly (clang, -O0):
<bufcon_putui>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x3b9aca00,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x10(%rbp)
jbe    1197 <bufcon_putui+0x87>
mov    -0x14(%rbp),%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1164 <bufcon_putui+0x54>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     117d <bufcon_putui+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x30,%esi
call   1030 <bufcon_putc@plt>
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1133 <bufcon_putui+0x23>
cmpl   $0x0,-0x1c(%rbp)
jne    11b0 <bufcon_putui+0xa0>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x30,%esi
call   1030 <bufcon_putc@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufcon_putui>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x3b9aca00,%ebx
xor    %ebp,%ebp
mov    $0x1,%r12d
mov    $0xcccccccd,%r13d
jmp    1152 <bufcon_putui+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0xa,%ebx
jb     1179 <bufcon_putui+0x69>
mov    %ebx,%ebx
imul   %r13,%rbx
shr    $0x23,%rbx
mov    %r15d,%esi
mov    %esi,%eax
xor    %edx,%edx
div    %ebx
mov    %edx,%r15d
cmp    %esi,%ebx
cmovbe %r12d,%ebp
test   %ebp,%ebp
je     1140 <bufcon_putui+0x30>
add    $0x30,%eax
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <bufcon_putc@plt>
cmp    $0xa,%ebx
jae    1145 <bufcon_putui+0x35>
jmp    1186 <bufcon_putui+0x76>
mov    %r14,%rdi
mov    $0x30,%esi
call   1030 <bufcon_putc@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @bufcon_putui(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
store i32 %9, i32* %6
store i32 1000000000, i32* %5
store i32 0, i32* %8
br label %10
10: ; preds = %31, %2
%11 = load i32, i32* %5
%12 = icmp ugt i32 %11, 0
br i1 %12, label %13, label %35
13: ; preds = %10
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = urem i32 %14, %15
store i32 %16, i32* %7
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = udiv i32 %17, %18
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 1, i32* %8
br label %23
23: ; preds = %22, %13
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i8*, i8** %3
%28 = load i32, i32* %6
%29 = add i32 %28, 48
%30 = call i32 @bufcon_putc(i8* %27, i32 %29)
br label %31
31: ; preds = %26, %23
%32 = load i32, i32* %5
%33 = udiv i32 %32, 10
store i32 %33, i32* %5
%34 = load i32, i32* %7
store i32 %34, i32* %6
br label %10
35: ; preds = %10
%36 = load i32, i32* %8
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = load i8*, i8** %3
%40 = load i32, i32* %6
%41 = add i32 %40, 48
%42 = call i32 @bufcon_putc(i8* %39, i32 %41)
br label %43
43: ; preds = %38, %35
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
define i8* @bufcon_putui(i8* returned %0, i32 %1) {
br label %3
3: ; preds = %14, %2
%4 = phi i32 [ 0, %2 ], [ %10, %14 ]
%5 = phi i32 [ 1000000000, %2 ], [ %15, %14 ]
%6 = phi i32 [ %1, %2 ], [ %7, %14 ]
%7 = urem i32 %6, %5
%8 = udiv i32 %6, %5
%9 = icmp ugt i32 %5, %6
%10 = select i1 %9, i32 %4, i32 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = icmp ult i32 %5, 10
br i1 %13, label %20, label %14
14: ; preds = %12, %16
%15 = udiv i32 %5, 10
br label %3
16: ; preds = %3
%17 = add i32 %8, 48
%18 = tail call i32 @bufcon_putc(i8* %0, i32 %17)
%19 = icmp ult i32 %5, 10
br i1 %19, label %22, label %14
20: ; preds = %12
%21 = tail call i32 @bufcon_putc(i8* %0, i32 48)
br label %22
22: ; preds = %16, %20
ret i8* %0
}