#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 */
typedef int /*<<< orphan*/ prefix;
typedef int /*<<< orphan*/ WINDOW;

/* Variables and functions */
int /*<<< orphan*/ wprintw(int /*<<< orphan*/ *, char *, unsigned long long,
                           char *);
void readable_1024(WINDOW *pad, unsigned long long value) {
  char *prefix[] = {"", "ki", "mi", "gi", "ti", "pi"};
  unsigned i = 0;
  while (i < sizeof(prefix) / sizeof(*prefix)) {
    if (value < 10240)
      break;
    value = (value + 512) / 1024;
    i++;
  }
  wprintw(pad, "%llu%s", value, prefix[i]);
}


x86 assembly (clang, -O0):
<readable_1024>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
lea    0xec1(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xea6(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe9e(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe96(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe8e(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    $0x6,%rax
jae    11c9 <readable_1024+0xa9>
cmpq   $0x2800,-0x10(%rbp)
jae    11a9 <readable_1024+0x89>
jmp    11c9 <readable_1024+0xa9>
mov    -0x10(%rbp),%rax
add    $0x200,%rax
shr    $0xa,%rax
mov    %rax,-0x10(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1189 <readable_1024+0x69>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x44(%rbp),%eax
mov    -0x40(%rbp,%rax,8),%rcx
lea    0xe2f(%rip),%rsi
call   1040 <wprintw@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readable_1024>:
mov    %rsi,%rdx
lea    0xee6(%rip),%rax
mov    %rax,-0x30(%rsp)
lea    0xedd(%rip),%rax
mov    %rax,-0x28(%rsp)
lea    0xed4(%rip),%rax
mov    %rax,-0x20(%rsp)
lea    0xecb(%rip),%rax
mov    %rax,-0x18(%rsp)
lea    0xec2(%rip),%rax
mov    %rax,-0x10(%rsp)
cmp    $0x2800,%rsi
jae    116b <readable_1024+0x5b>
lea    0xea9(%rip),%rcx
lea    0xea9(%rip),%rsi
jmp    1030 <wprintw@plt>
add    $0x200,%rdx
mov    %rdx,%rax
shr    $0xa,%rax
mov    $0x1,%ecx
cmp    $0xa00000,%rdx
jb     120d <readable_1024+0xfd>
add    $0x200,%rax
shr    $0xa,%rax
mov    %rdx,%rsi
shr    $0x13,%rsi
mov    $0x2,%ecx
cmp    $0x4fff,%rsi
jb     120d <readable_1024+0xfd>
add    $0x200,%rax
shr    $0xa,%rax
mov    $0x3,%ecx
cmp    $0x13ffbff,%rsi
jb     120d <readable_1024+0xfd>
add    $0x200,%rax
shr    $0xa,%rax
mov    $0x4,%ecx
movabs $0x27ff7fdff80000,%rsi
cmp    %rsi,%rdx
jb     120d <readable_1024+0xfd>
add    $0x200,%rax
shr    $0xa,%rax
mov    $0x5,%ecx
movabs $0x9ffdff7fdff80000,%rsi
ff fd 9f
cmp    %rsi,%rdx
jb     120d <readable_1024+0xfd>
add    $0x200,%rax
shr    $0xa,%rax
mov    $0x6,%ecx
mov    -0x38(%rsp,%rcx,8),%rcx
mov    %rax,%rdx
lea    0xdf3(%rip),%rsi
jmp    1030 <wprintw@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"ki\00"
@.str.2 = [3 x i8] c"mi\00"
@.str.3 = [3 x i8] c"gi\00"
@.str.4 = [3 x i8] c"ti\00"
@.str.5 = [3 x i8] c"pi\00"
@.str.6 = [7 x i8] c"%llu%s\00"
define void @readable_1024(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca [6 x i8*]
%6 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
%7 = bitcast [6 x i8*]* %5 to i8*
%8 = bitcast i8* %7 to [6 x i8*]*
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 0
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i32 0, i32 0), i8** %14
store i32 0, i32* %6
br label %15
15: ; preds = %23, %2
%16 = load i32, i32* %6
%17 = zext i32 %16 to i64
%18 = icmp ult i64 %17, 6
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = load i64, i64* %4
%21 = icmp ult i64 %20, 10240
br i1 %21, label %22, label %23
22: ; preds = %19
br label %29
23: ; preds = %19
%24 = load i64, i64* %4
%25 = add i64 %24, 512
%26 = udiv i64 %25, 1024
store i64 %26, i64* %4
%27 = load i32, i32* %6
%28 = add i32 %27, 1
store i32 %28, i32* %6
br label %15
29: ; preds = %22, %15
%30 = load i32*, i32** %3
%31 = load i64, i64* %4
%32 = load i32, i32* %6
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @wprintw(i32* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i64 %31, i8* %35)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"ki\00"
@.str.2 = [3 x i8] c"mi\00"
@.str.3 = [3 x i8] c"gi\00"
@.str.4 = [3 x i8] c"ti\00"
@.str.5 = [3 x i8] c"pi\00"
@.str.6 = [7 x i8] c"%llu%s\00"
define void @readable_1024(i32* %0, i64 %1) {
%3 = alloca [6 x i8*]
%4 = bitcast [6 x i8*]* %3 to i8*
%5 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %9
%10 = icmp ult i64 %1, 10240
br i1 %10, label %39, label %11
11: ; preds = %2
%12 = add i64 %1, 512
%13 = lshr i64 %12, 10
%14 = icmp ult i64 %12, 10485760
br i1 %14, label %34, label %15
15: ; preds = %11
%16 = add nuw nsw i64 %13, 512
%17 = lshr i64 %16, 10
%18 = icmp ult i64 %12, 10736893952
br i1 %18, label %34, label %19
19: ; preds = %15
%20 = add nuw nsw i64 %17, 512
%21 = lshr i64 %20, 10
%22 = icmp ult i64 %12, 10994578882560
br i1 %22, label %34, label %23
23: ; preds = %19
%24 = add nuw nsw i64 %21, 512
%25 = lshr i64 %24, 10
%26 = icmp ult i64 %12, 11258448775217152
br i1 %26, label %34, label %27
27: ; preds = %23
%28 = add nuw nsw i64 %25, 512
%29 = lshr i64 %28, 10
%30 = icmp ult i64 %12, -6918092527887712256
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = add nuw nsw i64 %29, 512
%33 = lshr i64 %32, 10
br label %34
34: ; preds = %31, %27, %23, %19, %15, %11
%35 = phi i64 [ %13, %11 ], [ %17, %15 ], [ %21, %19 ], [ %25, %23 ], [ %29, %27 ], [ %33, %31 ]
%36 = phi i64 [ 1, %11 ], [ 2, %15 ], [ 3, %19 ], [ 4, %23 ], [ 5, %27 ], [ 6, %31 ]
%37 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 %36
%38 = load i8*, i8** %37
br label %39
39: ; preds = %2, %34
%40 = phi i8* [ %38, %34 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
%41 = phi i64 [ %35, %34 ], [ %1, %2 ]
%42 = tail call i32 @wprintw(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i64 %41, i8* %40)
ret void
}