#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 */
char tty_hex(unsigned int);
int /*<<< orphan*/ tty_puts(char *);
void tty_put_ui32_hex(unsigned int v) {
  char *buff = "0x00000000";
  for (int i = 0; i < 8; i++)
    buff[2 + (7 - i)] = tty_hex((v >> (i * 4)) & 0xF);
  tty_puts(buff);
}


x86 assembly (clang, -O0):
<tty_put_ui32_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xece(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    117f <tty_put_ui32_hex+0x5f>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
shr    %cl,%edi
and    $0xf,%edi
call   1030 <tty_hex@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    $0x7,%ecx
sub    -0x14(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <tty_put_ui32_hex+0x1d>
mov    -0x10(%rbp),%rdi
call   1040 <tty_puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_put_ui32_hex>:
push   %rbx
mov    %edi,%ebx
and    $0xf,%edi
call   1030 <tty_hex@plt>
mov    %ebx,%edi
shr    $0x4,%edi
and    $0xf,%edi
call   1030 <tty_hex@plt>
mov    %ebx,%edi
shr    $0x8,%edi
and    $0xf,%edi
call   1030 <tty_hex@plt>
mov    %ebx,%edi
shr    $0xc,%edi
and    $0xf,%edi
call   1030 <tty_hex@plt>
mov    %ebx,%edi
shr    $0x10,%edi
and    $0xf,%edi
call   1030 <tty_hex@plt>
mov    %ebx,%edi
shr    $0x14,%edi
and    $0xf,%edi
call   1030 <tty_hex@plt>
mov    %ebx,%edi
shr    $0x18,%edi
and    $0xf,%edi
call   1030 <tty_hex@plt>
shr    $0x1c,%ebx
mov    %ebx,%edi
call   1030 <tty_hex@plt>
lea    0xe76(%rip),%rdi
pop    %rbx
jmp    1040 <tty_puts@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"0x00000000\00"
define void @tty_put_ui32_hex(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %21, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 8
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %4
%11 = mul nsw i32 %10, 4
%12 = lshr i32 %9, %11
%13 = and i32 %12, 15
%14 = call signext i8 @tty_hex(i32 %13)
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%17 = sub nsw i32 7, %16
%18 = add nsw i32 2, %17
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
store i8 %14, i8* %20
br label %21
21: ; preds = %8
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %5
24: ; preds = %5
%25 = load i8*, i8** %3
%26 = call i32 @tty_puts(i8* %25)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"0x00000000\00"
define void @tty_put_ui32_hex(i32 %0) {
%2 = and i32 %0, 15
%3 = tail call signext i8 @tty_hex(i32 %2)
%4 = lshr i32 %0, 4
%5 = and i32 %4, 15
%6 = tail call signext i8 @tty_hex(i32 %5)
%7 = lshr i32 %0, 8
%8 = and i32 %7, 15
%9 = tail call signext i8 @tty_hex(i32 %8)
%10 = lshr i32 %0, 12
%11 = and i32 %10, 15
%12 = tail call signext i8 @tty_hex(i32 %11)
%13 = lshr i32 %0, 16
%14 = and i32 %13, 15
%15 = tail call signext i8 @tty_hex(i32 %14)
%16 = lshr i32 %0, 20
%17 = and i32 %16, 15
%18 = tail call signext i8 @tty_hex(i32 %17)
%19 = lshr i32 %0, 24
%20 = and i32 %19, 15
%21 = tail call signext i8 @tty_hex(i32 %20)
%22 = lshr i32 %0, 28
%23 = tail call signext i8 @tty_hex(i32 %22)
%24 = tail call i32 @tty_puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
ret void
}