#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 get_term_width();
char *malloc(size_t);
int /*<<< orphan*/ memset(char *, char, size_t);
int /*<<< orphan*/ printf(char *, char *, char const *);
int strlen(char const *);
void welcome(void) {
  size_t margin, msglen;
  char *spaces;
  const char welcome_msg[] = "WELCOME TO TIC TAC TOE";
  msglen = strlen(welcome_msg);
  if (get_term_width() < msglen)
    margin = 0;
  else
    margin = get_term_width() - strlen(welcome_msg) / 2;
  spaces = malloc(margin + 1);
  memset(spaces, ' ', margin);
  spaces[margin] = 0;
  printf("%s%s\n\n", spaces, welcome_msg);
}


x86 assembly (clang, -O0):
<welcome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xea1(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe9e(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe9c(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xe96(%rip),%ax
mov    %ax,-0x1c(%rbp)
mov    0xe8e(%rip),%al
mov    %al,-0x1a(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <get_term_width@plt>
cltq
cmp    -0x10(%rbp),%rax
jae    11ba <welcome+0x6a>
movq   $0x0,-0x8(%rbp)
jmp    11e2 <welcome+0x92>
mov    $0x0,%al
call   1070 <get_term_width@plt>
mov    %eax,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
sub    %ecx,%eax
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x20,%esi
call   1050 <memset@plt>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    0xdf7(%rip),%rdi
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<welcome>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movaps 0xea3(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x454f5420434154,%rax
mov    %rax,0xf(%rsp)
mov    %rsp,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <get_term_width@plt>
cmp    %ebp,%eax
jb     11a6 <welcome+0x56>
xor    %eax,%eax
call   1070 <get_term_width@plt>
mov    %eax,%ebx
mov    %rsp,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
sub    %ecx,%ebx
movslq %ebx,%rbx
lea    0x1(%rbx),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
movb   $0x0,0x0(%rbp,%rbx,1)
lea    0xe49(%rip),%rdi
mov    %rsp,%rdx
mov    %rbp,%rsi
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.welcome.welcome_msg = [23 x i8] c"WELCOME TO TIC TAC TOE\00"
@.str = [7 x i8] c"%s%s\0A\0A\00"
define void @welcome() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i8*
%4 = alloca [23 x i8]
%5 = bitcast [23 x i8]* %4 to i8*
%6 = getelementptr inbounds [23 x i8], [23 x i8]* %4, i64 0, i64 0
%7 = call i32 @strlen(i8* %6)
%8 = sext i32 %7 to i64
store i64 %8, i64* %2
%9 = call i32 (...) @get_term_width()
%10 = sext i32 %9 to i64
%11 = load i64, i64* %2
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %0
store i64 0, i64* %1
br label %21
14: ; preds = %0
%15 = call i32 (...) @get_term_width()
%16 = getelementptr inbounds [23 x i8], [23 x i8]* %4, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = sdiv i32 %17, 2
%19 = sub nsw i32 %15, %18
%20 = sext i32 %19 to i64
store i64 %20, i64* %1
br label %21
21: ; preds = %14, %13
%22 = load i64, i64* %1
%23 = add i64 %22, 1
%24 = call i8* @malloc(i64 %23)
store i8* %24, i8** %3
%25 = load i8*, i8** %3
%26 = load i64, i64* %1
%27 = call i32 @memset(i8* %25, i8 signext 32, i64 %26)
%28 = load i8*, i8** %3
%29 = load i64, i64* %1
%30 = getelementptr inbounds i8, i8* %28, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %3
%32 = getelementptr inbounds [23 x i8], [23 x i8]* %4, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %31, i8* %32)
ret void
}

LLVM IR (-O2):
@__const.welcome.welcome_msg = [23 x i8] c"WELCOME TO TIC TAC TOE\00"
@.str = [7 x i8] c"%s%s\0A\0A\00"
define void @welcome() {
%1 = alloca [23 x i8]
%2 = getelementptr inbounds [23 x i8], [23 x i8]* %1, i64 0, i64 0
%3 = call i32 @strlen(i8* %2)
%4 = call i32 (...) @get_term_width()
%5 = icmp ult i32 %4, %3
br i1 %5, label %12, label %6
6: ; preds = %0
%7 = call i32 (...) @get_term_width()
%8 = call i32 @strlen(i8* %2)
%9 = sdiv i32 %8, -2
%10 = add i32 %9, %7
%11 = sext i32 %10 to i64
br label %12
12: ; preds = %0, %6
%13 = phi i64 [ %11, %6 ], [ 0, %0 ]
%14 = add nsw i64 %13, 1
%15 = call i8* @malloc(i64 %14)
%16 = call i32 @memset(i8* %15, i8 signext 32, i64 %13)
%17 = getelementptr inbounds i8, i8* %15, i64 %13
store i8 0, i8* %17
%18 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %2)
ret void
}