char *format_k(amt)
int amt;
{
  static char retarray[8][16];
  static int index = 0;
  register char *p;
  register char *ret;
  register char tag = 'K';
  p = ret = retarray[index];
  index = (index + 1) % 8;
  if (amt >= 10000) {
    amt = (amt + 512) / 1024;
    tag = 'M';
    if (amt >= 10000) {
      amt = (amt + 512) / 1024;
      tag = 'G';
    }
  }
  p = strecpy(p, itoa(amt));
  *p++ = tag;
  *p = '\0';
  return (ret);
}


x86 assembly (clang, -O0):
<format_k>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x4b,-0x19(%rbp)
movslq 0x2f8a(%rip),%rcx
lea    0x2f03(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
mov    0x2f6e(%rip),%eax
add    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,0x2f5d(%rip)
cmpl   $0x2710,-0x4(%rbp)
jl     11b0 <format_k+0x90>
mov    -0x4(%rbp),%eax
add    $0x200,%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
movb   $0x4d,-0x19(%rbp)
cmpl   $0x2710,-0x4(%rbp)
jl     11ab <format_k+0x8b>
mov    -0x4(%rbp),%eax
add    $0x200,%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
movb   $0x47,-0x19(%rbp)
jmp    11b0 <format_k+0x90>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1040 <itoa@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
mov    $0x0,%al
call   1030 <strecpy@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x19(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_k>:
push   %rbp
push   %rbx
push   %rax
mov    0x2f97(%rip),%eax
mov    %rax,%rcx
shl    $0x4,%rcx
lea    0x2f09(%rip),%rbx
add    %rcx,%rbx
lea    0x1(%rax),%ecx
lea    0x8(%rax),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
and    $0xfffffff8,%edx
neg    %edx
add    %edx,%eax
add    $0x1,%eax
mov    %eax,0x2f6b(%rip)
mov    $0x4b,%bpl
cmp    $0x2710,%edi
jl     1181 <format_k+0x61>
lea    0x200(%rdi),%eax
shr    $0xa,%eax
mov    $0x4d,%bpl
cmp    $0x9c3e00,%edi
jb     117f <format_k+0x5f>
add    $0x200,%eax
shr    $0xa,%eax
mov    $0x47,%bpl
mov    %eax,%edi
xor    %eax,%eax
call   1040 <itoa@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <strecpy@plt>
cltq
mov    %bpl,(%rax)
movb   $0x0,0x1(%rax)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@format_k.retarray = internal global [8 x [16 x i8]] zeroinitializer
@format_k.index = internal global i32 0
define i8* @format_k(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
store i32 %0, i32* %2
store i8 75, i8* %5
%6 = load i32, i32* @format_k.index
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [8 x [16 x i8]], [8 x [16 x i8]]* @format_k.retarray, i64 0, i64 %7
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
store i8* %9, i8** %4
store i8* %9, i8** %3
%10 = load i32, i32* @format_k.index
%11 = add nsw i32 %10, 1
%12 = srem i32 %11, 8
store i32 %12, i32* @format_k.index
%13 = load i32, i32* %2
%14 = icmp sge i32 %13, 10000
br i1 %14, label %15, label %26
15: ; preds = %1
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 512
%18 = sdiv i32 %17, 1024
store i32 %18, i32* %2
store i8 77, i8* %5
%19 = load i32, i32* %2
%20 = icmp sge i32 %19, 10000
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 512
%24 = sdiv i32 %23, 1024
store i32 %24, i32* %2
store i8 71, i8* %5
br label %25
25: ; preds = %21, %15
br label %26
26: ; preds = %25, %1
%27 = load i8*, i8** %3
%28 = load i32, i32* %2
%29 = call i32 (i32, ...) bitcast (i32 (...)* @itoa to i32 (i32, ...)*)(i32 %28)
%30 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @strecpy to i32 (i8*, i32, ...)*)(i8* %27, i32 %29)
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %3
%33 = load i8, i8* %5
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %3
store i8 %33, i8* %34
%36 = load i8*, i8** %3
store i8 0, i8* %36
%37 = load i8*, i8** %4
ret i8* %37
}

LLVM IR (-O2):
@format_k.retarray = internal global [8 x [16 x i8]] zeroinitializer
@format_k.index = internal unnamed_addr global i32 0
define i8* @format_k(i32 %0) {
%2 = load i32, i32* @format_k.index
%3 = zext i32 %2 to i64
%4 = getelementptr inbounds [8 x [16 x i8]], [8 x [16 x i8]]* @format_k.retarray, i64 0, i64 %3, i64 0
%5 = add nsw i32 %2, 1
%6 = srem i32 %5, 8
store i32 %6, i32* @format_k.index
%7 = icmp sgt i32 %0, 9999
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = add nuw nsw i32 %0, 512
%10 = lshr i32 %9, 10
%11 = icmp ugt i32 %0, 10239487
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = add nuw nsw i32 %10, 512
%14 = lshr i32 %13, 10
br label %15
15: ; preds = %8, %12, %1
%16 = phi i32 [ %14, %12 ], [ %10, %8 ], [ %0, %1 ]
%17 = phi i8 [ 71, %12 ], [ 77, %8 ], [ 75, %1 ]
%18 = tail call i32 (i32, ...) bitcast (i32 (...)* @itoa to i32 (i32, ...)*)(i32 %16)
%19 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @strecpy to i32 (i8*, i32, ...)*)(i8* %4, i32 %18)
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i8*
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8 %17, i8* %21
store i8 0, i8* %22
ret i8* %4
}