#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 */
scalar_t__ isdigit(int);
scalar_t__ pow(int, int);
int convertToStringFromNumber(int num, char str[]) {
  int i;
  for (i = 0;; ++i)
    if (!(num / (int)pow(10, i)))
      break;
  if (num == 0) {
    str[0] = '0';
    str[1] = '\0';
    return 1;
  }
  if (isdigit(num % 10)) {
    str[i - 1] = '0' + (num % 10);
  }
  if (num / 10 == 0)
    return 0;
  convertToStringFromNumber(num / 10, str);
  return i;
}


x86 assembly (clang, -O0):
<convertToStringFromNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%eax
cltd
idiv   %ecx
cmp    $0x0,%eax
jne    1170 <convertToStringFromNumber+0x40>
jmp    1183 <convertToStringFromNumber+0x53>
jmp    1175 <convertToStringFromNumber+0x45>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <convertToStringFromNumber+0x16>
cmpl   $0x0,-0x8(%rbp)
jne    11a8 <convertToStringFromNumber+0x78>
mov    -0x10(%rbp),%rax
movb   $0x30,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
movl   $0x1,-0x4(%rbp)
jmp    121e <convertToStringFromNumber+0xee>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e2 <convertToStringFromNumber+0xb2>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
jne    1202 <convertToStringFromNumber+0xd2>
movl   $0x0,-0x4(%rbp)
jmp    121e <convertToStringFromNumber+0xee>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <convertToStringFromNumber@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertToStringFromNumber>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
mov    %edi,%ebp
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0xa,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
mov    %rax,%rcx
mov    %ebp,%eax
cltd
idiv   %ecx
add    $0x1,%rbx
test   %eax,%eax
jne    1150 <convertToStringFromNumber+0x30>
test   %ebp,%ebp
je     11d1 <convertToStringFromNumber+0xb1>
movslq %ebp,%rax
imul   $0x66666667,%rax,%r14
mov    %r14,%rax
shr    $0x3f,%rax
sar    $0x22,%r14
add    %eax,%r14d
lea    (%r14,%r14,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ebp,%r15d
sub    %eax,%r15d
mov    %r15d,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11af <convertToStringFromNumber+0x8f>
add    $0x30,%r15b
mov    (%rsp),%rax
mov    %r15b,-0x2(%rax,%rbx,1)
add    $0x9,%ebp
cmp    $0x13,%ebp
jb     11e1 <convertToStringFromNumber+0xc1>
add    $0xffffffffffffffff,%rbx
test   $0x1,%r12b
cmovne %r13d,%ebx
mov    $0x1,%r12b
mov    %r14d,%ebp
mov    %ebx,%r13d
jmp    1140 <convertToStringFromNumber+0x20>
mov    (%rsp),%rax
movw   $0x30,(%rax)
mov    $0x1,%eax
jmp    11e3 <convertToStringFromNumber+0xc3>
xor    %eax,%eax
test   $0x1,%r12b
cmovne %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @convertToStringFromNumber(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %7
7: ; preds = %16, %2
%8 = load i32, i32* %4
%9 = load i32, i32* %6
%10 = call i64 @pow(i32 10, i32 %9)
%11 = trunc i64 %10 to i32
%12 = sdiv i32 %8, %11
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %7
br label %19
15: ; preds = %7
br label %16
16: ; preds = %15
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %6
br label %7
19: ; preds = %14
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 48, i8* %24
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8 0, i8* %26
store i32 1, i32* %3
br label %53
27: ; preds = %19
%28 = load i32, i32* %4
%29 = srem i32 %28, 10
%30 = call i64 @isdigit(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %27
%33 = load i32, i32* %4
%34 = srem i32 %33, 10
%35 = add nsw i32 48, %34
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %5
%38 = load i32, i32* %6
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 %36, i8* %41
br label %42
42: ; preds = %32, %27
%43 = load i32, i32* %4
%44 = sdiv i32 %43, 10
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 0, i32* %3
br label %53
47: ; preds = %42
%48 = load i32, i32* %4
%49 = sdiv i32 %48, 10
%50 = load i8*, i8** %5
%51 = call i32 @convertToStringFromNumber(i32 %49, i8* %50)
%52 = load i32, i32* %6
store i32 %52, i32* %3
br label %53
53: ; preds = %47, %46, %22
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
define i32 @convertToStringFromNumber(i32 %0, i8* nocapture writeonly %1) {
br label %3
3: ; preds = %32, %2
%4 = phi i32 [ %0, %2 ], [ %20, %32 ]
%5 = phi i32 [ undef, %2 ], [ %33, %32 ]
%6 = phi i1 [ false, %2 ], [ true, %32 ]
br label %7
7: ; preds = %7, %3
%8 = phi i32 [ 0, %3 ], [ %13, %7 ]
%9 = tail call i64 @pow(i32 10, i32 %8)
%10 = trunc i64 %9 to i32
%11 = sdiv i32 %4, %10
%12 = icmp eq i32 %11, 0
%13 = add nuw nsw i32 %8, 1
br i1 %12, label %14, label %7
14: ; preds = %7
%15 = icmp eq i32 %4, 0
br i1 %15, label %16, label %18
16: ; preds = %14
store i8 48, i8* %1
%17 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %17
br label %34
18: ; preds = %14
%19 = srem i32 %4, 10
%20 = sdiv i32 %4, 10
%21 = tail call i64 @isdigit(i32 %19)
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %18
%24 = trunc i32 %19 to i8
%25 = add nsw i8 %24, 48
%26 = add nsw i32 %8, -1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %1, i64 %27
store i8 %25, i8* %28
br label %29
29: ; preds = %23, %18
%30 = add i32 %4, 9
%31 = icmp ult i32 %30, 19
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = select i1 %6, i32 %5, i32 %8
br label %3
34: ; preds = %29, %16
%35 = phi i32 [ 1, %16 ], [ 0, %29 ]
%36 = select i1 %6, i32 %5, i32 %35
ret i32 %36
}