#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 */
typedef int /*<<< orphan*/ mem;

/* Variables and functions */
int /*<<< orphan*/ fputs(int, char *);
void fput_hex(int fd, unsigned n) {
  char mem[] = "0x00000000";
  char *stack = mem + (sizeof(mem) / sizeof(mem[0])) - 1;
  do {
    char c = n % 16;
    if (c < 10)
      c += '0';
    else
      c += 'a' - 10;
    *--stack = c;
  } while (n /= 16);
  fputs(fd, mem);
}


x86 assembly (clang, -O0):
<fput_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0xedb(%rip),%rax
mov    %rax,-0x13(%rbp)
mov    0xed8(%rip),%ax
mov    %ax,-0xb(%rbp)
mov    0xed0(%rip),%al
mov    %al,-0x9(%rbp)
lea    -0x13(%rbp),%rax
add    $0xb,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf,%eax
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jge    1172 <fput_hex+0x62>
movsbl -0x21(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x21(%rbp)
jmp    117c <fput_hex+0x6c>
movsbl -0x21(%rbp),%eax
add    $0x57,%eax
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x8(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    114d <fput_hex+0x3d>
mov    -0x4(%rbp),%edi
lea    -0x13(%rbp),%rsi
call   1030 <fputs@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fput_hex>:
sub    $0x18,%rsp
movabs $0x3030303030307830,%rax
30 30 30
mov    %rax,0x8(%rsp)
movl   $0x303030,0xf(%rsp)
lea    0x11(%rsp),%rax
mov    %esi,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %esi,%edx
and    $0xf,%edx
lea    0x30(%rdx),%r8d
lea    0x57(%rdx),%r9d
cmp    $0xa,%edx
movzbl %r8b,%r8d
movzbl %r9b,%edx
cmovb  %r8d,%edx
mov    %dl,(%rax)
shr    $0x4,%ecx
add    $0xffffffffffffffff,%rax
cmp    $0xf,%esi
mov    %ecx,%esi
ja     1140 <fput_hex+0x30>
lea    0x8(%rsp),%rsi
call   1030 <fputs@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.fput_hex.mem = [11 x i8] c"0x00000000\00"
define void @fput_hex(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [11 x i8]
%6 = alloca i8*
%7 = alloca i8
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = bitcast [11 x i8]* %5 to i8*
%9 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds i8, i8* %9, i64 11
%11 = getelementptr inbounds i8, i8* %10, i64 -1
store i8* %11, i8** %6
br label %12
12: ; preds = %33, %2
%13 = load i32, i32* %4
%14 = urem i32 %13, 16
%15 = trunc i32 %14 to i8
store i8 %15, i8* %7
%16 = load i8, i8* %7
%17 = sext i8 %16 to i32
%18 = icmp slt i32 %17, 10
br i1 %18, label %19, label %24
19: ; preds = %12
%20 = load i8, i8* %7
%21 = sext i8 %20 to i32
%22 = add nsw i32 %21, 48
%23 = trunc i32 %22 to i8
store i8 %23, i8* %7
br label %29
24: ; preds = %12
%25 = load i8, i8* %7
%26 = sext i8 %25 to i32
%27 = add nsw i32 %26, 87
%28 = trunc i32 %27 to i8
store i8 %28, i8* %7
br label %29
29: ; preds = %24, %19
%30 = load i8, i8* %7
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %6
store i8 %30, i8* %32
br label %33
33: ; preds = %29
%34 = load i32, i32* %4
%35 = udiv i32 %34, 16
store i32 %35, i32* %4
%36 = icmp ne i32 %35, 0
br i1 %36, label %12, label %37
37: ; preds = %33
%38 = load i32, i32* %3
%39 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%40 = call i32 @fputs(i32 %38, i8* %39)
ret void
}

LLVM IR (-O2):
@__const.fput_hex.mem = [11 x i8] c"0x00000000\00"
define void @fput_hex(i32 %0, i32 %1) {
%3 = alloca [11 x i8]
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 10
br label %6
6: ; preds = %6, %2
%7 = phi i32 [ %1, %2 ], [ %16, %6 ]
%8 = phi i8* [ %5, %2 ], [ %15, %6 ]
%9 = and i32 %7, 15
%10 = icmp ult i32 %9, 10
%11 = trunc i32 %9 to i8
%12 = or i8 %11, 48
%13 = add nuw nsw i8 %11, 87
%14 = select i1 %10, i8 %12, i8 %13
%15 = getelementptr inbounds i8, i8* %8, i64 -1
store i8 %14, i8* %15
%16 = lshr i32 %7, 4
%17 = icmp ult i32 %7, 16
br i1 %17, label %18, label %6
18: ; preds = %6
%19 = call i32 @fputs(i32 %0, i8* %4)
ret void
}