// File: /workspace/github_c_makefile_star2_O3/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 %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x6a227(%rip), %rax     # 0x86140
movq 0x18(%rdi), %r14
cmpb $0x1, (%rax)
jne 0x1bf85
leaq 0xb075(%rip), %rsi      # 0x26f9e
movq %r14, %rdi
callq 0xd1a0
testl %eax, %eax
jne 0x1c101
cmpb $0x1, 0x49(%rbx)
jne 0x1c0e9
movupd 0x98(%rbx), %xmm0
movapd %xmm0, %xmm1
movhpd 0x11f29(%rip), %xmm1    # xmm1 = xmm1[0],mem[0]
movapd %xmm0, %xmm2
movlpd 0x11f25(%rip), %xmm2    # xmm2 = mem[0],xmm2[1]
cmplepd %xmm1, %xmm2
andpd %xmm2, %xmm0
andnpd 0x11ecc(%rip), %xmm2    # 0x2de40
orpd %xmm0, %xmm2
movupd %xmm2, 0x98(%rbx)
jmp 0x1c101
movzbl (%r14), %eax
cmpl $0x50, %eax
je 0x1c021
cmpl $0x4b, %eax
je 0x1bfe1
cmpl $0x43, %eax
jne 0x1c033
cmpb $0x0, 0x1(%r14)
jne 0x1c033
movsd 0x30(%rbx), %xmm0
divsd 0x116f0(%rip), %xmm0    # 0x2d6a8
movsd %xmm0, 0x30(%rbx)
movupd 0x98(%rbx), %xmm0
divpd 0x11e53(%rip), %xmm0    # 0x2de20
movupd %xmm0, 0x98(%rbx)
leaq 0x13de7(%rip), %rdx     # 0x2fdc3
jmp 0x1c141
cmpb $0x0, 0x1(%r14)
jne 0x1c033
movabsq $-0x3f8eed999999999a, %rax # imm = 0xC071126666666666
movq %rax, 0x40(%rbx)
movupd 0x98(%rbx), %xmm0
addpd 0x11dfa(%rip), %xmm0    # 0x2de00
movupd %xmm0, 0x98(%rbx)
movl $0x2, 0x38(%rbx)
leaq 0xc65f(%rip), %rdx      # 0x2867b
jmp 0x1c141
cmpb $0x61, 0x1(%r14)
jne 0x1c033
cmpb $0x0, 0x2(%r14)
je 0x1c109
leaq 0xaf64(%rip), %rsi      # 0x26f9e
movq %r14, %rdi
callq 0xd1a0
testl %eax, %eax
je 0x1c093
leaq 0x15417(%rip), %rsi     # 0x31464
movq %r14, %rdi
callq 0xd1a0
testl %eax, %eax
jne 0x1c101
movsd 0x30(%rbx), %xmm0
mulsd 0x11dfe(%rip), %xmm0    # 0x2de68
movsd %xmm0, 0x30(%rbx)
movupd 0x98(%rbx), %xmm0
mulpd 0x11db1(%rip), %xmm0    # 0x2de30
movupd %xmm0, 0x98(%rbx)
leaq 0x153dc(%rip), %rdx     # 0x3146a
jmp 0x1c141
movsd 0x11dcd(%rip), %xmm0    # 0x2de68
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 0x11da3(%rip), %xmm0    # 0x2de70
movsd %xmm0, 0xa0(%rbx)
leaq 0x13206(%rip), %rdx     # 0x2f2e2
movq %rdx, 0x18(%rbx)
movl $0x1, 0x38(%rbx)
jmp 0x1c145
movsd 0xa0(%rbx), %xmm0
minsd 0x11d7f(%rip), %xmm0    # 0x2de78
movsd %xmm0, 0xa0(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movsd 0x30(%rbx), %xmm0
divsd 0x11d4a(%rip), %xmm0    # 0x2de60
movsd %xmm0, 0x30(%rbx)
movupd 0x98(%rbx), %xmm0
divpd 0x11ce5(%rip), %xmm0    # 0x2de10
movupd %xmm0, 0x98(%rbx)
movl $0x3, 0x38(%rbx)
leaq 0x1531f(%rip), %rdx     # 0x31460
movq %rdx, 0x18(%rbx)
movq (%rbx), %rsi
leaq 0x152fd(%rip), %rdi     # 0x3144c
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1cd55