#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*/ write_str(char *);
void write_sint64(int64_t v) {
  static char s[30], *s1, *s2, c;
  s1 = s;
  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--;
  }
  write_str(s);
}


x86 assembly (clang, -O0):
<write_sint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0x2f1e(%rip),%rax
mov    %rax,0x2f37(%rip)
cmpl   $0x0,-0x4(%rbp)
jge    1158 <write_sint64+0x48>
mov    0x2f26(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2f18(%rip)
movb   $0x2d,(%rax)
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117f <write_sint64+0x6f>
cmpl   $0x0,-0x4(%rbp)
jne    117a <write_sint64+0x6a>
mov    0x2ef7(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2ee9(%rip)
movb   $0x30,(%rax)
jmp    117f <write_sint64+0x6f>
mov    0x2eda(%rip),%rax
mov    %rax,0x2edb(%rip)
cmpl   $0x0,-0x4(%rbp)
jle    11d1 <write_sint64+0xc1>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    0x2eba(%rip),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,0x2eac(%rip)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    118d <write_sint64+0x7d>
mov    0x2e90(%rip),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x2e82(%rip)
movb   $0x0,(%rax)
mov    0x2e78(%rip),%rax
cmp    0x2e69(%rip),%rax
jbe    1256 <write_sint64+0x146>
mov    0x2e5c(%rip),%rax
mov    (%rax),%al
mov    %al,0x2e64(%rip)
mov    0x2e55(%rip),%rax
mov    (%rax),%cl
mov    0x2e44(%rip),%rax
mov    %cl,(%rax)
mov    0x2e4c(%rip),%cl
mov    0x2e3d(%rip),%rax
mov    %cl,(%rax)
mov    0x2e2c(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2e21(%rip)
mov    0x2e22(%rip),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x2e17(%rip)
jmp    11e9 <write_sint64+0xd9>
lea    0x2de3(%rip),%rdi
call   1030 <write_str@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_sint64>:
test   %edi,%edi
js     111f <write_sint64+0xf>
je     1165 <write_sint64+0x55>
lea    0x2f23(%rip),%r9
jmp    112f <write_sint64+0x1f>
movb   $0x2d,0x2f1a(%rip)
neg    %edi
lea    0x2f12(%rip),%r9
mov    $0xcccccccd,%r8d
mov    %r9,%rcx
nopl   0x0(%rax,%rax,1)
mov    %edi,%esi
imul   %r8,%rsi
shr    $0x23,%rsi
lea    (%rsi,%rsi,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %edi,%eax
sub    %edx,%eax
or     $0x30,%al
mov    %al,(%rcx)
add    $0x1,%rcx
cmp    $0x9,%edi
mov    %esi,%edi
ja     1140 <write_sint64+0x30>
jmp    1176 <write_sint64+0x66>
movb   $0x30,0x2ed4(%rip)
lea    0x2ece(%rip),%r9
mov    %r9,%rcx
lea    -0x1(%rcx),%rdx
mov    %rdx,0x2ee7(%rip)
movb   $0x0,(%rcx)
cmp    %r9,%rdx
jbe    11b7 <write_sint64+0xa7>
nopl   0x0(%rax)
movzbl (%r9),%eax
movzbl (%rdx),%ecx
mov    %cl,(%r9)
mov    %al,(%rdx)
add    $0x1,%r9
add    $0xffffffffffffffff,%rdx
cmp    %r9,%rdx
ja     1190 <write_sint64+0x80>
mov    %r9,0x2eb0(%rip)
mov    %rdx,0x2eb1(%rip)
lea    0x2e82(%rip),%rdi
jmp    1030 <write_str@plt>

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

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