// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %rsp
movl %edi, %ebx
cmpl $0x40, %edi
jb 0x247df
leaq 0xf313(%rip), %rsi      # 0x33ae1
pushq $0x1
popq %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x1f380
jmp 0x24a2e
movq %rdx, %r12
movl 0x2524c(%rip), %eax     # 0x49a34
movl %ebx, %r14d
cmpl $0x3, %eax
je 0x2481a
testl %eax, %eax
je 0x24811
movl %ebx, %ebp
cmpl $-0x1, %eax
jne 0x24828
leaq 0xf303(%rip), %rsi      # 0x33b05
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x1f380
jmp 0x24a2e
leaq 0x25f20(%rip), %rax     # 0x4a738
jmp 0x24821
leaq 0x25f1f(%rip), %rax     # 0x4a740
movq (%rax), %rax
movl (%rax,%r14,4), %ebp
testl %esi, %esi
je 0x24882
cmpl $0x1, %esi
je 0x2483f
cmpl $0x2, %esi
jne 0x24848
leaq 0xf315(%rip), %r15      # 0x33b52
jmp 0x2484f
leaq 0xf304(%rip), %r15      # 0x33b4a
jmp 0x2484f
leaq 0xf30a(%rip), %r15      # 0x33b59
leaq 0xf308(%rip), %rsi      # 0x33b5e
leaq 0x10(%rsp), %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1f0b0
callq 0x1f190
testl %eax, %eax
js 0x2496d
je 0x24985
movl %eax, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1f610
movq %r14, 0x20(%rsp)
movslq %ebp, %r13
leaq 0x251af(%rip), %r14     # 0x49a40
movl (%r14,%r13,4), %edi
cmpl $-0x1, %edi
jne 0x248cd
leaq 0xf34a(%rip), %rsi      # 0x33beb
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1f0b0
pushq $0x2
popq %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x1f540
movl %eax, %edi
movl %eax, (%r14,%r13,4)
testl %eax, %eax
js 0x249b7
movq %r12, 0x18(%rsp)
xorl %ebp, %ebp
leaq 0xc(%rsp), %rdx
movl $0x541b, %esi           # imm = 0x541B
xorl %eax, %eax
callq 0x1fba0
leaq 0xb(%rsp), %r15
pushq $0x1
popq %r12
cmpl 0xc(%rsp), %ebp
jge 0x24907
movl (%r14,%r13,4), %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1fc60
incl %ebp
jmp 0x248ee
leaq 0x25e72(%rip), %rax     # 0x4a780
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq %rcx, (%rax,%rdx,8)
leaq 0x2605d(%rip), %rdi     # 0x4a980
callq 0x1fc70
movl %ebx, 0x25212(%rip)     # 0x49b40
leaq 0x10b(%rip), %rdx       # 0x24a40
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x1ff70
pushq $0x1
popq %rbx
movl 0x251f4(%rip), %eax     # 0x49b40
cmpl $-0x1, %eax
je 0x2495a
movl %ebx, %edi
callq 0x1f630
jmp 0x24946
leaq 0x2601f(%rip), %rdi     # 0x4a980
callq 0x1f590
xorl %eax, %eax
jmp 0x24a31
callq 0x1f040
movl (%rax), %edi
callq 0x1f230
leaq 0xf1e1(%rip), %rsi      # 0x33b61
jmp 0x24a21
leaq 0xf1f3(%rip), %rdi      # 0x33b7f
pushq $0x1
popq %rsi
callq 0x1fe30
testl %eax, %eax
je 0x249de
leaq 0xf218(%rip), %rdi      # 0x33bb7
pushq $0x1
popq %rsi
callq 0x1fe30
testl %eax, %eax
je 0x249e7
leaq 0xf213(%rip), %rsi      # 0x33bc5
jmp 0x24802
callq 0x1f040
movl (%rax), %edi
callq 0x1f230
leaq 0xf23e(%rip), %rsi      # 0x33c08
pushq $0x1
popq %rdi
leaq 0x30(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1f380
jmp 0x24a2e
leaq 0xf19a(%rip), %rdi      # 0x33b7f
jmp 0x249ee
leaq 0xf1c9(%rip), %rdi      # 0x33bb7
leaq 0xf199(%rip), %rsi      # 0x33b8e
leaq 0xf197(%rip), %rdx      # 0x33b93
leaq 0x10(%rsp), %rcx
movq %r15, %r8
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x1fa30
callq 0x1f040
movl (%rax), %edi
callq 0x1f230
leaq 0xf177(%rip), %rsi      # 0x33b98
pushq $0x1
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1f380
pushq $-0x1
popq %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq