#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*/ write(int, char *, int);
void put_hex(char c) {
  int i;
  char str[64];
  char *hex;
  hex = "0123456789abcdef";
  i = 0;
  while (c) {
    str[i] = hex[c % 16];
    c = c / 16;
    ++i;
  }
  if (i < 2)
    write(1, "0", 1);
  while (i--) {
    write(1, &str[i], 1);
  }
  return;
}


x86 assembly (clang, -O0):
<put_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
lea    0xedb(%rip),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x8(%rbp)
cmpb   $0x0,-0x1(%rbp)
je     117d <put_hex+0x6d>
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
movsbl -0x1(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x60(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x8(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
movsbl -0x1(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %al,-0x1(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1130 <put_hex+0x20>
cmpl   $0x2,-0x8(%rbp)
jge    119a <put_hex+0x8a>
mov    $0x1,%edx
lea    0xe7e(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    119f <put_hex+0x8f>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11cf <put_hex+0xbf>
movslq -0x8(%rbp),%rax
lea    -0x50(%rbp),%rsi
add    %rax,%rsi
mov    $0x1,%edx
mov    %edx,%edi
call   1030 <write@plt>
jmp    119f <put_hex+0x8f>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_hex>:
test   %dil,%dil
je     11c4 <put_hex+0xb4>
push   %r14
push   %rbx
sub    $0x48,%rsp
xor    %r14d,%r14d
lea    0xed6(%rip),%rax
nopw   0x0(%rax,%rax,1)
mov    %edi,%ecx
sar    $0x7,%cl
shr    $0x4,%cl
add    %dil,%cl
mov    %ecx,%edx
and    $0xf0,%dl
mov    %edi,%ebx
sub    %dl,%bl
movsbq %bl,%rdx
movzbl (%rdx,%rax,1),%edx
mov    %dl,(%rsp,%r14,1)
sar    $0x4,%cl
add    $0x1,%r14
add    $0xf,%dil
cmp    $0x1e,%dil
mov    %ecx,%edi
ja     1130 <put_hex+0x20>
cmp    $0x1,%r14d
ja     118a <put_hex+0x7a>
lea    0xea1(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
test   %r14d,%r14d
mov    $0x1,%r14d
je     11bc <put_hex+0xac>
movslq %r14d,%rax
mov    %rsp,%rcx
lea    (%rax,%rcx,1),%rbx
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0xffffffffffffffff,%rbx
add    $0xffffffff,%r14d
jne    11a0 <put_hex+0x90>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe46(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
jmp    1030 <write@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789abcdef\00"
@.str.1 = [2 x i8] c"0\00"
define void @put_hex(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = alloca i8*
store i8 %0, i8* %2
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %5
store i32 0, i32* %3
br label %6
6: ; preds = %9, %1
%7 = load i8, i8* %2
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = load i8*, i8** %5
%11 = load i8, i8* %2
%12 = sext i8 %11 to i32
%13 = srem i32 %12, 16
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %10, i64 %14
%16 = load i8, i8* %15
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %18
store i8 %16, i8* %19
%20 = load i8, i8* %2
%21 = sext i8 %20 to i32
%22 = sdiv i32 %21, 16
%23 = trunc i32 %22 to i8
store i8 %23, i8* %2
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %6
26: ; preds = %6
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 2
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %31
31: ; preds = %29, %26
br label %32
32: ; preds = %36, %31
%33 = load i32, i32* %3
%34 = add nsw i32 %33, -1
store i32 %34, i32* %3
%35 = icmp ne i32 %33, 0
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %38
%40 = call i32 @write(i32 1, i8* %39, i32 1)
br label %32
41: ; preds = %32
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
@.str.1 = [2 x i8] c"0\00"
define void @put_hex(i8 signext %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8 %0, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %36
7: ; preds = %1, %7
%8 = phi i64 [ %16, %7 ], [ 0, %1 ]
%9 = phi i8 [ %15, %7 ], [ %0, %1 ]
%10 = srem i8 %9, 16
%11 = sext i8 %10 to i64
%12 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %8
store i8 %13, i8* %14
%15 = sdiv i8 %9, 16
%16 = add nuw i64 %8, 1
%17 = add i8 %9, 15
%18 = icmp ult i8 %17, 31
br i1 %18, label %19, label %7
19: ; preds = %7
%20 = trunc i64 %16 to i32
%21 = icmp ult i32 %20, 2
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%24 = icmp eq i32 %20, 0
br i1 %24, label %36, label %25
25: ; preds = %19, %22
%26 = phi i64 [ 1, %22 ], [ %16, %19 ]
%27 = shl i64 %26, 32
%28 = ashr exact i64 %27, 32
br label %29
29: ; preds = %25, %29
%30 = phi i64 [ %28, %25 ], [ %31, %29 ]
%31 = add nsw i64 %30, -1
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %31
%33 = call i32 @write(i32 1, i8* %32, i32 1)
%34 = trunc i64 %31 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %29
36: ; preds = %29, %5, %22
ret void
}