#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*/ logger_log(int, char *);
char *malloc(int);
char *convert_type_char(int type) {
  char *encoded = malloc(1);
  if (encoded == NULL) {
    logger_log(5, "[charcoal message] failed to allocate buffer");
  } else {
    logger_log(2, "[charcoal message] buffer allocated");
  }
  encoded[0] = type;
  return encoded;
}


x86 assembly (clang, -O0):
<convert_type_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115a <convert_type_char+0x3a>
mov    $0x5,%edi
lea    0xeb0(%rip),%rsi
call   1040 <logger_log@plt>
jmp    116b <convert_type_char+0x4b>
mov    $0x2,%edi
lea    0xec7(%rip),%rsi
call   1040 <logger_log@plt>
mov    -0x4(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_type_char>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1145 <convert_type_char+0x25>
lea    0xeef(%rip),%rsi
mov    $0x2,%edi
jmp    1151 <convert_type_char+0x31>
lea    0xeb4(%rip),%rsi
mov    $0x5,%edi
call   1040 <logger_log@plt>
mov    %bpl,(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"[charcoal message] failed to allocate buffer\00"
@.str.1 = [36 x i8] c"[charcoal message] buffer allocated\00"
define i8* @convert_type_char(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = call i8* @malloc(i32 1)
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @logger_log(i32 5, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %11
9: ; preds = %1
%10 = call i32 @logger_log(i32 2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %7
%12 = load i32, i32* %2
%13 = trunc i32 %12 to i8
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 %13, i8* %15
%16 = load i8*, i8** %3
ret i8* %16
}

LLVM IR (-O2):
@.str = [45 x i8] c"[charcoal message] failed to allocate buffer\00"
@.str.1 = [36 x i8] c"[charcoal message] buffer allocated\00"
define noalias i8* @convert_type_char(i32 %0) {
%2 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @logger_log(i32 5, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %8
6: ; preds = %1
%7 = tail call i32 @logger_log(i32 2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %4
%9 = trunc i32 %0 to i8
store i8 %9, i8* %2
ret i8* %2
}