#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 scalar_t__ int64_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ snprintf(char *, scalar_t__, char *, scalar_t__,
                            char const *);
char *rowkey2hex(const char *row_key, int64_t row_key_len) {
  static char *hex = NULL;
  static int64_t hex_len = 0;
  if (NULL == hex || hex_len <= row_key_len) {
    if (NULL != hex && hex_len <= row_key_len) {
      free(hex);
      hex = NULL;
    }
    hex = (char *)malloc(row_key_len + 1);
    if (NULL != hex) {
      hex_len = row_key_len + 1;
    }
  }
  if (NULL != hex) {
    snprintf(hex, hex_len, "%.*x", row_key_len, row_key);
  }
  return hex;
}


x86 assembly (clang, -O0):
<rowkey2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
cmp    0x2ef7(%rip),%rax
je     1160 <rowkey2hex+0x30>
mov    0x2ef2(%rip),%rax
cmp    -0x10(%rbp),%rax
jg     11ce <rowkey2hex+0x9e>
xor    %eax,%eax
cmp    0x2ed7(%rip),%rax
je     1197 <rowkey2hex+0x67>
mov    0x2ed2(%rip),%rax
cmp    -0x10(%rbp),%rax
jg     1197 <rowkey2hex+0x67>
mov    0x2eb9(%rip),%rdi
call   1030 <free@plt>
movq   $0x0,0x2ea9(%rip)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,0x2e95(%rip)
xor    %eax,%eax
cmp    0x2e8c(%rip),%rax
je     11c9 <rowkey2hex+0x99>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,0x2e7f(%rip)
jmp    11ce <rowkey2hex+0x9e>
xor    %eax,%eax
cmp    0x2e69(%rip),%rax
je     11ff <rowkey2hex+0xcf>
mov    0x2e5c(%rip),%rdi
mov    0x2e5d(%rip),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xe06(%rip),%rdx
call   1040 <snprintf@plt>
mov    0x2e3a(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rowkey2hex>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2efe(%rip),%rax
mov    0x2eff(%rip),%rbx
test   %rax,%rax
je     1153 <rowkey2hex+0x23>
cmp    %r15,%rbx
jg     118f <rowkey2hex+0x5f>
test   %rax,%rax
je     1170 <rowkey2hex+0x40>
cmp    %r15,%rbx
jg     1170 <rowkey2hex+0x40>
mov    %rax,%rdi
call   1030 <free@plt>
movq   $0x0,0x2ed0(%rip)
lea    0x1(%r15),%rbx
mov    %rbx,%rdi
call   1050 <malloc@plt>
mov    %rax,0x2ebd(%rip)
test   %rax,%rax
je     11ae <rowkey2hex+0x7e>
mov    %rbx,0x2eb9(%rip)
lea    0xe6a(%rip),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <snprintf@plt>
mov    0x2e92(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@rowkey2hex.hex = internal global i8* null
@rowkey2hex.hex_len = internal global i64 0
@.str = [5 x i8] c"%.*x\00"
define i8* @rowkey2hex(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%5 = load i8*, i8** @rowkey2hex.hex
%6 = icmp eq i8* null, %5
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i64, i64* @rowkey2hex.hex_len
%9 = load i64, i64* %4
%10 = icmp sle i64 %8, %9
br i1 %10, label %11, label %32
11: ; preds = %7, %2
%12 = load i8*, i8** @rowkey2hex.hex
%13 = icmp ne i8* null, %12
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i64, i64* @rowkey2hex.hex_len
%16 = load i64, i64* %4
%17 = icmp sle i64 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i8*, i8** @rowkey2hex.hex
%20 = call i32 @free(i8* %19)
store i8* null, i8** @rowkey2hex.hex
br label %21
21: ; preds = %18, %14, %11
%22 = load i64, i64* %4
%23 = add nsw i64 %22, 1
%24 = call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** @rowkey2hex.hex
%26 = load i8*, i8** @rowkey2hex.hex
%27 = icmp ne i8* null, %26
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i64, i64* %4
%30 = add nsw i64 %29, 1
store i64 %30, i64* @rowkey2hex.hex_len
br label %31
31: ; preds = %28, %21
br label %32
32: ; preds = %31, %7
%33 = load i8*, i8** @rowkey2hex.hex
%34 = icmp ne i8* null, %33
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = load i8*, i8** @rowkey2hex.hex
%37 = load i64, i64* @rowkey2hex.hex_len
%38 = load i64, i64* %4
%39 = load i8*, i8** %3
%40 = call i32 @snprintf(i8* %36, i64 %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %38, i8* %39)
br label %41
41: ; preds = %35, %32
%42 = load i8*, i8** @rowkey2hex.hex
ret i8* %42
}

LLVM IR (-O2):
@rowkey2hex.hex = internal unnamed_addr global i8* null
@rowkey2hex.hex_len = internal unnamed_addr global i64 0
@.str = [5 x i8] c"%.*x\00"
define i8* @rowkey2hex(i8* %0, i64 %1) {
%3 = load i8*, i8** @rowkey2hex.hex
%4 = icmp ne i8* %3, null
%5 = load i64, i64* @rowkey2hex.hex_len
%6 = icmp sgt i64 %5, %1
%7 = select i1 %4, i1 %6, i1 false
br i1 %7, label %19, label %8
8: ; preds = %2
%9 = icmp eq i8* %3, null
%10 = select i1 %9, i1 true, i1 %6
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @free(i8* %3)
store i8* null, i8** @rowkey2hex.hex
br label %13
13: ; preds = %11, %8
%14 = add nsw i64 %1, 1
%15 = tail call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** @rowkey2hex.hex
%17 = icmp eq i64 %15, 0
br i1 %17, label %24, label %18
18: ; preds = %13
store i64 %14, i64* @rowkey2hex.hex_len
br label %19
19: ; preds = %18, %2
%20 = phi i64 [ %14, %18 ], [ %5, %2 ]
%21 = phi i8* [ %16, %18 ], [ %3, %2 ]
%22 = tail call i32 @snprintf(i8* %21, i64 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %1, i8* %0)
%23 = load i8*, i8** @rowkey2hex.hex
br label %24
24: ; preds = %13, %19
%25 = phi i8* [ %16, %13 ], [ %23, %19 ]
ret i8* %25
}