#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*/ putch(char);
void print_hex(unsigned int i) {
  unsigned int x;
  int nibble;
  for (nibble = 0; nibble < 8; nibble++) {
    x = (i >> (4 * (7 - nibble))) & 0x0000000F;
    if (x < 10) {
      putch('0' + x);
    } else if (x >= 10 && x < 16) {
      putch('A' + x - 10);
    } else {
      putch('?');
    }
  }
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    11ab <print_hex+0x9b>
mov    -0x4(%rbp),%eax
mov    $0x7,%ecx
sub    -0xc(%rbp),%ecx
shl    $0x2,%ecx
shr    %cl,%eax
and    $0xf,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jae    115f <print_hex+0x4f>
mov    -0x8(%rbp),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1030 <putch@plt>
jmp    1198 <print_hex+0x88>
cmpl   $0xa,-0x8(%rbp)
jb     1189 <print_hex+0x79>
cmpl   $0x10,-0x8(%rbp)
jae    1189 <print_hex+0x79>
mov    -0x8(%rbp),%eax
add    $0x41,%eax
sub    $0xa,%eax
movsbl %al,%edi
call   1030 <putch@plt>
jmp    1193 <print_hex+0x83>
mov    $0x3f,%edi
call   1030 <putch@plt>
jmp    1198 <print_hex+0x88>
jmp    119d <print_hex+0x8d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1122 <print_hex+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbx
mov    %edi,%ebx
mov    %edi,%eax
shr    $0x1c,%eax
lea    0x30(%rax),%ecx
add    $0x37,%al
cmp    $0xa0000000,%edi
movzbl %cl,%ecx
movzbl %al,%eax
cmovb  %ecx,%eax
movzbl %al,%edi
call   1030 <putch@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   1030 <putch@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   1030 <putch@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   1030 <putch@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   1030 <putch@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   1030 <putch@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   1030 <putch@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    1030 <putch@plt>

LLVM IR (-O0):
define void @print_hex(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %5
5: ; preds = %38, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 8
br i1 %7, label %8, label %41
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %4
%11 = sub nsw i32 7, %10
%12 = mul nsw i32 4, %11
%13 = lshr i32 %9, %12
%14 = and i32 %13, 15
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp ult i32 %15, 10
br i1 %16, label %17, label %22
17: ; preds = %8
%18 = load i32, i32* %3
%19 = add i32 48, %18
%20 = trunc i32 %19 to i8
%21 = call i32 @putch(i8 signext %20)
br label %37
22: ; preds = %8
%23 = load i32, i32* %3
%24 = icmp uge i32 %23, 10
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i32, i32* %3
%27 = icmp ult i32 %26, 16
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32, i32* %3
%30 = add i32 65, %29
%31 = sub i32 %30, 10
%32 = trunc i32 %31 to i8
%33 = call i32 @putch(i8 signext %32)
br label %36
34: ; preds = %25, %22
%35 = call i32 @putch(i8 signext 63)
br label %36
36: ; preds = %34, %28
br label %37
37: ; preds = %36, %17
br label %38
38: ; preds = %37
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %5
41: ; preds = %5
ret void
}

LLVM IR (-O2):
define void @print_hex(i32 %0) {
%2 = lshr i32 %0, 28
%3 = icmp ult i32 %0, -1610612736
%4 = trunc i32 %2 to i8
%5 = or i8 %4, 48
%6 = add nuw nsw i8 %4, 55
%7 = select i1 %3, i8 %5, i8 %6
%8 = tail call i32 @putch(i8 signext %7)
%9 = lshr i32 %0, 24
%10 = and i32 %9, 15
%11 = icmp ult i32 %10, 10
%12 = trunc i32 %10 to i8
%13 = or i8 %12, 48
%14 = trunc i32 %10 to i8
%15 = add nuw nsw i8 %14, 55
%16 = select i1 %11, i8 %13, i8 %15
%17 = tail call i32 @putch(i8 signext %16)
%18 = lshr i32 %0, 20
%19 = and i32 %18, 15
%20 = icmp ult i32 %19, 10
%21 = trunc i32 %19 to i8
%22 = or i8 %21, 48
%23 = trunc i32 %19 to i8
%24 = add nuw nsw i8 %23, 55
%25 = select i1 %20, i8 %22, i8 %24
%26 = tail call i32 @putch(i8 signext %25)
%27 = lshr i32 %0, 16
%28 = and i32 %27, 15
%29 = icmp ult i32 %28, 10
%30 = trunc i32 %28 to i8
%31 = or i8 %30, 48
%32 = trunc i32 %28 to i8
%33 = add nuw nsw i8 %32, 55
%34 = select i1 %29, i8 %31, i8 %33
%35 = tail call i32 @putch(i8 signext %34)
%36 = lshr i32 %0, 12
%37 = and i32 %36, 15
%38 = icmp ult i32 %37, 10
%39 = trunc i32 %37 to i8
%40 = or i8 %39, 48
%41 = trunc i32 %37 to i8
%42 = add nuw nsw i8 %41, 55
%43 = select i1 %38, i8 %40, i8 %42
%44 = tail call i32 @putch(i8 signext %43)
%45 = lshr i32 %0, 8
%46 = and i32 %45, 15
%47 = icmp ult i32 %46, 10
%48 = trunc i32 %46 to i8
%49 = or i8 %48, 48
%50 = trunc i32 %46 to i8
%51 = add nuw nsw i8 %50, 55
%52 = select i1 %47, i8 %49, i8 %51
%53 = tail call i32 @putch(i8 signext %52)
%54 = lshr i32 %0, 4
%55 = and i32 %54, 15
%56 = icmp ult i32 %55, 10
%57 = trunc i32 %55 to i8
%58 = or i8 %57, 48
%59 = trunc i32 %55 to i8
%60 = add nuw nsw i8 %59, 55
%61 = select i1 %56, i8 %58, i8 %60
%62 = tail call i32 @putch(i8 signext %61)
%63 = and i32 %0, 15
%64 = icmp ult i32 %63, 10
%65 = trunc i32 %63 to i8
%66 = or i8 %65, 48
%67 = trunc i32 %63 to i8
%68 = add nuw nsw i8 %67, 55
%69 = select i1 %64, i8 %66, i8 %68
%70 = tail call i32 @putch(i8 signext %69)
ret void
}