// File: /workspace/github_cpp_makefile_star2_O3/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 0x2c94e9(%rip), %rax    # 0x33701a
cmpb $0x0, (%rax)
je 0x6db3b
popq %rbx
popq %r14
popq %rbp
retq
cmpl $0x3, %edi
movl $0x3, %r14d
cmovbl %edi, %r14d
xorl %ebx, %ebx
testl %edi, %edi
cmovnsl %r14d, %ebx
testl %ebx, %ebx
je 0x6db73
leaq 0x1ad175(%rip), %rax    # 0x21acd0
cmpl $0x0, (%rax)
je 0x6db73
callq 0x6cbe4
testl %eax, %eax
movl $0x3, %eax
cmovel %eax, %r14d
movl %r14d, %ebx
leaq 0x1ad1a2(%rip), %rax    # 0x21ad1c
movl $0x1, %ecx
movl %ecx, (%rax)
leaq 0x1ad37c(%rip), %rax    # 0x21af04
movl %ecx, (%rax)
leaq 0x1ad27b(%rip), %rax    # 0x21ae0c
movl %ebx, (%rax)
leaq 0x1ad386(%rip), %rax    # 0x21af20
movl %ebx, (%rax)
callq 0x6be07
cmpl $0x3, %ebx
jb 0x6dbd8
callq 0x6cbe4
testl %eax, %eax
je 0x6dc04
leaq 0x2ce66a(%rip), %r14    # 0x33c220
leaq 0xb6388(%rip), %rsi     # 0x123f45
movq %r14, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
movl $0x2be, %esi            # imm = 0x2BE
callq 0x5edda
jmp 0x6dc04
callq 0x6cbe4
testl %ebx, %ebx
je 0x6dc16
testl %eax, %eax
je 0x6dc04
leaq 0x2ce634(%rip), %r14    # 0x33c220
leaq 0xb6352(%rip), %rsi     # 0x123f45
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
jmp 0x6dc37
leaq 0x1ad2e5(%rip), %rax    # 0x21aef0
movl %ebx, (%rax)
popq %rbx
popq %r14
popq %rbp
jmp 0x8fd22
testl %eax, %eax
je 0x6dc41
leaq 0x2ce5ff(%rip), %rbx    # 0x33c220
leaq 0xb631d(%rip), %rsi     # 0x123f45
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
movl $0x2be, %esi            # imm = 0x2BE
callq 0x5edda
leaq 0x1ad2a8(%rip), %rax    # 0x21aef0
movl $0x0, (%rax)
jmp 0x6db36