#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*/ clear_ndigits(unsigned char *);
void split_digits(int n, unsigned char *a) {
  int i;
  unsigned char digit;
  clear_ndigits(a);
  for (i = 0; i < 10; i++) {
    digit = n % 10;
    a[i] = digit;
    n = (n - digit) / 10;
  }
}


x86 assembly (clang, -O0):
<split_digits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <clear_ndigits@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1179 <split_digits+0x69>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
movzbl -0x15(%rbp),%ecx
sub    %ecx,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112f <split_digits+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_digits>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1030 <clear_ndigits@plt>
movslq %ebp,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
mov    %dl,(%rbx)
movzbl %dl,%ecx
sub    %ecx,%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
mov    %dl,0x1(%rbx)
movzbl %dl,%ecx
sub    %ecx,%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
mov    %dl,0x2(%rbx)
movzbl %dl,%ecx
sub    %ecx,%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
mov    %dl,0x3(%rbx)
movzbl %dl,%ecx
sub    %ecx,%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
mov    %dl,0x4(%rbx)
movzbl %dl,%ecx
sub    %ecx,%eax
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
movswl %ax,%ecx
imul   $0x6667,%ecx,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x12,%ecx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
mov    %dl,0x5(%rbx)
movzbl %dl,%ecx
sub    %ecx,%eax
cwtl
imul   $0x6667,%eax,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x12,%eax
add    %ecx,%eax
imul   $0x6667,%eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x12,%ecx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
mov    %dl,0x6(%rbx)
movzbl %dl,%ecx
sub    %ecx,%eax
cwtl
imul   $0x6667,%eax,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x12,%eax
add    %ecx,%eax
imul   $0x6667,%eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x12,%ecx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
mov    %dl,0x7(%rbx)
movzbl %dl,%ecx
sub    %ecx,%eax
cwtl
imul   $0x6667,%eax,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x12,%eax
add    %ecx,%eax
movsbl %al,%ecx
imul   $0x67,%ecx,%ecx
movzwl %cx,%ecx
mov    %ecx,%edx
shr    $0xf,%edx
shr    $0x8,%ecx
sar    $0x2,%cl
add    %dl,%cl
movzbl %cl,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %cl,%dl
movzbl %dl,%ecx
mov    %cl,0x8(%rbx)
sub    %ecx,%eax
cwtl
imul   $0x6667,%eax,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x12,%eax
add    %ecx,%eax
movsbl %al,%ecx
imul   $0x67,%ecx,%ecx
movzwl %cx,%ecx
mov    %ecx,%edx
shr    $0xf,%edx
shr    $0x8,%ecx
sar    $0x2,%cl
add    %dl,%cl
movzbl %cl,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %cl,%al
mov    %al,0x9(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @split_digits(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @clear_ndigits(i8* %7)
store i32 0, i32* %5
br label %9
9: ; preds = %26, %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %29
12: ; preds = %9
%13 = load i32, i32* %3
%14 = srem i32 %13, 10
%15 = trunc i32 %14 to i8
store i8 %15, i8* %6
%16 = load i8, i8* %6
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8 %16, i8* %20
%21 = load i32, i32* %3
%22 = load i8, i8* %6
%23 = zext i8 %22 to i32
%24 = sub nsw i32 %21, %23
%25 = sdiv i32 %24, 10
store i32 %25, i32* %3
br label %26
26: ; preds = %12
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %9
29: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @split_digits(i32 %0, i8* %1) {
%3 = tail call i32 @clear_ndigits(i8* %1)
%4 = srem i32 %0, 10
%5 = trunc i32 %4 to i8
store i8 %5, i8* %1
%6 = and i32 %4, 255
%7 = sub nsw i32 %0, %6
%8 = sdiv i32 %7, 10
%9 = srem i32 %8, 10
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %10, i8* %11
%12 = and i32 %9, 255
%13 = sub nsw i32 %8, %12
%14 = sdiv i32 %13, 10
%15 = srem i32 %14, 10
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %16, i8* %17
%18 = and i32 %15, 255
%19 = sub nsw i32 %14, %18
%20 = sdiv i32 %19, 10
%21 = srem i32 %20, 10
%22 = trunc i32 %21 to i8
%23 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %22, i8* %23
%24 = and i32 %21, 255
%25 = sub nsw i32 %20, %24
%26 = sdiv i32 %25, 10
%27 = srem i32 %26, 10
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %28, i8* %29
%30 = and i32 %27, 255
%31 = sub nsw i32 %26, %30
%32 = sdiv i32 %31, 10
%33 = trunc i32 %32 to i16
%34 = srem i16 %33, 10
%35 = trunc i16 %34 to i8
%36 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %35, i8* %36
%37 = and i16 %34, 255
%38 = trunc i32 %32 to i16
%39 = sub i16 %38, %37
%40 = sdiv i16 %39, 10
%41 = srem i16 %40, 10
%42 = trunc i16 %41 to i8
%43 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %42, i8* %43
%44 = and i16 %41, 255
%45 = sub nsw i16 %40, %44
%46 = sdiv i16 %45, 10
%47 = srem i16 %46, 10
%48 = trunc i16 %47 to i8
%49 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %48, i8* %49
%50 = and i16 %47, 255
%51 = sub nsw i16 %46, %50
%52 = sdiv i16 %51, 10
%53 = trunc i16 %52 to i8
%54 = srem i8 %53, 10
%55 = zext i8 %54 to i16
%56 = getelementptr inbounds i8, i8* %1, i64 8
store i8 %54, i8* %56
%57 = sub nsw i16 %52, %55
%58 = sdiv i16 %57, 10
%59 = trunc i16 %58 to i8
%60 = srem i8 %59, 10
%61 = getelementptr inbounds i8, i8* %1, i64 9
store i8 %60, i8* %61
ret void
}