#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 */
scalar_t__ malloc(int);
char *repeat_string(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *center_string(char *str) {
  int str_length = strlen(str);
  int available_space = 20 - str_length;
  int left_padding = 0;
  int right_padding = 0;
  if (available_space < 0) {
    available_space = 0;
  } else {
    int m = available_space % 2;
    if (m == 0) {
      left_padding = available_space / 2;
      right_padding = left_padding;
    } else {
      left_padding = available_space / 2;
      right_padding = available_space - left_padding;
    }
  }
  char *leftString = repeat_string(" ", left_padding);
  char *rightString = repeat_string(" ", right_padding);
  char *final = (char *)malloc(1 + 20);
  strcpy(final, leftString);
  strcat(final, str);
  strcat(final, rightString);
  return final;
}


x86 assembly (clang, -O0):
<center_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    $0x14,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1197 <center_string+0x47>
movl   $0x0,-0x10(%rbp)
jmp    11e4 <center_string+0x94>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11c8 <center_string+0x78>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11df <center_string+0x8f>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11e4 <center_string+0x94>
mov    -0x14(%rbp),%esi
lea    0xe12(%rip),%rdi
call   1050 <repeat_string@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdff(%rip),%rdi
call   1050 <repeat_string@plt>
mov    %rax,-0x30(%rbp)
mov    $0x15,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<center_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
xor    %ebp,%ebp
mov    $0x0,%esi
sub    $0x14,%eax
jg     117f <center_string+0x2f>
neg    %eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
mov    %eax,%ebp
sub    %esi,%ebp
test   $0x1,%al
cmove  %esi,%ebp
lea    0xe7a(%rip),%r15
mov    %r15,%rdi
call   1050 <repeat_string@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %ebp,%esi
call   1050 <repeat_string@plt>
mov    %rax,%r15
mov    $0x15,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8* @center_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %2
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = sub nsw i32 20, %13
store i32 %14, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 0, i32* %4
br label %34
18: ; preds = %1
%19 = load i32, i32* %4
%20 = srem i32 %19, 2
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* %4
%25 = sdiv i32 %24, 2
store i32 %25, i32* %5
%26 = load i32, i32* %5
store i32 %26, i32* %6
br label %33
27: ; preds = %18
%28 = load i32, i32* %4
%29 = sdiv i32 %28, 2
store i32 %29, i32* %5
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = sub nsw i32 %30, %31
store i32 %32, i32* %6
br label %33
33: ; preds = %27, %23
br label %34
34: ; preds = %33, %17
%35 = load i32, i32* %5
%36 = call i8* @repeat_string(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %35)
store i8* %36, i8** %8
%37 = load i32, i32* %6
%38 = call i8* @repeat_string(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %37)
store i8* %38, i8** %9
%39 = call i64 @malloc(i32 21)
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %10
%41 = load i8*, i8** %10
%42 = load i8*, i8** %8
%43 = call i32 @strcpy(i8* %41, i8* %42)
%44 = load i8*, i8** %10
%45 = load i8*, i8** %2
%46 = call i32 @strcat(i8* %44, i8* %45)
%47 = load i8*, i8** %10
%48 = load i8*, i8** %9
%49 = call i32 @strcat(i8* %47, i8* %48)
%50 = load i8*, i8** %10
ret i8* %50
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8* @center_string(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sub nsw i32 20, %2
%4 = icmp sgt i32 %2, 20
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = and i32 %3, 1
%7 = icmp eq i32 %6, 0
%8 = sdiv i32 %3, 2
%9 = sub nsw i32 %3, %8
%10 = select i1 %7, i32 %8, i32 %9
br label %11
11: ; preds = %5, %1
%12 = phi i32 [ 0, %1 ], [ %10, %5 ]
%13 = phi i32 [ 0, %1 ], [ %8, %5 ]
%14 = tail call i8* @repeat_string(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = tail call i8* @repeat_string(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %12)
%16 = tail call i64 @malloc(i32 21)
%17 = inttoptr i64 %16 to i8*
%18 = tail call i32 @strcpy(i8* %17, i8* %14)
%19 = tail call i32 @strcat(i8* %17, i8* %0)
%20 = tail call i32 @strcat(i8* %17, i8* %15)
ret i8* %17
}