#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 *, int, ...);
void mfm_get_size_text(long long bytes, char *buf) {
  long long gb = 1 << 30, mb = 1 << 20, kb = 1 << 10;
  if (bytes > 1 << 30) {
    sprintf(buf, "%i Gb %i Mb", (int)(bytes / gb), (int)(bytes % gb / mb));
  } else if (bytes > 1 << 20) {
    sprintf(buf, "%i Mb %i Kb", (int)(bytes / mb), (int)(bytes % mb / kb));
  } else if (bytes > 1 << 10) {
    sprintf(buf, "%i Kb %i b", (int)(bytes / kb), (int)(bytes % kb));
  } else {
    sprintf(buf, "%i b", (int)(bytes));
  }
}


x86 assembly (clang, -O0):
<mfm_get_size_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x40000000,-0x18(%rbp)
40
movq   $0x100000,-0x20(%rbp)
movq   $0x400,-0x28(%rbp)
cmpq   $0x40000000,-0x8(%rbp)
40
jle    1182 <mfm_get_size_text+0x72>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %rdx,%rax
cqto
idivq  -0x20(%rbp)
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1232 <mfm_get_size_text+0x122>
cmpq   $0x100000,-0x8(%rbp)
jle    11cc <mfm_get_size_text+0xbc>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    %rdx,%rax
cqto
idivq  -0x28(%rbp)
mov    -0x30(%rbp),%edx
mov    %eax,%ecx
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    122d <mfm_get_size_text+0x11d>
cmpq   $0x400,-0x8(%rbp)
jle    1210 <mfm_get_size_text+0x100>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
cqto
idivq  -0x28(%rbp)
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
cqto
idivq  -0x28(%rbp)
mov    %rdx,%rax
mov    -0x34(%rbp),%edx
mov    %eax,%ecx
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1228 <mfm_get_size_text+0x118>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    %eax,%edx
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    122d <mfm_get_size_text+0x11d>
jmp    1232 <mfm_get_size_text+0x122>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mfm_get_size_text>:
mov    %rsi,%rax
mov    %rdi,%rcx
cmp    $0x40000001,%rdi
jl     1140 <mfm_get_size_text+0x30>
mov    %rcx,%rdx
shr    $0x1e,%rdx
shr    $0x14,%ecx
and    $0x3ff,%ecx
lea    0xeca(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
cmp    $0x100001,%rcx
jl     1160 <mfm_get_size_text+0x50>
mov    %ecx,%edx
shr    $0x14,%edx
shr    $0xa,%ecx
and    $0x3ff,%ecx
lea    0xeae(%rip),%rsi
jmp    117b <mfm_get_size_text+0x6b>
cmp    $0x401,%rcx
jl     1185 <mfm_get_size_text+0x75>
mov    %ecx,%edx
shr    $0xa,%edx
and    $0x3ff,%ecx
lea    0xe9d(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
lea    0xe92(%rip),%rsi
mov    %rax,%rdi
mov    %ecx,%edx
xor    %eax,%eax
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"%i Gb %i Mb\00"
@.str.1 = [12 x i8] c"%i Mb %i Kb\00"
@.str.2 = [11 x i8] c"%i Kb %i b\00"
@.str.3 = [5 x i8] c"%i b\00"
define void @mfm_get_size_text(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %3
store i8* %1, i8** %4
store i64 1073741824, i64* %5
store i64 1048576, i64* %6
store i64 1024, i64* %7
%8 = load i64, i64* %3
%9 = icmp sgt i64 %8, 1073741824
br i1 %9, label %10, label %23
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i64, i64* %3
%13 = load i64, i64* %5
%14 = sdiv i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = load i64, i64* %3
%17 = load i64, i64* %5
%18 = srem i64 %16, %17
%19 = load i64, i64* %6
%20 = sdiv i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %21)
br label %60
23: ; preds = %2
%24 = load i64, i64* %3
%25 = icmp sgt i64 %24, 1048576
br i1 %25, label %26, label %39
26: ; preds = %23
%27 = load i8*, i8** %4
%28 = load i64, i64* %3
%29 = load i64, i64* %6
%30 = sdiv i64 %28, %29
%31 = trunc i64 %30 to i32
%32 = load i64, i64* %3
%33 = load i64, i64* %6
%34 = srem i64 %32, %33
%35 = load i64, i64* %7
%36 = sdiv i64 %34, %35
%37 = trunc i64 %36 to i32
%38 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %37)
br label %59
39: ; preds = %23
%40 = load i64, i64* %3
%41 = icmp sgt i64 %40, 1024
br i1 %41, label %42, label %53
42: ; preds = %39
%43 = load i8*, i8** %4
%44 = load i64, i64* %3
%45 = load i64, i64* %7
%46 = sdiv i64 %44, %45
%47 = trunc i64 %46 to i32
%48 = load i64, i64* %3
%49 = load i64, i64* %7
%50 = srem i64 %48, %49
%51 = trunc i64 %50 to i32
%52 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %43, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %47, i32 %51)
br label %58
53: ; preds = %39
%54 = load i8*, i8** %4
%55 = load i64, i64* %3
%56 = trunc i64 %55 to i32
%57 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %53, %42
br label %59
59: ; preds = %58, %26
br label %60
60: ; preds = %59, %10
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%i Gb %i Mb\00"
@.str.1 = [12 x i8] c"%i Mb %i Kb\00"
@.str.2 = [11 x i8] c"%i Kb %i b\00"
@.str.3 = [5 x i8] c"%i b\00"
define void @mfm_get_size_text(i64 %0, i8* nocapture writeonly %1) {
%3 = icmp sgt i64 %0, 1073741824
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = lshr i64 %0, 30
%6 = trunc i64 %5 to i32
%7 = trunc i64 %0 to i32
%8 = lshr i32 %7, 20
%9 = and i32 %8, 1023
%10 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9)
br label %28
11: ; preds = %2
%12 = icmp sgt i64 %0, 1048576
br i1 %12, label %13, label %19
13: ; preds = %11
%14 = trunc i64 %0 to i32
%15 = lshr i32 %14, 20
%16 = lshr i32 %14, 10
%17 = and i32 %16, 1023
%18 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %17)
br label %28
19: ; preds = %11
%20 = icmp sgt i64 %0, 1024
%21 = trunc i64 %0 to i32
br i1 %20, label %22, label %26
22: ; preds = %19
%23 = lshr i32 %21, 10
%24 = and i32 %21, 1023
%25 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %24)
br label %28
26: ; preds = %19
%27 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %28
28: ; preds = %13, %26, %22, %4
ret void
}