void field(int pos, const char *buf, int bits) {
  int w = bits * 9 + bits - 1;
  int p;
  p = w - strlen(buf);
  if (p <= 0)
    printf("%.*s%c", w, buf, pos - bits ? '|' : '\n');
  else
    printf("%*s%s%*s%c", p / 2, "", buf, (p + 1) / 2, "",
           pos - bits ? '|' : '\n');
}


x86 assembly (clang, -O0):
<field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
imul   $0x9,-0x14(%rbp),%eax
add    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1197 <field+0x77>
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%edi
sub    -0x14(%rbp),%edi
mov    $0xa,%ecx
mov    $0x7c,%eax
cmp    $0x0,%edi
cmovne %eax,%ecx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ea <field+0xca>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%edi
cltd
idiv   %edi
mov    %eax,%r8d
mov    -0x4(%rbp),%edi
sub    -0x14(%rbp),%edi
mov    $0xa,%eax
mov    $0x7c,%edx
cmp    $0x0,%edi
cmovne %edx,%eax
lea    0xe31(%rip),%rdi
lea    0xe34(%rip),%r9
mov    %r9,%rdx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<field>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%r15d
lea    (%rbx,%rbx,4),%eax
lea    (%rax,%rax,1),%ebp
add    $0xffffffff,%ebp
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %ebp,%r8d
sub    %eax,%r8d
test   %r8d,%r8d
jle    1190 <field+0x70>
mov    %r8d,%esi
shr    %esi
add    $0x1,%r8d
shr    %r8d
cmp    %ebx,%r15d
mov    $0xa,%eax
mov    $0x7c,%ecx
cmove  %eax,%ecx
mov    %ecx,(%rsp)
lea    0xe96(%rip),%rdi
lea    0xe99(%rip),%rdx
mov    %r14,%rcx
mov    %rdx,%r9
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    %ebx,%r15d
mov    $0xa,%eax
mov    $0x7c,%ecx
cmove  %eax,%ecx
lea    0xe59(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%.*s%c\00"
@.str.1 = [11 x i8] c"%*s%s%*s%c\00"
@.str.2 = [1 x i8] zeroinitializer
define void @field(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = mul nsw i32 %9, 9
%11 = load i32, i32* %6
%12 = add nsw i32 %10, %11
%13 = sub nsw i32 %12, 1
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = load i8*, i8** %5
%17 = call i64 @strlen(i8* %16)
%18 = sub i64 %15, %17
%19 = trunc i64 %18 to i32
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp sle i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %3
%23 = load i32, i32* %7
%24 = load i8*, i8** %5
%25 = load i32, i32* %4
%26 = load i32, i32* %6
%27 = sub nsw i32 %25, %26
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 124, i32 10
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %23, i8* %24, i32 %30)
br label %46
32: ; preds = %3
%33 = load i32, i32* %8
%34 = sdiv i32 %33, 2
%35 = load i8*, i8** %5
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
%38 = sdiv i32 %37, 2
%39 = load i32, i32* %4
%40 = load i32, i32* %6
%41 = sub nsw i32 %39, %40
%42 = icmp ne i32 %41, 0
%43 = zext i1 %42 to i64
%44 = select i1 %42, i32 124, i32 10
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %34, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* %35, i32 %38, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %32, %22
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%.*s%c\00"
@.str.1 = [11 x i8] c"%*s%s%*s%c\00"
@.str.2 = [1 x i8] zeroinitializer
define void @field(i32 %0, i8* %1, i32 %2) {
%4 = mul nsw i32 %2, 10
%5 = add nsw i32 %4, -1
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = trunc i64 %6 to i32
%8 = sub i32 %5, %7
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = icmp eq i32 %0, %2
%12 = select i1 %11, i32 10, i32 124
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5, i8* %1, i32 %12)
br label %21
14: ; preds = %3
%15 = lshr i32 %8, 1
%16 = add nuw nsw i32 %8, 1
%17 = lshr i32 %16, 1
%18 = icmp eq i32 %0, %2
%19 = select i1 %18, i32 10, i32 124
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %14, %10
ret void
}