char *center(string, scr_len)
char *string;
int scr_len;
{
  static char line[500];
  int x, y;
  int str_len_div_two = strlen(string) / 2;
  int scr_len_div_two = scr_len / 2;
  for (x = 0; x < scr_len_div_two - str_len_div_two; x++)
    line[x] = ' ';
  line[x] = '\0';
  strcat(line, string);
  return line;
}


x86 assembly (clang, -O0):
<center>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
shr    $0x1,%rax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    1182 <center+0x62>
movslq -0x10(%rbp),%rcx
lea    0x2ed0(%rip),%rax
movb   $0x20,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1154 <center+0x34>
movslq -0x10(%rbp),%rcx
lea    0x2eb3(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rsi
lea    0x2ea4(%rip),%rdi
call   1040 <strcat@plt>
lea    0x2e98(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<center>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1030 <strlen@plt>
shr    %rax
mov    %ebp,%ebx
shr    $0x1f,%ebx
add    %ebp,%ebx
sar    %ebx
mov    %ebx,%ecx
sub    %eax,%ecx
test   %ecx,%ecx
jle    1172 <center+0x42>
not    %eax
add    %eax,%ebx
add    $0x1,%rbx
lea    0x2eef(%rip),%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
mov    %ebx,%eax
jmp    1174 <center+0x44>
xor    %eax,%eax
lea    0x2ed5(%rip),%rdi
movb   $0x0,(%rax,%rdi,1)
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <strcat@plt>

LLVM IR (-O0):
@center.line = internal global [500 x i8] zeroinitializer
define i8* @center(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
%11 = udiv i64 %10, 2
%12 = trunc i64 %11 to i32
store i32 %12, i32* %7
%13 = load i32, i32* %4
%14 = sdiv i32 %13, 2
store i32 %14, i32* %8
store i32 0, i32* %5
br label %15
15: ; preds = %25, %2
%16 = load i32, i32* %5
%17 = load i32, i32* %8
%18 = load i32, i32* %7
%19 = sub nsw i32 %17, %18
%20 = icmp slt i32 %16, %19
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [500 x i8], [500 x i8]* @center.line, i64 0, i64 %23
store i8 32, i8* %24
br label %25
25: ; preds = %21
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %15
28: ; preds = %15
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [500 x i8], [500 x i8]* @center.line, i64 0, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %3
%33 = call i8* @strcat(i8* getelementptr inbounds ([500 x i8], [500 x i8]* @center.line, i64 0, i64 0), i8* %32)
ret i8* getelementptr inbounds ([500 x i8], [500 x i8]* @center.line, i64 0, i64 0)
}

LLVM IR (-O2):
@center.line = internal global [500 x i8] zeroinitializer
define i8* @center(i8* nocapture %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = lshr i64 %3, 1
%5 = trunc i64 %4 to i32
%6 = sdiv i32 %1, 2
%7 = sub i32 %6, %5
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = xor i32 %5, -1
%11 = add i32 %6, %10
%12 = zext i32 %11 to i64
%13 = add nuw nsw i64 %12, 1
%14 = and i64 %13, 4294967295
br label %15
15: ; preds = %9, %2
%16 = phi i64 [ 0, %2 ], [ %14, %9 ]
%17 = getelementptr inbounds [500 x i8], [500 x i8]* @center.line, i64 0, i64 %16
store i8 0, i8* %17
%18 = tail call i8* @strcat(i8* dereferenceable(1) getelementptr inbounds ([500 x i8], [500 x i8]* @center.line, i64 0, i64 0), i8* dereferenceable(1) %0)
ret i8* getelementptr inbounds ([500 x i8], [500 x i8]* @center.line, i64 0, i64 0)
}