#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(unsigned char);
void puthex(unsigned long val) {
  unsigned char c;
  int i;
  putc('0');
  putc('x');
  for (i = 0; i < 8; i++) {
    c = (val >> ((7 - i) * 4)) & 0xF;
    if ((c >= 0) && (c <= 9)) {
      c = '0' + c;
    } else if ((c >= 0xA) && (c <= 0xF)) {
      c = 'A' + (c - 0xA);
    }
    putc(c);
  }
}


x86 assembly (clang, -O0):
<puthex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x30,%edi
call   1030 <putc@plt>
mov    $0x78,%edi
call   1030 <putc@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    11c8 <puthex+0xb8>
mov    -0x8(%rbp),%rax
mov    $0x7,%ecx
sub    -0x10(%rbp),%ecx
shl    $0x2,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
and    $0xf,%rax
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jl     1185 <puthex+0x75>
movzbl -0x9(%rbp),%eax
cmp    $0x9,%eax
jg     1185 <puthex+0x75>
movzbl -0x9(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x9(%rbp)
jmp    11b1 <puthex+0xa1>
movzbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jl     11ac <puthex+0x9c>
movzbl -0x9(%rbp),%eax
cmp    $0xf,%eax
jg     11ac <puthex+0x9c>
movzbl -0x9(%rbp),%eax
sub    $0xa,%eax
add    $0x41,%eax
mov    %al,-0x9(%rbp)
jmp    11b1 <puthex+0xa1>
movzbl -0x9(%rbp),%edi
call   1030 <putc@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1137 <puthex+0x27>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puthex>:
push   %rbx
mov    %rdi,%rbx
mov    $0x30,%edi
call   1030 <putc@plt>
mov    $0x78,%edi
call   1030 <putc@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   1030 <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   1030 <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   1030 <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   1030 <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   1030 <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   1030 <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   1030 <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    1030 <putc@plt>

LLVM IR (-O0):
define void @puthex(i64 %0) {
%2 = alloca i64
%3 = alloca i8
%4 = alloca i32
store i64 %0, i64* %2
%5 = call i32 @putc(i8 zeroext 48)
%6 = call i32 @putc(i8 zeroext 120)
store i32 0, i32* %4
br label %7
7: ; preds = %49, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 8
br i1 %9, label %10, label %52
10: ; preds = %7
%11 = load i64, i64* %2
%12 = load i32, i32* %4
%13 = sub nsw i32 7, %12
%14 = mul nsw i32 %13, 4
%15 = zext i32 %14 to i64
%16 = lshr i64 %11, %15
%17 = and i64 %16, 15
%18 = trunc i64 %17 to i8
store i8 %18, i8* %3
%19 = load i8, i8* %3
%20 = zext i8 %19 to i32
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %10
%23 = load i8, i8* %3
%24 = zext i8 %23 to i32
%25 = icmp sle i32 %24, 9
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i8, i8* %3
%28 = zext i8 %27 to i32
%29 = add nsw i32 48, %28
%30 = trunc i32 %29 to i8
store i8 %30, i8* %3
br label %46
31: ; preds = %22, %10
%32 = load i8, i8* %3
%33 = zext i8 %32 to i32
%34 = icmp sge i32 %33, 10
br i1 %34, label %35, label %45
35: ; preds = %31
%36 = load i8, i8* %3
%37 = zext i8 %36 to i32
%38 = icmp sle i32 %37, 15
br i1 %38, label %39, label %45
39: ; preds = %35
%40 = load i8, i8* %3
%41 = zext i8 %40 to i32
%42 = sub nsw i32 %41, 10
%43 = add nsw i32 65, %42
%44 = trunc i32 %43 to i8
store i8 %44, i8* %3
br label %45
45: ; preds = %39, %35, %31
br label %46
46: ; preds = %45, %26
%47 = load i8, i8* %3
%48 = call i32 @putc(i8 zeroext %47)
br label %49
49: ; preds = %46
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %7
52: ; preds = %7
ret void
}

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