#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 int int64_t;

/* Variables and functions */
int /*<<< orphan*/ strreverse(char *, char *);
void modp_ltoa10(int64_t value, char *str) {
  char *wstr = str;
  int neg = value < 0;
  if (neg)
    value = -value;
  do
    *wstr++ = 48 + (value % 10);
  while (value /= 10);
  if (neg)
    *wstr++ = '-';
  *wstr = '\0';
  strreverse(str, wstr - 1);
}


x86 assembly (clang, -O0):
<modp_ltoa10>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1148 <modp_ltoa10+0x38>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    114d <modp_ltoa10+0x3d>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jne    114d <modp_ltoa10+0x3d>
cmpl   $0x0,-0x1c(%rbp)
je     11a1 <modp_ltoa10+0x91>
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>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<modp_ltoa10>:
mov    %rsi,%r8
mov    %edi,%ecx
neg    %ecx
cmovs  %edi,%ecx
nopw   0x0(%rax,%rax,1)
movslq %ecx,%rdx
imul   $0x66666667,%rdx,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x22,%rcx
add    %eax,%ecx
lea    (%rcx,%rcx,1),%eax
lea    (%rax,%rax,4),%r9d
mov    %edx,%eax
sub    %r9d,%eax
add    $0x30,%al
mov    %al,(%rsi)
add    $0x1,%rsi
add    $0x9,%edx
cmp    $0x12,%edx
ja     1120 <modp_ltoa10+0x10>
test   %edi,%edi
jns    115e <modp_ltoa10+0x4e>
movb   $0x2d,(%rsi)
add    $0x1,%rsi
movb   $0x0,(%rsi)
add    $0xffffffffffffffff,%rsi
mov    %r8,%rdi
jmp    1030 <strreverse@plt>

LLVM IR (-O0):
define void @modp_ltoa10(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
store i8* %7, i8** %5
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
%10 = zext i1 %9 to i32
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* %3
%15 = sub nsw i32 0, %14
store i32 %15, i32* %3
br label %16
16: ; preds = %13, %2
br label %17
17: ; preds = %24, %16
%18 = load i32, i32* %3
%19 = srem i32 %18, 10
%20 = add nsw i32 48, %19
%21 = trunc i32 %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 i32, i32* %3
%26 = sdiv i32 %25, 10
store i32 %26, i32* %3
%27 = icmp ne i32 %26, 0
br i1 %27, label %17, label %28
28: ; preds = %24
%29 = load i32, i32* %6
%30 = icmp ne i32 %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)
ret void
}

LLVM IR (-O2):
define void @modp_ltoa10(i32 %0, i8* %1) {
%3 = icmp slt i32 %0, 0
%4 = sub nsw i32 0, %0
%5 = select i1 %3, i32 %4, i32 %0
br label %6
6: ; preds = %6, %2
%7 = phi i8* [ %1, %2 ], [ %12, %6 ]
%8 = phi i32 [ %5, %2 ], [ %13, %6 ]
%9 = srem i32 %8, 10
%10 = trunc i32 %9 to i8
%11 = add nsw i8 %10, 48
%12 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %11, i8* %7
%13 = sdiv i32 %8, 10
%14 = add i32 %8, 9
%15 = icmp ult i32 %14, 19
br i1 %15, label %16, label %6
16: ; preds = %6
br i1 %3, label %17, label %19
17: ; preds = %16
%18 = getelementptr inbounds i8, i8* %7, i64 2
store i8 45, i8* %12
br label %19
19: ; preds = %17, %16
%20 = phi i8* [ %18, %17 ], [ %12, %16 ]
store i8 0, i8* %20
%21 = getelementptr inbounds i8, i8* %20, i64 -1
%22 = tail call i32 @strreverse(i8* %1, i8* %21)
ret void
}