#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(int);
int /*<<< orphan*/ puts(char *);
void puthex(unsigned int val) {
  int i;
  int j;
  puts("0x");
  for (i = 0; i < 8; i++) {
    j = ((val >> (7 - i) * 4) & 0xf);
    if ((j >= 0) && (j <= 9))
      putc(j + '0');
    else
      putc(j + 'A' - 0xa);
  }
}


x86 assembly (clang, -O0):
<puthex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    11a3 <puthex+0x83>
mov    -0x4(%rbp),%eax
mov    $0x7,%ecx
sub    -0x8(%rbp),%ecx
shl    $0x2,%ecx
shr    %cl,%eax
and    $0xf,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1182 <puthex+0x62>
cmpl   $0x9,-0xc(%rbp)
jg     1182 <puthex+0x62>
mov    -0xc(%rbp),%edi
add    $0x30,%edi
call   1040 <putc@plt>
jmp    1190 <puthex+0x70>
mov    -0xc(%rbp),%edi
add    $0x41,%edi
sub    $0xa,%edi
call   1040 <putc@plt>
jmp    1195 <puthex+0x75>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113e <puthex+0x1e>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puthex>:
push   %rbx
mov    %edi,%ebx
lea    0xed6(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
shr    $0x1c,%edi
lea    0x30(%rdi),%eax
add    $0x37,%edi
cmp    $0xa0000000,%ebx
cmovb  %eax,%edi
call   1040 <putc@plt>
mov    %ebx,%eax
shr    $0x18,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edi
cmp    $0xa,%eax
cmovb  %ecx,%edi
call   1040 <putc@plt>
mov    %ebx,%eax
shr    $0x14,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edi
cmp    $0xa,%eax
cmovb  %ecx,%edi
call   1040 <putc@plt>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edi
cmp    $0xa,%eax
cmovb  %ecx,%edi
call   1040 <putc@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edi
cmp    $0xa,%eax
cmovb  %ecx,%edi
call   1040 <putc@plt>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edi
cmp    $0xa,%eax
cmovb  %ecx,%edi
call   1040 <putc@plt>
mov    %ebx,%eax
shr    $0x4,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edi
cmp    $0xa,%eax
cmovb  %ecx,%edi
call   1040 <putc@plt>
and    $0xf,%ebx
lea    0x30(%rbx),%eax
lea    0x37(%rbx),%edi
cmp    $0xa,%ebx
cmovb  %eax,%edi
pop    %rbx
jmp    1040 <putc@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
define void @puthex(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %6
6: ; preds = %31, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %34
9: ; preds = %6
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = sub nsw i32 7, %11
%13 = mul nsw i32 %12, 4
%14 = lshr i32 %10, %13
%15 = and i32 %14, 15
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %9
%19 = load i32, i32* %4
%20 = icmp sle i32 %19, 9
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 48
%24 = call i32 @putc(i32 %23)
br label %30
25: ; preds = %18, %9
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 65
%28 = sub nsw i32 %27, 10
%29 = call i32 @putc(i32 %28)
br label %30
30: ; preds = %25, %21
br label %31
31: ; preds = %30
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %6
34: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
define void @puthex(i32 %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = lshr i32 %0, 28
%4 = icmp ult i32 %0, -1610612736
%5 = or i32 %3, 48
%6 = add nuw nsw i32 %3, 55
%7 = select i1 %4, i32 %5, i32 %6
%8 = tail call i32 @putc(i32 %7)
%9 = lshr i32 %0, 24
%10 = and i32 %9, 15
%11 = icmp ult i32 %10, 10
%12 = or i32 %10, 48
%13 = add nuw nsw i32 %10, 55
%14 = select i1 %11, i32 %12, i32 %13
%15 = tail call i32 @putc(i32 %14)
%16 = lshr i32 %0, 20
%17 = and i32 %16, 15
%18 = icmp ult i32 %17, 10
%19 = or i32 %17, 48
%20 = add nuw nsw i32 %17, 55
%21 = select i1 %18, i32 %19, i32 %20
%22 = tail call i32 @putc(i32 %21)
%23 = lshr i32 %0, 16
%24 = and i32 %23, 15
%25 = icmp ult i32 %24, 10
%26 = or i32 %24, 48
%27 = add nuw nsw i32 %24, 55
%28 = select i1 %25, i32 %26, i32 %27
%29 = tail call i32 @putc(i32 %28)
%30 = lshr i32 %0, 12
%31 = and i32 %30, 15
%32 = icmp ult i32 %31, 10
%33 = or i32 %31, 48
%34 = add nuw nsw i32 %31, 55
%35 = select i1 %32, i32 %33, i32 %34
%36 = tail call i32 @putc(i32 %35)
%37 = lshr i32 %0, 8
%38 = and i32 %37, 15
%39 = icmp ult i32 %38, 10
%40 = or i32 %38, 48
%41 = add nuw nsw i32 %38, 55
%42 = select i1 %39, i32 %40, i32 %41
%43 = tail call i32 @putc(i32 %42)
%44 = lshr i32 %0, 4
%45 = and i32 %44, 15
%46 = icmp ult i32 %45, 10
%47 = or i32 %45, 48
%48 = add nuw nsw i32 %45, 55
%49 = select i1 %46, i32 %47, i32 %48
%50 = tail call i32 @putc(i32 %49)
%51 = and i32 %0, 15
%52 = icmp ult i32 %51, 10
%53 = or i32 %51, 48
%54 = add nuw nsw i32 %51, 55
%55 = select i1 %52, i32 %53, i32 %54
%56 = tail call i32 @putc(i32 %55)
ret void
}