char *gctr(s, maxllen)
char *s;
int maxllen;
{
  int pad;
  char *x;
  pad = (maxllen - strlen(s)) / 2;
  x = malloc(maxllen + 1);
  strcpy(x, s + 2);
  *s = 0;
  for (; pad > 0; pad--)
    strcat(s, " ");
  strcat(s, x);
  free(x);
  return (s);
}


x86 assembly (clang, -O0):
<gctr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
shr    $0x1,%rax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x2,%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x10(%rbp)
jle    11d3 <gctr+0x83>
mov    -0x8(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11ab <gctr+0x5b>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gctr>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
movslq %esi,%r14
call   1050 <strlen@plt>
mov    %r14,%rbx
sub    %rax,%rbx
shr    %rbx
add    $0x1,%r14d
movslq %r14d,%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0x2(%r15),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
movb   $0x0,(%r15)
test   %ebx,%ebx
jle    11a7 <gctr+0x57>
add    $0x1,%ebx
nop
mov    %r15,%rdi
call   1050 <strlen@plt>
movw   $0x20,(%r15,%rax,1)
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1190 <gctr+0x40>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @gctr(i8* returned %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = sub i64 %3, %4
%6 = lshr i64 %5, 1
%7 = trunc i64 %6 to i32
%8 = add nsw i32 %1, 1
%9 = sext i32 %8 to i64
%10 = tail call i8* @malloc(i64 %9)
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = tail call i8* @strcpy(i8* dereferenceable(1) %10, i8* %11)
store i8 0, i8* %0
%13 = icmp sgt i32 %7, 0
br i1 %13, label %14, label %21
14: ; preds = %2, %14
%15 = phi i32 [ %19, %14 ], [ %7, %2 ]
%16 = tail call i64 @strlen(i8* %0)
%17 = getelementptr i8, i8* %0, i64 %16
%18 = bitcast i8* %17 to i16*
store i16 32, i16* %18
%19 = add nsw i32 %15, -1
%20 = icmp ugt i32 %15, 1
br i1 %20, label %14, label %21
21: ; preds = %14, %2
%22 = tail call i8* @strcat(i8* %0, i8* dereferenceable(1) %10)
tail call void @free(i8* %10)
ret i8* %0
}