#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 uint8_t;
typedef unsigned long long uint64_t;
typedef unsigned long long uint16_t;

/* Variables and functions */
double charts_fixmax(uint64_t max, uint8_t *scale, uint8_t *mode,
                     uint16_t *base) {
  double rmax;
  if (max > 995000000000000000ULL) {
    (*base) = (max + 499999999999999999ULL) / 500000000000000000ULL;
    rmax = (*base) * 500000000000000000ULL;
    (*mode) = 1;
    (*scale) += 6;
  } else if (max > 99500000000000000ULL) {
    (*base) = (max + 4999999999999999ULL) / 5000000000000000ULL;
    rmax = (*base) * 5000000000000000ULL;
    (*mode) = 0;
    (*scale) += 5;
  } else if (max > 995000000000000ULL) {
    (*base) = (max + 499999999999999ULL) / 500000000000000ULL;
    rmax = (*base) * 500000000000000ULL;
    (*mode) = 1;
    (*scale) += 5;
  } else if (max > 99500000000000ULL) {
    (*base) = (max + 4999999999999ULL) / 5000000000000ULL;
    rmax = (*base) * 5000000000000ULL;
    (*mode) = 0;
    (*scale) += 4;
  } else if (max > 995000000000ULL) {
    (*base) = (max + 499999999999ULL) / 500000000000ULL;
    rmax = (*base) * 500000000000ULL;
    (*mode) = 1;
    (*scale) += 4;
  } else if (max > 99500000000ULL) {
    (*base) = (max + 4999999999ULL) / 5000000000ULL;
    rmax = (*base) * 5000000000ULL;
    (*mode) = 0;
    (*scale) += 3;
  } else if (max > 995000000ULL) {
    (*base) = (max + 499999999ULL) / 500000000ULL;
    rmax = (*base) * 500000000ULL;
    (*mode) = 1;
    (*scale) += 3;
  } else if (max > 99500000ULL) {
    (*base) = (max + 4999999ULL) / 5000000ULL;
    rmax = (*base) * 5000000ULL;
    (*mode) = 0;
    (*scale) += 2;
  } else if (max > 995000ULL) {
    (*base) = (max + 499999ULL) / 500000ULL;
    rmax = (*base) * 500000ULL;
    (*mode) = 1;
    (*scale) += 2;
  } else if (max > 99500ULL) {
    (*base) = (max + 4999ULL) / 5000ULL;
    rmax = (*base) * 5000ULL;
    (*mode) = 0;
    (*scale) += 1;
  } else if (max > 995ULL) {
    (*base) = (max + 499ULL) / 500ULL;
    rmax = (*base) * 500ULL;
    (*mode) = 1;
    (*scale) += 1;
  } else if (max > 99ULL) {
    (*base) = (max + 4ULL) / 5ULL;
    rmax = (*base) * 5ULL;
    (*mode) = 0;
  } else {
    if (max == 0) {
      max = 1;
    }
    (*base) = max * 2;
    rmax = ((*base) * 5) / 10.0;
    (*mode) = 1;
  }
  return rmax;
}


