// File: /workspace/github_cpp_makefile_star2_O3/mrlordkaj[P]i2cdevlib-pi/Arduino/wiringPi/wiringPi.c
// Function: wiringPiISR
int wiringPiISR (int pin, int mode, void (*function)(void))
{
  pthread_t threadId ;
  const char *modeS ;
  char fName   [64] ;
  char  pinS [8] ;
  pid_t pid ;
  int   count, i ;
  char  c ;
  int   bcmGpioPin ;

  if ((pin < 0) || (pin > 63))
    return wiringPiFailure (WPI_FATAL, "wiringPiISR: pin must be 0-63 (%d)\n", pin) ;

  /**/ if (wiringPiMode == WPI_MODE_UNINITIALISED)
    return wiringPiFailure (WPI_FATAL, "wiringPiISR: wiringPi has not been initialised. Unable to continue.\n") ;
  else if (wiringPiMode == WPI_MODE_PINS)
    bcmGpioPin = pinToGpio [pin] ;
  else if (wiringPiMode == WPI_MODE_PHYS)
    bcmGpioPin = physToGpio [pin] ;
  else
    bcmGpioPin = pin ;

// Now export the pin and set the right edge
//	We're going to use the gpio program to do this, so it assumes
//	a full installation of wiringPi. It's a bit 'clunky', but it
//	is a way that will work when we're running in "Sys" mode, as
//	a non-root user. (without sudo)

  if (mode != INT_EDGE_SETUP)
  {
    /**/ if (mode == INT_EDGE_FALLING)
      modeS = "falling" ;
    else if (mode == INT_EDGE_RISING)
      modeS = "rising" ;
    else
      modeS = "both" ;

    sprintf (pinS, "%d", bcmGpioPin) ;

    if ((pid = fork ()) < 0)	// Fail
      return wiringPiFailure (WPI_FATAL, "wiringPiISR: fork failed: %s\n", strerror (errno)) ;

    if (pid == 0)	// Child, exec
    {
      /**/ if (access ("/usr/local/bin/gpio", X_OK) == 0)
      {
	execl ("/usr/local/bin/gpio", "gpio", "edge", pinS, modeS, (char *)NULL) ;
	return wiringPiFailure (WPI_FATAL, "wiringPiISR: execl failed: %s\n", strerror (errno)) ;
      }
      else if (access ("/usr/bin/gpio", X_OK) == 0)
      {
	execl ("/usr/bin/gpio", "gpio", "edge", pinS, modeS, (char *)NULL) ;
	return wiringPiFailure (WPI_FATAL, "wiringPiISR: execl failed: %s\n", strerror (errno)) ;
      }
      else
	return wiringPiFailure (WPI_FATAL, "wiringPiISR: Can't find gpio program\n") ;
    }
    else		// Parent, wait
      waitpid (pid, NULL, 0) ;
  }

// Now pre-open the /sys/class node - but it may already be open if
//	we are in Sys mode...

  if (sysFds [bcmGpioPin] == -1)
  {
    sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ;
    if ((sysFds [bcmGpioPin] = open (fName, O_RDWR)) < 0)
      return wiringPiFailure (WPI_FATAL, "wiringPiISR: unable to open %s: %s\n", fName, strerror (errno)) ;
  }

// Clear any initial pending interrupt

  ioctl (sysFds [bcmGpioPin], FIONREAD, &count) ;
  for (i = 0 ; i < count ; ++i)
    read (sysFds [bcmGpioPin], &c, 1) ;

  isrFunctions [pin] = function ;

  pthread_mutex_lock (&pinMutex) ;
    pinPass = pin ;
    pthread_create (&threadId, NULL, interruptHandler, NULL) ;
    while (pinPass != -1)
      delay (1) ;
  pthread_mutex_unlock (&pinMutex) ;

  return 0 ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edi, %ebx
cmpl $0x40, %edi
jb 0x249c8
leaq 0x1112c(%rip), %rsi     # 0x35ae1
movl $0x1, %edi
movl %ebx, %edx
xorl %eax, %eax
callq 0x1f270
jmp 0x24c3d
movq %rdx, %r14
movl 0x22da3(%rip), %eax     # 0x47774
cmpl $0x3, %eax
je 0x24a02
testl %eax, %eax
je 0x249f9
movl %ebx, %ebp
cmpl $-0x1, %eax
jne 0x24a11
leaq 0x1111d(%rip), %rsi     # 0x35b05
movl $0x1, %edi
xorl %eax, %eax
callq 0x1f270
jmp 0x24c3d
leaq 0x23a78(%rip), %rax     # 0x48478
jmp 0x24a09
leaq 0x23a77(%rip), %rax     # 0x48480
movq (%rax), %rax
movl %ebx, %ecx
movl (%rax,%rcx,4), %ebp
testl %esi, %esi
je 0x24a6b
cmpl $0x1, %esi
je 0x24a28
cmpl $0x2, %esi
jne 0x24a31
leaq 0x1112c(%rip), %r15     # 0x35b52
jmp 0x24a38
leaq 0x1111b(%rip), %r15     # 0x35b4a
jmp 0x24a38
leaq 0x11121(%rip), %r15     # 0x35b59
leaq 0x1111f(%rip), %rsi     # 0x35b5e
leaq 0x10(%rsp), %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1f090
callq 0x1f120
testl %eax, %eax
js 0x24b74
je 0x24b8c
movl %eax, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1f450
movslq %ebp, %r12
leaq 0x22d0b(%rip), %r13     # 0x47780
movl (%r13,%r12,4), %edi
cmpl $-0x1, %edi
jne 0x24ab5
leaq 0x11165(%rip), %rsi     # 0x35beb
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1f090
movq %r15, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x1f3c0
movl %eax, %edi
movl %eax, (%r13,%r12,4)
testl %eax, %eax
js 0x24bc2
xorl %ebp, %ebp
leaq 0xc(%rsp), %r15
movl $0x541b, %esi           # imm = 0x541B
movq %r15, %rdx
xorl %eax, %eax
callq 0x1f840
cmpl $0x0, (%r15)
jle 0x24af0
leaq 0xb(%rsp), %r15
movl (%r13,%r12,4), %edi
movl $0x1, %edx
movq %r15, %rsi
callq 0x1f890
incl %ebp
cmpl 0xc(%rsp), %ebp
jl 0x24ad6
movl %ebx, %eax
leaq 0x239c7(%rip), %rcx     # 0x484c0
movq %r14, (%rcx,%rax,8)
leaq 0x23bbc(%rip), %rdi     # 0x486c0
callq 0x1f8a0
movl %ebx, 0x22d71(%rip)     # 0x47880
leaq 0x140(%rip), %rdx       # 0x24c56
xorl %ebx, %ebx
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x1fa70
movl 0x22d54(%rip), %eax     # 0x47880
cmpl $-0x1, %eax
je 0x24b63
leaq 0x18(%rsp), %r14
leaq 0x30(%rsp), %r15
movq $0x0, 0x18(%rsp)
movq $0xf4240, 0x20(%rsp)    # imm = 0xF4240
movq %r14, %rdi
movq %r15, %rsi
callq 0x1f160
movl 0x22d22(%rip), %eax     # 0x47880
cmpl $-0x1, %eax
jne 0x24b3b
leaq 0x23b56(%rip), %rdi     # 0x486c0
callq 0x1f400
jmp 0x24c42
callq 0x1f040
movl (%rax), %edi
callq 0x1f190
leaq 0x10fda(%rip), %rsi     # 0x35b61
jmp 0x24c2e
leaq 0x10fec(%rip), %rdi     # 0x35b7f
movl $0x1, %esi
callq 0x1f9c0
testl %eax, %eax
je 0x24beb
leaq 0x1100f(%rip), %rdi     # 0x35bb7
movl $0x1, %esi
callq 0x1f9c0
testl %eax, %eax
je 0x24bf4
leaq 0x11008(%rip), %rsi     # 0x35bc5
jmp 0x249e8
callq 0x1f040
movl (%rax), %edi
callq 0x1f190
leaq 0x11033(%rip), %rsi     # 0x35c08
leaq 0x40(%rsp), %rdx
movl $0x1, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x1f270
jmp 0x24c3d
leaq 0x10f8d(%rip), %rdi     # 0x35b7f
jmp 0x24bfb
leaq 0x10fbc(%rip), %rdi     # 0x35bb7
leaq 0x10f8c(%rip), %rsi     # 0x35b8e
leaq 0x10f8a(%rip), %rdx     # 0x35b93
leaq 0x10(%rsp), %rcx
movq %r15, %r8
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x1f740
callq 0x1f040
movl (%rax), %edi
callq 0x1f190
leaq 0x10f6a(%rip), %rsi     # 0x35b98
movl $0x1, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1f270
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq