// File: /workspace/github_c_makefile_star2_O1/canboat[P]canboat/analyzer/fieldtype.c
// Function: fixupUnit
void fixupUnit(Field *f)
{
  if (showSI)
  {
    if (strcmp(f->unit, "rad") == 0)
    {
      if (f->hasSign)
      {
        f->rangeMin = max(f->rangeMin, -3.1415926);
        f->rangeMax = min(f->rangeMax, 3.1415926);
      }
      else
      {
        f->rangeMax = min(f->rangeMax, 2 * 3.1415926);
      }
    }

    // Many more to follow, but pgn.h is not yet complete enough...
  }
  else // NOT SI
  {
    if (strcmp(f->unit, "C") == 0)
    {
      f->resolution /= 3600.0; // 3600 C = 1 Ah
      f->rangeMin /= 3600.0;
      f->rangeMax /= 3600.0;
      f->unit = "Ah";
      logDebug("fixup <%s> to '%s'\n", f->name, f->unit);
    }
    else if (strcmp(f->unit, "Pa") == 0)
    {
      f->resolution /= 100000.0;
      f->rangeMin /= 100000.0;
      f->rangeMax /= 100000.0;
      f->precision = 3;
      f->unit      = "bar";
      logDebug("fixup <%s> to '%s'\n", f->name, f->unit);
    }
    else if (strcmp(f->unit, "K") == 0)
    {
      f->unitOffset = -273.15;
      f->rangeMin += -273.15;
      f->rangeMax += -275.15;
      f->precision = 2;
      f->unit      = "C";
      logDebug("fixup <%s> to '%s'\n", f->name, f->unit);
    }
    else if (strcmp(f->unit, "rad") == 0)
    {
      f->resolution *= RadianToDegree;
      f->rangeMin *= RadianToDegree;
      f->rangeMax *= RadianToDegree;
      f->rangeMax  = max(f->rangeMax, 360);
      f->unit      = "deg";
      f->precision = 1;
      logDebug("fixup <%s> to '%s'\n", f->name, f->unit);
    }
    else if (strcmp(f->unit, "rad/s") == 0)
    {
      f->resolution *= RadianToDegree;
      f->rangeMin *= RadianToDegree;
      f->rangeMax *= RadianToDegree;
      f->unit = "deg/s";
      logDebug("fixup <%s> to '%s'\n", f->name, f->unit);
    }
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
leaq 0x6eb46(%rip), %rax     # 0x93140
movq 0x18(%rdi), %r14
cmpb $0x1, (%rax)
jne 0x24659
leaq 0xfc20(%rip), %rsi      # 0x3422a
movq %r14, %rdi
callq 0xd1a0
testl %eax, %eax
jne 0x247da
cmpb $0x1, 0x49(%rbx)
jne 0x247c2
movsd 0x98(%rbx), %xmm0
movsd 0xa0(%rbx), %xmm1
maxsd 0x16a84(%rip), %xmm0    # 0x3b0c0
movsd %xmm0, 0x98(%rbx)
minsd 0x16a7c(%rip), %xmm1    # 0x3b0c8
movsd %xmm1, 0xa0(%rbx)
jmp 0x247da
leaq 0x112a7(%rip), %r15     # 0x35907
movq %r14, %rdi
movq %r15, %rsi
callq 0xd1a0
testl %eax, %eax
je 0x24715
leaq 0x5620(%rip), %rsi      # 0x29c9a
movq %r14, %rdi
callq 0xd1a0
testl %eax, %eax
je 0x2475c
leaq 0x1498f(%rip), %rsi     # 0x39020
movq %r14, %rdi
callq 0xd1a0
testl %eax, %eax
je 0x247e0
leaq 0xfb82(%rip), %rsi      # 0x3422a
movq %r14, %rdi
callq 0xd1a0
testl %eax, %eax
je 0x2483b
leaq 0x19ff5(%rip), %rsi     # 0x3e6b4
movq %r14, %rdi
callq 0xd1a0
testl %eax, %eax
jne 0x247da
movsd 0x169b9(%rip), %xmm0    # 0x3b090
movsd 0x30(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rbx)
movsd 0x98(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x98(%rbx)
mulsd 0xa0(%rbx), %xmm0
movsd %xmm0, 0xa0(%rbx)
leaq 0x19faa(%rip), %rdx     # 0x3e6ba
jmp 0x247a8
movsd 0x30(%rbx), %xmm0
movsd 0x1620e(%rip), %xmm1    # 0x3a930
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rbx)
movsd 0x98(%rbx), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x98(%rbx)
movsd 0xa0(%rbx), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rbx)
leaq 0x188b9(%rip), %rdx     # 0x3d013
jmp 0x247a8
movsd 0x30(%rbx), %xmm0
movsd 0x16947(%rip), %xmm1    # 0x3b0b0
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rbx)
movsd 0x98(%rbx), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x98(%rbx)
movsd 0xa0(%rbx), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rbx)
movl $0x3, 0x38(%rbx)
leaq 0x19f08(%rip), %rdx     # 0x3e6b0
movq %rdx, 0x18(%rbx)
movq (%rbx), %rsi
leaq 0x19ee6(%rip), %rdi     # 0x3e69c
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmp 0x254dd
movsd 0xa0(%rbx), %xmm0
minsd 0x168e6(%rip), %xmm0    # 0x3b0b8
movsd %xmm0, 0xa0(%rbx)
popq %rbx
popq %r14
popq %r15
retq
movabsq $-0x3f8eed999999999a, %rax # imm = 0xC071126666666666
movq %rax, 0x40(%rbx)
movsd 0x98(%rbx), %xmm0
addsd 0x168a2(%rip), %xmm0    # 0x3b0a0
movsd %xmm0, 0x98(%rbx)
movsd 0xa0(%rbx), %xmm0
addsd 0x16892(%rip), %xmm0    # 0x3b0a8
movsd %xmm0, 0xa0(%rbx)
movl $0x2, 0x38(%rbx)
movq %r15, 0x18(%rbx)
movq (%rbx), %rsi
leaq 0x19e69(%rip), %rdi     # 0x3e69c
movq %r15, %rdx
jmp 0x247b6
movsd 0x1684d(%rip), %xmm0    # 0x3b090
movsd 0x30(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rbx)
movsd 0x98(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x98(%rbx)
mulsd 0xa0(%rbx), %xmm0
maxsd 0x16823(%rip), %xmm0    # 0x3b098
movsd %xmm0, 0xa0(%rbx)
leaq 0x17cae(%rip), %rdx     # 0x3c532
movq %rdx, 0x18(%rbx)
movl $0x1, 0x38(%rbx)
jmp 0x247ac