#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 strlen(char *);
char *adjust(char *p, char *str, char fill, int width) {
  int l = width - strlen(str);
  while (l-- > 0)
    *p++ = fill;
  while (*p = *str++)
    p++;
  return p;
}


x86 assembly (clang, -O0):
<adjust>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
jle    116e <adjust+0x5e>
mov    -0x11(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1141 <adjust+0x31>
jmp    1173 <adjust+0x63>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    -0x8(%rbp),%rcx
mov    %al,(%rcx)
cmp    $0x0,%al
je     11a3 <adjust+0x93>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1173 <adjust+0x63>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adjust>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    %r12d,%eax
jge    115f <adjust+0x3f>
mov    %eax,%ebp
not    %ebp
add    %r12d,%ebp
lea    0x1(%rbp),%rdx
movzbl %r15b,%esi
mov    %r14,%rdi
call   1040 <memset@plt>
add    %rbp,%r14
add    $0x1,%r14
mov    (%rbx),%al
mov    %al,(%r14)
test   %al,%al
je     1183 <adjust+0x63>
add    $0x1,%rbx
nopl   0x0(%rax)
movzbl (%rbx),%eax
mov    %al,0x1(%r14)
add    $0x1,%r14
add    $0x1,%rbx
test   %al,%al
jne    1170 <adjust+0x50>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @adjust(i8* %0, i8* %1, i8 signext %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8 %2, i8* %7
store i32 %3, i32* %8
%10 = load i32, i32* %8
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %10, %12
store i32 %13, i32* %9
br label %14
14: ; preds = %18, %4
%15 = load i32, i32* %9
%16 = add nsw i32 %15, -1
store i32 %16, i32* %9
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i8, i8* %7
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
store i8 %19, i8* %20
br label %14
22: ; preds = %14
br label %23
23: ; preds = %29, %22
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %6
%26 = load i8, i8* %24
%27 = load i8*, i8** %5
store i8 %26, i8* %27
%28 = icmp ne i8 %26, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %5
br label %23
32: ; preds = %23
%33 = load i8*, i8** %5
ret i8* %33
}

LLVM IR (-O2):
define i8* @adjust(i8* writeonly %0, i8* %1, i8 signext %2, i32 %3) {
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp slt i32 %5, %3
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = xor i32 %5, -1
%9 = add i32 %8, %3
%10 = zext i32 %9 to i64
%11 = add nuw nsw i64 %10, 1
%12 = getelementptr i8, i8* %0, i64 %11
br label %13
13: ; preds = %7, %4
%14 = phi i8* [ %0, %4 ], [ %12, %7 ]
%15 = load i8, i8* %1
store i8 %15, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %13, %17
%18 = phi i8* [ %21, %17 ], [ %14, %13 ]
%19 = phi i8* [ %20, %17 ], [ %1, %13 ]
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = load i8, i8* %20
store i8 %22, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %17
24: ; preds = %17, %13
%25 = phi i8* [ %14, %13 ], [ %21, %17 ]
ret i8* %25
}