// File: /workspace/github_c_makefile_star2_O0/kobolt[P]curses-collection/storage/storage.c
// Function: main
int main(int argc, char *argv[])
{
  int i, max_y, max_x, start_y, start_x, size_y, size_x, horizontal;
  double sum, share, used, value;
  char line[128], *p;
  data_t data[DATA_MAX];

  for (i = 0; i < DATA_MAX; i++) {
    data[i].value = 0.0;
    data[i].text[0] = '\0';
  }
  strncpy(data[DATA_MAX - 1].text, "*OTHER*", TEXT_MAX);

  i = 0;
  while (fgets(line, sizeof(line), stdin) != NULL) {
    p = strtok(line, DATA_DELIMITER);
    if (p == NULL)
      continue;

    value = atof(p);

    p = strtok(NULL, DATA_DELIMITER);
    if (p == NULL)
      continue;

    if (i >= (DATA_MAX - 1)) {
      data[DATA_MAX - 1].value += value;
    } else {
      data[i].value = value;
      strncpy(data[i].text, p, TEXT_MAX);
      data[i].text[TEXT_MAX] = '\0';
      i++;
    }
  }

  /* Sort to get largest value first. */
  qsort(data, DATA_MAX, sizeof(data_t), data_compare);

  sum = 0.0;
  for (i = 0; i < DATA_MAX; i++) {
    if (data[i].value <= 0.0)
      break;
    sum += data[i].value;
  }

  if (sum <= 0.0) {
    return 1; /* Will divide by zero, abort. */
  }

  screen_init(&max_y, &max_x);
  max_x -= TEXT_X_AREA;

  used = 0.0;
  horizontal = start_y = start_x = 0;
  size_y = max_y;
  size_x = max_x;
  for (i = 0; i < DATA_MAX; i++) {
    if (data[i].value <= 0.0)
      break;

    share = data[i].value / (sum - used);

    if (horizontal) {
      size_x = max_x - start_x;
      size_y = share * (double)(max_y - start_y);
      box_draw(i, start_y, start_x, size_y, size_x);
      start_y += size_y;
      horizontal = 0;
    } else {
      size_y = max_y - start_y;
      size_x = share * (double)(max_x - start_x);
      box_draw(i, start_y, start_x, size_y, size_x);
      start_x += size_x;
      horizontal = 1;
    }

    used += data[i].value;
  }

  for (i = 0; i < DATA_MAX; i++) {
    if (data[i].value <= 0.0)
      break;
    text_draw(i, data[i].text, i, max_x + 1);
  }

  move(0,0);
  refresh();
  while (1) {
    sleep(1); /* Ctrl-C to quit! */
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3e0, %rsp            # imm = 0x3E0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x18, -0x14(%rbp)
jge 0x12a0
movslq -0x14(%rbp), %rcx
leaq -0x3e0(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movslq -0x14(%rbp), %rcx
leaq -0x3e0(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movb $0x0, 0x8(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1260
leaq -0x3e0(%rbp), %rdi
addq $0x2e0, %rdi            # imm = 0x2E0
addq $0x8, %rdi
leaq 0xd4b(%rip), %rsi       # 0x2004
movl $0x11, %edx
callq 0x1050
movl $0x0, -0x14(%rbp)
leaq -0xd0(%rbp), %rdi
movq 0x2cf8(%rip), %rax      # 0x3fd0
movq (%rax), %rdx
movl $0x80, %esi
callq 0x10c0
cmpq $0x0, %rax
je 0x13cc
leaq -0xd0(%rbp), %rdi
leaq 0xd0f(%rip), %rsi       # 0x200c
callq 0x10f0
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0xd8(%rbp)
jne 0x1315
jmp 0x12ca
movq -0xd8(%rbp), %rdi
callq 0x1070
movsd %xmm0, -0x50(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0xcdb(%rip), %rsi       # 0x200c
callq 0x10f0
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0xd8(%rbp)
jne 0x1349
jmp 0x12ca
cmpl $0x17, -0x14(%rbp)
jl 0x1366
movsd -0x50(%rbp), %xmm0
addsd -0x100(%rbp), %xmm0
movsd %xmm0, -0x100(%rbp)
jmp 0x13c7
movsd -0x50(%rbp), %xmm0
movslq -0x14(%rbp), %rcx
leaq -0x3e0(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movslq -0x14(%rbp), %rax
leaq -0x3e0(%rbp), %rdi
shlq $0x5, %rax
addq %rax, %rdi
addq $0x8, %rdi
movq -0xd8(%rbp), %rsi
movl $0x11, %edx
callq 0x1050
movslq -0x14(%rbp), %rcx
leaq -0x3e0(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movb $0x0, 0x19(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x12ca
leaq -0x3e0(%rbp), %rdi
movl $0x18, %esi
movl $0x20, %edx
leaq 0x26c(%rip), %rcx       # 0x1650
callq 0x1060
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x18, -0x14(%rbp)
jge 0x1446
movslq -0x14(%rbp), %rcx
leaq -0x3e0(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
jb 0x141b
jmp 0x1446
movslq -0x14(%rbp), %rcx
leaq -0x3e0(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x13f8
xorps %xmm0, %xmm0
ucomisd -0x38(%rbp), %xmm0
jb 0x145e
movl $0x1, %eax
addq $0x3e0, %rsp            # imm = 0x3E0
popq %rbp
retq
leaq -0x18(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x1680
movl -0x1c(%rbp), %eax
subl $0x14, %eax
movl %eax, -0x1c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x18, -0x14(%rbp)
jge 0x15bd
movslq -0x14(%rbp), %rcx
leaq -0x3e0(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
jb 0x14ce
jmp 0x15bd
movslq -0x14(%rbp), %rcx
leaq -0x3e0(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd -0x38(%rbp), %xmm1
subsd -0x48(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x1547
movl -0x1c(%rbp), %eax
subl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movsd -0x40(%rbp), %xmm0
movl -0x18(%rbp), %eax
subl -0x20(%rbp), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x28(%rbp)
movl -0x14(%rbp), %edi
movl -0x20(%rbp), %esi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movl -0x2c(%rbp), %r8d
callq 0x17a0
movl -0x28(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x158f
movl -0x18(%rbp), %eax
subl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
movsd -0x40(%rbp), %xmm0
movl -0x1c(%rbp), %eax
subl -0x24(%rbp), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x2c(%rbp)
movl -0x14(%rbp), %edi
movl -0x20(%rbp), %esi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movl -0x2c(%rbp), %r8d
callq 0x17a0
movl -0x2c(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl $0x1, -0x30(%rbp)
movslq -0x14(%rbp), %rcx
leaq -0x3e0(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x14a4
movl $0x0, -0x14(%rbp)
cmpl $0x18, -0x14(%rbp)
jge 0x1619
movslq -0x14(%rbp), %rcx
leaq -0x3e0(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
jb 0x15e7
jmp 0x1619
movl -0x14(%rbp), %edi
movslq -0x14(%rbp), %rax
leaq -0x3e0(%rbp), %rsi
shlq $0x5, %rax
addq %rax, %rsi
addq $0x8, %rsi
movl -0x14(%rbp), %edx
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
callq 0x18b0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x15c4
movq 0x29b8(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x1100
movq 0x29a5(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
callq 0x10a0
movl $0x1, %edi
callq 0x1130
jmp 0x163b
nopw (%rax,%rax)