#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 */
int /*<<< orphan*/ center(char *, int);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int strlen(char *);
char *center_rpad(char *string, int screen_len) {
  static char line[512];
  int x;
  int str_len_div_two = strlen(string) / 2;
  int scr_len_div_two = screen_len / 2;
  char *ptr;
  strcpy(line, center(string, screen_len));
  ptr = line + strlen(line);
  for (x = 0; x < scr_len_div_two - str_len_div_two; x++)
    *ptr++ = ' ';
  *ptr = '\0';
  return line;
}


x86 assembly (clang, -O0):
<center_rpad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <center@plt>
mov    %eax,%esi
lea    0x2eda(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2ece(%rip),%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
lea    0x2ebf(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jge    11d0 <center_rpad+0xa0>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x20,(%rax)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119f <center_rpad+0x6f>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e72(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<center_rpad>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    %ebp,%ebx
shr    $0x1f,%ebx
add    %ebp,%ebx
sar    %ebx
sub    %ecx,%ebx
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <center@plt>
lea    0x2edd(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbp
lea    (%r14,%rbp,1),%rdi
test   %ebx,%ebx
jle    11ac <center_rpad+0x6c>
add    $0xffffffff,%ebx
lea    0x1(%rbx),%rdx
mov    $0x20,%esi
call   1050 <memset@plt>
add    %rbx,%rbp
lea    (%r14,%rbp,1),%rdi
add    $0x1,%rdi
movb   $0x0,(%rdi)
lea    0x2e9a(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@center_rpad.line = internal global [512 x i8] zeroinitializer
define i8* @center_rpad(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = sdiv i32 %3, -2
%5 = sdiv i32 %1, 2
%6 = tail call i32 @center(i8* %0, i32 %1)
%7 = tail call i32 @strcpy(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @center_rpad.line, i64 0, i64 0), i32 %6)
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @center_rpad.line, i64 0, i64 0))
%9 = sext i32 %8 to i64
%10 = getelementptr [512 x i8], [512 x i8]* @center_rpad.line, i64 0, i64 %9
%11 = add nsw i32 %4, %5
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = add nsw i32 %11, -1
%15 = zext i32 %14 to i64
%16 = add nuw nsw i64 %15, 1
%17 = add nsw i64 %9, %15
%18 = add nsw i64 %17, 1
%19 = getelementptr [512 x i8], [512 x i8]* @center_rpad.line, i64 0, i64 %18
br label %20
20: ; preds = %13, %2
%21 = phi i8* [ %10, %2 ], [ %19, %13 ]
store i8 0, i8* %21
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @center_rpad.line, i64 0, i64 0)
}