#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*/ sprintf(char *, char *, unsigned long, unsigned long,
                           char *);
void printMi(unsigned long bytes, char *buffer) {
  char *units[] = {"kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
  unsigned long unit = 1024;
  int u = -1;
  int i = -1;
  unsigned long tmp = 0;
  do {
    tmp = bytes % (unit == 1024 ? 1024 : (unit / 1024));
    bytes = bytes / unit;
    i++;
  } while (bytes > unit);
  sprintf(buffer, "%lu.%lu %s", bytes, tmp, units[u == -1 ? i : u]);
}


x86 assembly (clang, -O0):
<printMi>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0x2ca2(%rip),%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
movq   $0x400,-0x58(%rbp)
movl   $0xffffffff,-0x5c(%rbp)
movl   $0xffffffff,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
cmpq   $0x400,-0x58(%rbp)
jne    118a <printMi+0x6a>
mov    $0x400,%eax
mov    %rax,-0x78(%rbp)
jmp    1196 <printMi+0x76>
mov    -0x58(%rbp),%rax
shr    $0xa,%rax
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%rax
mov    -0x78(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x68(%rbp)
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x58(%rbp)
mov    %rax,-0x8(%rbp)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x58(%rbp),%rax
ja     1166 <printMi+0x46>
mov    -0x10(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x80(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jne    1204 <printMi+0xe4>
mov    -0x60(%rbp),%eax
mov    %eax,-0x94(%rbp)
jmp    120d <printMi+0xed>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    -0x80(%rbp),%rcx
mov    -0x88(%rbp),%rdx
mov    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%eax
cltq
mov    -0x50(%rbp,%rax,8),%r8
lea    0xde5(%rip),%rsi
call   1040 <sprintf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printMi>:
mov    %rsi,%rax
mov    %rdi,%rdx
lea    0xf03(%rip),%rsi
nopl   (%rax)
mov    %rdx,%rcx
shr    $0xa,%rdx
add    $0x4,%rsi
cmp    $0x1003ff,%rcx
ja     1120 <printMi+0x10>
and    $0x3ff,%ecx
movslq (%rsi),%rsi
lea    0xee0(%rip),%r8
add    %rsi,%r8
lea    0xeca(%rip),%rsi
mov    %rax,%rdi
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"kB\00"
@.str.1 = [3 x i8] c"MB\00"
@.str.2 = [3 x i8] c"GB\00"
@.str.3 = [3 x i8] c"TB\00"
@.str.4 = [3 x i8] c"PB\00"
@.str.5 = [3 x i8] c"EB\00"
@.str.6 = [3 x i8] c"ZB\00"
@.str.7 = [3 x i8] c"YB\00"
@__const.printMi.units = [8 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i32 0, i32 0)]
@.str.8 = [11 x i8] c"%lu.%lu %s\00"
define void @printMi(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca [8 x i8*]
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
store i64 %0, i64* %3
store i8* %1, i8** %4
%10 = bitcast [8 x i8*]* %5 to i8*
store i64 1024, i64* %6
store i32 -1, i32* %7
store i32 -1, i32* %8
store i64 0, i64* %9
br label %11
11: ; preds = %27, %2
%12 = load i64, i64* %3
%13 = load i64, i64* %6
%14 = icmp eq i64 %13, 1024
br i1 %14, label %15, label %16
15: ; preds = %11
br label %19
16: ; preds = %11
%17 = load i64, i64* %6
%18 = udiv i64 %17, 1024
br label %19
19: ; preds = %16, %15
%20 = phi i64 [ 1024, %15 ], [ %18, %16 ]
%21 = urem i64 %12, %20
store i64 %21, i64* %9
%22 = load i64, i64* %3
%23 = load i64, i64* %6
%24 = udiv i64 %22, %23
store i64 %24, i64* %3
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %27
27: ; preds = %19
%28 = load i64, i64* %3
%29 = load i64, i64* %6
%30 = icmp ugt i64 %28, %29
br i1 %30, label %11, label %31
31: ; preds = %27
%32 = load i8*, i8** %4
%33 = load i64, i64* %3
%34 = load i64, i64* %9
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = load i32, i32* %8
br label %41
39: ; preds = %31
%40 = load i32, i32* %7
br label %41
41: ; preds = %39, %37
%42 = phi i32 [ %38, %37 ], [ %40, %39 ]
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [8 x i8*], [8 x i8*]* %5, i64 0, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i64 %33, i64 %34, i8* %45)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"kB\00"
@.str.1 = [3 x i8] c"MB\00"
@.str.2 = [3 x i8] c"GB\00"
@.str.3 = [3 x i8] c"TB\00"
@.str.4 = [3 x i8] c"PB\00"
@.str.5 = [3 x i8] c"EB\00"
@.str.6 = [3 x i8] c"ZB\00"
@.str.7 = [3 x i8] c"YB\00"
@reltable.printMi = [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str to i64), i64 ptrtoint ([8 x i32]* @reltable.printMi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.printMi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.printMi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.printMi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.printMi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.printMi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.6 to i64), i64 ptrtoint ([8 x i32]* @reltable.printMi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.7 to i64), i64 ptrtoint ([8 x i32]* @reltable.printMi to i64)) to i32)]
@.str.8 = [11 x i8] c"%lu.%lu %s\00"
define void @printMi(i64 %0, i8* nocapture writeonly %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ %0, %2 ], [ %6, %3 ]
%5 = phi i32 [ -1, %2 ], [ %7, %3 ]
%6 = lshr i64 %4, 10
%7 = add nsw i32 %5, 1
%8 = icmp ugt i64 %4, 1049599
br i1 %8, label %3, label %9
9: ; preds = %3
%10 = and i64 %4, 1023
%11 = sext i32 %7 to i64
%12 = shl i64 %11, 2
%13 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.printMi to i8*), i64 %12)
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i64 %6, i64 %10, i8* %13)
ret void
}