#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 *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
char *starpad(int line_len, char *tmp) {
  char *buf = malloc(sizeof(char) * (line_len + 1)),
       *start = (buf + (line_len / 2 - strlen(tmp) / 2));
  int i;
  for (i = 0; i < line_len; i++)
    buf[i] = '*';
  sprintf(start, " %s", tmp);
  *(start + strlen(tmp) + 1) = '*';
  buf[line_len] = '\n';
  buf[line_len + 1] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<starpad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x34(%rbp),%ecx
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x30(%rbp),%rax
sub    %edx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11bf <starpad+0x8f>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x2a,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1199 <starpad+0x69>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe32(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
movb   $0x2a,0x1(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<starpad>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r12d
movslq %edi,%r13
lea    0x1(%r13),%r14
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r13d,%ebp
shr    $0x1f,%ebp
add    %r12d,%ebp
sar    %ebp
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
sub    %ecx,%ebp
movslq %ebp,%rbp
add    %rbx,%rbp
test   %r13d,%r13d
jle    119c <starpad+0x5c>
mov    %r12d,%edx
mov    %rbx,%rdi
mov    $0x2a,%esi
call   1040 <memset@plt>
lea    0xe5d(%rip),%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
call   1060 <sprintf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x2a,0x1(%rbp,%rax,1)
movb   $0xa,(%rbx,%r13,1)
movb   $0x0,(%rbx,%r14,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c" %s\00"
define noalias i8* @starpad(i32 %0, i8* %1) {
%3 = add nsw i32 %0, 1
%4 = tail call i8* @malloc(i32 %3)
%5 = sdiv i32 %0, 2
%6 = tail call i32 @strlen(i8* %1)
%7 = sdiv i32 %6, -2
%8 = add nsw i32 %7, %5
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %4, i64 %9
%11 = icmp sgt i32 %0, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = zext i32 %0 to i64
br label %14
14: ; preds = %12, %2
%15 = sext i32 %3 to i64
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%17 = tail call i32 @strlen(i8* %1)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %10, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8 42, i8* %20
%21 = sext i32 %0 to i64
%22 = getelementptr inbounds i8, i8* %4, i64 %21
store i8 10, i8* %22
%23 = getelementptr inbounds i8, i8* %4, i64 %15
store i8 0, i8* %23
ret i8* %4
}