char *imccenterline(const char *string, int length) {
  char stripped[300];
  static char outbuf[400];
  int amount;
  imcstrlcpy(stripped, imc_strip_colors(string), 300);
  amount = length - strlen(stripped);
  if (amount < 1)
    amount = 1;
  snprintf(outbuf, 400, "%*s%s%*s", (amount / 2), "", string,
           ((amount / 2) * 2) == amount ? (amount / 2) : ((amount / 2) + 1),
           "");
  return outbuf;
}


x86 assembly (clang, -O0):
<imccenterline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x140(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1050 <imc_strip_colors@plt>
mov    -0x158(%rbp),%rdi
mov    %eax,%esi
mov    $0x12c,%edx
mov    $0x0,%al
call   1060 <imcstrlcpy@plt>
movslq -0xc(%rbp),%rax
mov    %rax,-0x150(%rbp)
lea    -0x140(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x150(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x144(%rbp)
cmpl   $0x1,-0x144(%rbp)
jge    11c1 <imccenterline+0x81>
movl   $0x1,-0x144(%rbp)
mov    -0x144(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x164(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x144(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
shl    $0x1,%eax
cmp    -0x144(%rbp),%eax
jne    1216 <imccenterline+0xd6>
mov    -0x144(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x168(%rbp)
jmp    122d <imccenterline+0xed>
mov    -0x144(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x168(%rbp)
mov    -0x160(%rbp),%r9
mov    -0x164(%rbp),%ecx
mov    -0x168(%rbp),%r10d
lea    0x2e08(%rip),%rdi
mov    $0x190,%esi
lea    0xdac(%rip),%rdx
lea    0xdad(%rip),%rax
mov    %rax,%r8
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    0x2ddb(%rip),%rax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imccenterline>:
push   %rbp
push   %r14
push   %rbx
sub    $0x130,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <imc_strip_colors@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x12c,%edx
xor    %eax,%eax
call   1060 <imcstrlcpy@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
test   %ebp,%ebp
mov    $0x1,%eax
cmovg  %ebp,%eax
mov    %eax,%ecx
shr    %ecx
and    $0x80000001,%eax
cmp    $0x1,%eax
mov    %ecx,%ebp
sbb    $0xffffffff,%ebp
lea    0xe71(%rip),%r8
lea    0x2eb2(%rip),%rbx
lea    0xe5b(%rip),%rdx
mov    $0x190,%esi
mov    %rbx,%rdi
mov    %r14,%r9
xor    %eax,%eax
push   %r8
push   %rbp
call   1040 <snprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rax
add    $0x130,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@imccenterline.outbuf = internal global [400 x i8] zeroinitializer
@.str = [9 x i8] c"%*s%s%*s\00"
@.str.1 = [1 x i8] zeroinitializer
define i8* @imccenterline(i8* %0, i32 %1) {
%3 = alloca [300 x i8]
%4 = getelementptr inbounds [300 x i8], [300 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, ...) bitcast (i32 (...)* @imc_strip_colors to i32 (i8*, ...)*)(i8* %0)
%6 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @imcstrlcpy to i32 (i8*, i32, i32, ...)*)(i8* %4, i32 %5, i32 300)
%7 = call i64 @strlen(i8* %4)
%8 = trunc i64 %7 to i32
%9 = sub i32 %1, %8
%10 = icmp sgt i32 %9, 1
%11 = select i1 %10, i32 %9, i32 1
%12 = lshr i32 %11, 1
%13 = and i32 %11, 2147483646
%14 = icmp ne i32 %13, %11
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %12, %15
%17 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* dereferenceable(1) getelementptr inbounds ([400 x i8], [400 x i8]* @imccenterline.outbuf, i64 0, i64 0), i64 400, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
ret i8* getelementptr inbounds ([400 x i8], [400 x i8]* @imccenterline.outbuf, i64 0, i64 0)
}