// File: mrlordkaj[P]i2cdevlib-pi/Arduino/wiringPi/wiringPi.c
// Function: pinMode
void pinMode (int pin, int mode)
{
  int    fSel, shift, alt ;
  struct wiringPiNodeStruct *node = wiringPiNodes ;
  int origPin = pin ;

  setupCheck ("pinMode") ;

  if ((pin & PI_GPIO_MASK) == 0)		// On-board pin
  {
    /**/ if (wiringPiMode == WPI_MODE_PINS)
      pin = pinToGpio [pin] ;
    else if (wiringPiMode == WPI_MODE_PHYS)
      pin = physToGpio [pin] ;
    else if (wiringPiMode != WPI_MODE_GPIO)
      return ;

    softPwmStop  (origPin) ;
    softToneStop (origPin) ;

    fSel    = gpioToGPFSEL [pin] ;
    shift   = gpioToShift  [pin] ;

    /**/ if (mode == INPUT)
      *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) ; // Sets bits to zero = input
    else if (mode == OUTPUT)
      *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (1 << shift) ;
    else if (mode == SOFT_PWM_OUTPUT)
      softPwmCreate (origPin, 0, 100) ;
    else if (mode == SOFT_TONE_OUTPUT)
      softToneCreate (origPin) ;
    else if (mode == PWM_TONE_OUTPUT)
    {
      pinMode (origPin, PWM_OUTPUT) ;	// Call myself to enable PWM mode
      pwmSetMode (PWM_MODE_MS) ;
    }
    else if (mode == PWM_OUTPUT)
    {
      if ((alt = gpioToPwmALT [pin]) == 0)	// Not a hardware capable PWM pin
	return ;

      usingGpioMemCheck ("pinMode PWM") ;

// Set pin to PWM mode

      *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (alt << shift) ;
      delayMicroseconds (110) ;		// See comments in pwmSetClockWPi

      pwmSetMode  (PWM_MODE_BAL) ;	// Pi default mode
      pwmSetRange (1024) ;		// Default range of 1024
      pwmSetClock (32) ;		// 19.2 / 32 = 600KHz - Also starts the PWM
    }
    else if (mode == GPIO_CLOCK)
    {
      if ((alt = gpioToGpClkALT0 [pin]) == 0)	// Not a GPIO_CLOCK pin
	return ;

      usingGpioMemCheck ("pinMode CLOCK") ;

// Set pin to GPIO_CLOCK mode and set the clock frequency to 100KHz

      *(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | (alt << shift) ;
      delayMicroseconds (110) ;
      gpioClockSet      (pin, 100000) ;
    }
  }
  else
  {
    if ((node = wiringPiFindNode (pin)) != NULL)
      node->pinMode (node, pin, mode) ;
    return ;
  }
}

