#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 */
long num_hex_digits(long);
void make_hex_string_learning(long n, char *s) {
  const char hex_lookup[] = "0123456789abcdef";
  long len = num_hex_digits(n);
  if (len & 1) {
    *s++ = '0';
  }
  s[len] = '\0';
  for (--len; len >= 0; n >>= 4, --len) {
    s[len] = hex_lookup[n & 0xf];
  }
}


x86 assembly (clang, -O0):
<make_hex_string_learning>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xed9(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed6(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xed4(%rip),%al
mov    %al,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <num_hex_digits@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1170 <make_hex_string_learning+0x60>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x30,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jl     11c7 <make_hex_string_learning+0xb7>
mov    -0x8(%rbp),%rax
and    $0xf,%rax
mov    -0x30(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
sar    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
jmp    1188 <make_hex_string_learning+0x78>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_hex_string_learning>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <num_hex_digits@plt>
mov    %rax,%rcx
test   $0x1,%al
je     112e <make_hex_string_learning+0x1e>
movb   $0x30,(%r14)
add    $0x1,%r14
movb   $0x0,(%r14,%rcx,1)
test   %rax,%rax
jle    11cf <make_hex_string_learning+0xbf>
lea    -0x1(%rax),%r8
and    $0x3,%rax
je     116c <make_hex_string_learning+0x5c>
lea    0xeb3(%rip),%rsi
nopl   (%rax)
mov    %ebx,%edi
and    $0xf,%edi
movzbl (%rdi,%rsi,1),%edx
mov    %dl,-0x1(%r14,%rcx,1)
add    $0xffffffffffffffff,%rcx
sar    $0x4,%rbx
add    $0xffffffffffffffff,%rax
jne    1150 <make_hex_string_learning+0x40>
cmp    $0x3,%r8
jb     11cf <make_hex_string_learning+0xbf>
add    $0x1,%rcx
lea    0xe83(%rip),%rax
nopl   (%rax)
mov    %ebx,%edx
and    $0xf,%edx
movzbl (%rdx,%rax,1),%edx
mov    %dl,-0x2(%r14,%rcx,1)
mov    %ebx,%edx
shr    $0x4,%edx
and    $0xf,%edx
movzbl (%rdx,%rax,1),%edx
mov    %dl,-0x3(%r14,%rcx,1)
mov    %ebx,%edx
shr    $0x8,%edx
and    $0xf,%edx
movzbl (%rdx,%rax,1),%edx
mov    %dl,-0x4(%r14,%rcx,1)
mov    %ebx,%edx
shr    $0xc,%edx
and    $0xf,%edx
movzbl (%rdx,%rax,1),%edx
mov    %dl,-0x5(%r14,%rcx,1)
sar    $0x10,%rbx
add    $0xfffffffffffffffc,%rcx
cmp    $0x1,%rcx
ja     1180 <make_hex_string_learning+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.make_hex_string_learning.hex_lookup = [17 x i8] c"0123456789abcdef\00"
define void @make_hex_string_learning(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca [17 x i8]
%6 = alloca i64
store i64 %0, i64* %3
store i8* %1, i8** %4
%7 = bitcast [17 x i8]* %5 to i8*
%8 = load i64, i64* %3
%9 = call i64 @num_hex_digits(i64 %8)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = and i64 %10, 1
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %4
store i8 48, i8* %14
br label %16
16: ; preds = %13, %2
%17 = load i8*, i8** %4
%18 = load i64, i64* %6
%19 = getelementptr inbounds i8, i8* %17, i64 %18
store i8 0, i8* %19
%20 = load i64, i64* %6
%21 = add nsw i64 %20, -1
store i64 %21, i64* %6
br label %22
22: ; preds = %33, %16
%23 = load i64, i64* %6
%24 = icmp sge i64 %23, 0
br i1 %24, label %25, label %38
25: ; preds = %22
%26 = load i64, i64* %3
%27 = and i64 %26, 15
%28 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = load i8*, i8** %4
%31 = load i64, i64* %6
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8 %29, i8* %32
br label %33
33: ; preds = %25
%34 = load i64, i64* %3
%35 = ashr i64 %34, 4
store i64 %35, i64* %3
%36 = load i64, i64* %6
%37 = add nsw i64 %36, -1
store i64 %37, i64* %6
br label %22
38: ; preds = %22
ret void
}

LLVM IR (-O2):
@__const.make_hex_string_learning.hex_lookup = [17 x i8] c"0123456789abcdef\00"
define void @make_hex_string_learning(i64 %0, i8* nocapture writeonly %1) {
%3 = tail call i64 @num_hex_digits(i64 %0)
%4 = and i64 %3, 1
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %1, i64 1
store i8 48, i8* %1
br label %8
8: ; preds = %6, %2
%9 = phi i8* [ %7, %6 ], [ %1, %2 ]
%10 = getelementptr inbounds i8, i8* %9, i64 %3
store i8 0, i8* %10
%11 = icmp sgt i64 %3, 0
br i1 %11, label %12, label %60
12: ; preds = %8
%13 = add i64 %3, -1
%14 = and i64 %3, 3
%15 = icmp eq i64 %14, 0
br i1 %15, label %28, label %16
16: ; preds = %12, %16
%17 = phi i64 [ %20, %16 ], [ %3, %12 ]
%18 = phi i64 [ %25, %16 ], [ %0, %12 ]
%19 = phi i64 [ %26, %16 ], [ 0, %12 ]
%20 = add nsw i64 %17, -1
%21 = and i64 %18, 15
%22 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.make_hex_string_learning.hex_lookup, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %9, i64 %20
store i8 %23, i8* %24
%25 = ashr i64 %18, 4
%26 = add i64 %19, 1
%27 = icmp eq i64 %26, %14
br i1 %27, label %28, label %16
28: ; preds = %16, %12
%29 = phi i64 [ %3, %12 ], [ %20, %16 ]
%30 = phi i64 [ %0, %12 ], [ %25, %16 ]
%31 = icmp ult i64 %13, 3
br i1 %31, label %60, label %32
32: ; preds = %28, %32
%33 = phi i64 [ %53, %32 ], [ %29, %28 ]
%34 = phi i64 [ %58, %32 ], [ %30, %28 ]
%35 = add nsw i64 %33, -1
%36 = and i64 %34, 15
%37 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.make_hex_string_learning.hex_lookup, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = getelementptr inbounds i8, i8* %9, i64 %35
store i8 %38, i8* %39
%40 = lshr i64 %34, 4
%41 = add nsw i64 %33, -2
%42 = and i64 %40, 15
%43 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.make_hex_string_learning.hex_lookup, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = getelementptr inbounds i8, i8* %9, i64 %41
store i8 %44, i8* %45
%46 = lshr i64 %34, 8
%47 = add nsw i64 %33, -3
%48 = and i64 %46, 15
%49 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.make_hex_string_learning.hex_lookup, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = getelementptr inbounds i8, i8* %9, i64 %47
store i8 %50, i8* %51
%52 = lshr i64 %34, 12
%53 = add nsw i64 %33, -4
%54 = and i64 %52, 15
%55 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.make_hex_string_learning.hex_lookup, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = getelementptr inbounds i8, i8* %9, i64 %53
store i8 %56, i8* %57
%58 = ashr i64 %34, 16
%59 = icmp ugt i64 %47, 1
br i1 %59, label %32, label %60
60: ; preds = %28, %32, %8
ret void
}