#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 *embed_hotkey(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ memset(char *, char, size_t);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
void center_title(char *caption, char *key, char *decor, char *res,
                  size_t rlen) {
  size_t dlen, clen;
  char *fullcaption;
  dlen = strlen(decor);
  fullcaption = embed_hotkey(caption, key);
  clen = strlen(fullcaption);
  memset(res, ' ', rlen);
  memcpy(res, decor, dlen);
  memcpy(res + dlen + 4, fullcaption, clen);
  strncpy(res + rlen - dlen, decor, dlen);
  res[rlen] = 0;
  free(fullcaption);
}


x86 assembly (clang, -O0):
<center_title>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <embed_hotkey@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x20,%esi
call   1060 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1080 <memcpy@plt>
mov    -0x20(%rbp),%rdi
add    -0x30(%rbp),%rdi
add    $0x4,%rdi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1080 <memcpy@plt>
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
xor    %eax,%eax
sub    -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<center_title>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbp
mov    %rdx,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    %r13,%rsi
call   1070 <embed_hotkey@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %r14,%rdx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1080 <memcpy@plt>
lea    (%rbx,%r12,1),%rdi
add    $0x4,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1080 <memcpy@plt>
lea    (%rbx,%r14,1),%rdi
sub    %r12,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <strncpy@plt>
movb   $0x0,(%rbx,%r14,1)
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @center_title(i8* %0, i8* %1, i8* %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%14 = load i8*, i8** %8
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %11
%16 = load i8*, i8** %6
%17 = load i8*, i8** %7
%18 = call i8* @embed_hotkey(i8* %16, i8* %17)
store i8* %18, i8** %13
%19 = load i8*, i8** %13
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %12
%21 = load i8*, i8** %9
%22 = load i64, i64* %10
%23 = call i32 @memset(i8* %21, i8 signext 32, i64 %22)
%24 = load i8*, i8** %9
%25 = load i8*, i8** %8
%26 = load i64, i64* %11
%27 = call i32 @memcpy(i8* %24, i8* %25, i64 %26)
%28 = load i8*, i8** %9
%29 = load i64, i64* %11
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = getelementptr inbounds i8, i8* %30, i64 4
%32 = load i8*, i8** %13
%33 = load i64, i64* %12
%34 = call i32 @memcpy(i8* %31, i8* %32, i64 %33)
%35 = load i8*, i8** %9
%36 = load i64, i64* %10
%37 = getelementptr inbounds i8, i8* %35, i64 %36
%38 = load i64, i64* %11
%39 = sub i64 0, %38
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8*, i8** %8
%42 = load i64, i64* %11
%43 = call i32 @strncpy(i8* %40, i8* %41, i64 %42)
%44 = load i8*, i8** %9
%45 = load i64, i64* %10
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8 0, i8* %46
%47 = load i8*, i8** %13
%48 = call i32 @free(i8* %47)
ret void
}

LLVM IR (-O2):
define void @center_title(i8* %0, i8* %1, i8* %2, i8* %3, i64 %4) {
%6 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%7 = tail call i8* @embed_hotkey(i8* %0, i8* %1)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%9 = tail call i32 @memset(i8* %3, i8 signext 32, i64 %4)
%10 = tail call i32 @memcpy(i8* %3, i8* %2, i64 %6)
%11 = getelementptr inbounds i8, i8* %3, i64 %6
%12 = getelementptr inbounds i8, i8* %11, i64 4
%13 = tail call i32 @memcpy(i8* %12, i8* %7, i64 %8)
%14 = getelementptr inbounds i8, i8* %3, i64 %4
%15 = sub i64 0, %6
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = tail call i32 @strncpy(i8* %16, i8* %2, i64 %6)
store i8 0, i8* %14
%18 = tail call i32 @free(i8* %7)
ret void
}