#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_puti(char *buffer, int num) {
  unsigned int divisor;
  unsigned int current;
  unsigned int remainder;
  unsigned int found;
  if (num < 0) {
    bufcon_putc(buffer, '-');
    current = -num;
  } else
    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_puti>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1144 <bufcon_puti+0x34>
mov    -0x8(%rbp),%rdi
mov    $0x2d,%esi
call   1030 <bufcon_putc@plt>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    114a <bufcon_puti+0x3a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x3b9aca00,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x10(%rbp)
jbe    11bc <bufcon_puti+0xac>
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     1189 <bufcon_puti+0x79>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11a2 <bufcon_puti+0x92>
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    1158 <bufcon_puti+0x48>
cmpl   $0x0,-0x1c(%rbp)
jne    11d5 <bufcon_puti+0xc5>
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_puti>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
test   %esi,%esi
jns    1133 <bufcon_puti+0x23>
mov    %r14,%rdi
mov    $0x2d,%esi
call   1030 <bufcon_putc@plt>
neg    %ebp
mov    $0x3b9aca00,%ebx
xor    %r12d,%r12d
mov    $0x1,%r13d
jmp    1167 <bufcon_puti+0x57>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0xa,%ebx
jb     118f <bufcon_puti+0x7f>
mov    %ebx,%ebx
mov    $0xcccccccd,%eax
imul   %rax,%rbx
shr    $0x23,%rbx
mov    %r15d,%ebp
mov    %ebp,%eax
xor    %edx,%edx
div    %ebx
mov    %edx,%r15d
cmp    %ebp,%ebx
cmovbe %r13d,%r12d
test   %r12d,%r12d
je     1150 <bufcon_puti+0x40>
add    $0x30,%eax
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <bufcon_putc@plt>
cmp    $0xa,%ebx
jae    1155 <bufcon_puti+0x45>
jmp    119c <bufcon_puti+0x8c>
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_puti(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
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @bufcon_putc(i8* %12, i32 45)
%14 = load i32, i32* %4
%15 = sub nsw i32 0, %14
store i32 %15, i32* %6
br label %18
16: ; preds = %2
%17 = load i32, i32* %4
store i32 %17, i32* %6
br label %18
18: ; preds = %16, %11
store i32 1000000000, i32* %5
store i32 0, i32* %8
br label %19
19: ; preds = %40, %18
%20 = load i32, i32* %5
%21 = icmp ugt i32 %20, 0
br i1 %21, label %22, label %44
22: ; preds = %19
%23 = load i32, i32* %6
%24 = load i32, i32* %5
%25 = urem i32 %23, %24
store i32 %25, i32* %7
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = udiv i32 %26, %27
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %22
store i32 1, i32* %8
br label %32
32: ; preds = %31, %22
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i8*, i8** %3
%37 = load i32, i32* %6
%38 = add i32 %37, 48
%39 = call i32 @bufcon_putc(i8* %36, i32 %38)
br label %40
40: ; preds = %35, %32
%41 = load i32, i32* %5
%42 = udiv i32 %41, 10
store i32 %42, i32* %5
%43 = load i32, i32* %7
store i32 %43, i32* %6
br label %19
44: ; preds = %19
%45 = load i32, i32* %8
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %44
%48 = load i8*, i8** %3
%49 = load i32, i32* %6
%50 = add i32 %49, 48
%51 = call i32 @bufcon_putc(i8* %48, i32 %50)
br label %52
52: ; preds = %47, %44
%53 = load i8*, i8** %3
ret i8* %53
}

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