// File: /workspace/github_cpp_makefile_star2_O1/mrlordkaj[P]i2cdevlib-pi/Arduino/wiringPi/wiringPi.c
// Function: piBoardId
void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)
{
  FILE *cpuFd ;
  char line [120] ;
  char *c ;
  unsigned int revision ;
  int bRev, bType, bProc, bMfg, bMem, bWarranty ;

//	Will deal with the properly later on - for now, lets just get it going...
//  unsigned int modelNum ;

  (void)piGpioLayout () ;	// Call this first to make sure all's OK. Don't care about the result.

  if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
    piGpioLayoutOops ("Unable to open /proc/cpuinfo") ;

  while (fgets (line, 120, cpuFd) != NULL)
    if (strncmp (line, "Revision", 8) == 0)
      break ;

  fclose (cpuFd) ;

  if (strncmp (line, "Revision", 8) != 0)
    piGpioLayoutOops ("No \"Revision\" line") ;

// Chomp trailing CR/NL

  for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c)
    *c = 0 ;

  if (wiringPiDebug)
    printf ("piBoardId: Revision string: %s\n", line) ;

// Need to work out if it's using the new or old encoding scheme:

// Scan to the first character of the revision number

  for (c = line ; *c ; ++c)
    if (*c == ':')
      break ;

  if (*c != ':')
    piGpioLayoutOops ("Bogus \"Revision\" line (no colon)") ;

// Chomp spaces

  ++c ;
  while (isspace (*c))
    ++c ;

  if (!isxdigit (*c))
    piGpioLayoutOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ;

  revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x

