cat_hist_output(f, w, out, pt) int f;
int w;
char *out;
char *pt;
{
  char *output;
  output = out + strlen(out);
  if (out != output) {
    *output++ = ' ';
    *output = '\0';
  }
  switch (f) {
  case 'c':
    sprintf(output, "%s", pt);
    break;
  case 'C':
    if (w < 20)
      sprintf(output, "%-*s", w, pt);
    else
      sprintf(output, "%-20.20s", pt);
    break;
  case 'D':
    if (w < 20)
      sprintf(output, "%-*s", w, pt);
    else {
      int len;
      len = strlen(pt) - 20;
      if (len < 0)
        len = 0;
      sprintf(output, "%-20.20s", pt + len);
    }
    break;
  case 'd':
  case 'x':
    sprintf(output, "%-*s", w, pt);
    break;
  default:
    sprintf(output, "%*s", w, pt);
    break;
  }
}


x86 assembly (clang, -O0):
<cat_hist_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     117c <cat_hist_output+0x5c>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x20,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x43,%eax
je     11ef <cat_hist_output+0xcf>
jmp    1190 <cat_hist_output+0x70>
mov    -0x3c(%rbp),%eax
sub    $0x44,%eax
je     1232 <cat_hist_output+0x112>
jmp    11a1 <cat_hist_output+0x81>
mov    -0x3c(%rbp),%eax
sub    $0x63,%eax
je     11d4 <cat_hist_output+0xb4>
jmp    11b2 <cat_hist_output+0x92>
mov    -0x3c(%rbp),%eax
sub    $0x64,%eax
je     129d <cat_hist_output+0x17d>
jmp    11c3 <cat_hist_output+0xa3>
mov    -0x3c(%rbp),%eax
sub    $0x78,%eax
je     129d <cat_hist_output+0x17d>
jmp    12bb <cat_hist_output+0x19b>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    12d4 <cat_hist_output+0x1b4>
cmpl   $0x14,-0xc(%rbp)
jge    1217 <cat_hist_output+0xf7>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    122d <cat_hist_output+0x10d>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    12d4 <cat_hist_output+0x1b4>
cmpl   $0x14,-0xc(%rbp)
jge    125a <cat_hist_output+0x13a>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1298 <cat_hist_output+0x178>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x14,%rax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    127b <cat_hist_output+0x15b>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
movslq -0x2c(%rbp),%rax
add    %rax,%rdx
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    12d4 <cat_hist_output+0x1b4>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    12d4 <cat_hist_output+0x1b4>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xd44(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat_hist_output>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %edi,%ebp
mov    %rdx,%rdi
call   1040 <strlen@plt>
add    %rax,%rbx
test   %rax,%rax
je     115b <cat_hist_output+0x2b>
movw   $0x20,(%rbx)
add    $0x1,%rbx
lea    -0x43(%rbp),%eax
cmp    $0x21,%eax
ja     117b <cat_hist_output+0x4b>
lea    0xe96(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmp    $0x13,%r15d
jle    118f <cat_hist_output+0x5f>
jmp    11d1 <cat_hist_output+0xa1>
cmp    $0x78,%ebp
je     118f <cat_hist_output+0x5f>
lea    0xf0f(%rip),%rsi
jmp    1196 <cat_hist_output+0x66>
cmp    $0x13,%r15d
jg     11be <cat_hist_output+0x8e>
lea    0xef2(%rip),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <sprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    11a6 <cat_hist_output+0x76>
mov    %r14,%rdi
call   1040 <strlen@plt>
xor    %ecx,%ecx
add    $0xffffffec,%eax
cmovs  %ecx,%eax
add    %rax,%r14
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    11a6 <cat_hist_output+0x76>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"%-*s\00"
@.str.2 = [9 x i8] c"%-20.20s\00"
@.str.3 = [4 x i8] c"%*s\00"
define i32 @cat_hist_output(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%12 = load i8*, i8** %8
%13 = load i8*, i8** %8
%14 = call i64 @strlen(i8* %13)
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8* %15, i8** %10
%16 = load i8*, i8** %8
%17 = load i8*, i8** %10
%18 = icmp ne i8* %16, %17
br i1 %18, label %19, label %23
19: ; preds = %4
%20 = load i8*, i8** %10
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %10
store i8 32, i8* %20
%22 = load i8*, i8** %10
store i8 0, i8* %22
br label %23
23: ; preds = %19, %4
%24 = load i32, i32* %6
switch i32 %24, label %71 [
i32 99, label %25
i32 67, label %29
i32 68, label %42
i32 100, label %66
i32 120, label %66
]
25: ; preds = %23
%26 = load i8*, i8** %10
%27 = load i8*, i8** %9
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %27)
br label %76
29: ; preds = %23
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 20
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i8*, i8** %10
%34 = load i32, i32* %7
%35 = load i8*, i8** %9
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %34, i8* %35)
br label %41
37: ; preds = %29
%38 = load i8*, i8** %10
%39 = load i8*, i8** %9
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %37, %32
br label %76
42: ; preds = %23
%43 = load i32, i32* %7
%44 = icmp slt i32 %43, 20
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = load i8*, i8** %10
%47 = load i32, i32* %7
%48 = load i8*, i8** %9
%49 = call i32 (i8*, i8*, ...) @sprintf(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %47, i8* %48)
br label %65
50: ; preds = %42
%51 = load i8*, i8** %9
%52 = call i64 @strlen(i8* %51)
%53 = sub i64 %52, 20
%54 = trunc i64 %53 to i32
store i32 %54, i32* %11
%55 = load i32, i32* %11
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %50
store i32 0, i32* %11
br label %58
58: ; preds = %57, %50
%59 = load i8*, i8** %10
%60 = load i8*, i8** %9
%61 = load i32, i32* %11
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = call i32 (i8*, i8*, ...) @sprintf(i8* %59, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %58, %45
br label %76
66: ; preds = %23, %23
%67 = load i8*, i8** %10
%68 = load i32, i32* %7
%69 = load i8*, i8** %9
%70 = call i32 (i8*, i8*, ...) @sprintf(i8* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %68, i8* %69)
br label %76
71: ; preds = %23
%72 = load i8*, i8** %10
%73 = load i32, i32* %7
%74 = load i8*, i8** %9
%75 = call i32 (i8*, i8*, ...) @sprintf(i8* %72, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %73, i8* %74)
br label %76
76: ; preds = %71, %66, %65, %41, %25
%77 = load i32, i32* %5
ret i32 %77
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%-*s\00"
@.str.2 = [9 x i8] c"%-20.20s\00"
@.str.3 = [4 x i8] c"%*s\00"
define i32 @cat_hist_output(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%6 = getelementptr inbounds i8, i8* %2, i64 %5
%7 = icmp eq i64 %5, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %6, i64 1
store i8 32, i8* %6
store i8 0, i8* %9
br label %10
10: ; preds = %8, %4
%11 = phi i8* [ %9, %8 ], [ %6, %4 ]
switch i32 %0, label %35 [
i32 99, label %12
i32 67, label %14
i32 68, label %20
i32 100, label %33
i32 120, label %33
]
12: ; preds = %10
%13 = tail call i8* @strcpy(i8* dereferenceable(1) %11, i8* dereferenceable(1) %3)
br label %37
14: ; preds = %10
%15 = icmp slt i32 %1, 20
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %3)
br label %37
18: ; preds = %14
%19 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %37
20: ; preds = %10
%21 = icmp slt i32 %1, 20
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %3)
br label %37
24: ; preds = %20
%25 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%26 = trunc i64 %25 to i32
%27 = add i32 %26, -20
%28 = icmp sgt i32 %27, 0
%29 = select i1 %28, i32 %27, i32 0
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %3, i64 %30
%32 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %31)
br label %37
33: ; preds = %10, %10
%34 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %3)
br label %37
35: ; preds = %10
%36 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %1, i8* %3)
br label %37
37: ; preds = %22, %24, %16, %18, %35, %33, %12
ret i32 undef
}