void map2str(const int number, char *output) {
  if (number == 0) {
    strcpy(output, "      ");
    return;
  }
  int t = 1 << number;
  char bufferOfNumber[4] = "";
  sprintf(bufferOfNumber, "%i", t);
  int prefix = (6 - strlen(bufferOfNumber)) >> 1;
  int postfix = 6 - prefix - strlen(bufferOfNumber);
  sprintf(output, "%*s%s%*s", prefix, " ", bufferOfNumber, postfix, " ");
}


x86 assembly (clang, -O0):
<map2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    116e <map2str+0x2e>
mov    -0x10(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1030 <strcpy@plt>
jmp    120a <map2str+0xca>
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0x18(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    $0x6,%eax
sub    %rcx,%rax
shr    $0x1,%rax
mov    %eax,-0x1c(%rbp)
mov    $0x6,%eax
sub    -0x1c(%rbp),%eax
cltq
mov    %rax,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9d
lea    0xe15(%rip),%rsi
lea    0xe09(%rip),%rax
mov    %rax,%rcx
mov    %rax,(%rsp)
mov    $0x0,%al
call   1060 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<map2str>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
test   %edi,%edi
je     11a4 <map2str+0x84>
mov    $0x1,%edx
mov    %edi,%ecx
shl    %cl,%edx
movl   $0x0,0x14(%rsp)
lea    0xec1(%rip),%rsi
lea    0x14(%rsp),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    $0x6,%edx
sub    %rax,%rdx
shr    %rdx
mov    %rdx,%rcx
shl    $0x20,%rcx
movabs $0x600000000,%r9
sub    %rcx,%r9
shr    $0x20,%r9
sub    %eax,%r9d
lea    0xe7b(%rip),%rcx
mov    %rcx,(%rsp)
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%r8
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    11b1 <map2str+0x91>
movl   $0x202020,0x3(%rbx)
movl   $0x20202020,(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c" \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [9 x i8] c"%*s%s%*s\00"
@.str.3 = [2 x i8] c" \00"
define void @map2str(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [4 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i8* @strcpy(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %38
14: ; preds = %2
%15 = load i32, i32* %3
%16 = shl i32 1, %15
store i32 %16, i32* %5
%17 = bitcast [4 x i8]* %6 to i8*
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* %5
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = sub i64 6, %22
%24 = lshr i64 %23, 1
%25 = trunc i64 %24 to i32
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = sub nsw i32 6, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%30 = call i64 @strlen(i8* %29)
%31 = sub i64 %28, %30
%32 = trunc i64 %31 to i32
store i32 %32, i32* %8
%33 = load i8*, i8** %4
%34 = load i32, i32* %7
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%36 = load i32, i32* %8
%37 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %35, i32 %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %14, %11
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c" \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [9 x i8] c"%*s%s%*s\00"
@.str.3 = [2 x i8] c" \00"
define void @map2str(i32 %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 0
br i1 %4, label %5, label %6
5: ; preds = %2
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(7) %1, i8* align 1 dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 7, i1 false)
br label %20
6: ; preds = %2
%7 = shl nuw i32 1, %0
%8 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%9 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%10 = call i64 @strlen(i8* %8)
%11 = sub i64 6, %10
%12 = lshr i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = mul i64 %12, -4294967296
%15 = add i64 %14, 25769803776
%16 = lshr exact i64 %15, 32
%17 = sub i64 %16, %10
%18 = trunc i64 %17 to i32
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %6, %5
ret void
}