#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 LastCol(char *);
scalar_t__ strlen(char *);
char *PadTo(int col, char *buffer) {
  int any = 0;
  int len = (int)strlen(buffer);
  int now;
  char with;
  for (;;) {
    if ((now = LastCol(buffer)) >= col) {
      if (any)
        break;
      else
        with = ' ';
    } else if (col - now > 2)
      with = '\t';
    else
      with = ' ';
    buffer[len++] = with;
    buffer[len] = '\0';
    any++;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<PadTo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <LastCol@plt>
mov    %eax,-0x1c(%rbp)
cmp    -0x4(%rbp),%eax
jl     116f <PadTo+0x4f>
cmpl   $0x0,-0x14(%rbp)
je     1166 <PadTo+0x46>
jmp    11c2 <PadTo+0xa2>
movb   $0x20,-0x1d(%rbp)
jmp    1190 <PadTo+0x70>
mov    -0x4(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    $0x2,%eax
jle    1187 <PadTo+0x67>
movb   $0x9,-0x1d(%rbp)
jmp    118b <PadTo+0x6b>
movb   $0x20,-0x1d(%rbp)
jmp    1190 <PadTo+0x70>
mov    -0x1d(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1142 <PadTo+0x22>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PadTo>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsi,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rbx
add    $0x1,%rbx
xor    %ebp,%ebp
mov    $0x9,%r12d
jmp    116d <PadTo+0x4d>
nopw   0x0(%rax,%rax,1)
mov    %r15d,%ecx
sub    %eax,%ecx
cmp    $0x3,%ecx
mov    $0x20,%eax
cmovge %r12d,%eax
mov    %al,-0x1(%rbx,%rbp,1)
movb   $0x0,(%rbx,%rbp,1)
add    $0x1,%rbp
mov    %r14,%rdi
call   1040 <LastCol@plt>
cmp    %r15d,%eax
jl     1150 <PadTo+0x30>
mov    $0x20,%al
test   %ebp,%ebp
je     1161 <PadTo+0x41>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @PadTo(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = trunc i64 %10 to i32
store i32 %11, i32* %6
br label %12
12: ; preds = %31, %2
%13 = load i8*, i8** %4
%14 = call i32 @LastCol(i8* %13)
store i32 %14, i32* %7
%15 = load i32, i32* %3
%16 = icmp sge i32 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
br label %44
21: ; preds = %17
store i8 32, i8* %8
br label %22
22: ; preds = %21
br label %31
23: ; preds = %12
%24 = load i32, i32* %3
%25 = load i32, i32* %7
%26 = sub nsw i32 %24, %25
%27 = icmp sgt i32 %26, 2
br i1 %27, label %28, label %29
28: ; preds = %23
store i8 9, i8* %8
br label %30
29: ; preds = %23
store i8 32, i8* %8
br label %30
30: ; preds = %29, %28
br label %31
31: ; preds = %30, %22
%32 = load i8, i8* %8
%33 = load i8*, i8** %4
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 %32, i8* %37
%38 = load i8*, i8** %4
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 0, i8* %41
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %12
44: ; preds = %20
%45 = load i8*, i8** %4
ret i8* %45
}

LLVM IR (-O2):
define i8* @PadTo(i32 %0, i8* returned %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = shl i64 %3, 32
%5 = ashr exact i64 %4, 32
br label %6
6: ; preds = %17, %2
%7 = phi i64 [ %19, %17 ], [ %5, %2 ]
%8 = phi i32 [ %22, %17 ], [ 0, %2 ]
%9 = tail call i32 @LastCol(i8* %1)
%10 = icmp slt i32 %9, %0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = icmp eq i32 %8, 0
br i1 %12, label %17, label %23
13: ; preds = %6
%14 = sub nsw i32 %0, %9
%15 = icmp sgt i32 %14, 2
%16 = select i1 %15, i8 9, i8 32
br label %17
17: ; preds = %13, %11
%18 = phi i8 [ 32, %11 ], [ %16, %13 ]
%19 = add i64 %7, 1
%20 = getelementptr inbounds i8, i8* %1, i64 %7
store i8 %18, i8* %20
%21 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 0, i8* %21
%22 = add nuw nsw i32 %8, 1
br label %6
23: ; preds = %11
ret i8* %1
}