#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);
void printhex(int data) {
  int i = 0;
  char c;
  for (i = sizeof(int) * 2 - 1; i >= 0; i--) {
    c = data >> (i * 4);
    c &= 0xf;
    if (c > 9)
      putc(c - 10 + 'A');
    else
      putc(c + '0');
  }
}


x86 assembly (clang, -O0):
<printhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x7,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1191 <printhex+0x81>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x2,%ecx
sar    %cl,%eax
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
and    $0xf,%eax
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x9,%eax
jle    116f <printhex+0x5f>
movsbl -0x9(%rbp),%eax
sub    $0xa,%eax
add    $0x41,%eax
movsbl %al,%edi
call   1030 <putc@plt>
jmp    117e <printhex+0x6e>
movsbl -0x9(%rbp),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1030 <putc@plt>
jmp    1183 <printhex+0x73>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <printhex+0x19>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printhex>:
push   %rbx
mov    %edi,%ebx
mov    %edi,%eax
shr    $0x1c,%eax
lea    0x37(%rax),%ecx
or     $0x30,%al
cmp    $0xa0000000,%edi
movzbl %cl,%ecx
movzbl %al,%eax
cmovae %ecx,%eax
movzbl %al,%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x18,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
movzbl %cl,%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x14,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
movzbl %cl,%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
movzbl %cl,%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
movzbl %cl,%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
movzbl %cl,%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x4,%eax
and    $0xf,%eax
lea    0x37(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
movzbl %cl,%edi
call   1030 <putc@plt>
and    $0xf,%ebx
lea    0x37(%rbx),%eax
lea    0x30(%rbx),%ecx
cmp    $0xa,%ebx
movzbl %al,%eax
movzbl %cl,%ecx
cmovae %eax,%ecx
movzbl %cl,%edi
pop    %rbx
jmp    1030 <putc@plt>

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

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