#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_dec2(int sectors, char *buffer) {
  int b = (sectors / 2);
  int mib = b / 1000;
  int gib = mib / 1000;
  int tib = gib / 1000;
  if (tib > 0)
    sprintf(buffer, "%3d.%02d TB", tib, (((gib % 1000) * 100) / 1000));
  else if (gib > 0)
    sprintf(buffer, "%3d.%02d GB", gib, (((mib % 1000) * 100) / 1000));
  else if (mib > 0)
    sprintf(buffer, "%3d.%02d MB", mib, (((b % 1000) * 100) / 1000));
  else
    sprintf(buffer, "%d B", b);
}


x86 assembly (clang, -O0):
<sectors_to_size_dec2>:
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
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1199 <sectors_to_size_dec2+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x64,%edx,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    123c <sectors_to_size_dec2+0x12c>
cmpl   $0x0,-0x1c(%rbp)
jle    11db <sectors_to_size_dec2+0xcb>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x64,%edx,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%edx
mov    %eax,%ecx
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1237 <sectors_to_size_dec2+0x127>
cmpl   $0x0,-0x18(%rbp)
jle    121d <sectors_to_size_dec2+0x10d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x64,%edx,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1232 <sectors_to_size_dec2+0x122>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1237 <sectors_to_size_dec2+0x127>
jmp    123c <sectors_to_size_dec2+0x12c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sectors_to_size_dec2>:
mov    %rsi,%r8
movslq %edi,%rax
imul   $0x431bde83,%rax,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0x33,%rdx
add    %ecx,%edx
cmp    $0x77359400,%edi
jl     117c <sectors_to_size_dec2+0x6c>
imul   $0xffff8313,%edx,%eax
shr    $0x10,%eax
add    %edx,%eax
movzwl %ax,%eax
movswl %ax,%ecx
shr    $0xf,%eax
sar    $0x9,%ecx
add    %eax,%ecx
imul   $0x3e8,%ecx,%eax
sub    %eax,%edx
movswl %dx,%eax
imul   $0x6667,%eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x12,%ecx
add    %eax,%ecx
lea    0xe93(%rip),%rsi
mov    %r8,%rdi
mov    $0x1,%edx
xor    %eax,%eax
jmp    1030 <sprintf@plt>
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x27,%rax
add    %ecx,%eax
cmp    $0x1e8480,%edi
jl     11d9 <sectors_to_size_dec2+0xc9>
movslq %eax,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
shr    $0x26,%rcx
add    %esi,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
cwtl
imul   $0x6667,%eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x12,%ecx
add    %eax,%ecx
lea    0xe3d(%rip),%rsi
mov    %r8,%rdi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
mov    %edi,%edx
shr    $0x1f,%edx
add    %edi,%edx
sar    %edx
cmp    $0x7d0,%edi
jl     122f <sectors_to_size_dec2+0x11f>
movslq %edx,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
shr    $0x26,%rcx
add    %esi,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%edx
movswl %dx,%ecx
imul   $0x6667,%ecx,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x12,%ecx
add    %edx,%ecx
lea    0xdf5(%rip),%rsi
mov    %r8,%rdi
mov    %eax,%edx
xor    %eax,%eax
jmp    1030 <sprintf@plt>
lea    0xdee(%rip),%rsi
mov    %r8,%rdi
xor    %eax,%eax
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"%3d.%02d TB\00"
@.str.1 = [12 x i8] c"%3d.%02d GB\00"
@.str.2 = [12 x i8] c"%3d.%02d MB\00"
@.str.3 = [5 x i8] c"%d B\00"
define void @sectors_to_size_dec2(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 = sdiv i32 %11, 1000
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = sdiv i32 %13, 1000
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = sdiv i32 %15, 1000
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, 1000
%24 = mul nsw i32 %23, 100
%25 = sdiv i32 %24, 1000
%26 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([12 x i8], [12 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, 1000
%35 = mul nsw i32 %34, 100
%36 = sdiv i32 %35, 1000
%37 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %31, i8* getelementptr inbounds ([12 x i8], [12 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, 1000
%46 = mul nsw i32 %45, 100
%47 = sdiv i32 %46, 1000
%48 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %42, i8* getelementptr inbounds ([12 x i8], [12 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 = [12 x i8] c"%3d.%02d TB\00"
@.str.1 = [12 x i8] c"%3d.%02d GB\00"
@.str.2 = [12 x i8] c"%3d.%02d MB\00"
@.str.3 = [5 x i8] c"%d B\00"
define void @sectors_to_size_dec2(i32 %0, i8* nocapture writeonly %1) {
%3 = sdiv i32 %0, 2
%4 = sdiv i32 %0, 2000
%5 = sdiv i32 %0, 2000000
%6 = icmp sgt i32 %0, 1999999999
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = trunc i32 %5 to i16
%9 = srem i16 %8, 1000
%10 = sdiv i16 %9, 10
%11 = sext i16 %10 to i32
%12 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 1, i32 %11)
br label %31
13: ; preds = %2
%14 = icmp sgt i32 %0, 1999999
br i1 %14, label %15, label %21
15: ; preds = %13
%16 = srem i32 %4, 1000
%17 = trunc i32 %16 to i16
%18 = sdiv i16 %17, 10
%19 = sext i16 %18 to i32
%20 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %19)
br label %31
21: ; preds = %13
%22 = icmp sgt i32 %0, 1999
br i1 %22, label %23, label %29
23: ; preds = %21
%24 = srem i32 %3, 1000
%25 = trunc i32 %24 to i16
%26 = sdiv i16 %25, 10
%27 = sext i16 %26 to i32
%28 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %27)
br label %31
29: ; preds = %21
%30 = 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 %31
31: ; preds = %15, %29, %23, %7
ret void
}