#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 off_t;

/* Variables and functions */
int /*<<< orphan*/ dottedbyte(char *, int);
scalar_t__ lround(int);
scalar_t__ round(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
void prettybyte(char *s, off_t num) {
  off_t Gb, Mb, kB, b;
  off_t x;
  char a[255];
  Gb = 1000000000;
  Mb = 1000000;
  kB = 1000;
  b = 1;
  if (num >= Gb) {
    x = (off_t)(lround(num / Gb));
    dottedbyte(a, x);
    sprintf(s, "%s Gb", a);
  }
  if (num >= Mb) {
    x = (off_t)(round(num / Mb));
    dottedbyte(a, x);
    sprintf(s, "%s Mb", a);
  }
  if (num >= kB) {
    x = (off_t)(round(num / kB));
    dottedbyte(a, x);
    sprintf(s, "%s kB", a);
    return;
  }
  if (num >= b) {
    x = num;
    dottedbyte(a, x);
    sprintf(s, "%s bytes", a);
  }
}


x86 assembly (clang, -O0):
<prettybyte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x3b9aca00,-0x10(%rbp)
movl   $0xf4240,-0x14(%rbp)
movl   $0x3e8,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     11b1 <prettybyte+0x71>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,%edi
call   1030 <lround@plt>
mov    %eax,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1060 <dottedbyte@plt>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xe54(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11f4 <prettybyte+0xb4>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%edi
call   1040 <round@plt>
mov    %eax,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1060 <dottedbyte@plt>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xe17(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     123c <prettybyte+0xfc>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,%edi
call   1040 <round@plt>
mov    %eax,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1060 <dottedbyte@plt>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xdda(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1274 <prettybyte+0x134>
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1274 <prettybyte+0x134>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1060 <dottedbyte@plt>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xda3(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prettybyte>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r14
mov    %esi,%r15d
cmp    $0x3b9aca00,%esi
jl     118e <prettybyte+0x4e>
shr    $0x9,%esi
imul   $0x44b83,%rsi,%rdi
shr    $0x27,%rdi
call   1030 <lround@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <dottedbyte@plt>
lea    0xe7f(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1050 <sprintf@plt>
jmp    1196 <prettybyte+0x56>
cmp    $0xf4240,%esi
jl     1205 <prettybyte+0xc5>
imul   $0x431bde83,%r15,%rdi
shr    $0x32,%rdi
call   1040 <round@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <dottedbyte@plt>
lea    0xe4c(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1050 <sprintf@plt>
imul   $0x10624dd3,%r15,%rdi
shr    $0x26,%rdi
call   1040 <round@plt>
mov    %rax,%rsi
lea    0xe2d(%rip),%rbx
mov    %rsp,%r15
mov    %r15,%rdi
call   1060 <dottedbyte@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <sprintf@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
cmp    $0x3e8,%esi
jge    11c5 <prettybyte+0x85>
test   %esi,%esi
jle    11f8 <prettybyte+0xb8>
lea    0xdfa(%rip),%rbx
jmp    11df <prettybyte+0x9f>

LLVM IR (-O0):
@.str = [6 x i8] c"%s Gb\00"
@.str.1 = [6 x i8] c"%s Mb\00"
@.str.2 = [6 x i8] c"%s kB\00"
@.str.3 = [9 x i8] c"%s bytes\00"
define void @prettybyte(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [255 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 1000000000, i32* %5
store i32 1000000, i32* %6
store i32 1000, i32* %7
store i32 1, i32* %8
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = icmp sge i32 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %2
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = sdiv i32 %15, %16
%18 = call i64 @lround(i32 %17)
%19 = trunc i64 %18 to i32
store i32 %19, i32* %9
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%21 = load i32, i32* %9
%22 = call i32 @dottedbyte(i8* %20, i32 %21)
%23 = load i8*, i8** %3
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %14, %2
%27 = load i32, i32* %4
%28 = load i32, i32* %6
%29 = icmp sge i32 %27, %28
br i1 %29, label %30, label %42
30: ; preds = %26
%31 = load i32, i32* %4
%32 = load i32, i32* %6
%33 = sdiv i32 %31, %32
%34 = call i64 @round(i32 %33)
%35 = trunc i64 %34 to i32
store i32 %35, i32* %9
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%37 = load i32, i32* %9
%38 = call i32 @dottedbyte(i8* %36, i32 %37)
%39 = load i8*, i8** %3
%40 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%41 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %30, %26
%43 = load i32, i32* %4
%44 = load i32, i32* %7
%45 = icmp sge i32 %43, %44
br i1 %45, label %46, label %58
46: ; preds = %42
%47 = load i32, i32* %4
%48 = load i32, i32* %7
%49 = sdiv i32 %47, %48
%50 = call i64 @round(i32 %49)
%51 = trunc i64 %50 to i32
store i32 %51, i32* %9
%52 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%53 = load i32, i32* %9
%54 = call i32 @dottedbyte(i8* %52, i32 %53)
%55 = load i8*, i8** %3
%56 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%57 = call i32 @sprintf(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %56)
br label %70
58: ; preds = %42
%59 = load i32, i32* %4
%60 = load i32, i32* %8
%61 = icmp sge i32 %59, %60
br i1 %61, label %62, label %70
62: ; preds = %58
%63 = load i32, i32* %4
store i32 %63, i32* %9
%64 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%65 = load i32, i32* %9
%66 = call i32 @dottedbyte(i8* %64, i32 %65)
%67 = load i8*, i8** %3
%68 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%69 = call i32 @sprintf(i8* %67, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %46, %62, %58
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s Gb\00"
@.str.1 = [6 x i8] c"%s Mb\00"
@.str.2 = [6 x i8] c"%s kB\00"
@.str.3 = [9 x i8] c"%s bytes\00"
define void @prettybyte(i8* nocapture writeonly %0, i32 %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 999999999
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = udiv i32 %1, 1000000000
%8 = tail call i64 @lround(i32 %7)
%9 = trunc i64 %8 to i32
%10 = call i32 @dottedbyte(i8* %4, i32 %9)
%11 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %14
12: ; preds = %2
%13 = icmp sgt i32 %1, 999999
br i1 %13, label %14, label %20
14: ; preds = %12, %6
%15 = udiv i32 %1, 1000000
%16 = call i64 @round(i32 %15)
%17 = trunc i64 %16 to i32
%18 = call i32 @dottedbyte(i8* %4, i32 %17)
%19 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %22
20: ; preds = %12
%21 = icmp sgt i32 %1, 999
br i1 %21, label %22, label %26
22: ; preds = %14, %20
%23 = udiv i32 %1, 1000
%24 = call i64 @round(i32 %23)
%25 = trunc i64 %24 to i32
br label %28
26: ; preds = %20
%27 = icmp sgt i32 %1, 0
br i1 %27, label %28, label %33
28: ; preds = %26, %22
%29 = phi i32 [ %25, %22 ], [ %1, %26 ]
%30 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %22 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), %26 ]
%31 = call i32 @dottedbyte(i8* %4, i32 %29)
%32 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) %30, i8* %4)
br label %33
33: ; preds = %28, %26
ret void
}