#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void printhex(FILE *fp, int val) {
  int i;
  static char hexdigits[] = "0123456789abcdef";
  for (i = 0; i < 8; i++) {
    fputc(hexdigits[(val >> 28) & 15], fp);
    val <<= 4;
  }
}


x86 assembly (clang, -O0):
<printhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    1169 <printhex+0x59>
mov    -0xc(%rbp),%eax
sar    $0x1c,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0x2eed(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <printhex+0x16>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printhex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%r15d
mov    %r15,%rax
shr    $0x1c,%rax
lea    0xed2(%rip),%r12
movsbl (%rax,%r12,1),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %ebx,%eax
shr    $0x18,%eax
and    $0xf,%eax
movsbl (%rax,%r12,1),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %ebx,%eax
shr    $0x14,%eax
and    $0xf,%eax
movsbl (%rax,%r12,1),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
movsbl (%rax,%r12,1),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
movsbl (%rax,%r12,1),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
movsbl (%rax,%r12,1),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
shr    $0x4,%ebx
and    $0xf,%ebx
movsbl (%rbx,%r12,1),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
and    $0xf,%r15d
movsbl (%r15,%r12,1),%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <fputc@plt>

LLVM IR (-O0):
@printhex.hexdigits = internal global [17 x i8] c"0123456789abcdef\00"
define void @printhex(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %20, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = load i32, i32* %4
%11 = ashr i32 %10, 28
%12 = and i32 %11, 15
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [17 x i8], [17 x i8]* @printhex.hexdigits, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = load i32*, i32** %3
%17 = call i32 @fputc(i8 signext %15, i32* %16)
%18 = load i32, i32* %4
%19 = shl i32 %18, 4
store i32 %19, i32* %4
br label %20
20: ; preds = %9
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %6
23: ; preds = %6
ret void
}

LLVM IR (-O2):
@printhex.hexdigits = internal unnamed_addr constant [17 x i8] c"0123456789abcdef\00"
define void @printhex(i32* nocapture %0, i32 %1) {
%3 = lshr i32 %1, 28
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds [17 x i8], [17 x i8]* @printhex.hexdigits, i64 0, i64 %4
%6 = load i8, i8* %5
%7 = tail call i32 @fputc(i8 signext %6, i32* %0)
%8 = lshr i32 %1, 24
%9 = and i32 %8, 15
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [17 x i8], [17 x i8]* @printhex.hexdigits, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = tail call i32 @fputc(i8 signext %12, i32* %0)
%14 = lshr i32 %1, 20
%15 = and i32 %14, 15
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [17 x i8], [17 x i8]* @printhex.hexdigits, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = tail call i32 @fputc(i8 signext %18, i32* %0)
%20 = lshr i32 %1, 16
%21 = and i32 %20, 15
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [17 x i8], [17 x i8]* @printhex.hexdigits, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = tail call i32 @fputc(i8 signext %24, i32* %0)
%26 = lshr i32 %1, 12
%27 = and i32 %26, 15
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [17 x i8], [17 x i8]* @printhex.hexdigits, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = tail call i32 @fputc(i8 signext %30, i32* %0)
%32 = lshr i32 %1, 8
%33 = and i32 %32, 15
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [17 x i8], [17 x i8]* @printhex.hexdigits, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = tail call i32 @fputc(i8 signext %36, i32* %0)
%38 = lshr i32 %1, 4
%39 = and i32 %38, 15
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds [17 x i8], [17 x i8]* @printhex.hexdigits, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = tail call i32 @fputc(i8 signext %42, i32* %0)
%44 = and i32 %1, 15
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds [17 x i8], [17 x i8]* @printhex.hexdigits, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = tail call i32 @fputc(i8 signext %47, i32* %0)
ret void
}