#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 /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ abort();
char *hex_str(unsigned char *str, int len) {
  static char hexTab[] = "0123456789abcdef";
  static char buffer[200];
  int i;
  if (len > sizeof(buffer))
    abort();
  for (i = 0; i < len; ++i) {
    buffer[i * 2] = hexTab[str[i] >> 4];
    buffer[(i * 2) + 1] = hexTab[str[i] & 0x0F];
  }
  return buffer;
}


x86 assembly (clang, -O0):
<hex_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0xc8,%rax
jbe    1136 <hex_str+0x26>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b8 <hex_str+0xa8>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
movslq %eax,%rcx
lea    0x2ece(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
movslq %eax,%rcx
lea    0x2eeb(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0x2e9f(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2eb9(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113d <hex_str+0x2d>
lea    0x2ea1(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_str>:
push   %rax
cmp    $0xc8,%esi
ja     1160 <hex_str+0x50>
test   %esi,%esi
je     1157 <hex_str+0x47>
mov    %esi,%r8d
xor    %ecx,%ecx
lea    0xed7(%rip),%rdx
lea    0x2f10(%rip),%rsi
movzbl (%rdi,%rcx,1),%eax
shr    $0x4,%rax
movzbl (%rax,%rdx,1),%eax
mov    %al,(%rsi,%rcx,2)
movzbl (%rdi,%rcx,1),%eax
and    $0xf,%eax
movzbl (%rax,%rdx,1),%eax
mov    %al,0x1(%rsi,%rcx,2)
add    $0x1,%rcx
cmp    %rcx,%r8
jne    1130 <hex_str+0x20>
lea    0x2ee2(%rip),%rax
pop    %rcx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@hex_str.hexTab = internal global [17 x i8] c"0123456789abcdef\00"
@hex_str.buffer = internal global [200 x i8] zeroinitializer
define i8* @hex_str(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = sext i32 %6 to i64
%8 = icmp ugt i64 %7, 200
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (...) @abort()
unreachable
11: ; preds = %2
store i32 0, i32* %5
br label %12
12: ; preds = %46, %11
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %49
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = ashr i32 %22, 4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [17 x i8], [17 x i8]* @hex_str.hexTab, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = load i32, i32* %5
%28 = mul nsw i32 %27, 2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [200 x i8], [200 x i8]* @hex_str.buffer, i64 0, i64 %29
store i8 %26, i8* %30
%31 = load i8*, i8** %3
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = and i32 %36, 15
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [17 x i8], [17 x i8]* @hex_str.hexTab, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = load i32, i32* %5
%42 = mul nsw i32 %41, 2
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [200 x i8], [200 x i8]* @hex_str.buffer, i64 0, i64 %44
store i8 %40, i8* %45
br label %46
46: ; preds = %16
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %12
49: ; preds = %12
ret i8* getelementptr inbounds ([200 x i8], [200 x i8]* @hex_str.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@hex_str.hexTab = internal unnamed_addr constant [17 x i8] c"0123456789abcdef\00"
@hex_str.buffer = internal global [200 x i8] zeroinitializer
define i8* @hex_str(i8* nocapture %0, i32 %1) {
%3 = icmp ugt i32 %1, 200
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = icmp eq i32 %1, 0
br i1 %5, label %29, label %6
6: ; preds = %4
%7 = zext i32 %1 to i64
br label %10
8: ; preds = %2
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %6, %10
%11 = phi i64 [ 0, %6 ], [ %27, %10 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = lshr i8 %13, 4
%15 = zext i8 %14 to i64
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @hex_str.hexTab, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = shl nuw nsw i64 %11, 1
%19 = getelementptr inbounds [200 x i8], [200 x i8]* @hex_str.buffer, i64 0, i64 %18
store i8 %17, i8* %19
%20 = load i8, i8* %12
%21 = and i8 %20, 15
%22 = zext i8 %21 to i64
%23 = getelementptr inbounds [17 x i8], [17 x i8]* @hex_str.hexTab, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = or i64 %18, 1
%26 = getelementptr inbounds [200 x i8], [200 x i8]* @hex_str.buffer, i64 0, i64 %25
store i8 %24, i8* %26
%27 = add nuw nsw i64 %11, 1
%28 = icmp eq i64 %27, %7
br i1 %28, label %29, label %10
29: ; preds = %10, %4
ret i8* getelementptr inbounds ([200 x i8], [200 x i8]* @hex_str.buffer, i64 0, i64 0)
}