#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*/ int_to_string(int, char *);
void snprintf_signed_decimal_int(char **str, char *str_end, int value) {
  char buf[32];
  int_to_string(value, buf);
  char *pbuf = buf;
  while (*pbuf && *str != str_end) {
    **str = *pbuf;
    (*str)++;
    pbuf++;
  }
}


x86 assembly (clang, -O0):
<snprintf_signed_decimal_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1030 <int_to_string@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x49(%rbp)
je     115d <snprintf_signed_decimal_int+0x4d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmp    -0x10(%rbp),%rax
setne  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    116d <snprintf_signed_decimal_int+0x5d>
jmp    119b <snprintf_signed_decimal_int+0x8b>
mov    -0x48(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1137 <snprintf_signed_decimal_int+0x27>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snprintf_signed_decimal_int>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    %edx,%edi
call   1030 <int_to_string@plt>
mov    (%rsp),%al
test   %al,%al
je     115c <snprintf_signed_decimal_int+0x4c>
mov    (%rbx),%rdx
lea    0x1(%rsp),%rcx
cs nopw 0x0(%rax,%rax,1)
cmp    %r14,%rdx
je     115c <snprintf_signed_decimal_int+0x4c>
mov    %al,(%rdx)
mov    (%rbx),%rdx
add    $0x1,%rdx
mov    %rdx,(%rbx)
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
jne    1140 <snprintf_signed_decimal_int+0x30>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @snprintf_signed_decimal_int(i8** %0, i8* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [32 x i8]
%8 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%11 = call i32 @int_to_string(i32 %9, i8* %10)
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
store i8* %12, i8** %8
br label %13
13: ; preds = %25, %3
%14 = load i8*, i8** %8
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i8**, i8*** %4
%20 = load i8*, i8** %19
%21 = load i8*, i8** %5
%22 = icmp ne i8* %20, %21
br label %23
23: ; preds = %18, %13
%24 = phi i1 [ false, %13 ], [ %22, %18 ]
br i1 %24, label %25, label %35
25: ; preds = %23
%26 = load i8*, i8** %8
%27 = load i8, i8* %26
%28 = load i8**, i8*** %4
%29 = load i8*, i8** %28
store i8 %27, i8* %29
%30 = load i8**, i8*** %4
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %30
%33 = load i8*, i8** %8
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %8
br label %13
35: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @snprintf_signed_decimal_int(i8** nocapture %0, i8* readnone %1, i32 %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = call i32 @int_to_string(i32 %2, i8* %5)
%7 = load i8, i8* %5
%8 = icmp eq i8 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %3
%10 = load i8*, i8** %0
br label %11
11: ; preds = %9, %16
%12 = phi i8* [ %18, %16 ], [ %10, %9 ]
%13 = phi i8 [ %20, %16 ], [ %7, %9 ]
%14 = phi i8* [ %19, %16 ], [ %5, %9 ]
%15 = icmp eq i8* %12, %1
br i1 %15, label %22, label %16
16: ; preds = %11
store i8 %13, i8* %12
%17 = load i8*, i8** %0
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %18, i8** %0
%19 = getelementptr inbounds i8, i8* %14, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %11
22: ; preds = %11, %16, %3
ret void
}