#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 /*<<< orphan*/ printf(char *, long long, long long, char);
void printsize(long long n) {
  char unit = 'K';
  long long t;
  n *= 10;
  if (n > 1024 * 1024 * 10) {
    n /= 1024;
    unit = 'M';
  }
  if (n > 1024 * 1024 * 10) {
    n /= 1024;
    unit = 'G';
  }
  t = (n + 512) / 1024;
  printf("%4lld.%1lld%c", t / 10, t % 10, unit);
}


x86 assembly (clang, -O0):
<printsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x4b,-0x9(%rbp)
imul   $0xa,-0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
cmpq   $0xa00000,-0x8(%rbp)
jle    114d <printsize+0x3d>
mov    -0x8(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %rax,-0x8(%rbp)
movb   $0x4d,-0x9(%rbp)
cmpq   $0xa00000,-0x8(%rbp)
jle    1171 <printsize+0x61>
mov    -0x8(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %rax,-0x8(%rbp)
movb   $0x47,-0x9(%rbp)
mov    -0x8(%rbp),%rax
add    $0x200,%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,%rsi
mov    -0x18(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
lea    0xe51(%rip),%rdi
movsbl -0x9(%rbp),%ecx
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printsize>:
add    %rdi,%rdi
lea    (%rdi,%rdi,4),%rax
lea    (%rdi,%rdi,4),%rdx
add    $0x3ff,%rdx
test   %rax,%rax
cmovns %rax,%rdx
sar    $0xa,%rdx
cmp    $0xa00001,%rax
setge  %cl
cmovl  %rax,%rdx
add    %cl,%cl
add    $0x4b,%cl
lea    0x3ff(%rdx),%r8
test   %rdx,%rdx
cmovns %rdx,%r8
sar    $0xa,%r8
cmp    $0xa00001,%rdx
movzbl %cl,%eax
mov    $0x47,%ecx
cmovl  %eax,%ecx
cmovl  %rdx,%r8
lea    0x200(%r8),%rax
add    $0x5ff,%r8
test   %rax,%rax
cmovns %rax,%r8
sar    $0xa,%r8
movabs $0x6666666666666667,%rdi
66 66 66
imul   %rdi
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0xc,%rdx
add    %rdx,%rsi
mov    %r8,%rax
imul   %rdi
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
add    %rdx,%rdx
lea    (%rdx,%rdx,4),%rax
sub    %rax,%r8
movzbl %cl,%ecx
lea    0xe3d(%rip),%rdi
mov    %r8,%rdx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"%4lld.%1lld%c\00"
define void @printsize(i64 %0) {
%2 = alloca i64
%3 = alloca i8
%4 = alloca i64
store i64 %0, i64* %2
store i8 75, i8* %3
%5 = load i64, i64* %2
%6 = mul nsw i64 %5, 10
store i64 %6, i64* %2
%7 = load i64, i64* %2
%8 = icmp sgt i64 %7, 10485760
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i64, i64* %2
%11 = sdiv i64 %10, 1024
store i64 %11, i64* %2
store i8 77, i8* %3
br label %12
12: ; preds = %9, %1
%13 = load i64, i64* %2
%14 = icmp sgt i64 %13, 10485760
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i64, i64* %2
%17 = sdiv i64 %16, 1024
store i64 %17, i64* %2
store i8 71, i8* %3
br label %18
18: ; preds = %15, %12
%19 = load i64, i64* %2
%20 = add nsw i64 %19, 512
%21 = sdiv i64 %20, 1024
store i64 %21, i64* %4
%22 = load i64, i64* %4
%23 = sdiv i64 %22, 10
%24 = load i64, i64* %4
%25 = srem i64 %24, 10
%26 = load i8, i8* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 %23, i64 %25, i8 signext %26)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"%4lld.%1lld%c\00"
define void @printsize(i64 %0) {
%2 = mul nsw i64 %0, 10
%3 = icmp sgt i64 %2, 10485760
%4 = sdiv i64 %2, 1024
%5 = select i1 %3, i8 77, i8 75
%6 = select i1 %3, i64 %4, i64 %2
%7 = icmp sgt i64 %6, 10485760
%8 = sdiv i64 %6, 1024
%9 = select i1 %7, i8 71, i8 %5
%10 = select i1 %7, i64 %8, i64 %6
%11 = add nsw i64 %10, 512
%12 = sdiv i64 %11, 1024
%13 = sdiv i64 %11, 10240
%14 = srem i64 %12, 10
%15 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 %13, i64 %14, i8 signext %9)
ret void
}