#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*/ putc(char const);
void puthex(unsigned int x) {
  static const char *hex = "0123456789abcdef";
  for (int i = 0; i < 8; i++, x >>= 4)
    putc(hex[x & 0xf]);
}


x86 assembly (clang, -O0):
<puthex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    115b <puthex+0x4b>
mov    0x2ef5(%rip),%rax
mov    -0x4(%rbp),%ecx
and    $0xf,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <putc@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x4(%rbp)
jmp    1122 <puthex+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puthex>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    %edi,%r14d
mov    %r14d,%eax
and    $0xf,%eax
lea    0xed9(%rip),%r15
movsbl (%rax,%r15,1),%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x4,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x14,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
call   1030 <putc@plt>
shr    $0x18,%ebx
and    $0xf,%ebx
movsbl (%rbx,%r15,1),%edi
call   1030 <putc@plt>
shr    $0x1c,%r14
movsbl (%r14,%r15,1),%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putc@plt>

LLVM IR (-O0):
@puthex.hex = internal global i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i32 0, i32 0)
@.str = [17 x i8] c"0123456789abcdef\00"
define void @puthex(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %15, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 8
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = load i8*, i8** @puthex.hex
%9 = load i32, i32* %2
%10 = and i32 %9, 15
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = load i8, i8* %12
%14 = call i32 @putc(i8 signext %13)
br label %15
15: ; preds = %7
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
%18 = load i32, i32* %2
%19 = lshr i32 %18, 4
store i32 %19, i32* %2
br label %4
20: ; preds = %4
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
define void @puthex(i32 %0) {
%2 = and i32 %0, 15
%3 = zext i32 %2 to i64
%4 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %3
%5 = load i8, i8* %4
%6 = tail call i32 @putc(i8 signext %5)
%7 = lshr i32 %0, 4
%8 = and i32 %7, 15
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32 @putc(i8 signext %11)
%13 = lshr i32 %0, 8
%14 = and i32 %13, 15
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = tail call i32 @putc(i8 signext %17)
%19 = lshr i32 %0, 12
%20 = and i32 %19, 15
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @putc(i8 signext %23)
%25 = lshr i32 %0, 16
%26 = and i32 %25, 15
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = tail call i32 @putc(i8 signext %29)
%31 = lshr i32 %0, 20
%32 = and i32 %31, 15
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = tail call i32 @putc(i8 signext %35)
%37 = lshr i32 %0, 24
%38 = and i32 %37, 15
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = tail call i32 @putc(i8 signext %41)
%43 = lshr i32 %0, 28
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = tail call i32 @putc(i8 signext %46)
ret void
}