#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 */
scalar_t__ asprintf(char **, char *, char *);
int /*<<< orphan*/ free(char *);
char *hidrd_hex_buf_to_str(void const *, size_t);
char *hidrd_hex_buf_to_sstr(const void *buf, size_t size) {
  char *str;
  char *sstr;
  str = hidrd_hex_buf_to_str(buf, size);
  if (str == NULL)
    return NULL;
  if (asprintf(&sstr, "%sh", str) < 0) {
    free(str);
    return NULL;
  }
  free(str);
  return sstr;
}


x86 assembly (clang, -O0):
<hidrd_hex_buf_to_sstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <hidrd_hex_buf_to_str@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1169 <hidrd_hex_buf_to_sstr+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11ae <hidrd_hex_buf_to_sstr+0x7e>
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1050 <asprintf@plt>
cmp    $0x0,%rax
jge    119d <hidrd_hex_buf_to_sstr+0x6d>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ae <hidrd_hex_buf_to_sstr+0x7e>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hidrd_hex_buf_to_sstr>:
push   %r14
push   %rbx
push   %rax
call   1040 <hidrd_hex_buf_to_str@plt>
test   %rax,%rax
je     1169 <hidrd_hex_buf_to_sstr+0x39>
mov    %rax,%rbx
lea    0xeb8(%rip),%rsi
mov    %rsp,%rdi
mov    %rax,%rdx
call   1050 <asprintf@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
js     1169 <hidrd_hex_buf_to_sstr+0x39>
mov    (%rsp),%rax
jmp    116b <hidrd_hex_buf_to_sstr+0x3b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%sh\00"
define i8* @hidrd_hex_buf_to_sstr(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i8*, i8** %4
%9 = load i64, i64* %5
%10 = call i8* @hidrd_hex_buf_to_str(i8* %8, i64 %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i8* null, i8** %3
br label %25
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i64 @asprintf(i8** %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = call i32 @free(i8* %19)
store i8* null, i8** %3
br label %25
21: ; preds = %14
%22 = load i8*, i8** %6
%23 = call i32 @free(i8* %22)
%24 = load i8*, i8** %7
store i8* %24, i8** %3
br label %25
25: ; preds = %21, %18, %13
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
@.str = [4 x i8] c"%sh\00"
define i8* @hidrd_hex_buf_to_sstr(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i8* @hidrd_hex_buf_to_str(i8* %0, i64 %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = call i64 @asprintf(i8** %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
%9 = icmp slt i64 %8, 0
%10 = call i32 @free(i8* %5)
%11 = load i8*, i8** %3
%12 = select i1 %9, i8* null, i8* %11
br label %13
13: ; preds = %7, %2
%14 = phi i8* [ null, %2 ], [ %12, %7 ]
ret i8* %14
}