#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 IntLength(int);
int IntPower(int, int);
char *IntToCharArray(int x) {
  int z, e, i, a, b, c, d;
  z = x;
  d = IntPower(10, IntLength(x) - 1);
  static char ch[10];
  e = IntLength(x);
  for (i = 0; i < e; i++) {
    a = x % d;
    b = x - a;
    c = b / d;
    d = d / 10;
    ch[i] = '0' + c;
    x = a;
  }
  return ch;
}


x86 assembly (clang, -O0):
<IntToCharArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <IntLength@plt>
mov    %eax,%esi
sub    $0x1,%esi
mov    $0xa,%edi
call   1040 <IntPower@plt>
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <IntLength@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11be <IntToCharArray+0x9e>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%eax
mov    %al,%dl
movslq -0x10(%rbp),%rcx
lea    0x2e8a(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115d <IntToCharArray+0x3d>
lea    0x2e6c(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IntToCharArray>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1030 <IntLength@plt>
lea    -0x1(%rax),%esi
mov    $0xa,%edi
call   1040 <IntPower@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <IntLength@plt>
test   %eax,%eax
jle    117c <IntToCharArray+0x5c>
mov    %eax,%ecx
xor    %esi,%esi
lea    0x2ee2(%rip),%rdi
nop
mov    %ebp,%eax
cltd
idiv   %ebx
movslq %ebx,%rbp
imul   $0x66666667,%rbp,%rbx
mov    %rbx,%rbp
shr    $0x3f,%rbp
sar    $0x22,%rbx
add    %ebp,%ebx
add    $0x30,%al
mov    %al,(%rsi,%rdi,1)
add    $0x1,%rsi
mov    %edx,%ebp
cmp    %rsi,%rcx
jne    1150 <IntToCharArray+0x30>
lea    0x2eae(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@IntToCharArray.ch = internal global [10 x i8] zeroinitializer
define i8* @IntToCharArray(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %2
%10 = load i32, i32* %2
store i32 %10, i32* %3
%11 = load i32, i32* %2
%12 = call i32 @IntLength(i32 %11)
%13 = sub nsw i32 %12, 1
%14 = call i32 @IntPower(i32 10, i32 %13)
store i32 %14, i32* %9
%15 = load i32, i32* %2
%16 = call i32 @IntLength(i32 %15)
store i32 %16, i32* %4
store i32 0, i32* %5
br label %17
17: ; preds = %40, %1
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %43
21: ; preds = %17
%22 = load i32, i32* %2
%23 = load i32, i32* %9
%24 = srem i32 %22, %23
store i32 %24, i32* %6
%25 = load i32, i32* %2
%26 = load i32, i32* %6
%27 = sub nsw i32 %25, %26
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = load i32, i32* %9
%30 = sdiv i32 %28, %29
store i32 %30, i32* %8
%31 = load i32, i32* %9
%32 = sdiv i32 %31, 10
store i32 %32, i32* %9
%33 = load i32, i32* %8
%34 = add nsw i32 48, %33
%35 = trunc i32 %34 to i8
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [10 x i8], [10 x i8]* @IntToCharArray.ch, i64 0, i64 %37
store i8 %35, i8* %38
%39 = load i32, i32* %6
store i32 %39, i32* %2
br label %40
40: ; preds = %21
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %17
43: ; preds = %17
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @IntToCharArray.ch, i64 0, i64 0)
}

LLVM IR (-O2):
@IntToCharArray.ch = internal global [10 x i8] zeroinitializer
define i8* @IntToCharArray(i32 %0) {
%2 = tail call i32 @IntLength(i32 %0)
%3 = add nsw i32 %2, -1
%4 = tail call i32 @IntPower(i32 10, i32 %3)
%5 = tail call i32 @IntLength(i32 %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %1
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %19, %9 ]
%11 = phi i32 [ %4, %7 ], [ %15, %9 ]
%12 = phi i32 [ %0, %7 ], [ %13, %9 ]
%13 = srem i32 %12, %11
%14 = sdiv i32 %12, %11
%15 = sdiv i32 %11, 10
%16 = trunc i32 %14 to i8
%17 = add i8 %16, 48
%18 = getelementptr inbounds [10 x i8], [10 x i8]* @IntToCharArray.ch, i64 0, i64 %10
store i8 %17, i8* %18
%19 = add nuw nsw i64 %10, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %21, label %9
21: ; preds = %9, %1
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @IntToCharArray.ch, i64 0, i64 0)
}