#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*/ units;

/* Variables and functions */
scalar_t__ ERANGE;
scalar_t__ errno;
int /*<<< orphan*/ snprintf(char *, int, char *, float, char *);
scalar_t__ strtod(char *, char **);
char *convbytes(char *input) {
  char *units[] = {"Bytes", "KB", "MB", "GB", "TB", "PB"};
  char *endptr;
  static char output[50];
  float bytes;
  unsigned int i = 0;
  errno = 0;
  bytes = (float)strtod(input, &endptr);
  if (*endptr != '\0' || errno == ERANGE)
    return "Bad format";
  for (; i < (sizeof(units) / sizeof(char *)) - 1; i++) {
    if (bytes < 1024)
      break;
    bytes /= 1024;
  }
  snprintf(output, 50, "%.2f %s", bytes, units[i]);
  return output;
}


x86 assembly (clang, -O0):
<convbytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
lea    0xeb1(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xeac(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xea4(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe9c(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe94(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe8c(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x50(%rbp)
mov    0x2e3c(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1030 <strtod@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e4 <convbytes+0xb4>
mov    0x2e07(%rip),%rax
mov    (%rax),%rax
mov    0x2e0d(%rip),%rcx
cmp    (%rcx),%rax
jne    11f4 <convbytes+0xc4>
lea    0xe2e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1271 <convbytes+0x141>
jmp    11f9 <convbytes+0xc9>
mov    -0x50(%rbp),%eax
cmp    $0x5,%rax
jae    1241 <convbytes+0x111>
movss  0xdf2(%rip),%xmm0
ucomiss -0x4c(%rbp),%xmm0
jbe    121d <convbytes+0xed>
jmp    1241 <convbytes+0x111>
movss  -0x4c(%rbp),%xmm0
movss  0xdd6(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    11f9 <convbytes+0xc9>
movss  -0x4c(%rbp),%xmm0
mov    -0x50(%rbp),%eax
mov    -0x40(%rbp,%rax,8),%rcx
lea    0x2dfb(%rip),%rdi
mov    $0x32,%esi
lea    0xdc3(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2de3(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convbytes>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xed8(%rip),%r14
mov    %r14,0x10(%rsp)
lea    0xed2(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xec9(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xec0(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xeb7(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xeae(%rip),%rax
mov    %rax,0x38(%rsp)
mov    0x2e60(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
call   1030 <strtod@plt>
mov    0x8(%rsp),%rcx
lea    0xe88(%rip),%rbx
cmpb   $0x0,(%rcx)
jne    123e <convbytes+0x11e>
mov    (%r15),%rcx
mov    0x2e40(%rip),%rdx
cmp    (%rdx),%rcx
je     123e <convbytes+0x11e>
cvtsi2ss %rax,%xmm0
cmp    $0x400,%rax
jl     1220 <convbytes+0x100>
mulss  0xe3a(%rip),%xmm0
mov    $0x1,%eax
movss  0xe31(%rip),%xmm1
ucomiss %xmm0,%xmm1
ja     121b <convbytes+0xfb>
mulss  0xe20(%rip),%xmm0
mov    $0x2,%eax
ucomiss %xmm0,%xmm1
ja     121b <convbytes+0xfb>
mulss  0xe0e(%rip),%xmm0
mov    $0x3,%eax
ucomiss %xmm0,%xmm1
ja     121b <convbytes+0xfb>
mulss  0xdfc(%rip),%xmm0
mov    $0x4,%eax
ucomiss %xmm0,%xmm1
ja     121b <convbytes+0xfb>
mulss  0xdea(%rip),%xmm0
mov    $0x5,%eax
mov    0x10(%rsp,%rax,8),%r14
lea    0x2e19(%rip),%rbx
lea    0xdfa(%rip),%rdx
mov    %rbx,%rdi
mov    $0x32,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Bytes\00"
@.str.1 = [3 x i8] c"KB\00"
@.str.2 = [3 x i8] c"MB\00"
@.str.3 = [3 x i8] c"GB\00"
@.str.4 = [3 x i8] c"TB\00"
@.str.5 = [3 x i8] c"PB\00"
@convbytes.output = internal global [50 x i8] zeroinitializer
@errno = global i64 0
@ERANGE = global i64 0
@.str.6 = [11 x i8] c"Bad format\00"
@.str.7 = [8 x i8] c"%.2f %s\00"
define i8* @convbytes(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [6 x i8*]
%5 = alloca i8*
%6 = alloca float
%7 = alloca i32
store i8* %0, i8** %3
%8 = bitcast [6 x i8*]* %4 to i8*
%9 = bitcast i8* %8 to [6 x i8*]*
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i32 0, i32 0), i8** %15
store i32 0, i32* %7
store i64 0, i64* @errno
%16 = load i8*, i8** %3
%17 = call i64 @strtod(i8* %16, i8** %5)
%18 = sitofp i64 %17 to float
store float %18, float* %6
%19 = load i8*, i8** %5
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %1
%24 = load i64, i64* @errno
%25 = load i64, i64* @ERANGE
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23, %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %50
28: ; preds = %23
br label %29
29: ; preds = %40, %28
%30 = load i32, i32* %7
%31 = zext i32 %30 to i64
%32 = icmp ult i64 %31, 5
br i1 %32, label %33, label %43
33: ; preds = %29
%34 = load float, float* %6
%35 = fcmp olt float %34, 1.024000e+03
br i1 %35, label %36, label %37
36: ; preds = %33
br label %43
37: ; preds = %33
%38 = load float, float* %6
%39 = fdiv float %38, 1.024000e+03
store float %39, float* %6
br label %40
40: ; preds = %37
%41 = load i32, i32* %7
%42 = add i32 %41, 1
store i32 %42, i32* %7
br label %29
43: ; preds = %36, %29
%44 = load float, float* %6
%45 = load i32, i32* %7
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 @snprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @convbytes.output, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), float %44, i8* %48)
store i8* getelementptr inbounds ([50 x i8], [50 x i8]* @convbytes.output, i64 0, i64 0), i8** %2
br label %50
50: ; preds = %43, %27
%51 = load i8*, i8** %2
ret i8* %51
}

LLVM IR (-O2):
@.str = [6 x i8] c"Bytes\00"
@.str.1 = [3 x i8] c"KB\00"
@.str.2 = [3 x i8] c"MB\00"
@.str.3 = [3 x i8] c"GB\00"
@.str.4 = [3 x i8] c"TB\00"
@.str.5 = [3 x i8] c"PB\00"
@convbytes.output = internal global [50 x i8] zeroinitializer
@errno = global i64 0
@ERANGE = global i64 0
@.str.6 = [11 x i8] c"Bad format\00"
@.str.7 = [8 x i8] c"%.2f %s\00"
define i8* @convbytes(i8* %0) {
%2 = alloca [6 x i8*]
%3 = alloca i8*
%4 = bitcast [6 x i8*]* %2 to i8*
%5 = getelementptr inbounds [6 x i8*], [6 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [6 x i8*], [6 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [6 x i8*], [6 x i8*]* %2, i64 0, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [6 x i8*], [6 x i8*]* %2, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* %2, i64 0, i64 4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %2, i64 0, i64 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %10
%11 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%12 = call i64 @strtod(i8* %0, i8** %3)
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %46
16: ; preds = %1
%17 = sitofp i64 %12 to float
%18 = load i64, i64* @errno
%19 = load i64, i64* @ERANGE
%20 = icmp eq i64 %18, %19
br i1 %20, label %46, label %21
21: ; preds = %16
%22 = icmp slt i64 %12, 1024
br i1 %22, label %42, label %23
23: ; preds = %21
%24 = fmul float %17, 0x3F50000000000000
%25 = fcmp olt float %24, 1.024000e+03
br i1 %25, label %37, label %26
26: ; preds = %23
%27 = fmul float %24, 0x3F50000000000000
%28 = fcmp olt float %27, 1.024000e+03
br i1 %28, label %37, label %29
29: ; preds = %26
%30 = fmul float %27, 0x3F50000000000000
%31 = fcmp olt float %30, 1.024000e+03
br i1 %31, label %37, label %32
32: ; preds = %29
%33 = fmul float %30, 0x3F50000000000000
%34 = fcmp olt float %33, 1.024000e+03
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = fmul float %33, 0x3F50000000000000
br label %37
37: ; preds = %35, %32, %29, %26, %23
%38 = phi float [ %24, %23 ], [ %27, %26 ], [ %30, %29 ], [ %33, %32 ], [ %36, %35 ]
%39 = phi i64 [ 1, %23 ], [ 2, %26 ], [ 3, %29 ], [ 4, %32 ], [ 5, %35 ]
%40 = getelementptr inbounds [6 x i8*], [6 x i8*]* %2, i64 0, i64 %39
%41 = load i8*, i8** %40
br label %42
42: ; preds = %21, %37
%43 = phi i8* [ %41, %37 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %21 ]
%44 = phi float [ %38, %37 ], [ %17, %21 ]
%45 = tail call i32 @snprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @convbytes.output, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), float %44, i8* %43)
br label %46
46: ; preds = %1, %16, %42
%47 = phi i8* [ getelementptr inbounds ([50 x i8], [50 x i8]* @convbytes.output, i64 0, i64 0), %42 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), %16 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), %1 ]
ret i8* %47
}