#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int set_title(char *buffer, int sample, char *title, int centre) {
  int c = 0, l = 0;
  memset(&buffer[0x6c4f + (16 * sample)], ' ', 16);
  l = strlen(title);
  if (l > 16)
    l = 16;
  if (centre)
    c = (16 - l) / 2;
  strncpy(&buffer[0x6c4f + (16 * sample) + c], title, l);
}


x86 assembly (clang, -O0):
<set_title>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
add    $0x6c4f,%eax
cltq
add    %rax,%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x10,-0x2c(%rbp)
jle    1194 <set_title+0x64>
movl   $0x10,-0x2c(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11b1 <set_title+0x81>
mov    $0x10,%eax
sub    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
add    $0x6c4f,%eax
add    -0x28(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_title>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rdi,%r15
shl    $0x4,%esi
movslq %esi,%rbx
add    %rbx,%rdi
add    $0x6c4f,%rdi
mov    $0x10,%ebp
mov    $0x20,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x10,%eax
cmovge %ebp,%eax
sub    %eax,%ebp
shr    %ebp
test   %r12d,%r12d
cmove  %r12d,%ebp
lea    (%rbx,%rbp,1),%ecx
add    $0x6c4f,%ecx
movslq %ecx,%rdi
add    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
define i32 @set_title(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%12 = load i8*, i8** %6
%13 = load i32, i32* %7
%14 = mul nsw i32 16, %13
%15 = add nsw i32 27727, %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
%18 = call i32 @memset(i8* %17, i8 signext 32, i32 16)
%19 = load i8*, i8** %8
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %11
%21 = load i32, i32* %11
%22 = icmp sgt i32 %21, 16
br i1 %22, label %23, label %24
23: ; preds = %4
store i32 16, i32* %11
br label %24
24: ; preds = %23, %4
%25 = load i32, i32* %9
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* %11
%29 = sub nsw i32 16, %28
%30 = sdiv i32 %29, 2
store i32 %30, i32* %10
br label %31
31: ; preds = %27, %24
%32 = load i8*, i8** %6
%33 = load i32, i32* %7
%34 = mul nsw i32 16, %33
%35 = add nsw i32 27727, %34
%36 = load i32, i32* %10
%37 = add nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %32, i64 %38
%40 = load i8*, i8** %8
%41 = load i32, i32* %11
%42 = call i32 @strncpy(i8* %39, i8* %40, i32 %41)
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
define i32 @set_title(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = shl nsw i32 %1, 4
%6 = add nsw i32 %5, 27727
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = tail call i32 @memset(i8* %8, i8 signext 32, i32 16)
%10 = tail call i32 @strlen(i8* %2)
%11 = icmp slt i32 %10, 16
%12 = select i1 %11, i32 %10, i32 16
%13 = icmp eq i32 %3, 0
%14 = sub nsw i32 16, %12
%15 = lshr i32 %14, 1
%16 = select i1 %13, i32 0, i32 %15
%17 = add nsw i32 %16, %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = tail call i32 @strncpy(i8* %19, i8* %2, i32 %12)
ret i32 undef
}