// File: /workspace/github_c_makefile_star2_O2/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 0x6c1e1(%rip), %rax     # 0x87140
movq 0x18(%rdi), %r14
cmpb $0x1, (%rax)
jne 0x1afcb
leaq 0xb02f(%rip), %rsi      # 0x25f9e
movq %r14, %rdi
callq 0xd1a0
testl %eax, %eax
jne 0x1b147
cmpb $0x1, 0x49(%rbx)
jne 0x1b12f
movupd 0x98(%rbx), %xmm0
movapd %xmm0, %xmm1
movhpd 0x11ee3(%rip), %xmm1    # xmm1 = xmm1[0],mem[0]
movapd %xmm0, %xmm2
movlpd 0x11edf(%rip), %xmm2    # xmm2 = mem[0],xmm2[1]
cmplepd %xmm1, %xmm2
andpd %xmm2, %xmm0
andnpd 0x11e86(%rip), %xmm2    # 0x2ce40
orpd %xmm0, %xmm2
movupd %xmm2, 0x98(%rbx)
jmp 0x1b147
movzbl (%r14), %eax
cmpl $0x50, %eax
je 0x1b067
cmpl $0x4b, %eax
je 0x1b027
cmpl $0x43, %eax
jne 0x1b079
cmpb $0x0, 0x1(%r14)
jne 0x1b079
movsd 0x30(%rbx), %xmm0
divsd 0x116aa(%rip), %xmm0    # 0x2c6a8
movsd %xmm0, 0x30(%rbx)
movupd 0x98(%rbx), %xmm0
divpd 0x11e0d(%rip), %xmm0    # 0x2ce20
movupd %xmm0, 0x98(%rbx)
leaq 0x13da1(%rip), %rdx     # 0x2edc3
jmp 0x1b187
cmpb $0x0, 0x1(%r14)
jne 0x1b079
movabsq $-0x3f8eed999999999a, %rax # imm = 0xC071126666666666
movq %rax, 0x40(%rbx)
movupd 0x98(%rbx), %xmm0
addpd 0x11db4(%rip), %xmm0    # 0x2ce00
movupd %xmm0, 0x98(%rbx)
movl $0x2, 0x38(%rbx)
leaq 0xc619(%rip), %rdx      # 0x2767b
jmp 0x1b187
cmpb $0x61, 0x1(%r14)
jne 0x1b079
cmpb $0x0, 0x2(%r14)
je 0x1b14f
leaq 0xaf1e(%rip), %rsi      # 0x25f9e
movq %r14, %rdi
callq 0xd1a0
testl %eax, %eax
je 0x1b0d9
leaq 0x153d1(%rip), %rsi     # 0x30464
movq %r14, %rdi
callq 0xd1a0
testl %eax, %eax
jne 0x1b147
movsd 0x30(%rbx), %xmm0
mulsd 0x11db8(%rip), %xmm0    # 0x2ce68
movsd %xmm0, 0x30(%rbx)
movupd 0x98(%rbx), %xmm0
mulpd 0x11d6b(%rip), %xmm0    # 0x2ce30
movupd %xmm0, 0x98(%rbx)
leaq 0x15396(%rip), %rdx     # 0x3046a
jmp 0x1b187
movsd 0x11d87(%rip), %xmm0    # 0x2ce68
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 0x11d5d(%rip), %xmm0    # 0x2ce70
movsd %xmm0, 0xa0(%rbx)
leaq 0x131c0(%rip), %rdx     # 0x2e2e2
movq %rdx, 0x18(%rbx)
movl $0x1, 0x38(%rbx)
jmp 0x1b18b
movsd 0xa0(%rbx), %xmm0
minsd 0x11d39(%rip), %xmm0    # 0x2ce78
movsd %xmm0, 0xa0(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movsd 0x30(%rbx), %xmm0
divsd 0x11d04(%rip), %xmm0    # 0x2ce60
movsd %xmm0, 0x30(%rbx)
movupd 0x98(%rbx), %xmm0
divpd 0x11c9f(%rip), %xmm0    # 0x2ce10
movupd %xmm0, 0x98(%rbx)
movl $0x3, 0x38(%rbx)
leaq 0x152d9(%rip), %rdx     # 0x30460
movq %rdx, 0x18(%rbx)
movq (%rbx), %rsi
leaq 0x152b7(%rip), %rdi     # 0x3044c
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1bd48