#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 pow(int, int);
int /*<<< orphan*/ slog(int, char *);
char *cbase_itoa(int num) {
  int i;
  static char cha[64] = "0";
  if (num == 0)
    return cha;
  int tmp = num;
  int digits = 0;
  while ((int)(num / pow(10, digits)))
    ++digits;
  if (digits > 64)
    slog(0x04, "cbase: number to large.\n");
  for (i = 0; i < digits; ++i) {
    cha[digits - i - 1] = tmp % 10 + '0';
    tmp /= 10;
  }
  cha[digits] = '\0';
  return cha;
}


x86 assembly (clang, -O0):
<cbase_itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1145 <cbase_itoa+0x25>
lea    0x2f04(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    120c <cbase_itoa+0xec>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
mov    $0xa,%edi
call   1040 <pow@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cltd
idiv   %ecx
cmp    $0x0,%eax
je     1184 <cbase_itoa+0x64>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1152 <cbase_itoa+0x32>
cmpl   $0x40,-0x18(%rbp)
jle    119f <cbase_itoa+0x7f>
mov    $0x4,%edi
lea    0xe66(%rip),%rsi
call   1030 <slog@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11f2 <cbase_itoa+0xd2>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x18(%rbp),%eax
sub    -0x10(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e6d(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a6 <cbase_itoa+0x86>
movslq -0x18(%rbp),%rcx
lea    0x2e43(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e38(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cbase_itoa>:
test   %edi,%edi
je     11da <cbase_itoa+0xba>
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0xffffffffffffffff,%r14
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r14
mov    $0xa,%edi
mov    %r14d,%esi
call   1040 <pow@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
test   %eax,%eax
jne    1140 <cbase_itoa+0x20>
cmp    $0x41,%r14d
jb     1175 <cbase_itoa+0x55>
lea    0xe97(%rip),%rsi
mov    $0x4,%edi
call   1030 <slog@plt>
jmp    117a <cbase_itoa+0x5a>
test   %r14d,%r14d
je     11c4 <cbase_itoa+0xa4>
lea    0x1(%r14),%rax
lea    0x2ebb(%rip),%rcx
mov    %r14,%rdx
nopl   0x0(%rax,%rax,1)
movslq %ebx,%rsi
imul   $0x66666667,%rsi,%rbx
mov    %rbx,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rbx
add    %edi,%ebx
lea    (%rbx,%rbx,1),%edi
lea    (%rdi,%rdi,4),%edi
sub    %edi,%esi
add    $0x30,%sil
mov    %sil,-0x2(%rax,%rcx,1)
add    $0xffffffffffffffff,%rax
add    $0xffffffffffffffff,%rdx
jne    1190 <cbase_itoa+0x70>
jmp    11c7 <cbase_itoa+0xa7>
xor    %r14d,%r14d
lea    0x2e72(%rip),%rax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
lea    0x2e5f(%rip),%rax
ret

LLVM IR (-O0):
@cbase_itoa.cha = internal global [64 x i8] c"0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [25 x i8] c"cbase: number to large.\0A\00"
define i8* @cbase_itoa(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* getelementptr inbounds ([64 x i8], [64 x i8]* @cbase_itoa.cha, i64 0, i64 0), i8** %2
br label %51
10: ; preds = %1
%11 = load i32, i32* %3
store i32 %11, i32* %5
store i32 0, i32* %6
br label %12
12: ; preds = %18, %10
%13 = load i32, i32* %3
%14 = load i32, i32* %6
%15 = call i32 @pow(i32 10, i32 %14)
%16 = sdiv i32 %13, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %12
21: ; preds = %12
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 64
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @slog(i32 4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
store i32 0, i32* %4
br label %27
27: ; preds = %44, %26
%28 = load i32, i32* %4
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %47
31: ; preds = %27
%32 = load i32, i32* %5
%33 = srem i32 %32, 10
%34 = add nsw i32 %33, 48
%35 = trunc i32 %34 to i8
%36 = load i32, i32* %6
%37 = load i32, i32* %4
%38 = sub nsw i32 %36, %37
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [64 x i8], [64 x i8]* @cbase_itoa.cha, i64 0, i64 %40
store i8 %35, i8* %41
%42 = load i32, i32* %5
%43 = sdiv i32 %42, 10
store i32 %43, i32* %5
br label %44
44: ; preds = %31
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %27
47: ; preds = %27
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [64 x i8], [64 x i8]* @cbase_itoa.cha, i64 0, i64 %49
store i8 0, i8* %50
store i8* getelementptr inbounds ([64 x i8], [64 x i8]* @cbase_itoa.cha, i64 0, i64 0), i8** %2
br label %51
51: ; preds = %47, %9
%52 = load i8*, i8** %2
ret i8* %52
}

LLVM IR (-O2):
@cbase_itoa.cha = internal global [64 x i8] c"0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [25 x i8] c"cbase: number to large.\0A\00"
define i8* @cbase_itoa(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %33, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %8, %3 ], [ 0, %1 ]
%5 = tail call i32 @pow(i32 10, i32 %4)
%6 = sdiv i32 %0, %5
%7 = icmp eq i32 %6, 0
%8 = add nuw nsw i32 %4, 1
br i1 %7, label %9, label %3
9: ; preds = %3
%10 = icmp ugt i32 %4, 64
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 @slog(i32 4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %15
13: ; preds = %9
%14 = icmp eq i32 %4, 0
br i1 %14, label %30, label %15
15: ; preds = %11, %13
%16 = zext i32 %4 to i64
%17 = zext i32 %4 to i64
br label %18
18: ; preds = %15, %18
%19 = phi i64 [ 0, %15 ], [ %28, %18 ]
%20 = phi i32 [ %0, %15 ], [ %27, %18 ]
%21 = srem i32 %20, 10
%22 = trunc i32 %21 to i8
%23 = add nsw i8 %22, 48
%24 = xor i64 %19, -1
%25 = add nsw i64 %16, %24
%26 = getelementptr inbounds [64 x i8], [64 x i8]* @cbase_itoa.cha, i64 0, i64 %25
store i8 %23, i8* %26
%27 = sdiv i32 %20, 10
%28 = add nuw nsw i64 %19, 1
%29 = icmp eq i64 %28, %17
br i1 %29, label %30, label %18
30: ; preds = %18, %13
%31 = phi i64 [ 0, %13 ], [ %17, %18 ]
%32 = getelementptr inbounds [64 x i8], [64 x i8]* @cbase_itoa.cha, i64 0, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %1, %30
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @cbase_itoa.cha, i64 0, i64 0)
}