#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 *, double);
char *get_bytes_f(long bytes, char *str) {
  if (str != NULL) {
    if (bytes > 0) {
      if (bytes < 1024) {
        sprintf(str, "%ld bytes", bytes);
      }
      if ((bytes >= 1024) & (bytes < 1024 * 1024)) {
        sprintf(str, "%.3f Kbytes", ((double)bytes / (double)1024.00));
      }
      if (bytes >= 1024 * 1024) {
        sprintf(str, "%.3f Mbytes", (double)bytes / (double)(1024 * 1024));
      }
    }
  } else {
    return NULL;
  }
  return str;
}


x86 assembly (clang, -O0):
<get_bytes_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e2 <get_bytes_f+0xd2>
cmpq   $0x0,-0x10(%rbp)
jle    11dd <get_bytes_f+0xcd>
cmpq   $0x400,-0x10(%rbp)
jge    115a <get_bytes_f+0x4a>
mov    -0x18(%rbp),%rdi
cvtsi2sdq -0x10(%rbp),%xmm0
lea    0xebb(%rip),%rsi
call   1030 <sprintf@plt>
cmpq   $0x400,-0x10(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%eax
cmpq   $0x100000,-0x10(%rbp)
setl   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11a8 <get_bytes_f+0x98>
mov    -0x18(%rbp),%rdi
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe68(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe77(%rip),%rsi
call   1030 <sprintf@plt>
cmpq   $0x100000,-0x10(%rbp)
jl     11d8 <get_bytes_f+0xc8>
mov    -0x18(%rbp),%rdi
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe40(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe53(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11dd <get_bytes_f+0xcd>
jmp    11ef <get_bytes_f+0xdf>
movq   $0x0,-0x8(%rbp)
jmp    11f7 <get_bytes_f+0xe7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bytes_f>:
push   %rbx
mov    %rsi,%rbx
test   %rdi,%rdi
jle    1171 <get_bytes_f+0x61>
test   %rbx,%rbx
je     1171 <get_bytes_f+0x61>
cmp    $0x3ff,%rdi
ja     1135 <get_bytes_f+0x25>
cvtsi2sd %rdi,%xmm0
lea    0xedd(%rip),%rsi
jmp    1169 <get_bytes_f+0x59>
lea    -0x400(%rdi),%rax
cvtsi2sd %rdi,%xmm0
cmp    $0xffbff,%rax
ja     115a <get_bytes_f+0x4a>
mulsd  0xeb7(%rip),%xmm0
lea    0xec2(%rip),%rsi
jmp    1169 <get_bytes_f+0x59>
mulsd  0xe9e(%rip),%xmm0
lea    0xebd(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%ld bytes\00"
@.str.1 = [12 x i8] c"%.3f Kbytes\00"
@.str.2 = [12 x i8] c"%.3f Mbytes\00"
define i8* @get_bytes_f(i64 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %4
store i8* %1, i8** %5
%6 = load i8*, i8** %5
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %45
8: ; preds = %2
%9 = load i64, i64* %4
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %44
11: ; preds = %8
%12 = load i64, i64* %4
%13 = icmp slt i64 %12, 1024
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = load i64, i64* %4
%17 = sitofp i64 %16 to double
%18 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %17)
br label %19
19: ; preds = %14, %11
%20 = load i64, i64* %4
%21 = icmp sge i64 %20, 1024
%22 = zext i1 %21 to i32
%23 = load i64, i64* %4
%24 = icmp slt i64 %23, 1048576
%25 = zext i1 %24 to i32
%26 = and i32 %22, %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %19
%29 = load i8*, i8** %5
%30 = load i64, i64* %4
%31 = sitofp i64 %30 to double
%32 = fdiv double %31, 1.024000e+03
%33 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %32)
br label %34
34: ; preds = %28, %19
%35 = load i64, i64* %4
%36 = icmp sge i64 %35, 1048576
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load i8*, i8** %5
%39 = load i64, i64* %4
%40 = sitofp i64 %39 to double
%41 = fdiv double %40, 0x4130000000000000
%42 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %41)
br label %43
43: ; preds = %37, %34
br label %44
44: ; preds = %43, %8
br label %46
45: ; preds = %2
store i8* null, i8** %3
br label %48
46: ; preds = %44
%47 = load i8*, i8** %5
store i8* %47, i8** %3
br label %48
48: ; preds = %46, %45
%49 = load i8*, i8** %3
ret i8* %49
}

LLVM IR (-O2):
@.str = [10 x i8] c"%ld bytes\00"
@.str.1 = [12 x i8] c"%.3f Kbytes\00"
@.str.2 = [12 x i8] c"%.3f Mbytes\00"
define i8* @get_bytes_f(i64 %0, i8* writeonly %1) {
%3 = icmp ne i8* %1, null
%4 = icmp sgt i64 %0, 0
%5 = and i1 %4, %3
br i1 %5, label %6, label %21
6: ; preds = %2
%7 = icmp ult i64 %0, 1024
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = sitofp i64 %0 to double
%10 = tail call i32 @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %9)
br label %21
11: ; preds = %6
%12 = add nsw i64 %0, -1024
%13 = icmp ult i64 %12, 1047552
%14 = sitofp i64 %0 to double
br i1 %13, label %15, label %18
15: ; preds = %11
%16 = fmul double %14, 0x3F50000000000000
%17 = tail call i32 @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %16)
br label %21
18: ; preds = %11
%19 = fmul double %14, 0x3EB0000000000000
%20 = tail call i32 @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %19)
br label %21
21: ; preds = %15, %8, %18, %2
ret i8* %1
}