#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 */
typedef unsigned long int64_t;

/* Variables and functions */
int /*<<< orphan*/ strreverse(char *, char *);
char *modp_litoa10(int64_t value, char *str) {
  char *wstr = str;
  unsigned long uvalue = (value < 0) ? -value : value;
  do
    *wstr++ = (char)(48 + (uvalue % 10));
  while (uvalue /= 10);
  if (value < 0)
    *wstr++ = '-';
  *wstr = '\0';
  strreverse(str, wstr - 1);
  return wstr;
}


x86 assembly (clang, -O0):
<modp_litoa10>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jae    1142 <modp_litoa10+0x32>
xor    %eax,%eax
sub    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    114a <modp_litoa10+0x3a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
add    $0x30,%rdx
mov    %dl,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1152 <modp_litoa10+0x42>
cmpq   $0x0,-0x8(%rbp)
jae    11b0 <modp_litoa10+0xa0>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <strreverse@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<modp_litoa10>:
push   %rbx
mov    %rsi,%r8
movabs $0xcccccccccccccccd,%rsi
cc cc cc
mov    %r8,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rdi,%rax
mul    %rsi
shr    $0x3,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %edi,%ecx
sub    %eax,%ecx
or     $0x30,%cl
mov    %cl,(%rbx)
add    $0x1,%rbx
cmp    $0x9,%rdi
mov    %rdx,%rdi
ja     1130 <modp_litoa10+0x20>
movb   $0x0,(%rbx)
lea    -0x1(%rbx),%rsi
mov    %r8,%rdi
call   1030 <strreverse@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @modp_litoa10(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i64 %0, i64* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
store i8* %7, i8** %5
%8 = load i64, i64* %3
%9 = icmp ult i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i64, i64* %3
%12 = sub i64 0, %11
br label %15
13: ; preds = %2
%14 = load i64, i64* %3
br label %15
15: ; preds = %13, %10
%16 = phi i64 [ %12, %10 ], [ %14, %13 ]
store i64 %16, i64* %6
br label %17
17: ; preds = %24, %15
%18 = load i64, i64* %6
%19 = urem i64 %18, 10
%20 = add i64 48, %19
%21 = trunc i64 %20 to i8
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %5
store i8 %21, i8* %22
br label %24
24: ; preds = %17
%25 = load i64, i64* %6
%26 = udiv i64 %25, 10
store i64 %26, i64* %6
%27 = icmp ne i64 %26, 0
br i1 %27, label %17, label %28
28: ; preds = %24
%29 = load i64, i64* %3
%30 = icmp ult i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %5
store i8 45, i8* %32
br label %34
34: ; preds = %31, %28
%35 = load i8*, i8** %5
store i8 0, i8* %35
%36 = load i8*, i8** %4
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 -1
%39 = call i32 @strreverse(i8* %36, i8* %38)
%40 = load i8*, i8** %5
ret i8* %40
}

LLVM IR (-O2):
define i8* @modp_litoa10(i64 %0, i8* %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i8* [ %1, %2 ], [ %9, %3 ]
%5 = phi i64 [ %0, %2 ], [ %10, %3 ]
%6 = urem i64 %5, 10
%7 = trunc i64 %6 to i8
%8 = or i8 %7, 48
%9 = getelementptr inbounds i8, i8* %4, i64 1
store i8 %8, i8* %4
%10 = udiv i64 %5, 10
%11 = icmp ult i64 %5, 10
br i1 %11, label %12, label %3
12: ; preds = %3
store i8 0, i8* %9
%13 = tail call i32 @strreverse(i8* %1, i8* %4)
ret i8* %9
}