char *filblanks(buf, lr, len)
char *buf;
int lr, len;
{
  static char retbuf[32];
  int l;
  memset(retbuf, ' ', sizeof retbuf);
  if ((l = strlen(buf)) > len)
    l = len;
  strncpy(retbuf + ((lr == 1) ? (len - l) : 0), buf, l);
  retbuf[len] = '\0';
  return (retbuf);
}


x86 assembly (clang, -O0):
<filblanks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0x2f07(%rip),%rdi
mov    $0x20,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmp    -0x10(%rbp),%eax
jle    1173 <filblanks+0x43>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    118b <filblanks+0x5b>
mov    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1195 <filblanks+0x65>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    1195 <filblanks+0x65>
mov    -0x18(%rbp),%eax
cltq
lea    0x2eaf(%rip),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rdx
call   1030 <strncpy@plt>
movslq -0x10(%rbp),%rcx
lea    0x2e94(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e89(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filblanks>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
movaps 0xeca(%rip),%xmm0
movaps %xmm0,0x2f13(%rip)
movaps %xmm0,0x2efc(%rip)
lea    0x2ef5(%rip),%r15
call   1040 <strlen@plt>
cmp    %ebx,%eax
cmovg  %ebx,%eax
mov    %ebx,%ecx
sub    %eax,%ecx
xor    %edx,%edx
cmp    $0x1,%r14d
cmove  %ecx,%edx
movslq %edx,%rdi
add    %r15,%rdi
movslq %eax,%rdx
mov    %rbp,%rsi
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,(%rax,%r15,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@filblanks.retbuf = internal global [32 x i8] zeroinitializer
define i8* @filblanks(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %7
%11 = load i32, i32* %6
%12 = icmp sgt i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i32, i32* %6
store i32 %14, i32* %7
br label %15
15: ; preds = %13, %3
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = sub nsw i32 %19, %20
br label %23
22: ; preds = %15
br label %23
23: ; preds = %22, %18
%24 = phi i32 [ %21, %18 ], [ 0, %22 ]
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @filblanks.retbuf, i64 0, i64 0), i64 %25
%27 = load i8*, i8** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = call i8* @strncpy(i8* %26, i8* %27, i64 %29)
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [32 x i8], [32 x i8]* @filblanks.retbuf, i64 0, i64 %32
store i8 0, i8* %33
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @filblanks.retbuf, i64 0, i64 0)
}

LLVM IR (-O2):
@filblanks.retbuf = internal global [32 x i8] zeroinitializer
define i8* @filblanks(i8* nocapture %0, i32 %1, i32 %2) {
tail call void @llvm.memset.p0i8.i64(i8* align 16 dereferenceable(32) getelementptr inbounds ([32 x i8], [32 x i8]* @filblanks.retbuf, i64 0, i64 0), i8 32, i64 32, i1 false)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = trunc i64 %4 to i32
%6 = icmp sgt i32 %5, %2
%7 = select i1 %6, i32 %2, i32 %5
%8 = icmp eq i32 %1, 1
%9 = sub nsw i32 %2, %7
%10 = select i1 %8, i32 %9, i32 0
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [32 x i8], [32 x i8]* @filblanks.retbuf, i64 0, i64 %11
%13 = sext i32 %7 to i64
%14 = tail call i8* @strncpy(i8* %12, i8* %0, i64 %13)
%15 = sext i32 %2 to i64
%16 = getelementptr inbounds [32 x i8], [32 x i8]* @filblanks.retbuf, i64 0, i64 %15
store i8 0, i8* %16
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @filblanks.retbuf, i64 0, i64 0)
}