// Check for new way:

  if ((revision &  (1 << 23)) != 0)	// New way
  {
    if (wiringPiDebug)
      printf ("piBoardId: New Way: revision is: %08X\n", revision) ;

    bRev      = (revision & (0x0F <<  0)) >>  0 ;
    bType     = (revision & (0xFF <<  4)) >>  4 ;
    bProc     = (revision & (0x0F << 12)) >> 12 ;	// Not used for now.
    bMfg      = (revision & (0x0F << 16)) >> 16 ;
    bMem      = (revision & (0x07 << 20)) >> 20 ;
    bWarranty = (revision & (0x03 << 24)) != 0 ;

    *model    = bType ;
    *rev      = bRev ;
    *mem      = bMem ;
    *maker    = bMfg  ;
    *warranty = bWarranty ;

    if (wiringPiDebug)
      printf ("piBoardId: rev: %d, type: %d, proc: %d, mfg: %d, mem: %d, warranty: %d\n",
		bRev, bType, bProc, bMfg, bMem, bWarranty) ;
  }
  else					// Old way
  {
    if (wiringPiDebug)
      printf ("piBoardId: Old Way: revision is: %s\n", c) ;

    if (!isdigit (*c))
      piGpioLayoutOops ("Bogus \"Revision\" line (no digit at start of revision)") ;

// Make sure its long enough

    if (strlen (c) < 4)
      piGpioLayoutOops ("Bogus \"Revision\" line (not long enough)") ;

// If longer than 4, we'll assume it's been overvolted

    *warranty = strlen (c) > 4 ;

// Extract last 4 characters:

    c = c + strlen (c) - 4 ;

// Fill out the replys as appropriate

    /**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B  ; *rev = PI_VERSION_1   ; *mem = 0 ; *maker = PI_MAKER_EGOMAN  ; }
    else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B  ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN  ; }

    else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B  ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_SONY    ; }
    else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B  ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN  ; }
    else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B  ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN  ; }

    else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A  ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN  ; }
    else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A  ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ;  ; }
    else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_A  ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN  ; }

    else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B  ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN  ; }
    else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B  ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY    ; }
    else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B  ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN  ; }

    else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY    ; }
    else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_EMBEST  ; }
    else if (strcmp (c, "0016") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY    ; }
    else if (strcmp (c, "0019") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN  ; }

    else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_1 ; *mem = 1 ; *maker = PI_MAKER_SONY    ; }
    else if (strcmp (c, "0014") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_1 ; *mem = 1 ; *maker = PI_MAKER_EMBEST  ; }
    else if (strcmp (c, "0017") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_1 ; *mem = 1 ; *maker = PI_MAKER_SONY    ; }
    else if (strcmp (c, "001a") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_1 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN  ; }

    else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_SONY    ; }
    else if (strcmp (c, "0015") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 1 ; *maker = PI_MAKER_EMBEST  ; }
    else if (strcmp (c, "0018") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_SONY    ; }
    else if (strcmp (c, "001b") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN  ; }

    else                              { *model = 0           ; *rev = 0              ; *mem =   0 ; *maker = 0 ;               }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r8, %r13
movq %rcx, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
callq 0x1fb20
leaq 0x120c9(%rip), %rdi     # 0x356bb
leaq 0x120b1(%rip), %rsi     # 0x356aa
callq 0x1f6c0
testq %rax, %rax
je 0x23bdc
movq %rax, %rbx
movabsq $0x6e6f697369766552, %r14 # imm = 0x6E6F697369766552
leaq 0x20(%rsp), %rbp
movq %rbp, %rdi
movl $0x78, %esi
movq %rbx, %rdx
callq 0x1f940
testq %rax, %rax
je 0x23635
cmpq %r14, 0x20(%rsp)
jne 0x23619
movq %rbx, %rdi
callq 0x1f5b0
cmpq %r14, 0x20(%rsp)
jne 0x23be8
movq %rbp, %rdi
callq 0x1f200
addq %rbp, %rax
decq %rax
movzbl (%rax), %ecx
cmpl $0xd, %ecx
je 0x23663
cmpl $0xa, %ecx
jne 0x2366b
movb $0x0, (%rax)
decq %rax
jmp 0x23656
movq 0x238ee(%rip), %r15     # 0x46f60
cmpl $0x0, (%r15)
je 0x23698
leaq 0x12182(%rip), %rdi     # 0x35801
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x1f050
jmp 0x23698
testl %eax, %eax
je 0x23bab
incq %rbp
movzbl (%rbp), %eax
cmpl $0x3a, %eax
jne 0x2368d
callq 0x1f650
movq %rax, %r14
movq (%rax), %rax
movsbq 0x1(%rbp), %rcx
incq %rbp
movzwl (%rax,%rcx,2), %ecx
btl $0xd, %ecx
jb 0x236ac
btl $0xc, %ecx
jae 0x23bf4
movq %rbp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1f830
movq %rax, %rbx
btl $0x17, %ebx
movl (%r15), %eax
jb 0x23962
testl %eax, %eax
je 0x236fc
leaq 0x1219e(%rip), %rdi     # 0x35890
movq %rbp, %rsi
xorl %eax, %eax
callq 0x1f050
movq (%r14), %rax
movsbq (%rbp), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x23c00
movq %rbp, %rdi
callq 0x1f200
cmpq $0x3, %rax
jbe 0x23c0c
movq %rbp, %rdi
callq 0x1f200
xorl %ecx, %ecx
cmpq $0x5, %rax
setae %cl
movl %ecx, (%r13)
movq %rbp, %rdi
callq 0x1f200
leaq (%rax,%rbp), %r13
addq $-0x4, %r13
leaq 0x12080(%rip), %rsi     # 0x357cd
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x239e8
leaq 0x1206e(%rip), %rsi     # 0x357d2
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a03
leaq 0x12198(%rip), %rsi     # 0x35913
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a36
leaq 0x12186(%rip), %rsi     # 0x35918
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a15
leaq 0x12174(%rip), %rsi     # 0x3591d
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a15
leaq 0x12162(%rip), %rsi     # 0x35922
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a6b
leaq 0x12150(%rip), %rsi     # 0x35927
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a90
leaq 0x1213e(%rip), %rsi     # 0x3592c
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a6b
leaq 0x1212c(%rip), %rsi     # 0x35931
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a94
leaq 0x1211a(%rip), %rsi     # 0x35936
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23aaa
leaq 0x12108(%rip), %rsi     # 0x3593b
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a94
leaq 0x120f6(%rip), %rsi     # 0x35940
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23ac7
leaq 0x120e4(%rip), %rsi     # 0x35945
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23af5
leaq 0x120d2(%rip), %rsi     # 0x3594a
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23ac7
leaq 0x120c0(%rip), %rsi     # 0x3594f
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b19
leaq 0x120ae(%rip), %rsi     # 0x35954
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b36
leaq 0x1209c(%rip), %rsi     # 0x35959
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b4f
leaq 0x1208a(%rip), %rsi     # 0x3595e
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b36
leaq 0x12078(%rip), %rsi     # 0x35963
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b7a
leaq 0x12066(%rip), %rsi     # 0x35968
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b93
leaq 0x12054(%rip), %rsi     # 0x3596d
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23bb7
leaq 0x12042(%rip), %rsi     # 0x35972
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b93
leaq 0x12030(%rip), %rsi     # 0x35977
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23bca
xorl %eax, %eax
movl %eax, (%r12)
jmp 0x23b87
testl %eax, %eax
je 0x23976
leaq 0x11eb4(%rip), %rdi     # 0x35821
movl %ebx, %esi
xorl %eax, %eax
callq 0x1f050
movl %ebx, %esi
andl $0xf, %esi
movl %ebx, %eax
shrl $0x4, %eax
movzbl %al, %edx
movl %ebx, %r8d
shrl $0x10, %r8d
andl $0xf, %r8d
movl %ebx, %r9d
shrl $0x14, %r9d
andl $0x7, %r9d
xorl %eax, %eax
testl $0x3000000, %ebx        # imm = 0x3000000
setne %al
movl %edx, (%r12)
movq 0x8(%rsp), %rcx
movl %esi, (%rcx)
movq 0x10(%rsp), %rcx
movl %r9d, (%rcx)
movq 0x18(%rsp), %rcx
movl %r8d, (%rcx)
movl %eax, (%r13)
cmpl $0x0, (%r15)
je 0x23a59
shrl $0xc, %ebx
andl $0xf, %ebx
movl %eax, (%rsp)
leaq 0x11e6b(%rip), %rdi     # 0x35848
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1f050
jmp 0x23a59
movl $0x1, %eax
movl %eax, (%r12)
xorl %ecx, %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movq 0x10(%rsp), %rdx
movl %ecx, (%rdx)
jmp 0x23a52
movl $0x1, %eax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x23a29
movl $0x1, %eax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl $0x2, (%rcx)
movq 0x10(%rsp), %rcx
movl $0x0, (%rcx)
jmp 0x23a52
movl $0x1, (%r12)
movq 0x8(%rsp), %rax
movl $0x2, (%rax)
xorl %eax, %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
movq 0x18(%rsp), %rcx
movl %eax, (%rcx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl $0x2, (%rcx)
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
movq 0x18(%rsp), %rax
movl $0x1, (%rax)
jmp 0x23a59
xorl %eax, %eax
jmp 0x23a99
movl $0x1, %eax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl $0x2, (%rcx)
jmp 0x23a4b
movl $0x1, %eax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl $0x2, (%rcx)
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x23ae5
movl $0x3, (%r12)
movq 0x8(%rsp), %rax
movl $0x2, (%rax)
movq 0x10(%rsp), %rax
movl $0x1, (%rax)
movq 0x18(%rsp), %rax
movl $0x0, (%rax)
jmp 0x23a59
movl $0x3, (%r12)
movl $0x2, %eax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movq 0x10(%rsp), %rcx
movl $0x1, (%rcx)
jmp 0x23a52
movl $0x3, (%r12)
movq 0x8(%rsp), %rax
movl $0x2, (%rax)
movl $0x1, %eax
jmp 0x23a4b
movl $0x6, (%r12)
movl $0x1, %eax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x23abe
movl $0x6, (%r12)
movl $0x1, %eax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
movq 0x18(%rsp), %rax
movl $0x2, (%rax)
jmp 0x23a59
movl $0x6, (%r12)
movl $0x1, %eax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x23a4b
movl $0x2, (%r12)
movq 0x8(%rsp), %rax
movl $0x1, (%rax)
jmp 0x23a49
leaq 0x11b7c(%rip), %rdi     # 0x3572e
callq 0x2355d
movl $0x2, %eax
movl %eax, (%r12)
movl $0x1, %ecx
jmp 0x239f3
movl $0x2, (%r12)
movl $0x1, %eax
jmp 0x23a0c
leaq 0x11ac9(%rip), %rdi     # 0x356ac
callq 0x2355d
leaq 0x11b09(%rip), %rdi     # 0x356f8
callq 0x2355d
leaq 0x11b54(%rip), %rdi     # 0x3574f
callq 0x2355d
leaq 0x11cae(%rip), %rdi     # 0x358b5
callq 0x2355d
leaq 0x11cd8(%rip), %rdi     # 0x358eb
callq 0x2355d