x86 assembly (clang, -O0):
<charts_fixmax>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movabs $0xdcef33a6f838000,%rax
f3 ce 0d
cmp    %rax,-0x8(%rbp)
jbe    11b0 <charts_fixmax+0xb0>
mov    -0x8(%rbp),%rax
movabs $0x6f05b59d3b1ffff,%rcx
5b f0 06
add    %rcx,%rax
shr    $0x11,%rax
movabs $0x49c97747490f,%rcx
mul    %rcx
shr    $0x18,%rdx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movabs $0x6f05b59d3b20000,%rcx
5b f0 06
imul   %rcx,%rax
movq   %rax,%xmm0
movaps 0xe9a(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xe9e(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x6,%ecx
mov    %ecx,(%rax)
jmp    185e <charts_fixmax+0x75e>
movabs $0x1617eb90b26c000,%rax
7e 61 01
cmp    %rax,-0x8(%rbp)
jbe    1248 <charts_fixmax+0x148>
mov    -0x8(%rbp),%rax
movabs $0x11c37937e07fff,%rcx
add    %rcx,%rax
movabs $0x39a5652fb1137857,%rcx
65 a5 39
mul    %rcx
shr    $0x32,%rdx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movabs $0x11c37937e08000,%rcx
imul   %rcx,%rax
movq   %rax,%xmm0
movaps 0xe02(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xe06(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x5,%ecx
mov    %ecx,(%rax)
jmp    1859 <charts_fixmax+0x759>
movabs $0x388f27d8d3000,%rax
cmp    %rax,-0x8(%rbp)
jbe    12e4 <charts_fixmax+0x1e4>
mov    -0x8(%rbp),%rax
movabs $0x1c6bf52633fff,%rcx
add    %rcx,%rax
shr    $0xe,%rax
movabs $0x24075f3dceac3,%rcx
mul    %rcx
shr    $0x14,%rdx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movabs $0x1c6bf52634000,%rcx
imul   %rcx,%rax
movq   %rax,%xmm0
movaps 0xd66(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xd6a(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x5,%ecx
mov    %ecx,(%rax)
jmp    1854 <charts_fixmax+0x754>
movabs $0x5a7ea627b800,%rax
cmp    %rax,-0x8(%rbp)
jbe    137c <charts_fixmax+0x27c>
mov    -0x8(%rbp),%rax
movabs $0x48c27394fff,%rcx
add    %rcx,%rax
movabs $0x384b84d092ed0385,%rcx
84 4b 38
mul    %rcx
shr    $0x28,%rdx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movabs $0x48c27395000,%rcx
imul   %rcx,%rax
movq   %rax,%xmm0
movaps 0xcce(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xcd2(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x4,%ecx
mov    %ecx,(%rax)
jmp    184f <charts_fixmax+0x74f>
movabs $0xe7aa9f1e00,%rax
cmp    %rax,-0x8(%rbp)
jbe    1414 <charts_fixmax+0x314>
mov    -0x8(%rbp),%rax
movabs $0x746a5287ff,%rcx
add    %rcx,%rax
movabs $0x232f33025bd42233,%rcx
33 2f 23
mul    %rcx
shr    $0x24,%rdx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movabs $0x746a528800,%rcx
imul   %rcx,%rax
movq   %rax,%xmm0
movaps 0xc36(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xc3a(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x4,%ecx
mov    %ecx,(%rax)
jmp    184a <charts_fixmax+0x74a>
movabs $0x172aa98300,%rax
cmp    %rax,-0x8(%rbp)
jbe    14ac <charts_fixmax+0x3ac>
mov    -0x8(%rbp),%rax
movabs $0x12a05f1ff,%rcx
add    %rcx,%rax
movabs $0xdbe6fecebdedd5bf,%rcx
fe e6 db
mul    %rcx
shr    $0x20,%rdx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movabs $0x12a05f200,%rcx
imul   %rcx,%rax
movq   %rax,%xmm0
movaps 0xb9e(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xba2(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x3,%ecx
mov    %ecx,(%rax)
jmp    1845 <charts_fixmax+0x745>
cmpq   $0x3b4e7ec0,-0x8(%rbp)
3b
jbe    1534 <charts_fixmax+0x434>
mov    -0x8(%rbp),%rax
add    $0x1dcd64ff,%rax
shr    $0x8,%rax
movabs $0x44b82fa09b5a53,%rcx
mul    %rcx
shr    $0xb,%rdx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
imul   $0x1dcd6500,%rax,%rax
movq   %rax,%xmm0
movaps 0xb16(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xb1a(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x3,%ecx
mov    %ecx,(%rax)
jmp    1840 <charts_fixmax+0x740>
cmpq   $0x5ee3fe0,-0x8(%rbp)
05
jbe    15b8 <charts_fixmax+0x4b8>
mov    -0x8(%rbp),%rax
add    $0x4c4b3f,%rax
movabs $0xd6bf94d5e57a42bd,%rcx
94 bf d6
mul    %rcx
shr    $0x16,%rdx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
imul   $0x4c4b40,%rax,%rax
movq   %rax,%xmm0
movaps 0xa92(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xa96(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x2,%ecx
mov    %ecx,(%rax)
jmp    183b <charts_fixmax+0x73b>
cmpq   $0xf2eb8,-0x8(%rbp)
jbe    163c <charts_fixmax+0x53c>
mov    -0x8(%rbp),%rax
add    $0x7a11f,%rax
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mul    %rcx
shr    $0x11,%rdx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
imul   $0x7a120,%rax,%rax
movq   %rax,%xmm0
movaps 0xa0e(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xa12(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x2,%ecx
mov    %ecx,(%rax)
jmp    1836 <charts_fixmax+0x736>
cmpq   $0x184ac,-0x8(%rbp)
jbe    16c0 <charts_fixmax+0x5c0>
mov    -0x8(%rbp),%rax
add    $0x1387,%rax
movabs $0x346dc5d63886594b,%rcx
c5 6d 34
mul    %rcx
shr    $0xa,%rdx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
imul   $0x1388,%rax,%rax
movq   %rax,%xmm0
movaps 0x98a(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0x98e(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1831 <charts_fixmax+0x731>
cmpq   $0x3e3,-0x8(%rbp)
jbe    1748 <charts_fixmax+0x648>
mov    -0x8(%rbp),%rax
add    $0x1f3,%rax
shr    $0x2,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
shr    $0x4,%rdx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
imul   $0x1f4,%rax,%rax
movq   %rax,%xmm0
movaps 0x902(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0x906(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    182c <charts_fixmax+0x72c>
cmpq   $0x63,-0x8(%rbp)
jbe    17b9 <charts_fixmax+0x6b9>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mul    %rcx
shr    $0x2,%rdx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
lea    (%rax,%rax,4),%rax
movq   %rax,%xmm0
movaps 0x886(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0x88a(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    1827 <charts_fixmax+0x727>
cmpq   $0x0,-0x8(%rbp)
jne    17cc <charts_fixmax+0x6cc>
movq   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%rcx
add    %rcx,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
lea    (%rax,%rax,4),%rax
movq   %rax,%xmm0
movaps 0x81f(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0x823(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0x7ec(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    182c <charts_fixmax+0x72c>
jmp    1831 <charts_fixmax+0x731>
jmp    1836 <charts_fixmax+0x736>
jmp    183b <charts_fixmax+0x73b>
jmp    1840 <charts_fixmax+0x740>
jmp    1845 <charts_fixmax+0x745>
jmp    184a <charts_fixmax+0x74a>
jmp    184f <charts_fixmax+0x74f>
jmp    1854 <charts_fixmax+0x754>
jmp    1859 <charts_fixmax+0x759>
jmp    185e <charts_fixmax+0x75e>
movsd  -0x28(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<charts_fixmax>:
mov    %rdx,%r8
movabs $0xdcef33a6f838001,%rax
f3 ce 0d
cmp    %rax,%rdi
jb     116e <charts_fixmax+0x6e>
movabs $0x6f05b59d3b1ffff,%r9
5b f0 06
add    %r9,%rdi
shr    $0x11,%rdi
movabs $0x49c97747490f,%rdx
mov    %rdi,%rax
mul    %rdx
shr    $0x18,%rdx
mov    %rdx,(%rcx)
add    $0x1,%r9
imul   %rdx,%r9
movq   %r9,%xmm1
punpckldq 0xeb1(%rip),%xmm1
subpd  0xeb9(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movl   $0x1,(%r8)
addl   $0x6,(%rsi)
ret
movabs $0x1617eb90b26c001,%rax
7e 61 01
cmp    %rax,%rdi
jb     11d5 <charts_fixmax+0xd5>
movabs $0x11c37937e07fff,%r9
add    %r9,%rdi
movabs $0x39a5652fb1137857,%rdx
65 a5 39
mov    %rdi,%rax
mul    %rdx
shr    $0x32,%rdx
mov    %rdx,(%rcx)
add    $0x1,%r9
imul   %rdx,%r9
movq   %r9,%xmm1
punpckldq 0xe4a(%rip),%xmm1
subpd  0xe52(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movl   $0x0,(%r8)
addl   $0x5,(%rsi)
ret
movabs $0x388f27d8d3001,%rax
cmp    %rax,%rdi
jb     1240 <charts_fixmax+0x140>
movabs $0x1c6bf52633fff,%r9
add    %r9,%rdi
shr    $0xe,%rdi
movabs $0x24075f3dceac3,%rdx
mov    %rdi,%rax
mul    %rdx
shr    $0x14,%rdx
mov    %rdx,(%rcx)
add    $0x1,%r9
imul   %rdx,%r9
movq   %r9,%xmm1
punpckldq 0xddf(%rip),%xmm1
subpd  0xde7(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movl   $0x1,(%r8)
addl   $0x5,(%rsi)
ret
movabs $0x5a7ea627b801,%rax
cmp    %rax,%rdi
jb     12a7 <charts_fixmax+0x1a7>
movabs $0x48c27394fff,%r9
add    %r9,%rdi
movabs $0x384b84d092ed0385,%rdx
84 4b 38
mov    %rdi,%rax
mul    %rdx
shr    $0x28,%rdx
mov    %rdx,(%rcx)
add    $0x1,%r9
imul   %rdx,%r9
movq   %r9,%xmm1
punpckldq 0xd78(%rip),%xmm1
subpd  0xd80(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movl   $0x0,(%r8)
addl   $0x4,(%rsi)
ret
movabs $0xe7aa9f1e01,%rax
cmp    %rax,%rdi
jb     130e <charts_fixmax+0x20e>
movabs $0x746a5287ff,%r9
add    %r9,%rdi
movabs $0x232f33025bd42233,%rdx
33 2f 23
mov    %rdi,%rax
mul    %rdx
shr    $0x24,%rdx
mov    %rdx,(%rcx)
add    $0x1,%r9
imul   %rdx,%r9
movq   %r9,%xmm1
punpckldq 0xd11(%rip),%xmm1
subpd  0xd19(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movl   $0x1,(%r8)
addl   $0x4,(%rsi)
ret
movabs $0x172aa98301,%rax
cmp    %rax,%rdi
jb     1375 <charts_fixmax+0x275>
movabs $0x12a05f1ff,%r9
add    %r9,%rdi
movabs $0xdbe6fecebdedd5bf,%rdx
fe e6 db
mov    %rdi,%rax
mul    %rdx
shr    $0x20,%rdx
mov    %rdx,(%rcx)
add    $0x1,%r9
imul   %rdx,%r9
movq   %r9,%xmm1
punpckldq 0xcaa(%rip),%xmm1
subpd  0xcb2(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movl   $0x0,(%r8)
addl   $0x3,(%rsi)
ret
cmp    $0x3b4e7ec1,%rdi
jb     13d3 <charts_fixmax+0x2d3>
add    $0x1dcd64ff,%rdi
shr    $0x8,%rdi
movabs $0x44b82fa09b5a53,%rdx
mov    %rdi,%rax
mul    %rdx
shr    $0xb,%rdx
mov    %rdx,(%rcx)
imul   $0x1dcd6500,%rdx,%rax
movq   %rax,%xmm1
punpckldq 0xc4c(%rip),%xmm1
subpd  0xc54(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movl   $0x1,(%r8)
addl   $0x3,(%rsi)
ret
cmp    $0x5ee3fe1,%rdi
jb     1407 <charts_fixmax+0x307>
add    $0x4c4b3f,%edi
imul   $0x6b5fca6b,%rdi,%rax
shr    $0x35,%rax
mov    %rax,(%rcx)
imul   $0x4c4b40,%rax,%rax
cvtsi2sd %rax,%xmm0
movl   $0x0,(%r8)
addl   $0x2,(%rsi)
ret
cmp    $0xf2eb9,%rdi
jb     143b <charts_fixmax+0x33b>
add    $0x7a11f,%edi
imul   $0x431bde83,%rdi,%rax
shr    $0x31,%rax
mov    %rax,(%rcx)
imul   $0x7a120,%rax,%rax
cvtsi2sd %rax,%xmm0
movl   $0x1,(%r8)
addl   $0x2,(%rsi)
ret
cmp    $0x184ad,%rdi
jb     1471 <charts_fixmax+0x371>
add    $0x1387,%edi
mov    $0xd1b71759,%eax
imul   %rdi,%rax
shr    $0x2c,%rax
mov    %rax,(%rcx)
imul   $0x1388,%rax,%rax
cvtsi2sd %rax,%xmm0
movl   $0x0,(%r8)
addl   $0x1,(%rsi)
ret
cmp    $0x3e4,%rdi
jb     14a5 <charts_fixmax+0x3a5>
add    $0x1f3,%edi
imul   $0x10624dd3,%rdi,%rax
shr    $0x25,%rax
mov    %rax,(%rcx)
imul   $0x1f4,%rax,%rax
cvtsi2sd %rax,%xmm0
movl   $0x1,(%r8)
addl   $0x1,(%rsi)
ret
cmp    $0x64,%rdi
jb     14cc <charts_fixmax+0x3cc>
add    $0x4,%edi
movzwl %di,%eax
imul   $0xcccd,%eax,%eax
shr    $0x12,%eax
mov    %rax,(%rcx)
lea    (%rax,%rax,4),%eax
cvtsi2sd %eax,%xmm0
movl   $0x0,(%r8)
ret
test   %rdi,%rdi
mov    $0x1,%eax
cmovne %rdi,%rax
add    %rax,%rax
lea    (%rax,%rax,4),%rdx
movq   %rdx,%xmm1
punpckldq 0xb14(%rip),%xmm1
mov    %rax,(%rcx)
subpd  0xb19(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
divsd  0xb15(%rip),%xmm0
movl   $0x1,(%r8)
ret

LLVM IR (-O0):
define double @charts_fixmax(i64 %0, i32* %1, i32* %2, i64* %3) {
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i64*
%9 = alloca double
store i64 %0, i64* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i64* %3, i64** %8
%10 = load i64, i64* %5
%11 = icmp ugt i64 %10, 995000000000000000
br i1 %11, label %12, label %25
12: ; preds = %4
%13 = load i64, i64* %5
%14 = add i64 %13, 499999999999999999
%15 = udiv i64 %14, 500000000000000000
%16 = load i64*, i64** %8
store i64 %15, i64* %16
%17 = load i64*, i64** %8
%18 = load i64, i64* %17
%19 = mul i64 %18, 500000000000000000
%20 = uitofp i64 %19 to double
store double %20, double* %9
%21 = load i32*, i32** %7
store i32 1, i32* %21
%22 = load i32*, i32** %6
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 6
store i32 %24, i32* %22
br label %223
25: ; preds = %4
%26 = load i64, i64* %5
%27 = icmp ugt i64 %26, 99500000000000000
br i1 %27, label %28, label %41
28: ; preds = %25
%29 = load i64, i64* %5
%30 = add i64 %29, 4999999999999999
%31 = udiv i64 %30, 5000000000000000
%32 = load i64*, i64** %8
store i64 %31, i64* %32
%33 = load i64*, i64** %8
%34 = load i64, i64* %33
%35 = mul i64 %34, 5000000000000000
%36 = uitofp i64 %35 to double
store double %36, double* %9
%37 = load i32*, i32** %7
store i32 0, i32* %37
%38 = load i32*, i32** %6
%39 = load i32, i32* %38
%40 = add nsw i32 %39, 5
store i32 %40, i32* %38
br label %222
41: ; preds = %25
%42 = load i64, i64* %5
%43 = icmp ugt i64 %42, 995000000000000
br i1 %43, label %44, label %57
44: ; preds = %41
%45 = load i64, i64* %5
%46 = add i64 %45, 499999999999999
%47 = udiv i64 %46, 500000000000000
%48 = load i64*, i64** %8
store i64 %47, i64* %48
%49 = load i64*, i64** %8
%50 = load i64, i64* %49
%51 = mul i64 %50, 500000000000000
%52 = uitofp i64 %51 to double
store double %52, double* %9
%53 = load i32*, i32** %7
store i32 1, i32* %53
%54 = load i32*, i32** %6
%55 = load i32, i32* %54
%56 = add nsw i32 %55, 5
store i32 %56, i32* %54
br label %221
57: ; preds = %41
%58 = load i64, i64* %5
%59 = icmp ugt i64 %58, 99500000000000
br i1 %59, label %60, label %73
60: ; preds = %57
%61 = load i64, i64* %5
%62 = add i64 %61, 4999999999999
%63 = udiv i64 %62, 5000000000000
%64 = load i64*, i64** %8
store i64 %63, i64* %64
%65 = load i64*, i64** %8
%66 = load i64, i64* %65
%67 = mul i64 %66, 5000000000000
%68 = uitofp i64 %67 to double
store double %68, double* %9
%69 = load i32*, i32** %7
store i32 0, i32* %69
%70 = load i32*, i32** %6
%71 = load i32, i32* %70
%72 = add nsw i32 %71, 4
store i32 %72, i32* %70
br label %220
73: ; preds = %57
%74 = load i64, i64* %5
%75 = icmp ugt i64 %74, 995000000000
br i1 %75, label %76, label %89
76: ; preds = %73
%77 = load i64, i64* %5
%78 = add i64 %77, 499999999999
%79 = udiv i64 %78, 500000000000
%80 = load i64*, i64** %8
store i64 %79, i64* %80
%81 = load i64*, i64** %8
%82 = load i64, i64* %81
%83 = mul i64 %82, 500000000000
%84 = uitofp i64 %83 to double
store double %84, double* %9
%85 = load i32*, i32** %7
store i32 1, i32* %85
%86 = load i32*, i32** %6
%87 = load i32, i32* %86
%88 = add nsw i32 %87, 4
store i32 %88, i32* %86
br label %219
89: ; preds = %73
%90 = load i64, i64* %5
%91 = icmp ugt i64 %90, 99500000000
br i1 %91, label %92, label %105
92: ; preds = %89
%93 = load i64, i64* %5
%94 = add i64 %93, 4999999999
%95 = udiv i64 %94, 5000000000
%96 = load i64*, i64** %8
store i64 %95, i64* %96
%97 = load i64*, i64** %8
%98 = load i64, i64* %97
%99 = mul i64 %98, 5000000000
%100 = uitofp i64 %99 to double
store double %100, double* %9
%101 = load i32*, i32** %7
store i32 0, i32* %101
%102 = load i32*, i32** %6
%103 = load i32, i32* %102
%104 = add nsw i32 %103, 3
store i32 %104, i32* %102
br label %218
105: ; preds = %89
%106 = load i64, i64* %5
%107 = icmp ugt i64 %106, 995000000
br i1 %107, label %108, label %121
108: ; preds = %105
%109 = load i64, i64* %5
%110 = add i64 %109, 499999999
%111 = udiv i64 %110, 500000000
%112 = load i64*, i64** %8
store i64 %111, i64* %112
%113 = load i64*, i64** %8
%114 = load i64, i64* %113
%115 = mul i64 %114, 500000000
%116 = uitofp i64 %115 to double
store double %116, double* %9
%117 = load i32*, i32** %7
store i32 1, i32* %117
%118 = load i32*, i32** %6
%119 = load i32, i32* %118
%120 = add nsw i32 %119, 3
store i32 %120, i32* %118
br label %217
121: ; preds = %105
%122 = load i64, i64* %5
%123 = icmp ugt i64 %122, 99500000
br i1 %123, label %124, label %137
124: ; preds = %121
%125 = load i64, i64* %5
%126 = add i64 %125, 4999999
%127 = udiv i64 %126, 5000000
%128 = load i64*, i64** %8
store i64 %127, i64* %128
%129 = load i64*, i64** %8
%130 = load i64, i64* %129
%131 = mul i64 %130, 5000000
%132 = uitofp i64 %131 to double
store double %132, double* %9
%133 = load i32*, i32** %7
store i32 0, i32* %133
%134 = load i32*, i32** %6
%135 = load i32, i32* %134
%136 = add nsw i32 %135, 2
store i32 %136, i32* %134
br label %216
137: ; preds = %121
%138 = load i64, i64* %5
%139 = icmp ugt i64 %138, 995000
br i1 %139, label %140, label %153
140: ; preds = %137
%141 = load i64, i64* %5
%142 = add i64 %141, 499999
%143 = udiv i64 %142, 500000
%144 = load i64*, i64** %8
store i64 %143, i64* %144
%145 = load i64*, i64** %8
%146 = load i64, i64* %145
%147 = mul i64 %146, 500000
%148 = uitofp i64 %147 to double
store double %148, double* %9
%149 = load i32*, i32** %7
store i32 1, i32* %149
%150 = load i32*, i32** %6
%151 = load i32, i32* %150
%152 = add nsw i32 %151, 2
store i32 %152, i32* %150
br label %215
153: ; preds = %137
%154 = load i64, i64* %5
%155 = icmp ugt i64 %154, 99500
br i1 %155, label %156, label %169
156: ; preds = %153
%157 = load i64, i64* %5
%158 = add i64 %157, 4999
%159 = udiv i64 %158, 5000
%160 = load i64*, i64** %8
store i64 %159, i64* %160
%161 = load i64*, i64** %8
%162 = load i64, i64* %161
%163 = mul i64 %162, 5000
%164 = uitofp i64 %163 to double
store double %164, double* %9
%165 = load i32*, i32** %7
store i32 0, i32* %165
%166 = load i32*, i32** %6
%167 = load i32, i32* %166
%168 = add nsw i32 %167, 1
store i32 %168, i32* %166
br label %214
169: ; preds = %153
%170 = load i64, i64* %5
%171 = icmp ugt i64 %170, 995
br i1 %171, label %172, label %185
172: ; preds = %169
%173 = load i64, i64* %5
%174 = add i64 %173, 499
%175 = udiv i64 %174, 500
%176 = load i64*, i64** %8
store i64 %175, i64* %176
%177 = load i64*, i64** %8
%178 = load i64, i64* %177
%179 = mul i64 %178, 500
%180 = uitofp i64 %179 to double
store double %180, double* %9
%181 = load i32*, i32** %7
store i32 1, i32* %181
%182 = load i32*, i32** %6
%183 = load i32, i32* %182
%184 = add nsw i32 %183, 1
store i32 %184, i32* %182
br label %213
185: ; preds = %169
%186 = load i64, i64* %5
%187 = icmp ugt i64 %186, 99
br i1 %187, label %188, label %198
188: ; preds = %185
%189 = load i64, i64* %5
%190 = add i64 %189, 4
%191 = udiv i64 %190, 5
%192 = load i64*, i64** %8
store i64 %191, i64* %192
%193 = load i64*, i64** %8
%194 = load i64, i64* %193
%195 = mul i64 %194, 5
%196 = uitofp i64 %195 to double
store double %196, double* %9
%197 = load i32*, i32** %7
store i32 0, i32* %197
br label %212
198: ; preds = %185
%199 = load i64, i64* %5
%200 = icmp eq i64 %199, 0
br i1 %200, label %201, label %202
201: ; preds = %198
store i64 1, i64* %5
br label %202
202: ; preds = %201, %198
%203 = load i64, i64* %5
%204 = mul i64 %203, 2
%205 = load i64*, i64** %8
store i64 %204, i64* %205
%206 = load i64*, i64** %8
%207 = load i64, i64* %206
%208 = mul i64 %207, 5
%209 = uitofp i64 %208 to double
%210 = fdiv double %209, 1.000000e+01
store double %210, double* %9
%211 = load i32*, i32** %7
store i32 1, i32* %211
br label %212
212: ; preds = %202, %188
br label %213
213: ; preds = %212, %172
br label %214
214: ; preds = %213, %156
br label %215
215: ; preds = %214, %140
br label %216
216: ; preds = %215, %124
br label %217
217: ; preds = %216, %108
br label %218
218: ; preds = %217, %92
br label %219
219: ; preds = %218, %76
br label %220
220: ; preds = %219, %60
br label %221
221: ; preds = %220, %44
br label %222
222: ; preds = %221, %28
br label %223
223: ; preds = %222, %12
%224 = load double, double* %9
ret double %224
}

LLVM IR (-O2):
define double @charts_fixmax(i64 %0, i32* %1, i32* nocapture writeonly %2, i64* nocapture writeonly %3) {
%5 = icmp ugt i64 %0, 995000000000000000
br i1 %5, label %6, label %13
6: ; preds = %4
%7 = add i64 %0, 499999999999999999
%8 = udiv i64 %7, 500000000000000000
store i64 %8, i64* %3
%9 = mul nuw i64 %8, 500000000000000000
%10 = uitofp i64 %9 to double
store i32 1, i32* %2
%11 = load i32, i32* %1
%12 = add nsw i32 %11, 6
store i32 %12, i32* %1
br label %127
13: ; preds = %4
%14 = icmp ugt i64 %0, 99500000000000000
br i1 %14, label %15, label %22
15: ; preds = %13
%16 = add nuw nsw i64 %0, 4999999999999999
%17 = udiv i64 %16, 5000000000000000
store i64 %17, i64* %3
%18 = mul nuw nsw i64 %17, 5000000000000000
%19 = uitofp i64 %18 to double
store i32 0, i32* %2
%20 = load i32, i32* %1
%21 = add nsw i32 %20, 5
store i32 %21, i32* %1
br label %127
22: ; preds = %13
%23 = icmp ugt i64 %0, 995000000000000
br i1 %23, label %24, label %31
24: ; preds = %22
%25 = add nuw nsw i64 %0, 499999999999999
%26 = udiv i64 %25, 500000000000000
store i64 %26, i64* %3
%27 = mul nuw nsw i64 %26, 500000000000000
%28 = uitofp i64 %27 to double
store i32 1, i32* %2
%29 = load i32, i32* %1
%30 = add nsw i32 %29, 5
store i32 %30, i32* %1
br label %127
31: ; preds = %22
%32 = icmp ugt i64 %0, 99500000000000
br i1 %32, label %33, label %40
33: ; preds = %31
%34 = add nuw nsw i64 %0, 4999999999999
%35 = udiv i64 %34, 5000000000000
store i64 %35, i64* %3
%36 = mul nuw nsw i64 %35, 5000000000000
%37 = uitofp i64 %36 to double
store i32 0, i32* %2
%38 = load i32, i32* %1
%39 = add nsw i32 %38, 4
store i32 %39, i32* %1
br label %127
40: ; preds = %31
%41 = icmp ugt i64 %0, 995000000000
br i1 %41, label %42, label %49
42: ; preds = %40
%43 = add nuw nsw i64 %0, 499999999999
%44 = udiv i64 %43, 500000000000
store i64 %44, i64* %3
%45 = mul nuw nsw i64 %44, 500000000000
%46 = uitofp i64 %45 to double
store i32 1, i32* %2
%47 = load i32, i32* %1
%48 = add nsw i32 %47, 4
store i32 %48, i32* %1
br label %127
49: ; preds = %40
%50 = icmp ugt i64 %0, 99500000000
br i1 %50, label %51, label %58
51: ; preds = %49
%52 = add nuw nsw i64 %0, 4999999999
%53 = udiv i64 %52, 5000000000
store i64 %53, i64* %3
%54 = mul nuw nsw i64 %53, 5000000000
%55 = uitofp i64 %54 to double
store i32 0, i32* %2
%56 = load i32, i32* %1
%57 = add nsw i32 %56, 3
store i32 %57, i32* %1
br label %127
58: ; preds = %49
%59 = icmp ugt i64 %0, 995000000
br i1 %59, label %60, label %67
60: ; preds = %58
%61 = add nuw nsw i64 %0, 499999999
%62 = udiv i64 %61, 500000000
store i64 %62, i64* %3
%63 = mul nuw nsw i64 %62, 500000000
%64 = uitofp i64 %63 to double
store i32 1, i32* %2
%65 = load i32, i32* %1
%66 = add nsw i32 %65, 3
store i32 %66, i32* %1
br label %127
67: ; preds = %58
%68 = icmp ugt i64 %0, 99500000
br i1 %68, label %69, label %78
69: ; preds = %67
%70 = trunc i64 %0 to i32
%71 = add nuw nsw i32 %70, 4999999
%72 = udiv i32 %71, 5000000
%73 = zext i32 %72 to i64
store i64 %73, i64* %3
%74 = mul nuw nsw i64 %73, 5000000
%75 = uitofp i64 %74 to double
store i32 0, i32* %2
%76 = load i32, i32* %1
%77 = add nsw i32 %76, 2
store i32 %77, i32* %1
br label %127
78: ; preds = %67
%79 = icmp ugt i64 %0, 995000
br i1 %79, label %80, label %89
80: ; preds = %78
%81 = trunc i64 %0 to i32
%82 = add nuw nsw i32 %81, 499999
%83 = udiv i32 %82, 500000
%84 = zext i32 %83 to i64
store i64 %84, i64* %3
%85 = mul nuw nsw i64 %84, 500000
%86 = uitofp i64 %85 to double
store i32 1, i32* %2
%87 = load i32, i32* %1
%88 = add nsw i32 %87, 2
store i32 %88, i32* %1
br label %127
89: ; preds = %78
%90 = icmp ugt i64 %0, 99500
br i1 %90, label %91, label %100
91: ; preds = %89
%92 = trunc i64 %0 to i32
%93 = add nuw nsw i32 %92, 4999
%94 = udiv i32 %93, 5000
%95 = zext i32 %94 to i64
store i64 %95, i64* %3
%96 = mul nuw nsw i64 %95, 5000
%97 = uitofp i64 %96 to double
store i32 0, i32* %2
%98 = load i32, i32* %1
%99 = add nsw i32 %98, 1
store i32 %99, i32* %1
br label %127
100: ; preds = %89
%101 = icmp ugt i64 %0, 995
br i1 %101, label %102, label %111
102: ; preds = %100
%103 = trunc i64 %0 to i32
%104 = add nuw nsw i32 %103, 499
%105 = udiv i32 %104, 500
%106 = zext i32 %105 to i64
store i64 %106, i64* %3
%107 = mul nuw nsw i64 %106, 500
%108 = uitofp i64 %107 to double
store i32 1, i32* %2
%109 = load i32, i32* %1
%110 = add nsw i32 %109, 1
store i32 %110, i32* %1
br label %127
111: ; preds = %100
%112 = icmp ugt i64 %0, 99
br i1 %112, label %113, label %120
113: ; preds = %111
%114 = trunc i64 %0 to i16
%115 = add nuw nsw i16 %114, 4
%116 = udiv i16 %115, 5
%117 = zext i16 %116 to i64
store i64 %117, i64* %3
%118 = mul nuw nsw i64 %117, 5
%119 = uitofp i64 %118 to double
store i32 0, i32* %2
br label %127
120: ; preds = %111
%121 = icmp eq i64 %0, 0
%122 = select i1 %121, i64 1, i64 %0
%123 = shl nuw nsw i64 %122, 1
store i64 %123, i64* %3
%124 = mul nuw nsw i64 %122, 10
%125 = uitofp i64 %124 to double
%126 = fdiv double %125, 1.000000e+01
store i32 1, i32* %2
br label %127
127: ; preds = %15, %33, %51, %69, %91, %113, %120, %102, %80, %60, %42, %24, %6
%128 = phi double [ %10, %6 ], [ %19, %15 ], [ %28, %24 ], [ %37, %33 ], [ %46, %42 ], [ %55, %51 ], [ %64, %60 ], [ %75, %69 ], [ %86, %80 ], [ %97, %91 ], [ %108, %102 ], [ %119, %113 ], [ %126, %120 ]
ret double %128
}