#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 int32_t;

/* Variables and functions */
void write_createsint32(int32_t v, char *sp) {
  static char *s1, *s2, c;
  s1 = sp;
  if (v < 0) {
    *s1++ = '-';
    v = -v;
  } else if (v == 0)
    *s1++ = '0';
  s2 = s1;
  while (v > 0) {
    *s2++ = (v % 10) + '0';
    v /= 10;
  }
  *s2-- = 0;
  while (s2 > s1) {
    c = *s1;
    *s1 = *s2;
    *s2 = c;
    s1++;
    s2--;
  }
}


x86 assembly (clang, -O0):
<write_createsint32>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,0x2f12(%rip)
cmpl   $0x0,-0x4(%rbp)
jge    1145 <write_createsint32+0x45>
mov    0x2f01(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2ef3(%rip)
movb   $0x2d,(%rax)
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    116c <write_createsint32+0x6c>
cmpl   $0x0,-0x4(%rbp)
jne    1167 <write_createsint32+0x67>
mov    0x2ed2(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2ec4(%rip)
movb   $0x30,(%rax)
jmp    116c <write_createsint32+0x6c>
mov    0x2eb5(%rip),%rax
mov    %rax,0x2eb6(%rip)
cmpl   $0x0,-0x4(%rbp)
jle    11be <write_createsint32+0xbe>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    0x2e95(%rip),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,0x2e87(%rip)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    117a <write_createsint32+0x7a>
mov    0x2e6b(%rip),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x2e5d(%rip)
movb   $0x0,(%rax)
mov    0x2e53(%rip),%rax
cmp    0x2e44(%rip),%rax
jbe    1243 <write_createsint32+0x143>
mov    0x2e37(%rip),%rax
mov    (%rax),%al
mov    %al,0x2e3f(%rip)
mov    0x2e30(%rip),%rax
mov    (%rax),%cl
mov    0x2e1f(%rip),%rax
mov    %cl,(%rax)
mov    0x2e27(%rip),%cl
mov    0x2e18(%rip),%rax
mov    %cl,(%rax)
mov    0x2e07(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2dfc(%rip)
mov    0x2dfd(%rip),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x2df2(%rip)
jmp    11d6 <write_createsint32+0xd6>
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_createsint32>:
test   %edi,%edi
js     1112 <write_createsint32+0x12>
jne    111b <write_createsint32+0x1b>
movb   $0x30,(%rsi)
add    $0x1,%rsi
mov    %rsi,%rax
jmp    1156 <write_createsint32+0x56>
movb   $0x2d,(%rsi)
add    $0x1,%rsi
neg    %edi
mov    $0xcccccccd,%r8d
mov    %rsi,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %edi,%edx
imul   %r8,%rdx
shr    $0x23,%rdx
lea    (%rdx,%rdx,1),%ecx
lea    (%rcx,%rcx,4),%r9d
mov    %edi,%ecx
sub    %r9d,%ecx
or     $0x30,%cl
mov    %cl,(%rax)
add    $0x1,%rax
cmp    $0x9,%edi
mov    %edx,%edi
ja     1130 <write_createsint32+0x30>
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rsi,%rax
jbe    118c <write_createsint32+0x8c>
add    $0x1,%rsi
cs nopw 0x0(%rax,%rax,1)
movzbl -0x1(%rsi),%ecx
movzbl (%rax),%edx
mov    %dl,-0x1(%rsi)
mov    %cl,(%rax)
add    $0xffffffffffffffff,%rax
lea    0x1(%rsi),%rcx
cmp    %rsi,%rax
mov    %rcx,%rsi
ja     1170 <write_createsint32+0x70>
ret

LLVM IR (-O0):
@write_createsint32.s1 = internal global i8* null
@write_createsint32.s2 = internal global i8* null
@write_createsint32.c = internal global i8 0
define void @write_createsint32(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
store i8* %5, i8** @write_createsint32.s1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i8*, i8** @write_createsint32.s1
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** @write_createsint32.s1
store i8 45, i8* %9
%11 = load i32, i32* %3
%12 = sub nsw i32 0, %11
store i32 %12, i32* %3
br label %20
13: ; preds = %2
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i8*, i8** @write_createsint32.s1
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** @write_createsint32.s1
store i8 48, i8* %17
br label %19
19: ; preds = %16, %13
br label %20
20: ; preds = %19, %8
%21 = load i8*, i8** @write_createsint32.s1
store i8* %21, i8** @write_createsint32.s2
br label %22
22: ; preds = %25, %20
%23 = load i32, i32* %3
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i32, i32* %3
%27 = srem i32 %26, 10
%28 = add nsw i32 %27, 48
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** @write_createsint32.s2
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** @write_createsint32.s2
store i8 %29, i8* %30
%32 = load i32, i32* %3
%33 = sdiv i32 %32, 10
store i32 %33, i32* %3
br label %22
34: ; preds = %22
%35 = load i8*, i8** @write_createsint32.s2
%36 = getelementptr inbounds i8, i8* %35, i32 -1
store i8* %36, i8** @write_createsint32.s2
store i8 0, i8* %35
br label %37
37: ; preds = %41, %34
%38 = load i8*, i8** @write_createsint32.s2
%39 = load i8*, i8** @write_createsint32.s1
%40 = icmp ugt i8* %38, %39
br i1 %40, label %41, label %53
41: ; preds = %37
%42 = load i8*, i8** @write_createsint32.s1
%43 = load i8, i8* %42
store i8 %43, i8* @write_createsint32.c
%44 = load i8*, i8** @write_createsint32.s2
%45 = load i8, i8* %44
%46 = load i8*, i8** @write_createsint32.s1
store i8 %45, i8* %46
%47 = load i8, i8* @write_createsint32.c
%48 = load i8*, i8** @write_createsint32.s2
store i8 %47, i8* %48
%49 = load i8*, i8** @write_createsint32.s1
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** @write_createsint32.s1
%51 = load i8*, i8** @write_createsint32.s2
%52 = getelementptr inbounds i8, i8* %51, i32 -1
store i8* %52, i8** @write_createsint32.s2
br label %37
53: ; preds = %37
ret void
}

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