#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 */
unsigned int mem_getAllocated();
int /*<<< orphan*/ printf(char *, unsigned int, int);
void mem_printUsage(void) {
  unsigned int allocated = mem_getAllocated();
  if (allocated > 1048576) {
    printf("mem stat: %d/%d mB allocated\n", allocated / 1024 / 1024,
           536870912 / 1024 / 1024);
  } else if (allocated > 1024) {
    printf("mem stat: %d/%d kB allocated\n", allocated / 1024,
           536870912 / 1024);
  } else {
    printf("mem stat: %d/%d bytes allocated\n", allocated, 536870912);
  }
}


x86 assembly (clang, -O0):
<mem_printUsage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <mem_getAllocated@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x100000,-0x4(%rbp)
jbe    115e <mem_printUsage+0x3e>
mov    -0x4(%rbp),%esi
shr    $0xa,%esi
shr    $0xa,%esi
lea    0xeb1(%rip),%rdi
mov    $0x200,%edx
call   1030 <printf@plt>
jmp    11a0 <mem_printUsage+0x80>
cmpl   $0x400,-0x4(%rbp)
jbe    1187 <mem_printUsage+0x67>
mov    -0x4(%rbp),%esi
shr    $0xa,%esi
lea    0xea6(%rip),%rdi
mov    $0x80000,%edx
call   1030 <printf@plt>
jmp    119b <mem_printUsage+0x7b>
mov    -0x4(%rbp),%esi
lea    0xeab(%rip),%rdi
mov    $0x20000000,%edx
call   1030 <printf@plt>
jmp    11a0 <mem_printUsage+0x80>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_printUsage>:
push   %rax
xor    %eax,%eax
call   1040 <mem_getAllocated@plt>
cmp    $0x100001,%eax
jb     1146 <mem_printUsage+0x26>
shr    $0x14,%eax
lea    0xec7(%rip),%rdi
mov    %eax,%esi
mov    $0x200,%edx
pop    %rax
jmp    1030 <printf@plt>
cmp    $0x401,%eax
jb     1164 <mem_printUsage+0x44>
shr    $0xa,%eax
lea    0xec7(%rip),%rdi
mov    %eax,%esi
mov    $0x80000,%edx
pop    %rax
jmp    1030 <printf@plt>
lea    0xed1(%rip),%rdi
mov    %eax,%esi
mov    $0x20000000,%edx
pop    %rax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"mem stat: %d/%d mB allocated\0A\00"
@.str.1 = [30 x i8] c"mem stat: %d/%d kB allocated\0A\00"
@.str.2 = [33 x i8] c"mem stat: %d/%d bytes allocated\0A\00"
define void @mem_printUsage() {
%1 = alloca i32
%2 = call i32 (...) @mem_getAllocated()
store i32 %2, i32* %1
%3 = load i32, i32* %1
%4 = icmp ugt i32 %3, 1048576
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* %1
%7 = udiv i32 %6, 1024
%8 = udiv i32 %7, 1024
%9 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %8, i32 512)
br label %21
10: ; preds = %0
%11 = load i32, i32* %1
%12 = icmp ugt i32 %11, 1024
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* %1
%15 = udiv i32 %14, 1024
%16 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 524288)
br label %20
17: ; preds = %10
%18 = load i32, i32* %1
%19 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 536870912)
br label %20
20: ; preds = %17, %13
br label %21
21: ; preds = %20, %5
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"mem stat: %d/%d mB allocated\0A\00"
@.str.1 = [30 x i8] c"mem stat: %d/%d kB allocated\0A\00"
@.str.2 = [33 x i8] c"mem stat: %d/%d bytes allocated\0A\00"
define void @mem_printUsage() {
%1 = tail call i32 (...) @mem_getAllocated()
%2 = icmp ugt i32 %1, 1048576
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = lshr i32 %1, 20
%5 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %4, i32 512)
br label %13
6: ; preds = %0
%7 = icmp ugt i32 %1, 1024
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = lshr i32 %1, 10
%10 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 524288)
br label %13
11: ; preds = %6
%12 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %1, i32 536870912)
br label %13
13: ; preds = %8, %11, %3
ret void
}