#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*/ LCD_Write_Char(unsigned char);
int /*<<< orphan*/ LCD_Write_String(char *);
void LCD_Write_Int(long num) {
  if (num < 0) {
    LCD_Write_String("-");
    num *= -1;
  }
  unsigned char number[10];
  unsigned char num_count = 0;
  do {
    number[num_count] = num % 10;
    num_count++;
    num /= 10;
  } while (num > 0);
  for (int i = num_count - 1; i >= 0; i--) {
    LCD_Write_Char(number[i] + 0b00110000);
  }
}


x86 assembly (clang, -O0):
<LCD_Write_Int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    114c <LCD_Write_Int+0x2c>
lea    0xec2(%rip),%rdi
call   1040 <LCD_Write_String@plt>
imul   $0xffffffffffffffff,-0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
movb   $0x0,-0x13(%rbp)
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %dl,%cl
movzbl -0x13(%rbp),%eax
mov    %cl,-0x12(%rbp,%rax,1)
mov    -0x13(%rbp),%al
add    $0x1,%al
mov    %al,-0x13(%rbp)
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jg     1150 <LCD_Write_Int+0x30>
movzbl -0x13(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11c3 <LCD_Write_Int+0xa3>
movslq -0x18(%rbp),%rax
movzbl -0x12(%rbp,%rax,1),%eax
add    $0x30,%eax
movzbl %al,%edi
call   1030 <LCD_Write_Char@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1197 <LCD_Write_Int+0x77>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LCD_Write_Int>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
test   %rdi,%rdi
jns    113c <LCD_Write_Int+0x1c>
lea    0xecc(%rip),%rdi
call   1040 <LCD_Write_String@plt>
neg    %rbx
xor    %ecx,%ecx
movabs $0x6666666666666667,%rsi
66 66 66
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rax
imul   %rsi
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ebx,%edi
sub    %eax,%edi
movzbl %cl,%ecx
mov    %dil,0x6(%rsp,%rcx,1)
add    $0x1,%cl
cmp    $0x9,%rbx
mov    %rdx,%rbx
jg     1150 <LCD_Write_Int+0x30>
test   %cl,%cl
je     11a9 <LCD_Write_Int+0x89>
movzbl %cl,%ebx
add    $0x1,%rbx
nopl   (%rax)
movzbl 0x4(%rsp,%rbx,1),%eax
add    $0x30,%al
movzbl %al,%edi
call   1030 <LCD_Write_Char@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1190 <LCD_Write_Int+0x70>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
define void @LCD_Write_Int(i64 %0) {
%2 = alloca i64
%3 = alloca [10 x i8]
%4 = alloca i8
%5 = alloca i32
store i64 %0, i64* %2
%6 = load i64, i64* %2
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = call i32 @LCD_Write_String(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = load i64, i64* %2
%11 = mul nsw i64 %10, -1
store i64 %11, i64* %2
br label %12
12: ; preds = %8, %1
store i8 0, i8* %4
br label %13
13: ; preds = %24, %12
%14 = load i64, i64* %2
%15 = srem i64 %14, 10
%16 = trunc i64 %15 to i8
%17 = load i8, i8* %4
%18 = zext i8 %17 to i64
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %18
store i8 %16, i8* %19
%20 = load i8, i8* %4
%21 = add i8 %20, 1
store i8 %21, i8* %4
%22 = load i64, i64* %2
%23 = sdiv i64 %22, 10
store i64 %23, i64* %2
br label %24
24: ; preds = %13
%25 = load i64, i64* %2
%26 = icmp sgt i64 %25, 0
br i1 %26, label %13, label %27
27: ; preds = %24
%28 = load i8, i8* %4
%29 = zext i8 %28 to i32
%30 = sub nsw i32 %29, 1
store i32 %30, i32* %5
br label %31
31: ; preds = %43, %27
%32 = load i32, i32* %5
%33 = icmp sge i32 %32, 0
br i1 %33, label %34, label %46
34: ; preds = %31
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = add nsw i32 %39, 48
%41 = trunc i32 %40 to i8
%42 = call i32 @LCD_Write_Char(i8 zeroext %41)
br label %43
43: ; preds = %34
%44 = load i32, i32* %5
%45 = add nsw i32 %44, -1
store i32 %45, i32* %5
br label %31
46: ; preds = %31
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
define void @LCD_Write_Int(i64 %0) {
%2 = alloca [10 x i8]
%3 = icmp slt i64 %0, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @LCD_Write_String(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = sub nsw i64 0, %0
br label %7
7: ; preds = %4, %1
%8 = phi i64 [ %6, %4 ], [ %0, %1 ]
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
br label %10
10: ; preds = %10, %7
%11 = phi i64 [ %8, %7 ], [ %18, %10 ]
%12 = phi i8 [ 0, %7 ], [ %17, %10 ]
%13 = srem i64 %11, 10
%14 = trunc i64 %13 to i8
%15 = zext i8 %12 to i64
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %15
store i8 %14, i8* %16
%17 = add i8 %12, 1
%18 = sdiv i64 %11, 10
%19 = icmp sgt i64 %11, 9
br i1 %19, label %10, label %20
20: ; preds = %10
%21 = icmp eq i8 %17, 0
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = zext i8 %17 to i64
br label %25
24: ; preds = %25, %20
ret void
25: ; preds = %22, %25
%26 = phi i64 [ %23, %22 ], [ %27, %25 ]
%27 = add nsw i64 %26, -1
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = add i8 %29, 48
%31 = tail call i32 @LCD_Write_Char(i8 zeroext %30)
%32 = icmp ugt i64 %26, 1
br i1 %32, label %25, label %24
}