#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*/ memset(char *, char, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
scalar_t__ xmalloc(int);
char *centre_line(const char *line, int max) {
  char *result;
  int len;
  len = strlen(line);
  if (len < (max - 1)) {
    int space;
    space = (max - len) / 2;
    result = (char *)xmalloc(space + len + 2);
    memset(result, ' ', space);
    strcpy(&result[space], line);
    len += space;
  } else {
    result = (char *)xmalloc(max + 2);
    strncpy(result, line, max);
    len = max;
  }
  strcpy(&result[len], "\n");
  return result;
}


x86 assembly (clang, -O0):
<centre_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d2 <centre_line+0x82>
mov    -0xc(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
add    -0x1c(%rbp),%edi
add    $0x2,%edi
call   1070 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    $0x20,%esi
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11f7 <centre_line+0xa7>
mov    -0xc(%rbp),%edi
add    $0x2,%edi
call   1070 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    0xdf7(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<centre_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    -0x1(%r12),%ecx
cmp    %ecx,%eax
jge    11ab <centre_line+0x5b>
sub    %eax,%r12d
mov    %r12d,%ebx
shr    $0x1f,%ebx
add    %r12d,%ebx
sar    %ebx
lea    (%rbx,%rax,1),%r12d
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1070 <xmalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x20,%esi
mov    %ebx,%edx
call   1060 <memset@plt>
movslq %ebx,%rdi
add    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
jmp    11c6 <centre_line+0x76>
lea    0x2(%r12),%edi
call   1070 <xmalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
movslq %r12d,%rdi
add    %r15,%rdi
lea    0xe2d(%rip),%rsi
call   1040 <strcpy@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i8* @centre_line(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %1, -1
%5 = icmp slt i32 %3, %4
br i1 %5, label %6, label %17
6: ; preds = %2
%7 = sub nsw i32 %1, %3
%8 = sdiv i32 %7, 2
%9 = add nsw i32 %8, %3
%10 = add nsw i32 %9, 2
%11 = tail call i64 @xmalloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 @memset(i8* %12, i8 signext 32, i32 %8)
%14 = sext i32 %8 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = tail call i32 @strcpy(i8* %15, i8* %0)
br label %22
17: ; preds = %2
%18 = add nsw i32 %1, 2
%19 = tail call i64 @xmalloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
%21 = tail call i32 @strncpy(i8* %20, i8* %0, i32 %1)
br label %22
22: ; preds = %17, %6
%23 = phi i32 [ %9, %6 ], [ %1, %17 ]
%24 = phi i8* [ %12, %6 ], [ %20, %17 ]
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = tail call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret i8* %24
}