#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*/ uart_putc(char);
void uart_send_int(int data) {
  char num[80];
  int i = 0;
  while (1) {
    num[i++] = data % 10 + '0';
    data /= 10;
    if (data == 0)
      break;
  }
  if (data < 0)
    uart_putc('-');
  for (i -= 1; i >= 0; --i) {
    uart_putc(num[i]);
  }
  return;
}


x86 assembly (clang, -O0):
<uart_send_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x64(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x64(%rbp)
cltq
mov    %cl,-0x60(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1160 <uart_send_int+0x50>
jmp    1165 <uart_send_int+0x55>
jmp    1122 <uart_send_int+0x12>
cmpl   $0x0,-0x4(%rbp)
jge    1179 <uart_send_int+0x69>
mov    $0x2d,%edi
call   1030 <uart_putc@plt>
mov    -0x64(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jl     11a8 <uart_send_int+0x98>
movslq -0x64(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%edi
call   1030 <uart_putc@plt>
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
jmp    1182 <uart_send_int+0x72>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_send_int>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
xor    %r15d,%r15d
nopl   0x0(%rax)
movslq %edi,%rax
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rdi
add    %ecx,%edi
lea    (%rdi,%rdi,1),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
add    $0x30,%dl
mov    %dl,(%rsp,%r15,1)
add    $0x1,%r15
add    $0x9,%eax
cmp    $0x12,%eax
ja     1120 <uart_send_int+0x10>
add    $0xffffffffffffffff,%r15
mov    %r15d,%eax
lea    (%rsp,%rax,1),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
call   1030 <uart_putc@plt>
lea    -0x1(%rbx),%rax
add    %r15d,%ebx
test   %ebx,%ebx
mov    %rax,%rbx
jg     1170 <uart_send_int+0x60>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @uart_send_int(i32 %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ %10, %4 ], [ 0, %1 ]
%6 = phi i32 [ %12, %4 ], [ %0, %1 ]
%7 = srem i32 %6, 10
%8 = trunc i32 %7 to i8
%9 = add nsw i8 %8, 48
%10 = add nuw i64 %5, 1
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %5
store i8 %9, i8* %11
%12 = sdiv i32 %6, 10
%13 = add i32 %6, 9
%14 = icmp ult i32 %13, 19
br i1 %14, label %15, label %4
15: ; preds = %4
%16 = and i64 %5, 4294967295
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ %16, %15 ], [ %22, %17 ]
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = tail call i32 @uart_putc(i8 signext %20)
%22 = add nsw i64 %18, -1
%23 = trunc i64 %18 to i32
%24 = icmp sgt i32 %23, 0
br i1 %24, label %17, label %25
25: ; preds = %17
ret void
}