#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*/ write_char(char);
int write_llint(long long lld) {
  char buf[100];
  int p = 0, ret;
  unsigned long long llu;
  if (lld < 0) {
    write_char('-');
    lld = -lld;
  }
  llu = lld;
  do {
    buf[p++] = llu % 10;
    llu /= 10;
  } while (llu > 0);
  ret = p;
  while (p > 0)
    write_char('0' + buf[--p]);
  return ret;
}


x86 assembly (clang, -O0):
<write_llint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x74(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    1145 <write_llint+0x35>
mov    $0x2d,%edi
call   1030 <write_char@plt>
xor    %eax,%eax
sub    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %dl,%cl
mov    -0x74(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x74(%rbp)
cltq
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x80(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
ja     114d <write_llint+0x3d>
mov    -0x74(%rbp),%eax
mov    %eax,-0x78(%rbp)
cmpl   $0x0,-0x74(%rbp)
jle    11bb <write_llint+0xab>
mov    -0x74(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x74(%rbp)
cltq
movsbl -0x70(%rbp,%rax,1),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1030 <write_char@plt>
jmp    1191 <write_llint+0x81>
mov    -0x78(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_llint>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rdi,%rbx
test   %rdi,%rdi
jns    112d <write_llint+0x1d>
mov    $0x2d,%edi
call   1030 <write_char@plt>
neg    %rbx
xor    %r14d,%r14d
movabs $0xcccccccccccccccd,%rcx
cc cc cc
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rax
mul    %rcx
shr    $0x3,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ebx,%esi
sub    %eax,%esi
mov    %sil,(%rsp,%r14,1)
add    $0x1,%r14
cmp    $0x9,%rbx
mov    %rdx,%rbx
ja     1140 <write_llint+0x30>
mov    %r14d,%ebx
add    $0xffffffffffffffff,%rbx
lea    0x1(%r14),%ebp
mov    %ebx,%eax
movzbl (%rsp,%rax,1),%eax
add    $0x30,%al
movsbl %al,%edi
call   1030 <write_char@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%ebp
jg     1170 <write_llint+0x60>
mov    %r14d,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @write_llint(i64 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = icmp slt i64 %0, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @write_char(i8 signext 45)
%7 = sub nsw i64 0, %0
br label %8
8: ; preds = %5, %1
%9 = phi i64 [ %0, %1 ], [ %7, %5 ]
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ %15, %10 ], [ 0, %8 ]
%12 = phi i64 [ %17, %10 ], [ %9, %8 ]
%13 = urem i64 %12, 10
%14 = trunc i64 %13 to i8
%15 = add nuw i64 %11, 1
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %11
store i8 %14, i8* %16
%17 = udiv i64 %12, 10
%18 = icmp ult i64 %12, 10
br i1 %18, label %19, label %10
19: ; preds = %10
%20 = and i64 %15, 4294967295
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ %20, %19 ], [ %23, %21 ]
%23 = add nsw i64 %22, -1
%24 = and i64 %23, 4294967295
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = add i8 %26, 48
%28 = tail call i32 @write_char(i8 signext %27)
%29 = trunc i64 %22 to i32
%30 = icmp sgt i32 %29, 1
br i1 %30, label %21, label %31
31: ; preds = %21
%32 = trunc i64 %15 to i32
ret i32 %32
}