#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*/ memmove(char *, char *, int);
int sprintf(char *, char *, unsigned long);
int store_size(char *buffer, unsigned long value) {
  unsigned long divisor = 1;
  char trailer = 0;
  int n;
  if (value > 1000000000UL) {
    divisor = 100000000UL;
    trailer = 'G';
  } else if (value > 1000000UL) {
    divisor = 100000UL;
    trailer = 'M';
  } else if (value > 1000UL) {
    divisor = 100;
    trailer = 'K';
  }
  value /= divisor;
  n = sprintf(buffer, "%ld", value);
  if (trailer) {
    buffer[n] = trailer;
    n++;
    buffer[n] = 0;
  }
  if (divisor != 1) {
    memmove(buffer + n - 2, buffer + n - 3, 4);
    buffer[n - 2] = '.';
    n++;
  }
  return n;
}


x86 assembly (clang, -O0):
<store_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
cmpq   $0x3b9aca00,-0x10(%rbp)
3b
jbe    115b <store_size+0x3b>
movq   $0x5f5e100,-0x18(%rbp)
05
movb   $0x47,-0x19(%rbp)
jmp    119e <store_size+0x7e>
cmpq   $0xf4240,-0x10(%rbp)
jbe    117a <store_size+0x5a>
movq   $0x186a0,-0x18(%rbp)
movb   $0x4d,-0x19(%rbp)
jmp    1199 <store_size+0x79>
cmpq   $0x3e8,-0x10(%rbp)
jbe    1194 <store_size+0x74>
movq   $0x64,-0x18(%rbp)
movb   $0x4b,-0x19(%rbp)
jmp    1199 <store_size+0x79>
jmp    119e <store_size+0x7e>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe42(%rip),%rsi
call   1040 <sprintf@plt>
mov    %eax,-0x20(%rbp)
cmpb   $0x0,-0x19(%rbp)
je     11f3 <store_size+0xd3>
mov    -0x19(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x1,-0x18(%rbp)
je     1240 <store_size+0x120>
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffe,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffffd,%rsi
mov    $0x4,%edx
call   1030 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<store_size>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rax
mov    %rdi,%r14
cmp    $0x3b9aca00,%rsi
jbe    113d <store_size+0x1d>
mov    $0x47,%bpl
mov    $0x5f5e100,%ecx
jmp    115f <store_size+0x3f>
cmp    $0xf4240,%rax
jbe    114f <store_size+0x2f>
mov    $0x4d,%bpl
mov    $0x186a0,%ecx
jmp    115f <store_size+0x3f>
cmp    $0x3e8,%rax
jbe    11bc <store_size+0x9c>
mov    $0x4b,%bpl
mov    $0x64,%ecx
mov    %rax,%rdx
shr    $0x20,%rdx
je     116f <store_size+0x4f>
xor    %edx,%edx
div    %rcx
jmp    1173 <store_size+0x53>
xor    %edx,%edx
div    %ecx
lea    0xe86(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
call   1040 <sprintf@plt>
movslq %eax,%rbx
mov    %bpl,(%r14,%rbx,1)
movb   $0x0,0x1(%r14,%rbx,1)
lea    (%r14,%rbx,1),%rsi
add    $0xfffffffffffffffe,%rsi
lea    (%r14,%rbx,1),%rdi
add    $0xffffffffffffffff,%rdi
mov    $0x4,%edx
call   1030 <memmove@plt>
movb   $0x2e,-0x1(%r14,%rbx,1)
add    $0x2,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe3d(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <sprintf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
define i32 @store_size(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 1, i64* %5
store i8 0, i8* %6
%8 = load i64, i64* %4
%9 = icmp ugt i64 %8, 1000000000
br i1 %9, label %10, label %11
10: ; preds = %2
store i64 100000000, i64* %5
store i8 71, i8* %6
br label %21
11: ; preds = %2
%12 = load i64, i64* %4
%13 = icmp ugt i64 %12, 1000000
br i1 %13, label %14, label %15
14: ; preds = %11
store i64 100000, i64* %5
store i8 77, i8* %6
br label %20
15: ; preds = %11
%16 = load i64, i64* %4
%17 = icmp ugt i64 %16, 1000
br i1 %17, label %18, label %19
18: ; preds = %15
store i64 100, i64* %5
store i8 75, i8* %6
br label %19
19: ; preds = %18, %15
br label %20
20: ; preds = %19, %14
br label %21
21: ; preds = %20, %10
%22 = load i64, i64* %5
%23 = load i64, i64* %4
%24 = udiv i64 %23, %22
store i64 %24, i64* %4
%25 = load i8*, i8** %3
%26 = load i64, i64* %4
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %26)
store i32 %27, i32* %7
%28 = load i8, i8* %6
%29 = icmp ne i8 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %21
%31 = load i8, i8* %6
%32 = load i8*, i8** %3
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
%38 = load i8*, i8** %3
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 0, i8* %41
br label %42
42: ; preds = %30, %21
%43 = load i64, i64* %5
%44 = icmp ne i64 %43, 1
br i1 %44, label %45, label %64
45: ; preds = %42
%46 = load i8*, i8** %3
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = getelementptr inbounds i8, i8* %49, i64 -2
%51 = load i8*, i8** %3
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = getelementptr inbounds i8, i8* %54, i64 -3
%56 = call i32 @memmove(i8* %50, i8* %55, i32 4)
%57 = load i8*, i8** %3
%58 = load i32, i32* %7
%59 = sub nsw i32 %58, 2
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
store i8 46, i8* %61
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %64
64: ; preds = %45, %42
%65 = load i32, i32* %7
ret i32 %65
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
define i32 @store_size(i8* %0, i64 %1) {
%3 = icmp ugt i64 %1, 1000000000
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = icmp ugt i64 %1, 1000000
br i1 %5, label %10, label %6
6: ; preds = %4
%7 = icmp ugt i64 %1, 1000
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %1)
br label %27
10: ; preds = %6, %2, %4
%11 = phi i64 [ 100000, %4 ], [ 100000000, %2 ], [ 100, %6 ]
%12 = phi i8 [ 77, %4 ], [ 71, %2 ], [ 75, %6 ]
%13 = udiv i64 %1, %11
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %13)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 %12, i8* %16
%17 = add nsw i32 %14, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds i8, i8* %19, i64 -2
%21 = getelementptr inbounds i8, i8* %19, i64 -3
%22 = tail call i32 @memmove(i8* %20, i8* %21, i32 4)
%23 = add nsw i32 %14, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %0, i64 %24
store i8 46, i8* %25
%26 = add nsw i32 %14, 2
br label %27
27: ; preds = %8, %10
%28 = phi i32 [ %26, %10 ], [ %9, %8 ]
ret i32 %28
}