#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*/ inttoa(int, char *, int);
char *intoa(int i) {
  int c, d = 1;
  for (c = 0; i / d; c++) {
    d *= 10;
  }
  static char s[100];
  inttoa(i, s, c - 1);
  s[c] = '\0';
  return s;
}


x86 assembly (clang, -O0):
<intoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%eax
je     114e <intoa+0x3e>
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <intoa+0x19>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
lea    0x2ee2(%rip),%rsi
call   1030 <inttoa@plt>
movslq -0x8(%rbp),%rcx
lea    0x2ed2(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ec7(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intoa>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %edi,%edi
je     1131 <intoa+0x21>
mov    $0x1,%ecx
nop
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
add    $0x1,%ebx
mov    %edi,%eax
cltd
idiv   %ecx
test   %eax,%eax
jne    1120 <intoa+0x10>
lea    -0x1(%rbx),%edx
lea    0x2f05(%rip),%r14
mov    %r14,%rsi
call   1030 <inttoa@plt>
mov    %ebx,%eax
movb   $0x0,(%rax,%r14,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@intoa.s = internal global [100 x i8] zeroinitializer
define i8* @intoa(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %4
store i32 0, i32* %3
br label %5
5: ; preds = %13, %1
%6 = load i32, i32* %2
%7 = load i32, i32* %4
%8 = sdiv i32 %6, %7
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = load i32, i32* %4
%12 = mul nsw i32 %11, 10
store i32 %12, i32* %4
br label %13
13: ; preds = %10
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %5
16: ; preds = %5
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 1
%20 = call i32 @inttoa(i32 %17, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @intoa.s, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x i8], [100 x i8]* @intoa.s, i64 0, i64 %22
store i8 0, i8* %23
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @intoa.s, i64 0, i64 0)
}

LLVM IR (-O2):
@intoa.s = internal global [100 x i8] zeroinitializer
define i8* @intoa(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %10, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %6, %3 ], [ 1, %1 ]
%5 = phi i32 [ %7, %3 ], [ 0, %1 ]
%6 = mul nuw nsw i32 %4, 10
%7 = add nuw nsw i32 %5, 1
%8 = sdiv i32 %0, %6
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %3
10: ; preds = %3, %1
%11 = phi i32 [ 0, %1 ], [ %7, %3 ]
%12 = add nsw i32 %11, -1
%13 = tail call i32 @inttoa(i32 %0, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @intoa.s, i64 0, i64 0), i32 %12)
%14 = zext i32 %11 to i64
%15 = getelementptr inbounds [100 x i8], [100 x i8]* @intoa.s, i64 0, i64 %14
store i8 0, i8* %15
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @intoa.s, i64 0, i64 0)
}