#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 *, char *, unsigned long, char);
void print_mem(char *s, unsigned long p) {
  unsigned long size;
  char *sf = "KMG???";
  size = (p <<= 12) >> 10;
  while (size >> 10) {
    size >>= 10;
    sf++;
  }
  printf("%s %lu%c\n", s, size, *sf);
}


x86 assembly (clang, -O0):
<print_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xed9(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
shl    $0xc,%rax
mov    %rax,-0x10(%rbp)
shr    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shr    $0xa,%rax
cmp    $0x0,%rax
je     116e <print_mem+0x5e>
mov    -0x18(%rbp),%rax
shr    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113f <print_mem+0x2f>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rax
lea    0xe86(%rip),%rdi
movsbl (%rax),%ecx
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_mem>:
mov    %rdi,%rax
shl    $0x2,%rsi
movabs $0x3ffffffffffffc,%rdx
and    %rsi,%rdx
lea    0xed5(%rip),%rcx
cmp    $0x400,%rdx
jb     1154 <print_mem+0x44>
mov    %rdx,%rsi
nopw   0x0(%rax,%rax,1)
shr    $0xa,%rdx
add    $0x1,%rcx
cmp    $0xfffff,%rsi
mov    %rdx,%rsi
ja     1140 <print_mem+0x30>
movsbl (%rcx),%ecx
lea    0xea9(%rip),%rdi
mov    %rax,%rsi
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"KMG???\00"
@.str.1 = [10 x i8] c"%s %lu%c\0A\00"
define void @print_mem(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = load i64, i64* %4
%8 = shl i64 %7, 12
store i64 %8, i64* %4
%9 = lshr i64 %8, 10
store i64 %9, i64* %5
br label %10
10: ; preds = %14, %2
%11 = load i64, i64* %5
%12 = lshr i64 %11, 10
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i64, i64* %5
%16 = lshr i64 %15, 10
store i64 %16, i64* %5
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %6
br label %10
19: ; preds = %10
%20 = load i8*, i8** %3
%21 = load i64, i64* %5
%22 = load i8*, i8** %6
%23 = load i8, i8* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %20, i64 %21, i8 signext %23)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"KMG???\00"
@.str.1 = [10 x i8] c"%s %lu%c\0A\00"
define void @print_mem(i8* %0, i64 %1) {
%3 = shl i64 %1, 2
%4 = and i64 %3, 18014398509481980
%5 = icmp ult i64 %4, 1024
br i1 %5, label %12, label %6
6: ; preds = %2, %6
%7 = phi i8* [ %10, %6 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %2 ]
%8 = phi i64 [ %9, %6 ], [ %4, %2 ]
%9 = lshr i64 %8, 10
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = icmp ult i64 %8, 1048576
br i1 %11, label %12, label %6
12: ; preds = %6, %2
%13 = phi i64 [ %4, %2 ], [ %9, %6 ]
%14 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %2 ], [ %10, %6 ]
%15 = load i8, i8* %14
%16 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %0, i64 %13, i8 signext %15)
ret void
}