#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);
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('0' + j);
    else
      putc('A' + j - 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    11a9 <puthex+0x89>
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     1185 <puthex+0x65>
cmpl   $0x9,-0xc(%rbp)
jg     1185 <puthex+0x65>
mov    -0xc(%rbp),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1040 <putc@plt>
jmp    1196 <puthex+0x76>
mov    -0xc(%rbp),%eax
add    $0x41,%eax
sub    $0xa,%eax
movsbl %al,%edi
call   1040 <putc@plt>
jmp    119b <puthex+0x7b>
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,%eax
shr    $0x1c,%eax
lea    0x30(%rax),%ecx
add    $0x37,%al
cmp    $0xa0000000,%ebx
movzbl %cl,%ecx
movzbl %al,%eax
cmovb  %ecx,%eax
movzbl %al,%edi
call   1040 <putc@plt>
mov    %ebx,%eax
shr    $0x18,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1040 <putc@plt>
mov    %ebx,%eax
shr    $0x14,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1040 <putc@plt>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1040 <putc@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1040 <putc@plt>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1040 <putc@plt>
mov    %ebx,%eax
shr    $0x4,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x37(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1040 <putc@plt>
and    $0xf,%ebx
lea    0x30(%rbx),%eax
lea    0x37(%rbx),%ecx
cmp    $0xa,%ebx
movzbl %al,%eax
movzbl %cl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%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 = %33, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %36
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 %26
18: ; preds = %9
%19 = load i32, i32* %4
%20 = icmp sle i32 %19, 9
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i32, i32* %4
%23 = add nsw i32 48, %22
%24 = trunc i32 %23 to i8
%25 = call i32 @putc(i8 signext %24)
br label %32
26: ; preds = %18, %9
%27 = load i32, i32* %4
%28 = add nsw i32 65, %27
%29 = sub nsw i32 %28, 10
%30 = trunc i32 %29 to i8
%31 = call i32 @putc(i8 signext %30)
br label %32
32: ; preds = %26, %21
br label %33
33: ; preds = %32
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %6
36: ; 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 = trunc i32 %3 to i8
%6 = or i8 %5, 48
%7 = add nuw nsw i8 %5, 55
%8 = select i1 %4, i8 %6, i8 %7
%9 = tail call i32 @putc(i8 signext %8)
%10 = lshr i32 %0, 24
%11 = and i32 %10, 15
%12 = icmp ult i32 %11, 10
%13 = trunc i32 %11 to i8
%14 = or i8 %13, 48
%15 = trunc i32 %11 to i8
%16 = add nuw nsw i8 %15, 55
%17 = select i1 %12, i8 %14, i8 %16
%18 = tail call i32 @putc(i8 signext %17)
%19 = lshr i32 %0, 20
%20 = and i32 %19, 15
%21 = icmp ult i32 %20, 10
%22 = trunc i32 %20 to i8
%23 = or i8 %22, 48
%24 = trunc i32 %20 to i8
%25 = add nuw nsw i8 %24, 55
%26 = select i1 %21, i8 %23, i8 %25
%27 = tail call i32 @putc(i8 signext %26)
%28 = lshr i32 %0, 16
%29 = and i32 %28, 15
%30 = icmp ult i32 %29, 10
%31 = trunc i32 %29 to i8
%32 = or i8 %31, 48
%33 = trunc i32 %29 to i8
%34 = add nuw nsw i8 %33, 55
%35 = select i1 %30, i8 %32, i8 %34
%36 = tail call i32 @putc(i8 signext %35)
%37 = lshr i32 %0, 12
%38 = and i32 %37, 15
%39 = icmp ult i32 %38, 10
%40 = trunc i32 %38 to i8
%41 = or i8 %40, 48
%42 = trunc i32 %38 to i8
%43 = add nuw nsw i8 %42, 55
%44 = select i1 %39, i8 %41, i8 %43
%45 = tail call i32 @putc(i8 signext %44)
%46 = lshr i32 %0, 8
%47 = and i32 %46, 15
%48 = icmp ult i32 %47, 10
%49 = trunc i32 %47 to i8
%50 = or i8 %49, 48
%51 = trunc i32 %47 to i8
%52 = add nuw nsw i8 %51, 55
%53 = select i1 %48, i8 %50, i8 %52
%54 = tail call i32 @putc(i8 signext %53)
%55 = lshr i32 %0, 4
%56 = and i32 %55, 15
%57 = icmp ult i32 %56, 10
%58 = trunc i32 %56 to i8
%59 = or i8 %58, 48
%60 = trunc i32 %56 to i8
%61 = add nuw nsw i8 %60, 55
%62 = select i1 %57, i8 %59, i8 %61
%63 = tail call i32 @putc(i8 signext %62)
%64 = and i32 %0, 15
%65 = icmp ult i32 %64, 10
%66 = trunc i32 %64 to i8
%67 = or i8 %66, 48
%68 = trunc i32 %64 to i8
%69 = add nuw nsw i8 %68, 55
%70 = select i1 %65, i8 %67, i8 %69
%71 = tail call i32 @putc(i8 signext %70)
ret void
}