#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 print_str(char *);
int print_hex(int i) {
  int index = 7;
  int count = print_str("0x");
  char char_map[] = "0123456789ABCDEF";
  char digits[9];
  while (index >= 0) {
    digits[index] = char_map[i & 15];
    i = i >> 4;
    index--;
  }
  digits[8] = 0;
  count += print_str(digits);
  return count;
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x7,-0x8(%rbp)
lea    0xed7(%rip),%rdi
call   1030 <print_str@plt>
mov    %eax,-0xc(%rbp)
mov    0xed8(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed5(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xed3(%rip),%al
mov    %al,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1185 <print_hex+0x75>
mov    -0x4(%rbp),%eax
and    $0xf,%eax
cltq
mov    -0x20(%rbp,%rax,1),%cl
movslq -0x8(%rbp),%rax
mov    %cl,-0x29(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1150 <print_hex+0x40>
movb   $0x0,-0x21(%rbp)
lea    -0x29(%rbp),%rdi
call   1030 <print_str@plt>
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0xee1(%rip),%rdi
call   1030 <print_str@plt>
mov    %eax,%ebp
mov    %ebx,%eax
mov    %eax,%edx
and    $0xf,%edx
lea    0xedc(%rip),%rcx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x16(%rsp)
mov    %ebx,%edx
shr    $0x4,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x15(%rsp)
mov    %ebx,%edx
shr    $0x8,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x14(%rsp)
mov    %ebx,%edx
shr    $0xc,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x13(%rsp)
mov    %ebx,%edx
shr    $0x10,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x12(%rsp)
mov    %ebx,%edx
shr    $0x14,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x11(%rsp)
shr    $0x18,%ebx
and    $0xf,%ebx
mov    (%rbx,%rcx,1),%dl
mov    %dl,0x10(%rsp)
shr    $0x1c,%rax
mov    (%rax,%rcx,1),%al
mov    %al,0xf(%rsp)
movb   $0x0,0x17(%rsp)
lea    0xf(%rsp),%rdi
call   1030 <print_str@plt>
add    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
@__const.print_hex.char_map = [17 x i8] c"0123456789ABCDEF\00"
define i32 @print_hex(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [17 x i8]
%6 = alloca [9 x i8]
store i32 %0, i32* %2
store i32 7, i32* %3
%7 = call i32 @print_str(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %7, i32* %4
%8 = bitcast [17 x i8]* %5 to i8*
br label %9
9: ; preds = %12, %1
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = load i32, i32* %2
%14 = and i32 %13, 15
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 %19
store i8 %17, i8* %20
%21 = load i32, i32* %2
%22 = ashr i32 %21, 4
store i32 %22, i32* %2
%23 = load i32, i32* %3
%24 = add nsw i32 %23, -1
store i32 %24, i32* %3
br label %9
25: ; preds = %9
%26 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 8
store i8 0, i8* %26
%27 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%28 = call i32 @print_str(i8* %27)
%29 = load i32, i32* %4
%30 = add nsw i32 %29, %28
store i32 %30, i32* %4
%31 = load i32, i32* %4
ret i32 %31
}

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