// File: /workspace/github_cpp_makefile_star2_O1/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 %r14
pushq %rbx
leaq 0x2c93df(%rip), %rax    # 0x33701a
cmpb $0x0, (%rax)
je 0x6dc45
popq %rbx
popq %r14
popq %rbp
retq
cmpl $0x3, %edi
movl $0x3, %eax
cmovll %edi, %eax
xorl %ebx, %ebx
testl %eax, %eax
cmovgl %eax, %ebx
testl %edi, %edi
jle 0x6dc76
leaq 0x1ad06e(%rip), %rax    # 0x21acd0
cmpl $0x0, (%rax)
je 0x6dc76
callq 0x6cc14
testl %eax, %eax
movl $0x3, %eax
cmovel %eax, %ebx
leaq 0x1ad09f(%rip), %rax    # 0x21ad1c
movl $0x1, %ecx
movl %ecx, (%rax)
leaq 0x1ad279(%rip), %rax    # 0x21af04
movl %ecx, (%rax)
leaq 0x1ad178(%rip), %rax    # 0x21ae0c
movl %ebx, (%rax)
leaq 0x1ad283(%rip), %rax    # 0x21af20
movl %ebx, (%rax)
callq 0x6bcbc
cmpl $0x3, %ebx
jl 0x6dcdb
callq 0x6cc14
testl %eax, %eax
je 0x6dd07
leaq 0x2ce567(%rip), %r14    # 0x33c220
leaq 0xb61a5(%rip), %rsi     # 0x123e65
movq %r14, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
movl $0x2be, %esi            # imm = 0x2BE
callq 0x5ee52
jmp 0x6dd07
callq 0x6cc14
testl %ebx, %ebx
je 0x6dd19
testl %eax, %eax
je 0x6dd07
leaq 0x2ce531(%rip), %r14    # 0x33c220
leaq 0xb616f(%rip), %rsi     # 0x123e65
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
jmp 0x6dd3a
leaq 0x1ad1e2(%rip), %rax    # 0x21aef0
movl %ebx, (%rax)
popq %rbx
popq %r14
popq %rbp
jmp 0x8fcc8
testl %eax, %eax
je 0x6dd44
leaq 0x2ce4fc(%rip), %rbx    # 0x33c220
leaq 0xb613a(%rip), %rsi     # 0x123e65
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
movl $0x2be, %esi            # imm = 0x2BE
callq 0x5ee52
leaq 0x1ad1a5(%rip), %rax    # 0x21aef0
movl $0x0, (%rax)
jmp 0x6dc40