void print_centered(const char *line, const int max_width, const char border) {
  int ws = max_width - strlen(line);
  printf("%c%*s%s%*s%c\n", border, ws / 2, " ", line,
         ws % 2 == 0 ? ws / 2 : (ws / 2) + 1, " ", border);
}


x86 assembly (clang, -O0):
<print_centered>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
movslq -0xc(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
movsbl -0xd(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1196 <print_centered+0x76>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
jmp    11a7 <print_centered+0x87>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%esi
mov    -0x34(%rbp),%r9d
movsbl -0xd(%rbp),%eax
lea    0xe40(%rip),%rdi
lea    0xe47(%rip),%r10
mov    %r10,%rcx
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_centered>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
sub    %eax,%ebp
mov    %ebp,%edx
shr    $0x1f,%edx
add    %ebp,%edx
sar    %edx
and    $0x1,%ebp
add    %edx,%ebp
lea    0xec6(%rip),%rcx
lea    0xeb1(%rip),%rdi
mov    %r14d,%esi
mov    %rbx,%r8
mov    %ebp,%r9d
xor    %eax,%eax
push   %r14
push   %rcx
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"%c%*s%s%*s%c\0A\00"
@.str.1 = [2 x i8] c" \00"
define void @print_centered(i8* %0, i32 %1, i8 signext %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = trunc i64 %4 to i32
%6 = sub i32 %1, %5
%7 = sdiv i32 %6, 2
%8 = and i32 %6, 1
%9 = add nsw i32 %7, %8
%10 = sext i8 %2 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %10)
ret void
}