#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ writechar(char);
void writeHex(uint32_t v) {
  int i;
  uint8_t nibble;
  char c;
  for (i = 7; i >= 0; i--) {
    nibble = (v >> (i * 4)) & 0x0f;
    if (nibble <= 9)
      c = (char)(nibble + '0');
    else
      c = (char)(nibble - 10 + 'A');
    writechar(c);
  }
}


x86 assembly (clang, -O0):
<writeHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x7,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1178 <writeHex+0x68>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x2,%ecx
sar    %cl,%eax
and    $0xf,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x9,-0xc(%rbp)
jg     1155 <writeHex+0x45>
mov    -0xc(%rbp),%eax
add    $0x30,%eax
mov    %al,-0xd(%rbp)
jmp    1161 <writeHex+0x51>
mov    -0xc(%rbp),%eax
sub    $0xa,%eax
add    $0x41,%eax
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%edi
call   1030 <writechar@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1122 <writeHex+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeHex>:
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 <writechar@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 <writechar@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 <writechar@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 <writechar@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 <writechar@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 <writechar@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 <writechar@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 <writechar@plt>

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

LLVM IR (-O2):
define void @writeHex(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 @writechar(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 = add nuw nsw i8 %12, 55
%15 = select i1 %11, i8 %13, i8 %14
%16 = tail call i32 @writechar(i8 signext %15)
%17 = lshr i32 %0, 20
%18 = and i32 %17, 15
%19 = icmp ult i32 %18, 10
%20 = trunc i32 %18 to i8
%21 = or i8 %20, 48
%22 = add nuw nsw i8 %20, 55
%23 = select i1 %19, i8 %21, i8 %22
%24 = tail call i32 @writechar(i8 signext %23)
%25 = lshr i32 %0, 16
%26 = and i32 %25, 15
%27 = icmp ult i32 %26, 10
%28 = trunc i32 %26 to i8
%29 = or i8 %28, 48
%30 = add nuw nsw i8 %28, 55
%31 = select i1 %27, i8 %29, i8 %30
%32 = tail call i32 @writechar(i8 signext %31)
%33 = lshr i32 %0, 12
%34 = and i32 %33, 15
%35 = icmp ult i32 %34, 10
%36 = trunc i32 %34 to i8
%37 = or i8 %36, 48
%38 = add nuw nsw i8 %36, 55
%39 = select i1 %35, i8 %37, i8 %38
%40 = tail call i32 @writechar(i8 signext %39)
%41 = lshr i32 %0, 8
%42 = and i32 %41, 15
%43 = icmp ult i32 %42, 10
%44 = trunc i32 %42 to i8
%45 = or i8 %44, 48
%46 = add nuw nsw i8 %44, 55
%47 = select i1 %43, i8 %45, i8 %46
%48 = tail call i32 @writechar(i8 signext %47)
%49 = lshr i32 %0, 4
%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 @writechar(i8 signext %55)
%57 = and i32 %0, 15
%58 = icmp ult i32 %57, 10
%59 = trunc i32 %57 to i8
%60 = or i8 %59, 48
%61 = add nuw nsw i8 %59, 55
%62 = select i1 %58, i8 %60, i8 %61
%63 = tail call i32 @writechar(i8 signext %62)
ret void
}