#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 /*<<< orphan*/ free(char *);
char *get_bin_str(unsigned char);
char *make_str(char *, char *, unsigned char, unsigned char, unsigned char,
               unsigned char);
char *get_multi_base_str(unsigned char val) {
  char *str = NULL;
  char *binStr = get_bin_str(val);
  if (val >= 0x20 && val < 0x7f)
    str = make_str("bin:%s oct:0%03o hex:%02x  dec:%3d  char:'%c'", binStr, val,
                   val, val, val);
  else
    str = make_str("bin:%s oct:0%03o hex:%02x  dec:%3d  char:'\\x%02x'", binStr,
                   val, val, val, val);
  free(binStr);
  return str;
}


x86 assembly (clang, -O0):
<get_multi_base_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movq   $0x0,-0x10(%rbp)
movzbl -0x1(%rbp),%edi
call   1040 <get_bin_str@plt>
mov    %rax,-0x18(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0x20,%eax
jl     119e <get_multi_base_str+0x6e>
movzbl -0x1(%rbp),%eax
cmp    $0x7f,%eax
jge    119e <get_multi_base_str+0x6e>
mov    -0x18(%rbp),%rsi
mov    -0x1(%rbp),%dl
mov    -0x1(%rbp),%cl
mov    -0x1(%rbp),%al
lea    0xe7f(%rip),%rdi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %al,%r8d
movzbl -0x1(%rbp),%r9d
call   1050 <make_str@plt>
mov    %rax,-0x10(%rbp)
jmp    11ca <get_multi_base_str+0x9a>
mov    -0x18(%rbp),%rsi
mov    -0x1(%rbp),%dl
mov    -0x1(%rbp),%cl
mov    -0x1(%rbp),%al
lea    0xe7c(%rip),%rdi
movzbl %dl,%edx
movzbl %cl,%ecx
movzbl %al,%r8d
movzbl -0x1(%rbp),%r9d
call   1050 <make_str@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_multi_base_str>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
call   1040 <get_bin_str@plt>
mov    %rax,%r14
lea    -0x20(%rbx),%eax
cmp    $0x5f,%al
lea    0xeb6(%rip),%rax
lea    0xedd(%rip),%rdi
cmovb  %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %ebx,%ecx
mov    %ebx,%r8d
mov    %ebx,%r9d
call   1050 <make_str@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [46 x i8] c"bin:%s oct:0%03o hex:%02x dec:%3d char:'%c'\00"
@.str.1 = [50 x i8] c"bin:%s oct:0%03o hex:%02x dec:%3d char:'\\x%02x'\00"
define i8* @get_multi_base_str(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i8*
store i8 %0, i8* %2
store i8* null, i8** %3
%5 = load i8, i8* %2
%6 = call i8* @get_bin_str(i8 zeroext %5)
store i8* %6, i8** %4
%7 = load i8, i8* %2
%8 = zext i8 %7 to i32
%9 = icmp sge i32 %8, 32
br i1 %9, label %10, label %21
10: ; preds = %1
%11 = load i8, i8* %2
%12 = zext i8 %11 to i32
%13 = icmp slt i32 %12, 127
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i8, i8* %2
%17 = load i8, i8* %2
%18 = load i8, i8* %2
%19 = load i8, i8* %2
%20 = call i8* @make_str(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %15, i8 zeroext %16, i8 zeroext %17, i8 zeroext %18, i8 zeroext %19)
store i8* %20, i8** %3
br label %28
21: ; preds = %10, %1
%22 = load i8*, i8** %4
%23 = load i8, i8* %2
%24 = load i8, i8* %2
%25 = load i8, i8* %2
%26 = load i8, i8* %2
%27 = call i8* @make_str(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8 zeroext %23, i8 zeroext %24, i8 zeroext %25, i8 zeroext %26)
store i8* %27, i8** %3
br label %28
28: ; preds = %21, %14
%29 = load i8*, i8** %4
%30 = call i32 @free(i8* %29)
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
@.str = [46 x i8] c"bin:%s oct:0%03o hex:%02x dec:%3d char:'%c'\00"
@.str.1 = [50 x i8] c"bin:%s oct:0%03o hex:%02x dec:%3d char:'\\x%02x'\00"
define i8* @get_multi_base_str(i8 zeroext %0) {
%2 = tail call i8* @get_bin_str(i8 zeroext %0)
%3 = add i8 %0, -32
%4 = icmp ult i8 %3, 95
%5 = select i1 %4, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0)
%6 = tail call i8* @make_str(i8* %5, i8* %2, i8 zeroext %0, i8 zeroext %0, i8 zeroext %0, i8 zeroext %0)
%7 = tail call i32 @free(i8* %2)
ret i8* %6
}