// File: /workspace/github_cpp_makefile_star2_O1/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 0x24a2c
leaq 0x110c8(%rip), %rsi     # 0x35ae1
movl $0x1, %edi
movl %ebx, %edx
xorl %eax, %eax
callq 0x1f270
jmp 0x24ca2
movq %rdx, %r14
movl 0x22d3f(%rip), %eax     # 0x47774
cmpl $0x3, %eax
je 0x24a66
testl %eax, %eax
je 0x24a5d
movl %ebx, %ebp
cmpl $-0x1, %eax
jne 0x24a75
leaq 0x110b9(%rip), %rsi     # 0x35b05
movl $0x1, %edi
xorl %eax, %eax
callq 0x1f270
jmp 0x24ca2
leaq 0x23a14(%rip), %rax     # 0x48478
jmp 0x24a6d
leaq 0x23a13(%rip), %rax     # 0x48480
movq (%rax), %rax
movl %ebx, %ecx
movl (%rax,%rcx,4), %ebp
testl %esi, %esi
je 0x24acf
cmpl $0x1, %esi
je 0x24a8c
cmpl $0x2, %esi
jne 0x24a95
leaq 0x110c8(%rip), %r15     # 0x35b52
jmp 0x24a9c
leaq 0x110b7(%rip), %r15     # 0x35b4a
jmp 0x24a9c
leaq 0x110bd(%rip), %r15     # 0x35b59
leaq 0x110bb(%rip), %rsi     # 0x35b5e
leaq 0x10(%rsp), %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1f090
callq 0x1f120
testl %eax, %eax
js 0x24bd9
je 0x24bf1
movl %eax, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1f450
movslq %ebp, %r12
leaq 0x22ca7(%rip), %r13     # 0x47780
cmpl $-0x1, (%r13,%r12,4)
jne 0x24b15
leaq 0x11103(%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, (%r13,%r12,4)
testl %eax, %eax
js 0x24c27
movl (%r13,%r12,4), %edi
xorl %ebp, %ebp
leaq 0xc(%rsp), %r15
movl $0x541b, %esi           # imm = 0x541B
movq %r15, %rdx
xorl %eax, %eax
callq 0x1f840
cmpl $0x0, (%r15)
jle 0x24b55
leaq 0xb(%rsp), %r15
movl (%r13,%r12,4), %edi
movl $0x1, %edx
movq %r15, %rsi
callq 0x1f890
incl %ebp
cmpl 0xc(%rsp), %ebp
jl 0x24b3b
movl %ebx, %eax
leaq 0x23962(%rip), %rcx     # 0x484c0
movq %r14, (%rcx,%rax,8)
leaq 0x23b57(%rip), %rdi     # 0x486c0
callq 0x1f8a0
movl %ebx, 0x22d0c(%rip)     # 0x47880
leaq 0x140(%rip), %rdx       # 0x24cbb
xorl %ebx, %ebx
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x1fa70
movl 0x22cef(%rip), %eax     # 0x47880
cmpl $-0x1, %eax
je 0x24bc8
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 0x22cbd(%rip), %eax     # 0x47880
cmpl $-0x1, %eax
jne 0x24ba0
leaq 0x23af1(%rip), %rdi     # 0x486c0
callq 0x1f400
jmp 0x24ca7
callq 0x1f040
movl (%rax), %edi
callq 0x1f190
leaq 0x10f75(%rip), %rsi     # 0x35b61
jmp 0x24c93
leaq 0x10f87(%rip), %rdi     # 0x35b7f
movl $0x1, %esi
callq 0x1f9c0
testl %eax, %eax
je 0x24c50
leaq 0x10faa(%rip), %rdi     # 0x35bb7
movl $0x1, %esi
callq 0x1f9c0
testl %eax, %eax
je 0x24c59
leaq 0x10fa3(%rip), %rsi     # 0x35bc5
jmp 0x24a4c
callq 0x1f040
movl (%rax), %edi
callq 0x1f190
leaq 0x10fce(%rip), %rsi     # 0x35c08
leaq 0x40(%rsp), %rdx
movl $0x1, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x1f270
jmp 0x24ca2
leaq 0x10f28(%rip), %rdi     # 0x35b7f
jmp 0x24c60
leaq 0x10f57(%rip), %rdi     # 0x35bb7
leaq 0x10f27(%rip), %rsi     # 0x35b8e
leaq 0x10f25(%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 0x10f05(%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