#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
char *make_space(int);
int /*<<< orphan*/ str_glue(char *, char *);
int str_length(char *);
char *xerox(char *);
char *center(char *s, int width) {
  int len = str_length(s);
  if (width <= len) {
    return xerox(s);
  } else {
    int space = (width - len) / 2;
    char *ns;
    ns = make_space(space);
    str_glue(ns, s);
    str_glue(ns, make_space(space));
    return ns;
  }
}


x86 assembly (clang, -O0):
<center>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <str_length@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1179 <center+0x39>
mov    -0x10(%rbp),%rdi
call   1060 <xerox@plt>
mov    %rax,-0x8(%rbp)
jmp    11c7 <center+0x87>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <make_space@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <str_glue@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <make_space@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
call   1050 <str_glue@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<center>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
call   1040 <str_length@plt>
cmp    %ebx,%eax
jge    118c <center+0x4c>
sub    %eax,%ebx
mov    %ebx,%ebp
shr    $0x1f,%ebp
add    %ebx,%ebp
sar    %ebp
mov    %ebp,%edi
call   1030 <make_space@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <str_glue@plt>
mov    %ebp,%edi
call   1030 <make_space@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <str_glue@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <xerox@plt>

LLVM IR (-O0):
define i8* @center(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32 @str_length(i8* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i8* @xerox(i8* %15)
store i8* %16, i8** %3
br label %32
17: ; preds = %2
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = sub nsw i32 %18, %19
%21 = sdiv i32 %20, 2
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = call i8* @make_space(i32 %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = load i8*, i8** %4
%26 = call i32 @str_glue(i8* %24, i8* %25)
%27 = load i8*, i8** %8
%28 = load i32, i32* %7
%29 = call i8* @make_space(i32 %28)
%30 = call i32 @str_glue(i8* %27, i8* %29)
%31 = load i8*, i8** %8
store i8* %31, i8** %3
br label %32
32: ; preds = %17, %14
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
define i8* @center(i8* %0, i32 %1) {
%3 = tail call i32 @str_length(i8* %0)
%4 = icmp slt i32 %3, %1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i8* @xerox(i8* %0)
br label %14
7: ; preds = %2
%8 = sub nsw i32 %1, %3
%9 = sdiv i32 %8, 2
%10 = tail call i8* @make_space(i32 %9)
%11 = tail call i32 @str_glue(i8* %10, i8* %0)
%12 = tail call i8* @make_space(i32 %9)
%13 = tail call i32 @str_glue(i8* %10, i8* %12)
br label %14
14: ; preds = %7, %5
%15 = phi i8* [ %6, %5 ], [ %10, %7 ]
ret i8* %15
}