#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*/ sprintf(char *, char *, unsigned long);
void convert_bytes(char *buf, unsigned long bytes) {
  if (bytes > (10000000))
    sprintf(buf, "%lu MB", bytes / 1000000L);
  else if (bytes > (10000))
    sprintf(buf, "%lu kB", bytes / 1000L);
  else
    sprintf(buf, "%lu B", bytes);
}


x86 assembly (clang, -O0):
<convert_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x989680,-0x10(%rbp)
jbe    1154 <convert_bytes+0x44>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
lea    0xeb6(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11a1 <convert_bytes+0x91>
cmpq   $0x2710,-0x10(%rbp)
jbe    1188 <convert_bytes+0x78>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
lea    0xe89(%rip),%rsi
call   1030 <sprintf@plt>
jmp    119c <convert_bytes+0x8c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe77(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11a1 <convert_bytes+0x91>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_bytes>:
mov    %rsi,%rax
cmp    $0x989681,%rsi
jb     1139 <convert_bytes+0x29>
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mul    %rcx
shr    $0x12,%rdx
lea    0xecc(%rip),%rsi
jmp    1030 <sprintf@plt>
cmp    $0x2711,%rax
jb     115a <convert_bytes+0x4a>
mov    %eax,%eax
imul   $0x10624dd3,%rax,%rdx
shr    $0x26,%rdx
lea    0xeb2(%rip),%rsi
jmp    1030 <sprintf@plt>
lea    0xead(%rip),%rsi
mov    %rax,%rdx
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%lu MB\00"
@.str.1 = [7 x i8] c"%lu kB\00"
@.str.2 = [6 x i8] c"%lu B\00"
define void @convert_bytes(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%5 = load i64, i64* %4
%6 = icmp ugt i64 %5, 10000000
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = load i64, i64* %4
%10 = udiv i64 %9, 1000000
%11 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %10)
br label %25
12: ; preds = %2
%13 = load i64, i64* %4
%14 = icmp ugt i64 %13, 10000
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = load i64, i64* %4
%18 = udiv i64 %17, 1000
%19 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %18)
br label %24
20: ; preds = %12
%21 = load i8*, i8** %3
%22 = load i64, i64* %4
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %22)
br label %24
24: ; preds = %20, %15
br label %25
25: ; preds = %24, %7
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%lu MB\00"
@.str.1 = [7 x i8] c"%lu kB\00"
@.str.2 = [6 x i8] c"%lu B\00"
define void @convert_bytes(i8* nocapture writeonly %0, i64 %1) {
%3 = icmp ugt i64 %1, 10000000
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = udiv i64 %1, 1000000
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %5)
br label %16
7: ; preds = %2
%8 = icmp ugt i64 %1, 10000
br i1 %8, label %9, label %14
9: ; preds = %7
%10 = trunc i64 %1 to i32
%11 = udiv i32 %10, 1000
%12 = zext i32 %11 to i64
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %12)
br label %16
14: ; preds = %7
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %1)
br label %16
16: ; preds = %9, %14, %4
ret void
}