#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*/ tk_putc(char);
int /*<<< orphan*/ tk_puts(char *);
void tk_print_decimal(int val) {
  char tb[256];
  char *t, *te;
  int i, k, s;
  if (val == 0) {
    tk_putc('0');
    return;
  }
  if (val == (1 << 31)) {
    tk_puts("-2147483648");
    return;
  }
  k = val;
  s = 0;
  if (k < 0) {
    k = -k;
    s = 1;
  }
  t = tb;
  te = tb + 18;
  if (!k)
    *t++ = '0';
  while ((k > 0) && (t < te)) {
    i = k % 10;
    *t++ = '0' + i;
    k = k / 10;
  }
  if (s)
    *t++ = '-';
  if (tb[0] == '-')
    *(int *)-1 = -1;
  while (t > tb) {
    t--;
    tk_putc(*t);
  }
}


x86 assembly (clang, -O0):
<tk_print_decimal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1147 <tk_print_decimal+0x27>
mov    $0x30,%edi
call   1030 <tk_putc@plt>
jmp    12f9 <tk_print_decimal+0x1d9>
cmpl   $0x80000000,-0x4(%rbp)
jne    1165 <tk_print_decimal+0x45>
lea    0xea5(%rip),%rdi
call   1040 <tk_puts@plt>
jmp    12f9 <tk_print_decimal+0x1d9>
mov    -0x4(%rbp),%eax
mov    %eax,-0x128(%rbp)
movl   $0x0,-0x12c(%rbp)
cmpl   $0x0,-0x128(%rbp)
jge    119d <tk_print_decimal+0x7d>
xor    %eax,%eax
sub    -0x128(%rbp),%eax
mov    %eax,-0x128(%rbp)
movl   $0x1,-0x12c(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
lea    -0x110(%rbp),%rax
add    $0x12,%rax
mov    %rax,-0x120(%rbp)
cmpl   $0x0,-0x128(%rbp)
jne    11e2 <tk_print_decimal+0xc2>
mov    -0x118(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x118(%rbp)
movb   $0x30,(%rax)
jmp    11e7 <tk_print_decimal+0xc7>
xor    %eax,%eax
cmpl   $0x0,-0x128(%rbp)
mov    %al,-0x12d(%rbp)
jle    1213 <tk_print_decimal+0xf3>
mov    -0x118(%rbp),%rax
cmp    -0x120(%rbp),%rax
setb   %al
mov    %al,-0x12d(%rbp)
mov    -0x12d(%rbp),%al
test   $0x1,%al
jne    1226 <tk_print_decimal+0x106>
jmp    1275 <tk_print_decimal+0x155>
mov    -0x128(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x124(%rbp)
mov    -0x124(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x118(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x118(%rbp)
mov    %cl,(%rax)
mov    -0x128(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x128(%rbp)
jmp    11e7 <tk_print_decimal+0xc7>
cmpl   $0x0,-0x12c(%rbp)
je     129a <tk_print_decimal+0x17a>
mov    -0x118(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x118(%rbp)
movb   $0x2d,(%rax)
movsbl -0x110(%rbp),%eax
cmp    $0x2d,%eax
jne    12b7 <tk_print_decimal+0x197>
mov    $0xffffffffffffffff,%rax
movl   $0xffffffff,(%rax)
jmp    12bc <tk_print_decimal+0x19c>
mov    -0x118(%rbp),%rax
lea    -0x110(%rbp),%rcx
cmp    %rcx,%rax
jbe    12f9 <tk_print_decimal+0x1d9>
mov    -0x118(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tk_putc@plt>
jmp    12bc <tk_print_decimal+0x19c>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tk_print_decimal>:
push   %r14
push   %rbx
sub    $0x108,%rsp
cmp    $0x80000000,%edi
je     114a <tk_print_decimal+0x2a>
test   %edi,%edi
jne    1160 <tk_print_decimal+0x40>
mov    $0x30,%edi
add    $0x108,%rsp
pop    %rbx
pop    %r14
jmp    1030 <tk_putc@plt>
lea    0xeaf(%rip),%rdi
add    $0x108,%rsp
pop    %rbx
pop    %r14
jmp    1040 <tk_puts@plt>
mov    %rsp,%rbx
lea    0x12(%rsp),%r8
mov    %edi,%ecx
neg    %ecx
cmovs  %edi,%ecx
mov    $0xcccccccd,%r9d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,%edx
mov    %ecx,%ecx
imul   %r9,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %edx,%esi
sub    %eax,%esi
or     $0x30,%sil
mov    %sil,(%rbx)
add    $0x1,%rbx
cmp    $0xa,%edx
jb     11ab <tk_print_decimal+0x8b>
cmp    %r8,%rbx
jb     1180 <tk_print_decimal+0x60>
test   %edi,%edi
js     11ed <tk_print_decimal+0xcd>
cmpb   $0x2d,(%rsp)
jne    11c0 <tk_print_decimal+0xa0>
movl   $0xffffffff,0xffffffffffffffff
ff ff ff ff
mov    %rsp,%r14
cmp    %r14,%rbx
jbe    11e2 <tk_print_decimal+0xc2>
nopl   0x0(%rax,%rax,1)
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1030 <tk_putc@plt>
cmp    %r14,%rbx
ja     11d0 <tk_print_decimal+0xb0>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
movb   $0x2d,(%rbx)
add    $0x1,%rbx
cmpb   $0x2d,(%rsp)
je     11b5 <tk_print_decimal+0x95>
jmp    11c0 <tk_print_decimal+0xa0>

LLVM IR (-O0):
@.str = [12 x i8] c"-2147483648\00"
define void @tk_print_decimal(i32 %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @tk_putc(i8 signext 48)
br label %77
13: ; preds = %1
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, -2147483648
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @tk_puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %77
18: ; preds = %13
%19 = load i32, i32* %2
store i32 %19, i32* %7
store i32 0, i32* %8
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %7
%24 = sub nsw i32 0, %23
store i32 %24, i32* %7
store i32 1, i32* %8
br label %25
25: ; preds = %22, %18
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
store i8* %26, i8** %4
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%28 = getelementptr inbounds i8, i8* %27, i64 18
store i8* %28, i8** %5
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %25
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %4
store i8 48, i8* %32
br label %34
34: ; preds = %31, %25
br label %35
35: ; preds = %44, %34
%36 = load i32, i32* %7
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i8*, i8** %4
%40 = load i8*, i8** %5
%41 = icmp ult i8* %39, %40
br label %42
42: ; preds = %38, %35
%43 = phi i1 [ false, %35 ], [ %41, %38 ]
br i1 %43, label %44, label %54
44: ; preds = %42
%45 = load i32, i32* %7
%46 = srem i32 %45, 10
store i32 %46, i32* %6
%47 = load i32, i32* %6
%48 = add nsw i32 48, %47
%49 = trunc i32 %48 to i8
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %4
store i8 %49, i8* %50
%52 = load i32, i32* %7
%53 = sdiv i32 %52, 10
store i32 %53, i32* %7
br label %35
54: ; preds = %42
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = load i8*, i8** %4
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %4
store i8 45, i8* %58
br label %60
60: ; preds = %57, %54
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 45
br i1 %64, label %65, label %66
65: ; preds = %60
store i32 -1, i32* inttoptr (i64 -1 to i32*)
br label %66
66: ; preds = %65, %60
br label %67
67: ; preds = %71, %66
%68 = load i8*, i8** %4
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%70 = icmp ugt i8* %68, %69
br i1 %70, label %71, label %77
71: ; preds = %67
%72 = load i8*, i8** %4
%73 = getelementptr inbounds i8, i8* %72, i32 -1
store i8* %73, i8** %4
%74 = load i8*, i8** %4
%75 = load i8, i8* %74
%76 = call i32 @tk_putc(i8 signext %75)
br label %67
77: ; preds = %11, %16, %67
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"-2147483648\00"
define void @tk_print_decimal(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
switch i32 %0, label %8 [
i32 0, label %4
i32 -2147483648, label %6
]
4: ; preds = %1
%5 = tail call i32 @tk_putc(i8 signext 48)
br label %40
6: ; preds = %1
%7 = tail call i32 @tk_puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %40
8: ; preds = %1
%9 = icmp slt i32 %0, 0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 18
%11 = sub nsw i32 0, %0
%12 = select i1 %9, i32 %11, i32 %0
br label %13
13: ; preds = %8, %13
%14 = phi i32 [ %20, %13 ], [ %12, %8 ]
%15 = phi i8* [ %19, %13 ], [ %3, %8 ]
%16 = urem i32 %14, 10
%17 = trunc i32 %16 to i8
%18 = or i8 %17, 48
%19 = getelementptr inbounds i8, i8* %15, i64 1
store i8 %18, i8* %15
%20 = udiv i32 %14, 10
%21 = icmp ugt i32 %14, 9
%22 = icmp ult i8* %19, %10
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %13, label %24
24: ; preds = %13
br i1 %9, label %25, label %27
25: ; preds = %24
%26 = getelementptr inbounds i8, i8* %15, i64 2
store i8 45, i8* %19
br label %27
27: ; preds = %25, %24
%28 = phi i8* [ %26, %25 ], [ %19, %24 ]
%29 = load i8, i8* %3
%30 = icmp eq i8 %29, 45
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 -1, i32* inttoptr (i64 -1 to i32*)
br label %32
32: ; preds = %31, %27
%33 = icmp ugt i8* %28, %3
br i1 %33, label %34, label %40
34: ; preds = %32, %34
%35 = phi i8* [ %36, %34 ], [ %28, %32 ]
%36 = getelementptr inbounds i8, i8* %35, i64 -1
%37 = load i8, i8* %36
%38 = call i32 @tk_putc(i8 signext %37)
%39 = icmp ugt i8* %36, %3
br i1 %39, label %34, label %40
40: ; preds = %34, %32, %6, %4
ret void
}