// File: /workspace/github_c_makefile_star2_O1/canboat[P]canboat/n2kd/gps_ais.c
// Function: aisInteger
static long int aisInteger(const char *msg, const char *fieldName)
{
  typedef struct
  {
    int         hash;
    const char *value;
    long int    min;
    long int    max;
    long int    defValue;
  } intParam;

  // Initialisation of type keys, done at most once
  static const int p1 = 'U' + 's' + 'e' + 'r' + ' ' + 'I' + 'D';
  static const int p2
      = 'C' + 'o' + 'm' + 'm' + 'u' + 'n' + 'i' + 'c' + 'a' + 't' + 'i' + 'o' + 'n' + ' ' + 'S' + 't' + 'a' + 't' + 'e';
  static const int p3 = 'I' + 'M' + 'O' + ' ' + 'n' + 'u' + 'm' + 'b' + 'e' + 'r';
  static const int p4 = 'M' + 'o' + 't' + 'h' + 'e' + 'r' + 's' + 'h' + 'i' + 'p' + ' ' + 'U' + 's' + 'e' + 'r' + ' ' + 'I' + 'D';
  static const int p5 = 'S' + 'o' + 'u' + 'r' + 'c' + 'e' + ' ' + 'I' + 'D';
  static const int p6 = 'S' + 'e' + 'q' + 'u' + 'e' + 'n' + 'c' + 'e' + ' ' + 'N' + 'u' + 'm' + 'b' + 'e' + 'r';
  static const int p7 = 'D' + 'e' + 's' + 't' + 'i' + 'n' + 'a' + 't' + 'i' + 'o' + 'n' + ' ' + 'I' + 'D';
  static const int p8 = 'R' + 'e' + 't' + 'r' + 'a' + 'n' + 's' + 'm' + 'i' + 't' + ' ' + 'f' + 'l' + 'a' + 'g';

  char     jsonString[40];
  int      i, h = 0;
  long int value;

  intParam paramRange[] = {{p1, "User ID", 0, 999999999, 0},
                           {p2, "Communication State", 0, 524287, 393222},
                           {p3, "IMO number", 1000000, 9999999, 0},
                           {p4, "Mothership User ID", 0, 999999999, 0},
                           {p5, "Source ID", 0, 999999999, 0},
                           {p6, "Sequence Number", 0, 3, 0},
                           {p7, "Destination ID", 0, 999999999, 0},
                           {p8, "Retransmit flag", 0, 1, 0}};

  // Calculate index
  for (i = 0; fieldName[i] != '\0'; i++)
  {
    h += fieldName[i];
  }
  for (i = 0; i < sizeof(paramRange) / sizeof(intParam); i++)
  {
    if (paramRange[i].hash == h && !strcmp(fieldName, paramRange[i].value))
    {
      break;
    }
  }

  if (!getJSONValue(msg, fieldName, jsonString, sizeof(jsonString)))
  {
    return paramRange[i].defValue;
  }
  if (jsonString[0] == '\0')
  {
    return paramRange[i].defValue;
  }
  value = atol(jsonString);
  if (value >= paramRange[i].min && value <= paramRange[i].max)
  {
    return value;
  }
  return paramRange[i].defValue;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movb (%rsi), %al
testb %al, %al
je 0x628d
leaq 0x1(%rbx), %rcx
xorl %ebp, %ebp
movsbl %al, %eax
addl %eax, %ebp
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x627d
jmp 0x628f
xorl %ebp, %ebp
leaq 0x76d2(%rip), %r12      # 0xd968
xorl %r15d, %r15d
cmpl %ebp, -0x8(%r12)
jne 0x62b0
movq (%r12), %rsi
movq %rbx, %rdi
callq 0x21d0
testl %eax, %eax
je 0x62c3
incq %r15
addq $0x28, %r12
cmpq $0x8, %r15
jne 0x6299
movl $0x8, %r15d
movq %rsp, %rdx
movl $0x28, %ecx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7c81
testb %al, %al
je 0x6309
cmpb $0x0, (%rsp)
je 0x6309
movq %rsp, %rdi
callq 0x22a0
leaq (%r15,%r15,4), %rcx
leaq 0x766d(%rip), %rdx      # 0xd960
leaq (%rdx,%rcx,8), %rcx
cmpq 0x10(%rcx), %rax
jl 0x6303
cmpq 0x18(%rcx), %rax
jle 0x631f
addq $0x20, %rcx
jmp 0x631c
leaq (%r15,%r15,4), %rax
leaq 0x764c(%rip), %rcx      # 0xd960
leaq (%rcx,%rax,8), %rcx
addq $0x20, %rcx
movq (%rcx), %rax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq