#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void ut_CenterMessage(char *text, int width, char *output) {
  char *blank;
  int ntest, nn;
  memset(output, 0, strlen(output));
  ntest = (width - strlen(text)) / 2;
  blank = (char *)malloc(ntest + 1);
  for (nn = 0; nn < ntest; nn++)
    blank[nn] = ' ';
  blank[ntest] = '\0';
  strcpy(output, blank);
  strcat(output, text);
  strcat(output, blank);
  free(blank);
}


x86 assembly (clang, -O0):
<ut_CenterMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11ee <ut_CenterMessage+0x8e>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c8 <ut_CenterMessage+0x68>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ut_CenterMessage>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r14
mov    %rdx,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
sub    %eax,%ebp
mov    %ebp,%ebx
shr    $0x1f,%ebx
add    %ebp,%ebx
sar    %ebx
lea    0x1(%rbx),%edi
call   1070 <malloc@plt>
mov    %rax,%r12
cmp    $0x2,%ebp
jl     11bb <ut_CenterMessage+0x5b>
lea    -0x1(%rbx),%edx
add    $0x1,%rdx
mov    %r12,%rdi
mov    $0x20,%esi
call   1060 <memset@plt>
movslq %ebx,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @ut_CenterMessage(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = tail call i32 @memset(i8* %2, i32 0, i32 %4)
%6 = tail call i32 @strlen(i8* %0)
%7 = sub nsw i32 %1, %6
%8 = sdiv i32 %7, 2
%9 = add nsw i32 %8, 1
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp sgt i32 %7, 1
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = add nsw i32 %8, -1
%15 = zext i32 %14 to i64
%16 = add nuw nsw i64 %15, 1
br label %17
17: ; preds = %13, %3
%18 = sext i32 %8 to i64
%19 = getelementptr inbounds i8, i8* %11, i64 %18
store i8 0, i8* %19
%20 = tail call i32 @strcpy(i8* %2, i8* %11)
%21 = tail call i32 @strcat(i8* %2, i8* %0)
%22 = tail call i32 @strcat(i8* %2, i8* %11)
%23 = tail call i32 @free(i8* %11)
ret void
}