// Assembly:
subq $0x28, %rsp
movl %edi, 0x24(%rsp)
movl %esi, 0x20(%rsp)
movq 0x301cd(%rip), %rax     # 0x5bfb0
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x4(%rsp)
leaq 0x1f922(%rip), %rdi     # 0x4b71c
callq 0x2bd90
movl 0x24(%rsp), %eax
andl $-0x40, %eax
cmpl $0x0, %eax
jne 0x2c097
cmpl $0x0, 0x30ebe(%rip)     # 0x5ccd4
jne 0x2be2d
movq 0x31e79(%rip), %rax     # 0x5dc98
movslq 0x24(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x24(%rsp)
jmp 0x2be5d
cmpl $0x3, 0x30ea0(%rip)     # 0x5ccd4
jne 0x2be4b
movq 0x31e63(%rip), %rax     # 0x5dca0
movslq 0x24(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x24(%rsp)
jmp 0x2be5b
cmpl $0x1, 0x30e82(%rip)     # 0x5ccd4
je 0x2be59
jmp 0x2c0c5
jmp 0x2be5b
jmp 0x2be5d
movl 0x4(%rsp), %edi
callq 0x22940
movl 0x4(%rsp), %edi
callq 0x227a0
movslq 0x24(%rsp), %rcx
leaq 0x30e65(%rip), %rax     # 0x5cce0
movzbl (%rax,%rcx), %eax
movl %eax, 0x1c(%rsp)
movslq 0x24(%rsp), %rcx
leaq 0x30e91(%rip), %rax     # 0x5cd20
movzbl (%rax,%rcx), %eax
movl %eax, 0x18(%rsp)
cmpl $0x0, 0x20(%rsp)
jne 0x2bed1
movq 0x31e0b(%rip), %rax     # 0x5dcb0
movslq 0x1c(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movl 0x18(%rsp), %ecx
movl $0x7, %eax
shll %cl, %eax
xorl $-0x1, %eax
andl %eax, %edx
movq 0x31dec(%rip), %rax     # 0x5dcb0
movslq 0x1c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x2c095
cmpl $0x1, 0x20(%rsp)
jne 0x2bf18
movq 0x31dd1(%rip), %rax     # 0x5dcb0
movslq 0x1c(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movl 0x18(%rsp), %ecx
movl $0x7, %eax
shll %cl, %eax
xorl $-0x1, %eax
andl %eax, %edx
movl 0x18(%rsp), %ecx
movl $0x1, %eax
shll %cl, %eax
orl %eax, %edx
movq 0x31da5(%rip), %rax     # 0x5dcb0
movslq 0x1c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x2c093
cmpl $0x4, 0x20(%rsp)
jne 0x2bf34
movl 0x4(%rsp), %edi
xorl %esi, %esi
movl $0x64, %edx
callq 0x22200
jmp 0x2c091
cmpl $0x5, 0x20(%rsp)
jne 0x2bf49
movl 0x4(%rsp), %edi
callq 0x227d0
jmp 0x2c08f
cmpl $0x6, 0x20(%rsp)
jne 0x2bf6a
movl 0x4(%rsp), %edi
movl $0x2, %esi
callq 0x22680
xorl %edi, %edi
callq 0x22380
jmp 0x2c08d
cmpl $0x2, 0x20(%rsp)
jne 0x2c006
movslq 0x24(%rsp), %rcx
leaq 0x3146f(%rip), %rax     # 0x5d3f0
movzbl (%rax,%rcx), %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, %eax
jne 0x2bf93
jmp 0x2c0c5
leaq 0x1f78a(%rip), %rdi     # 0x4b724
callq 0x2c0d0
movq 0x31d0a(%rip), %rax     # 0x5dcb0
movslq 0x1c(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movl 0x18(%rsp), %ecx
movl $0x7, %eax
shll %cl, %eax
xorl $-0x1, %eax
andl %eax, %edx
movl 0x14(%rsp), %eax
movl 0x18(%rsp), %ecx
shll %cl, %eax
orl %eax, %edx
movq 0x31cdf(%rip), %rax     # 0x5dcb0
movslq 0x1c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x6e, %edi
callq 0x22650
movl $0x1, %edi
callq 0x22380
movl $0x400, %edi            # imm = 0x400
callq 0x22700
movl $0x20, %edi
callq 0x22a20
jmp 0x2c08b
cmpl $0x3, 0x20(%rsp)
jne 0x2c089
movslq 0x24(%rsp), %rcx
leaq 0x31417(%rip), %rax     # 0x5d430
movzbl (%rax,%rcx), %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, %eax
jne 0x2c02b
jmp 0x2c0c5
leaq 0x1f6fe(%rip), %rdi     # 0x4b730
callq 0x2c0d0
movq 0x31c72(%rip), %rax     # 0x5dcb0
movslq 0x1c(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movl 0x18(%rsp), %ecx
movl $0x7, %eax
shll %cl, %eax
xorl $-0x1, %eax
andl %eax, %edx
movl 0x14(%rsp), %eax
movl 0x18(%rsp), %ecx
shll %cl, %eax
orl %eax, %edx
movq 0x31c47(%rip), %rax     # 0x5dcb0
movslq 0x1c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x6e, %edi
callq 0x22650
movl 0x24(%rsp), %edi
movl $0x186a0, %esi          # imm = 0x186A0
callq 0x22d00
jmp 0x2c08b
jmp 0x2c08d
jmp 0x2c08f
jmp 0x2c091
jmp 0x2c093
jmp 0x2c095
jmp 0x2c0c5
movl 0x24(%rsp), %edi
callq 0x22cd0
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x2c0c3
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rsp), %rdi
movl 0x24(%rsp), %esi
movl 0x20(%rsp), %edx
callq *%rax
jmp 0x2c0c5
addq $0x28, %rsp
retq
nopw (%rax,%rax)