#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*/ strcpy(char *, char const *);
unsigned long count_bytes(unsigned long d, char *sz) {
  const char *xb[] = {"b", "KiB", "MiB", "GiB", "TiB"};
  int i = 0;
  if (d < 1024)
    i = 0;
  else if (d < 1048576) {
    i = 1;
    d = d / 1024;
  } else if (d < 1073741824) {
    i = 2;
    d = d / 1048576;
  } else if (d < 1099511627776) {
    i = 3;
    d = d / 1073741824;
  } else {
    i = 4;
    d = d / 1099511627776;
  }
  strcpy(sz, xb[i]);
  return d;
}


x86 assembly (clang, -O0):
<count_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    0xeb9(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xeb0(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xea9(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xea2(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe9b(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x44(%rbp)
cmpq   $0x400,-0x8(%rbp)
jae    1198 <count_bytes+0x78>
movl   $0x0,-0x44(%rbp)
jmp    1232 <count_bytes+0x112>
cmpq   $0x100000,-0x8(%rbp)
jae    11be <count_bytes+0x9e>
movl   $0x1,-0x44(%rbp)
mov    -0x8(%rbp),%rax
shr    $0xa,%rax
mov    %rax,-0x8(%rbp)
jmp    122d <count_bytes+0x10d>
cmpq   $0x40000000,-0x8(%rbp)
40
jae    11e4 <count_bytes+0xc4>
movl   $0x2,-0x44(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x14,%rax
mov    %rax,-0x8(%rbp)
jmp    1228 <count_bytes+0x108>
movabs $0x10000000000,%rax
cmp    %rax,-0x8(%rbp)
jae    1210 <count_bytes+0xf0>
movl   $0x3,-0x44(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x1e,%rax
mov    %rax,-0x8(%rbp)
jmp    1223 <count_bytes+0x103>
movl   $0x4,-0x44(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x28,%rax
mov    %rax,-0x8(%rbp)
jmp    1228 <count_bytes+0x108>
jmp    122d <count_bytes+0x10d>
jmp    1232 <count_bytes+0x112>
mov    -0x10(%rbp),%rdi
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_bytes>:
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xede(%rip),%rcx
mov    %rcx,(%rsp)
lea    0xed5(%rip),%rcx
mov    %rcx,0x8(%rsp)
lea    0xecd(%rip),%rcx
mov    %rcx,0x10(%rsp)
lea    0xec5(%rip),%rcx
mov    %rcx,0x18(%rsp)
lea    0xebd(%rip),%rcx
mov    %rcx,0x20(%rsp)
cmp    $0x400,%rdi
jae    1163 <count_bytes+0x53>
xor    %ecx,%ecx
jmp    11a7 <count_bytes+0x97>
cmp    $0xfffff,%rbx
ja     1177 <count_bytes+0x67>
shr    $0xa,%rbx
mov    $0x1,%ecx
jmp    11a7 <count_bytes+0x97>
cmp    $0x3fffffff,%rbx
ja     118b <count_bytes+0x7b>
shr    $0x14,%rbx
mov    $0x2,%ecx
jmp    11a7 <count_bytes+0x97>
mov    %rbx,%rdx
shr    $0x28,%rdx
jne    119f <count_bytes+0x8f>
shr    $0x1e,%rbx
mov    $0x3,%ecx
jmp    11a7 <count_bytes+0x97>
mov    $0x4,%ecx
mov    %rdx,%rbx
mov    (%rsp,%rcx,8),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"b\00"
@.str.1 = [4 x i8] c"KiB\00"
@.str.2 = [4 x i8] c"MiB\00"
@.str.3 = [4 x i8] c"GiB\00"
@.str.4 = [4 x i8] c"TiB\00"
define i64 @count_bytes(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca [5 x i8*]
%6 = alloca i32
store i64 %0, i64* %3
store i8* %1, i8** %4
%7 = bitcast [5 x i8*]* %5 to i8*
%8 = bitcast i8* %7 to [5 x i8*]*
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %8, i32 0, i32 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %8, i32 0, i32 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %8, i32 0, i32 2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %8, i32 0, i32 3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %8, i32 0, i32 4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8** %13
store i32 0, i32* %6
%14 = load i64, i64* %3
%15 = icmp ult i64 %14, 1024
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 0, i32* %6
br label %41
17: ; preds = %2
%18 = load i64, i64* %3
%19 = icmp ult i64 %18, 1048576
br i1 %19, label %20, label %23
20: ; preds = %17
store i32 1, i32* %6
%21 = load i64, i64* %3
%22 = udiv i64 %21, 1024
store i64 %22, i64* %3
br label %40
23: ; preds = %17
%24 = load i64, i64* %3
%25 = icmp ult i64 %24, 1073741824
br i1 %25, label %26, label %29
26: ; preds = %23
store i32 2, i32* %6
%27 = load i64, i64* %3
%28 = udiv i64 %27, 1048576
store i64 %28, i64* %3
br label %39
29: ; preds = %23
%30 = load i64, i64* %3
%31 = icmp ult i64 %30, 1099511627776
br i1 %31, label %32, label %35
32: ; preds = %29
store i32 3, i32* %6
%33 = load i64, i64* %3
%34 = udiv i64 %33, 1073741824
store i64 %34, i64* %3
br label %38
35: ; preds = %29
store i32 4, i32* %6
%36 = load i64, i64* %3
%37 = udiv i64 %36, 1099511627776
store i64 %37, i64* %3
br label %38
38: ; preds = %35, %32
br label %39
39: ; preds = %38, %26
br label %40
40: ; preds = %39, %20
br label %41
41: ; preds = %40, %16
%42 = load i8*, i8** %4
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 %44
%46 = load i8*, i8** %45
%47 = call i32 @strcpy(i8* %42, i8* %46)
%48 = load i64, i64* %3
ret i64 %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"b\00"
@.str.1 = [4 x i8] c"KiB\00"
@.str.2 = [4 x i8] c"MiB\00"
@.str.3 = [4 x i8] c"GiB\00"
@.str.4 = [4 x i8] c"TiB\00"
define i64 @count_bytes(i64 %0, i8* %1) {
%3 = alloca [5 x i8*]
%4 = bitcast [5 x i8*]* %3 to i8*
%5 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %9
%10 = icmp ult i64 %0, 1024
br i1 %10, label %25, label %11
11: ; preds = %2
%12 = icmp ult i64 %0, 1048576
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = lshr i64 %0, 10
br label %25
15: ; preds = %11
%16 = icmp ult i64 %0, 1073741824
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = lshr i64 %0, 20
br label %25
19: ; preds = %15
%20 = icmp ult i64 %0, 1099511627776
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = lshr i64 %0, 30
br label %25
23: ; preds = %19
%24 = lshr i64 %0, 40
br label %25
25: ; preds = %2, %13, %21, %23, %17
%26 = phi i64 [ %14, %13 ], [ %18, %17 ], [ %22, %21 ], [ %24, %23 ], [ %0, %2 ]
%27 = phi i64 [ 1, %13 ], [ 2, %17 ], [ 3, %21 ], [ 4, %23 ], [ 0, %2 ]
%28 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 %27
%29 = load i8*, i8** %28
%30 = tail call i32 @strcpy(i8* %1, i8* %29)
ret i64 %26
}