#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 *, ...);
void PrintMemory(long long v) {
  printf("%lld[", v);
  int GBs = v / (1024 * 1024 * 1024);
  v %= (1024 * 1024 * 1024);
  int MBs = v / (1024 * 1024);
  v %= (1024 * 1024);
  int KBs = v / 1024;
  v %= 1024;
  int Bs = v;
  int first = 1;
  if (GBs) {
    if (!first)
      printf(":");
    printf("%dg", GBs);
    first = 0;
  }
  if (MBs) {
    if (!first)
      printf(":");
    printf("%dm", MBs);
    first = 0;
  }
  if (KBs) {
    if (!first)
      printf(":");
    printf("%dk", KBs);
    first = 0;
  }
  if (Bs) {
    if (!first)
      printf(":");
    printf("%db", Bs);
    first = 0;
  }
  printf("]");
}


x86 assembly (clang, -O0):
<PrintMemory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    $0x40000000,%ecx
cqto
idiv   %rcx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x40000000,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x100000,%ecx
cqto
idiv   %rcx
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x100000,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11df <PrintMemory+0xcf>
cmpl   $0x0,-0x1c(%rbp)
jne    11c7 <PrintMemory+0xb7>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1219 <PrintMemory+0x109>
cmpl   $0x0,-0x1c(%rbp)
jne    1201 <PrintMemory+0xf1>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1253 <PrintMemory+0x143>
cmpl   $0x0,-0x1c(%rbp)
jne    123b <PrintMemory+0x12b>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     128d <PrintMemory+0x17d>
cmpl   $0x0,-0x1c(%rbp)
jne    1275 <PrintMemory+0x165>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrintMemory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbp
lea    0xece(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x3fffffff(%rbp),%rsi
test   %rbp,%rbp
cmovns %rbp,%rsi
shr    $0x1e,%rsi
mov    %esi,%eax
shl    $0x1e,%eax
sub    %eax,%ebp
lea    0xfffff(%rbp),%r12d
test   %ebp,%ebp
mov    %ebp,%r15d
cmovs  %r12d,%r15d
mov    %r15d,%eax
and    $0xfff00000,%eax
mov    %ebp,%ebx
sub    %eax,%ebx
neg    %eax
add    %eax,%ebp
add    $0x3ff,%ebp
test   %ebx,%ebx
cmovns %ebx,%ebp
mov    %ebp,%eax
and    $0xfffffc00,%eax
mov    %ebx,%r14d
sub    %eax,%r14d
test   %esi,%esi
je     11b4 <PrintMemory+0x94>
lea    0xe6e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1fffff,%r12d
jb     11e7 <PrintMemory+0xc7>
mov    $0x3a,%edi
call   1030 <putchar@plt>
jmp    11d2 <PrintMemory+0xb2>
cmp    $0x1fffff,%r12d
jae    11d2 <PrintMemory+0xb2>
add    $0x3ff,%ebx
cmp    $0x7ff,%ebx
jae    11ff <PrintMemory+0xdf>
test   %r14d,%r14d
jne    1221 <PrintMemory+0x101>
jmp    1232 <PrintMemory+0x112>
sar    $0x14,%r15d
lea    0xe2d(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x3ff,%ebx
cmp    $0x7ff,%ebx
jb     1212 <PrintMemory+0xf2>
mov    $0x3a,%edi
call   1030 <putchar@plt>
sar    $0xa,%ebp
lea    0xe05(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
je     1232 <PrintMemory+0x112>
mov    $0x3a,%edi
call   1030 <putchar@plt>
lea    0xdea(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x5d,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [6 x i8] c"%lld[\00"
@.str.2 = [4 x i8] c"%dg\00"
@.str.3 = [4 x i8] c"%dm\00"
@.str.4 = [4 x i8] c"%dk\00"
@.str.5 = [4 x i8] c"%db\00"
define void @PrintMemory(i64 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %0)
%3 = sdiv i64 %0, 1073741824
%4 = trunc i64 %3 to i32
%5 = srem i64 %0, 1073741824
%6 = trunc i64 %5 to i32
%7 = sdiv i32 %6, 1048576
%8 = srem i32 %6, 1048576
%9 = sdiv i32 %8, 1024
%10 = srem i32 %8, 1024
%11 = icmp eq i32 %4, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = add nsw i32 %6, 1048575
%14 = icmp ult i32 %13, 2097151
br i1 %14, label %26, label %21
15: ; preds = %1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%17 = add nsw i32 %6, 1048575
%18 = icmp ult i32 %17, 2097151
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = tail call i32 @putchar(i32 58)
br label %21
21: ; preds = %12, %19
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %7)
br label %23
23: ; preds = %15, %21
%24 = add nsw i32 %8, 1023
%25 = icmp ult i32 %24, 2047
br i1 %25, label %33, label %29
26: ; preds = %12
%27 = add nsw i32 %8, 1023
%28 = icmp ult i32 %27, 2047
br i1 %28, label %35, label %31
29: ; preds = %23
%30 = tail call i32 @putchar(i32 58)
br label %31
31: ; preds = %26, %29
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %9)
br label %33
33: ; preds = %31, %23
%34 = icmp eq i32 %10, 0
br i1 %34, label %41, label %37
35: ; preds = %26
%36 = icmp eq i32 %10, 0
br i1 %36, label %41, label %39
37: ; preds = %33
%38 = tail call i32 @putchar(i32 58)
br label %39
39: ; preds = %35, %37
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %10)
br label %41
41: ; preds = %35, %39, %33
%42 = tail call i32 @putchar(i32 93)
ret void
}