#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void maxlenprint(char *value, int maxlen) {
  char *p;
  int lack;
  p = (char *)malloc(maxlen * sizeof(char));
  if (p != NULL) {
    lack = maxlen - strlen(value);
    strcpy(p, value);
    while (lack != 0) {
      strcat(p, " ");
      lack--;
    }
    printf("%s ", p);
  } else {
    fprintf(stderr, "malloc error!\n");
    exit(EXIT_FAILURE);
  }
  free(p);
  p = NULL;
}


x86 assembly (clang, -O0):
<maxlenprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1210 <maxlenprint+0x90>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11fb <maxlenprint+0x7b>
mov    -0x18(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d3 <maxlenprint+0x53>
mov    -0x18(%rbp),%rsi
lea    0xdfa(%rip),%rdi
call   1060 <printf@plt>
jmp    1233 <maxlenprint+0xb3>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maxlenprint>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
mov    %esi,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     11f0 <maxlenprint+0x70>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
cmp    %ebp,%r14d
je     11cf <maxlenprint+0x4f>
sub    %r14d,%ebp
lea    0xe42(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
inc    %ebp
jne    11c0 <maxlenprint+0x40>
lea    0xe2a(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [4 x i8] c"%s \00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"malloc error!\0A\00"
@EXIT_FAILURE = global i32 0
define void @maxlenprint(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 1
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %34
15: ; preds = %2
%16 = load i32, i32* %4
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* %17)
%19 = sub nsw i32 %16, %18
store i32 %19, i32* %6
%20 = load i8*, i8** %5
%21 = load i8*, i8** %3
%22 = call i32 @strcpy(i8* %20, i8* %21)
br label %23
23: ; preds = %26, %15
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i8*, i8** %5
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* %6
%30 = add nsw i32 %29, -1
store i32 %30, i32* %6
br label %23
31: ; preds = %23
%32 = load i8*, i8** %5
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %32)
br label %39
34: ; preds = %2
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %31
%40 = load i8*, i8** %5
%41 = call i32 @free(i8* %40)
store i8* null, i8** %5
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [4 x i8] c"%s \00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"malloc error!\0A\00"
@EXIT_FAILURE = global i32 0
define void @maxlenprint(i8* %0, i32 %1) {
%3 = tail call i64 @malloc(i32 %1)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = sub nsw i32 %1, %7
%9 = tail call i32 @strcpy(i8* %4, i8* %0)
%10 = icmp eq i32 %8, 0
br i1 %10, label %16, label %11
11: ; preds = %6, %11
%12 = phi i32 [ %14, %11 ], [ %8, %6 ]
%13 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = add nsw i32 %12, -1
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %11
16: ; preds = %11, %6
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%18 = tail call i32 @free(i8* %4)
ret void
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
}