#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");
  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>
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   %rbx
sub    $0x10,%rsp
movabs $0x3030303030303030,%rax
30 30 30
mov    %rax,(%rsp)
movb   $0x0,0x8(%rsp)
mov    $0x8,%ebx
test   %rdi,%rdi
je     116d <UART0_SendData32+0x5d>
mov    %rdi,%rax
cs nopw 0x0(%rax,%rax,1)
nop
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(%rsp,%rbx,1)
add    $0xffffffffffffffff,%rbx
shr    $0x4,%rax
cmp    $0xf,%rdi
mov    %rax,%rdi
ja     1140 <UART0_SendData32+0x30>
lea    0xe95(%rip),%rdi
call   1030 <UART0_SendString@plt>
lea    (%rsp,%rbx,1),%rdi
call   1030 <UART0_SendString@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.UART0_SendData32.hex_string = [9 x i8] c"00000000\00"
@.str = [3 x i8] c"0x\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 i64
%52 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %51
%53 = call i32 @UART0_SendString(i8* %52)
ret void
}

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