// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: set_x72_discipline(int)
void set_x72_discipline(int val)
{
   // set the X72 PPS discipline mode
   // 0=off, 1=enabled, lock pin normal mode,  2=enabled, lock pin indicates Rb and disipline locked
   // 3=enable SW discipline on units with firmware capability
   if(read_only) return;

   if(val < 0) val = 0;
   else if(val > 3) val = 3;
//if(debug_file) fprintf(debug_file, "set dmode %d  have_pps:%d  hw:%d\n", val, have_x72_pps, x72_fw_discipline());  //burp
//sprintf(debug_text, "set dmode %d  have_pps:%d  hw:%d", val, have_x72_pps, x72_fw_discipline());

   if(have_x72_pps && val && (x72_fw_discipline() == 0)) {  // can only do software discipline
      val = 3;
   }

   have_x72_dmode = 1;
   user_set_x72_dmode = 1;
   x72_dmode_val = val;
   last_x72_dmode = val;

   save_x72_state();

   if(val > 2) {
      if(x72_fw_discipline()) {  // disable firmware disciplining
         sprintf(out, "g%d", 0);
         queue_x72_cmd(out, X72_SET_DMODE_MSG);
      }
      x72_user_dis = val; // enable SW disciplining
      x72_start_discipline();
   }
   else if(val) {  // enabling discipline
      if(x72_fw_discipline()) {  // firmware disciplining
         sprintf(out, "g%d", val);
         queue_x72_cmd(out, X72_SET_DMODE_MSG);
         x72_user_dis = 0;
      }
      else {  // enable software discipline algorithm
         x72_user_dis = val;
         x72_start_discipline();
      }
   }
   else {  // disabling disipline
      if(x72_fw_discipline()) {  // disable firmware disciplining
         sprintf(out, "g%d", val);
         queue_x72_cmd(out, X72_SET_DMODE_MSG);
      }
      x72_user_dis = val; // disable SW disciplining
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
leaq 0x2bc817(%rip), %rax    # 0x32101a
cmpb $0x0, (%rax)
je 0x64813
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, %edi
pushq $0x3
popq %r15
movl %r15d, %r14d
cmovbl %edi, %r14d
xorl %ebx, %ebx
testl %edi, %edi
cmovnsl %r14d, %ebx
testl %ebx, %ebx
je 0x64847
leaq 0x1a049c(%rip), %rax    # 0x204cd0
cmpl $0x0, (%rax)
je 0x64847
callq 0x63a49
testl %eax, %eax
cmovel %r15d, %r14d
movl %r14d, %ebx
leaq 0x1a04ce(%rip), %rax    # 0x204d1c
pushq $0x1
popq %rcx
movl %ecx, (%rax)
leaq 0x1a06aa(%rip), %rax    # 0x204f04
movl %ecx, (%rax)
leaq 0x1a05a9(%rip), %rax    # 0x204e0c
movl %ebx, (%rax)
leaq 0x1a06b4(%rip), %rax    # 0x204f20
movl %ebx, (%rax)
callq 0x62d03
cmpl $0x3, %ebx
jb 0x648aa
callq 0x63a49
testl %eax, %eax
je 0x648d6
leaq 0x2c1998(%rip), %r14    # 0x326220
leaq 0xa95fe(%rip), %rsi     # 0x10de8d
movq %r14, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
movl $0x2be, %esi            # imm = 0x2BE
callq 0x576d4
jmp 0x648d6
callq 0x63a49
testl %ebx, %ebx
je 0x648ee
testl %eax, %eax
je 0x648d6
leaq 0x2c1962(%rip), %r14    # 0x326220
leaq 0xa95c8(%rip), %rsi     # 0x10de8d
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
jmp 0x6490f
leaq 0x1a0613(%rip), %rax    # 0x204ef0
movl %ebx, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x83005
testl %eax, %eax
je 0x64919
leaq 0x2c1927(%rip), %rbx    # 0x326220
leaq 0xa958d(%rip), %rsi     # 0x10de8d
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
movl $0x2be, %esi            # imm = 0x2BE
callq 0x576d4
leaq 0x1a05d0(%rip), %rax    # 0x204ef0
andl $0x0, (%rax)
jmp 0x64808