#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 asprintf(char **, char *, ...);
char *blackstrap_stringify_uchar_bin(unsigned char);
int /*<<< orphan*/ free(char *);
char *blackstrap_stringify_msg_uchar(const char *message, unsigned char value) {
  char *bin_str = blackstrap_stringify_uchar_bin(value);
  if (!bin_str)
    return NULL;
  char *string = NULL;
  int result = 0;
  if (message)
    result = asprintf(&string,
                      "%s: "
                      "%ud, %02xh, %sb",
                      message, value, value, bin_str);
  else
    result = asprintf(&string, "%ud, %02xh, %sb", value, value, bin_str);
  free(bin_str);
  if (result < 0)
    return NULL;
  return string;
}


x86 assembly (clang, -O0):
<blackstrap_stringify_msg_uchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%edi
call   1040 <blackstrap_stringify_uchar_bin@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1167 <blackstrap_stringify_msg_uchar+0x37>
movq   $0x0,-0x8(%rbp)
jmp    11f5 <blackstrap_stringify_msg_uchar+0xc5>
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ac <blackstrap_stringify_msg_uchar+0x7c>
mov    -0x10(%rbp),%rdx
movzbl -0x11(%rbp),%ecx
movzbl -0x11(%rbp),%r8d
mov    -0x20(%rbp),%r9
lea    -0x28(%rbp),%rdi
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1050 <asprintf@plt>
mov    %eax,-0x2c(%rbp)
jmp    11cd <blackstrap_stringify_msg_uchar+0x9d>
movzbl -0x11(%rbp),%edx
movzbl -0x11(%rbp),%ecx
mov    -0x20(%rbp),%r8
lea    -0x28(%rbp),%rdi
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1050 <asprintf@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x2c(%rbp)
jge    11ed <blackstrap_stringify_msg_uchar+0xbd>
movq   $0x0,-0x8(%rbp)
jmp    11f5 <blackstrap_stringify_msg_uchar+0xc5>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blackstrap_stringify_msg_uchar>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%edi
call   1040 <blackstrap_stringify_uchar_bin@plt>
test   %rax,%rax
je     11a9 <blackstrap_stringify_msg_uchar+0x79>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
movzbl %bpl,%ecx
test   %r14,%r14
je     117c <blackstrap_stringify_msg_uchar+0x4c>
lea    0xe9b(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %r14,%rdx
mov    %ecx,%r8d
mov    %rbx,%r9
xor    %eax,%eax
call   1050 <asprintf@plt>
jmp    1194 <blackstrap_stringify_msg_uchar+0x64>
lea    0xe81(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %ecx,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <asprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
js     11a9 <blackstrap_stringify_msg_uchar+0x79>
mov    0x8(%rsp),%rax
jmp    11ab <blackstrap_stringify_msg_uchar+0x7b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"%s: %ud, %02xh, %sb\00"
@.str.1 = [16 x i8] c"%ud, %02xh, %sb\00"
define i8* @blackstrap_stringify_msg_uchar(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8 %1, i8* %5
%9 = load i8, i8* %5
%10 = call i8* @blackstrap_stringify_uchar_bin(i8 zeroext %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i8* null, i8** %3
br label %40
14: ; preds = %2
store i8* null, i8** %7
store i32 0, i32* %8
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = load i8, i8* %5
%20 = zext i8 %19 to i32
%21 = load i8, i8* %5
%22 = zext i8 %21 to i32
%23 = load i8*, i8** %6
%24 = call i32 (i8**, i8*, ...) @asprintf(i8** %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %20, i32 %22, i8* %23)
store i32 %24, i32* %8
br label %32
25: ; preds = %14
%26 = load i8, i8* %5
%27 = zext i8 %26 to i32
%28 = load i8, i8* %5
%29 = zext i8 %28 to i32
%30 = load i8*, i8** %6
%31 = call i32 (i8**, i8*, ...) @asprintf(i8** %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %29, i8* %30)
store i32 %31, i32* %8
br label %32
32: ; preds = %25, %17
%33 = load i8*, i8** %6
%34 = call i32 @free(i8* %33)
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i8* null, i8** %3
br label %40
38: ; preds = %32
%39 = load i8*, i8** %7
store i8* %39, i8** %3
br label %40
40: ; preds = %38, %37, %13
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
@.str = [20 x i8] c"%s: %ud, %02xh, %sb\00"
@.str.1 = [16 x i8] c"%ud, %02xh, %sb\00"
define i8* @blackstrap_stringify_msg_uchar(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = tail call i8* @blackstrap_stringify_uchar_bin(i8 zeroext %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %20, label %6
6: ; preds = %2
%7 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%8 = icmp eq i8* %0, null
%9 = zext i8 %1 to i32
br i1 %8, label %12, label %10
10: ; preds = %6
%11 = call i32 (i8**, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %9, i32 %9, i8* %4)
br label %14
12: ; preds = %6
%13 = call i32 (i8**, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %9, i8* %4)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ %11, %10 ], [ %13, %12 ]
%16 = call i32 @free(i8* %4)
%17 = icmp slt i32 %15, 0
%18 = load i8*, i8** %3
%19 = select i1 %17, i8* null, i8* %18
br label %20
20: ; preds = %2, %14
%21 = phi i8* [ %19, %14 ], [ null, %2 ]
ret i8* %21
}