// File: /workspace/github_cpp_makefile_star2_O3/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 0x1210f(%rip), %rdi     # 0x356bb
leaq 0x120f7(%rip), %rsi     # 0x356aa
callq 0x1f6c0
testq %rax, %rax
je 0x23b8e
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 0x235ef
cmpq %r14, 0x20(%rsp)
jne 0x235d3
movq %rbx, %rdi
callq 0x1f5b0
cmpq %r14, 0x20(%rsp)
jne 0x23b9a
movq %rbp, %rdi
callq 0x1f200
addq %rbp, %rax
decq %rax
movzbl (%rax), %ecx
cmpl $0xd, %ecx
je 0x2361d
cmpl $0xa, %ecx
jne 0x23625
movb $0x0, (%rax)
decq %rax
jmp 0x23610
movq 0x23934(%rip), %r15     # 0x46f60
cmpl $0x0, (%r15)
je 0x23652
leaq 0x121c8(%rip), %rdi     # 0x35801
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x1f050
jmp 0x23652
testl %eax, %eax
je 0x23b5d
incq %rbp
movzbl (%rbp), %eax
cmpl $0x3a, %eax
jne 0x23647
callq 0x1f650
movq %rax, %r14
movq (%rax), %rax
movsbq 0x1(%rbp), %rcx
incq %rbp
movzwl (%rax,%rcx,2), %ecx
btl $0xd, %ecx
jb 0x23666
btl $0xc, %ecx
jae 0x23ba6
movq %rbp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1f830
movq %rax, %rbx
btl $0x17, %ebx
movl (%r15), %eax
jb 0x23914
testl %eax, %eax
je 0x236b6
leaq 0x121e4(%rip), %rdi     # 0x35890
movq %rbp, %rsi
xorl %eax, %eax
callq 0x1f050
movq (%r14), %rax
movsbq (%rbp), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x23bb2
movq %rbp, %rdi
callq 0x1f200
cmpq $0x3, %rax
jbe 0x23bbe
xorl %ecx, %ecx
cmpq $0x4, %rax
setne %cl
movl %ecx, (%r13)
movq %rbp, %rdi
callq 0x1f200
leaq (%rax,%rbp), %r13
addq $-0x4, %r13
leaq 0x120ce(%rip), %rsi     # 0x357cd
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x2399a
leaq 0x120bc(%rip), %rsi     # 0x357d2
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x239b5
leaq 0x121e6(%rip), %rsi     # 0x35913
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x239e8
leaq 0x121d4(%rip), %rsi     # 0x35918
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x239c7
leaq 0x121c2(%rip), %rsi     # 0x3591d
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x239c7
leaq 0x121b0(%rip), %rsi     # 0x35922
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a1d
leaq 0x1219e(%rip), %rsi     # 0x35927
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a42
leaq 0x1218c(%rip), %rsi     # 0x3592c
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a1d
leaq 0x1217a(%rip), %rsi     # 0x35931
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a46
leaq 0x12168(%rip), %rsi     # 0x35936
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a5c
leaq 0x12156(%rip), %rsi     # 0x3593b
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a46
leaq 0x12144(%rip), %rsi     # 0x35940
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a79
leaq 0x12132(%rip), %rsi     # 0x35945
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23aa7
leaq 0x12120(%rip), %rsi     # 0x3594a
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23a79
leaq 0x1210e(%rip), %rsi     # 0x3594f
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23acb
leaq 0x120fc(%rip), %rsi     # 0x35954
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23ae8
leaq 0x120ea(%rip), %rsi     # 0x35959
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b01
leaq 0x120d8(%rip), %rsi     # 0x3595e
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23ae8
leaq 0x120c6(%rip), %rsi     # 0x35963
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b2c
leaq 0x120b4(%rip), %rsi     # 0x35968
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b45
leaq 0x120a2(%rip), %rsi     # 0x3596d
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b69
leaq 0x12090(%rip), %rsi     # 0x35972
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b45
leaq 0x1207e(%rip), %rsi     # 0x35977
movq %r13, %rdi
callq 0x1f820
testl %eax, %eax
je 0x23b7c
xorl %eax, %eax
movl %eax, (%r12)
jmp 0x23b39
testl %eax, %eax
je 0x23928
leaq 0x11f02(%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 0x23a0b
shrl $0xc, %ebx
andl $0xf, %ebx
movl %eax, (%rsp)
leaq 0x11eb9(%rip), %rdi     # 0x35848
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1f050
jmp 0x23a0b
movl $0x1, %eax
movl %eax, (%r12)
xorl %ecx, %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movq 0x10(%rsp), %rdx
movl %ecx, (%rdx)
jmp 0x23a04
movl $0x1, %eax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x239db
movl $0x1, %eax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl $0x2, (%rcx)
movq 0x10(%rsp), %rcx
movl $0x0, (%rcx)
jmp 0x23a04
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 0x23a0b
xorl %eax, %eax
jmp 0x23a4b
movl $0x1, %eax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl $0x2, (%rcx)
jmp 0x239fd
movl $0x1, %eax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl $0x2, (%rcx)
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x23a97
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 0x23a0b
movl $0x3, (%r12)
movl $0x2, %eax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movq 0x10(%rsp), %rcx
movl $0x1, (%rcx)
jmp 0x23a04
movl $0x3, (%r12)
movq 0x8(%rsp), %rax
movl $0x2, (%rax)
movl $0x1, %eax
jmp 0x239fd
movl $0x6, (%r12)
movl $0x1, %eax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x23a70
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 0x23a0b
movl $0x6, (%r12)
movl $0x1, %eax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x239fd
movl $0x2, (%r12)
movq 0x8(%rsp), %rax
movl $0x1, (%rax)
jmp 0x239fb
leaq 0x11bca(%rip), %rdi     # 0x3572e
callq 0x23517
movl $0x2, %eax
movl %eax, (%r12)
movl $0x1, %ecx
jmp 0x239a5
movl $0x2, (%r12)
movl $0x1, %eax
jmp 0x239be
leaq 0x11b17(%rip), %rdi     # 0x356ac
callq 0x23517
leaq 0x11b57(%rip), %rdi     # 0x356f8
callq 0x23517
leaq 0x11ba2(%rip), %rdi     # 0x3574f
callq 0x23517
leaq 0x11cfc(%rip), %rdi     # 0x358b5
callq 0x23517
leaq 0x11d26(%rip), %rdi     # 0x358eb
callq 0x23517