#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
unsigned int strlen(char *);
char *justify(char *s, unsigned n) {
  char res[256];
  strcpy(res, s);
  while (strlen(res) < n)
    strcat(res, " ");
  return strdup(res);
}


x86 assembly (clang, -O0):
<justify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0xc(%rbp),%eax
jae    118f <justify+0x4f>
lea    -0x110(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <strcat@plt>
jmp    1162 <justify+0x22>
lea    -0x110(%rbp),%rdi
call   1060 <strdup@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<justify>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %esi,%ebp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jae    1197 <justify+0x57>
lea    0xe92(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jb     1180 <justify+0x40>
mov    %rsp,%rdi
call   1060 <strdup@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8* @justify(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [256 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = call i32 @strcpy(i8* %6, i8* %7)
br label %9
9: ; preds = %14, %2
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = load i32, i32* %4
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %9
17: ; preds = %9
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%19 = call i8* @strdup(i8* %18)
ret i8* %19
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define noalias i8* @justify(i8* %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = call i32 @strlen(i8* %4)
%7 = icmp ult i32 %6, %1
br i1 %7, label %8, label %12
8: ; preds = %2, %8
%9 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @strlen(i8* %4)
%11 = icmp ult i32 %10, %1
br i1 %11, label %8, label %12
12: ; preds = %8, %2
%13 = call i8* @strdup(i8* %4)
ret i8* %13
}