#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 *, int, ...);
void sectors_to_size(int sectors, char *buffer) {
  int b = (sectors / 2);
  int mib = b >> 10;
  int gib = mib >> 10;
  int tib = gib >> 10;
  if (tib > 0)
    sprintf(buffer, "%3d.%02d TiB", tib, (((gib % 1024) * 100) >> 10));
  else if (gib > 0)
    sprintf(buffer, "%3d.%02d GiB", gib, (((mib % 1024) * 100) >> 10));
  else if (mib > 0)
    sprintf(buffer, "%3d.%02d MiB", mib, (((b % 1024) * 100) >> 10));
  else
    sprintf(buffer, "%d B", b);
}


x86 assembly (clang, -O0):
<sectors_to_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sar    $0xa,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0xa,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0xa,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1185 <sectors_to_size+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x24(%rbp),%edx
imul   $0x64,%eax,%ecx
sar    $0xa,%ecx
lea    0xe87(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    121e <sectors_to_size+0x10e>
cmpl   $0x0,-0x1c(%rbp)
jle    11c2 <sectors_to_size+0xb2>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x28(%rbp),%edx
imul   $0x64,%eax,%ecx
sar    $0xa,%ecx
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1219 <sectors_to_size+0x109>
cmpl   $0x0,-0x18(%rbp)
jle    11ff <sectors_to_size+0xef>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x2c(%rbp),%edx
imul   $0x64,%eax,%ecx
sar    $0xa,%ecx
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1214 <sectors_to_size+0x104>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1219 <sectors_to_size+0x109>
jmp    121e <sectors_to_size+0x10e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sectors_to_size>:
mov    %rsi,%r8
mov    %edi,%eax
shr    $0x1f,%eax
add    %edi,%eax
mov    %eax,%edx
sar    %edx
sar    $0xb,%eax
cmp    $0x200000,%edi
jl     1156 <sectors_to_size+0x46>
sar    $0x14,%edx
lea    0x3ff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffc00,%ecx
sub    %ecx,%eax
imul   $0x64,%eax,%ecx
sar    $0xa,%ecx
lea    0xeb4(%rip),%rsi
mov    %r8,%rdi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
cmp    $0x800,%edi
jl     118a <sectors_to_size+0x7a>
lea    0x3ff(%rdx),%ecx
test   %edx,%edx
cmovns %edx,%ecx
and    $0xfffffc00,%ecx
sub    %ecx,%edx
imul   $0x64,%edx,%ecx
sar    $0xa,%ecx
lea    0xe8f(%rip),%rsi
mov    %r8,%rdi
mov    %eax,%edx
xor    %eax,%eax
jmp    1030 <sprintf@plt>
lea    0xe89(%rip),%rsi
mov    %r8,%rdi
xor    %eax,%eax
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"%3d.%02d TiB\00"
@.str.1 = [13 x i8] c"%3d.%02d GiB\00"
@.str.2 = [13 x i8] c"%3d.%02d MiB\00"
@.str.3 = [5 x i8] c"%d B\00"
define void @sectors_to_size(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = load i32, i32* %3
%10 = sdiv i32 %9, 2
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = ashr i32 %11, 10
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = ashr i32 %13, 10
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = ashr i32 %15, 10
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = load i32, i32* %8
%22 = load i32, i32* %7
%23 = srem i32 %22, 1024
%24 = mul nsw i32 %23, 100
%25 = ashr i32 %24, 10
%26 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %25)
br label %55
27: ; preds = %2
%28 = load i32, i32* %7
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i8*, i8** %4
%32 = load i32, i32* %7
%33 = load i32, i32* %6
%34 = srem i32 %33, 1024
%35 = mul nsw i32 %34, 100
%36 = ashr i32 %35, 10
%37 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %36)
br label %54
38: ; preds = %27
%39 = load i32, i32* %6
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = load i8*, i8** %4
%43 = load i32, i32* %6
%44 = load i32, i32* %5
%45 = srem i32 %44, 1024
%46 = mul nsw i32 %45, 100
%47 = ashr i32 %46, 10
%48 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %42, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %43, i32 %47)
br label %53
49: ; preds = %38
%50 = load i8*, i8** %4
%51 = load i32, i32* %5
%52 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %49, %41
br label %54
54: ; preds = %53, %30
br label %55
55: ; preds = %54, %19
ret void
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"%3d.%02d GiB\00"
@.str.2 = [13 x i8] c"%3d.%02d MiB\00"
@.str.3 = [5 x i8] c"%d B\00"
define void @sectors_to_size(i32 %0, i8* nocapture writeonly %1) {
%3 = sdiv i32 %0, 2
%4 = ashr i32 %3, 10
%5 = icmp sgt i32 %0, 2097151
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = ashr i32 %3, 20
%8 = srem i32 %4, 1024
%9 = mul nsw i32 %8, 100
%10 = ashr i32 %9, 10
%11 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %10)
br label %21
12: ; preds = %2
%13 = icmp sgt i32 %0, 2047
br i1 %13, label %14, label %19
14: ; preds = %12
%15 = srem i32 %3, 1024
%16 = mul nsw i32 %15, 100
%17 = ashr i32 %16, 10
%18 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %17)
br label %21
19: ; preds = %12
%20 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %3)
br label %21
21: ; preds = %6, %19, %14
ret void
}