#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*/ UART0_SendString(char *);
void UART0_SendData32(unsigned long int data) {
  char hex_string[] = "00000000";
  unsigned char ch = 0;
  char index = 8;
  while (data) {
    ch = (unsigned char)(data & 0x0000000F);
    switch (ch) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
    case 8:
    case 9:
      hex_string[index - 1] = '0' + ch;
      break;
    case 10:
    case 11:
    case 12:
    case 13:
    case 14:
    case 15:
      hex_string[index - 1] = 'A' + ch - 10;
      break;
    default:
      hex_string[index - 1] = 'X';
      break;
    }
    data = data >> 4;
    index--;
  }
  UART0_SendString("0x");
  if (index == 8)
    UART0_SendString("0");
  else
    UART0_SendString(&hex_string[index]);
}


x86 assembly (clang, -O0):
<UART0_SendData32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xedd(%rip),%rax
mov    %rax,-0x11(%rbp)
mov    0xedb(%rip),%al
mov    %al,-0x9(%rbp)
movb   $0x0,-0x12(%rbp)
movb   $0x8,-0x13(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11d4 <UART0_SendData32+0xc4>
mov    -0x8(%rbp),%al
and    $0xf,%al
mov    %al,-0x12(%rbp)
movzbl -0x12(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0xa,%eax
jb     1174 <UART0_SendData32+0x64>
jmp    1160 <UART0_SendData32+0x50>
mov    -0x18(%rbp),%eax
add    $0xfffffff6,%eax
sub    $0x6,%eax
jb     118f <UART0_SendData32+0x7f>
jmp    11ad <UART0_SendData32+0x9d>
movzbl -0x12(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
movsbl -0x13(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0x11(%rbp,%rax,1)
jmp    11bb <UART0_SendData32+0xab>
movzbl -0x12(%rbp),%eax
add    $0x41,%eax
sub    $0xa,%eax
mov    %al,%cl
movsbl -0x13(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0x11(%rbp,%rax,1)
jmp    11bb <UART0_SendData32+0xab>
movsbl -0x13(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x58,-0x11(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
shr    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x13(%rbp),%al
add    $0xff,%al
mov    %al,-0x13(%rbp)
jmp    1138 <UART0_SendData32+0x28>
lea    0xe2e(%rip),%rdi
call   1030 <UART0_SendString@plt>
movsbl -0x13(%rbp),%eax
cmp    $0x8,%eax
jne    11fe <UART0_SendData32+0xee>
lea    0xe13(%rip),%rdi
call   1030 <UART0_SendString@plt>
jmp    120f <UART0_SendData32+0xff>
movsbq -0x13(%rbp),%rax
lea    -0x11(%rbp),%rdi
add    %rax,%rdi
call   1030 <UART0_SendString@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UART0_SendData32>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movabs $0x3030303030303030,%rax
30 30 30
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
test   %rdi,%rdi
je     1190 <UART0_SendData32+0x80>
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
mov    %rdi,%rax
nopl   0x0(%rax)
mov    %edi,%ecx
and    $0xf,%ecx
lea    0x37(%rcx),%edx
lea    0x30(%rcx),%esi
cmp    $0xa,%ecx
movzbl %sil,%ecx
movzbl %dl,%edx
cmovb  %ecx,%edx
mov    %dl,-0x1(%rbx)
add    $0xffffffffffffffff,%rbx
shr    $0x4,%rax
add    $0x1,%bpl
cmp    $0xf,%rdi
mov    %rax,%rdi
ja     1140 <UART0_SendData32+0x30>
lea    0xe92(%rip),%rdi
call   1030 <UART0_SendString@plt>
test   %bpl,%bpl
je     119c <UART0_SendData32+0x8c>
mov    %rbx,%rdi
call   1030 <UART0_SendString@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe72(%rip),%rdi
call   1030 <UART0_SendString@plt>
lea    0xe64(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <UART0_SendString@plt>

LLVM IR (-O0):
@__const.UART0_SendData32.hex_string = [9 x i8] c"00000000\00"
@.str = [3 x i8] c"0x\00"
@.str.1 = [2 x i8] c"0\00"
define void @UART0_SendData32(i64 %0) {
%2 = alloca i64
%3 = alloca [9 x i8]
%4 = alloca i8
%5 = alloca i8
store i64 %0, i64* %2
%6 = bitcast [9 x i8]* %3 to i8*
store i8 0, i8* %4
store i8 8, i8* %5
br label %7
7: ; preds = %43, %1
%8 = load i64, i64* %2
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %48
10: ; preds = %7
%11 = load i64, i64* %2
%12 = and i64 %11, 15
%13 = trunc i64 %12 to i8
store i8 %13, i8* %4
%14 = load i8, i8* %4
%15 = zext i8 %14 to i32
switch i32 %15, label %37 [
i32 0, label %16
i32 1, label %16
i32 2, label %16
i32 3, label %16
i32 4, label %16
i32 5, label %16
i32 6, label %16
i32 7, label %16
i32 8, label %16
i32 9, label %16
i32 10, label %26
i32 11, label %26
i32 12, label %26
i32 13, label %26
i32 14, label %26
i32 15, label %26
]
16: ; preds = %10, %10, %10, %10, %10, %10, %10, %10, %10, %10
%17 = load i8, i8* %4
%18 = zext i8 %17 to i32
%19 = add nsw i32 48, %18
%20 = trunc i32 %19 to i8
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %24
store i8 %20, i8* %25
br label %43
26: ; preds = %10, %10, %10, %10, %10, %10
%27 = load i8, i8* %4
%28 = zext i8 %27 to i32
%29 = add nsw i32 65, %28
%30 = sub nsw i32 %29, 10
%31 = trunc i32 %30 to i8
%32 = load i8, i8* %5
%33 = sext i8 %32 to i32
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %35
store i8 %31, i8* %36
br label %43
37: ; preds = %10
%38 = load i8, i8* %5
%39 = sext i8 %38 to i32
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %41
store i8 88, i8* %42
br label %43
43: ; preds = %37, %26, %16
%44 = load i64, i64* %2
%45 = lshr i64 %44, 4
store i64 %45, i64* %2
%46 = load i8, i8* %5
%47 = add i8 %46, -1
store i8 %47, i8* %5
br label %7
48: ; preds = %7
%49 = call i32 @UART0_SendString(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%50 = load i8, i8* %5
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 8
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = call i32 @UART0_SendString(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %60
55: ; preds = %48
%56 = load i8, i8* %5
%57 = sext i8 %56 to i64
%58 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %57
%59 = call i32 @UART0_SendString(i8* %58)
br label %60
60: ; preds = %55, %53
ret void
}

LLVM IR (-O2):
@__const.UART0_SendData32.hex_string = [9 x i8] c"00000000\00"
@.str = [3 x i8] c"0x\00"
@.str.1 = [2 x i8] c"0\00"
define void @UART0_SendData32(i64 %0) {
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%4 = icmp eq i64 %0, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @UART0_SendString(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %25
7: ; preds = %1, %7
%8 = phi i64 [ %17, %7 ], [ 8, %1 ]
%9 = phi i64 [ %19, %7 ], [ %0, %1 ]
%10 = trunc i64 %9 to i32
%11 = and i32 %10, 15
%12 = icmp ult i32 %11, 10
%13 = trunc i32 %11 to i8
%14 = add nuw nsw i8 %13, 55
%15 = or i8 %13, 48
%16 = select i1 %12, i8 %15, i8 %14
%17 = add nsw i64 %8, -1
%18 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 %17
store i8 %16, i8* %18
%19 = lshr i64 %9, 4
%20 = icmp ult i64 %9, 16
br i1 %20, label %21, label %7
21: ; preds = %7
%22 = trunc i64 %17 to i8
%23 = tail call i32 @UART0_SendString(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i8 %22, 8
br i1 %24, label %25, label %27
25: ; preds = %5, %21
%26 = tail call i32 @UART0_SendString(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %32
27: ; preds = %21
%28 = shl i64 %17, 56
%29 = ashr exact i64 %28, 56
%30 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 %29
%31 = call i32 @UART0_SendString(i8* %30)
br label %32
32: ; preds = %27, %25
ret void
}