// File: /workspace/github_cpp_makefile_star2_O2/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 0x20090
leaq 0x10230(%rip), %rdi     # 0x336bb
leaq 0x10218(%rip), %rsi     # 0x336aa
callq 0x1f990
testq %rax, %rax
je 0x23a5f
movq %rax, %rbx
movabsq $0x6e6f697369766552, %r15 # imm = 0x6E6F697369766552
leaq 0x20(%rsp), %rbp
pushq $0x78
popq %r14
movq %rbp, %rdi
movl %r14d, %esi
movq %rbx, %rdx
callq 0x1fd60
testq %rax, %rax
je 0x234d0
cmpq %r15, 0x20(%rsp)
jne 0x234b6
movq %rbx, %rdi
callq 0x1f7d0
cmpq %r15, 0x20(%rsp)
jne 0x23a6b
movq %rbp, %rdi
callq 0x1f2c0
addq %rbp, %rax
decq %rax
movzbl (%rax), %ecx
cmpl $0xd, %ecx
je 0x234fe
cmpl $0xa, %ecx
jne 0x23506
movb $0x0, (%rax)
decq %rax
jmp 0x234f1
movq 0x25a53(%rip), %r15     # 0x48f60
cmpl $0x0, (%r15)
je 0x23533
leaq 0x102e7(%rip), %rdi     # 0x33801
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x1f050
jmp 0x23533
testl %eax, %eax
je 0x23a26
incq %rbp
movzbl (%rbp), %eax
cmpl $0x3a, %eax
jne 0x23528
callq 0x1f8c0
movq %rax, %r14
movq (%rax), %rax
movsbq 0x1(%rbp), %rcx
incq %rbp
movzwl (%rax,%rcx,2), %ecx
btl $0xd, %ecx
jb 0x23547
btl $0xc, %ecx
jae 0x23a77
pushq $0x10
popq %rdx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x1fb90
movq %rax, %rbx
btl $0x17, %ebx
movl (%r15), %eax
jb 0x237fa
testl %eax, %eax
je 0x23595
leaq 0x10305(%rip), %rdi     # 0x33890
movq %rbp, %rsi
xorl %eax, %eax
callq 0x1f050
movq (%r14), %rax
movsbq (%rbp), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x23a83
movq %rbp, %rdi
callq 0x1f2c0
cmpq $0x3, %rax
jbe 0x23a8f
xorl %ecx, %ecx
cmpq $0x4, %rax
setne %cl
movl %ecx, (%r13)
movq %rbp, %rdi
callq 0x1f2c0
leaq (%rax,%rbp), %r13
addq $-0x4, %r13
leaq 0x101ef(%rip), %rsi     # 0x337cd
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x2387c
leaq 0x101dd(%rip), %rsi     # 0x337d2
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x2388d
leaq 0x10307(%rip), %rsi     # 0x33913
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x238d0
leaq 0x102f5(%rip), %rsi     # 0x33918
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x2389d
leaq 0x102e3(%rip), %rsi     # 0x3391d
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x2389d
leaq 0x102d1(%rip), %rsi     # 0x33922
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x238f5
leaq 0x102bf(%rip), %rsi     # 0x33927
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x2391a
leaq 0x102ad(%rip), %rsi     # 0x3392c
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x238f5
leaq 0x1029b(%rip), %rsi     # 0x33931
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x23921
leaq 0x10289(%rip), %rsi     # 0x33936
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x2393f
leaq 0x10277(%rip), %rsi     # 0x3393b
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x23921
leaq 0x10265(%rip), %rsi     # 0x33940
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x2395a
leaq 0x10253(%rip), %rsi     # 0x33945
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x2397d
leaq 0x10241(%rip), %rsi     # 0x3394a
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x2395a
leaq 0x1022f(%rip), %rsi     # 0x3394f
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x2399f
leaq 0x1021d(%rip), %rsi     # 0x33954
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x239ba
leaq 0x1020b(%rip), %rsi     # 0x33959
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x239ce
leaq 0x101f9(%rip), %rsi     # 0x3395e
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x239ba
leaq 0x101e7(%rip), %rsi     # 0x33963
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x239f7
leaq 0x101d5(%rip), %rsi     # 0x33968
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x23a0e
leaq 0x101c3(%rip), %rsi     # 0x3396d
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x23a32
leaq 0x101b1(%rip), %rsi     # 0x33972
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x23a0e
leaq 0x1019f(%rip), %rsi     # 0x33977
movq %r13, %rdi
callq 0x1fb80
testl %eax, %eax
je 0x23a4f
andl $0x0, (%r12)
movq 0x8(%rsp), %rax
andl $0x0, (%rax)
jmp 0x238e3
testl %eax, %eax
je 0x2380e
leaq 0x1001c(%rip), %rdi     # 0x33821
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 0x238be
shrl $0xc, %ebx
andl $0xf, %ebx
movl %eax, (%rsp)
leaq 0xffd7(%rip), %rdi      # 0x33848
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1f050
jmp 0x238be
pushq $0x1
popq %rax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
andl $0x0, (%rcx)
jmp 0x238af
pushq $0x1
popq %rax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x238af
pushq $0x1
popq %rax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl $0x2, (%rcx)
movq 0x10(%rsp), %rcx
andl $0x0, (%rcx)
movq 0x18(%rsp), %rcx
movl %eax, (%rcx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, (%r12)
movq 0x8(%rsp), %rax
movl $0x2, (%rax)
movq 0x10(%rsp), %rax
andl $0x0, (%rax)
movq 0x18(%rsp), %rax
andl $0x0, (%rax)
jmp 0x238be
andl $0x0, (%r12)
movq 0x8(%rsp), %rax
movl $0x2, (%rax)
movq 0x10(%rsp), %rax
andl $0x0, (%rax)
movq 0x18(%rsp), %rax
movl $0x1, (%rax)
jmp 0x238be
andl $0x0, (%r12)
jmp 0x238d8
pushq $0x1
popq %rax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl $0x2, (%rcx)
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x238b7
pushq $0x1
popq %rax
movl %eax, (%r12)
movq 0x8(%rsp), %rcx
movl $0x2, (%rcx)
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x238eb
movl $0x3, (%r12)
movq 0x8(%rsp), %rax
movl $0x2, (%rax)
movq 0x10(%rsp), %rax
movl $0x1, (%rax)
jmp 0x238eb
movl $0x3, (%r12)
pushq $0x2
popq %rax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movq 0x10(%rsp), %rcx
movl $0x1, (%rcx)
jmp 0x238b7
movl $0x3, (%r12)
movq 0x8(%rsp), %rax
movl $0x2, (%rax)
pushq $0x1
popq %rax
jmp 0x23933
movl $0x6, (%r12)
pushq $0x1
popq %rax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x23951
movl $0x6, (%r12)
pushq $0x1
popq %rax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
movq 0x18(%rsp), %rax
movl $0x2, (%rax)
jmp 0x238be
movl $0x6, (%r12)
pushq $0x1
popq %rax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x23933
movl $0x2, (%r12)
movq 0x8(%rsp), %rax
movl $0x1, (%rax)
jmp 0x238e3
leaq 0xfd01(%rip), %rdi      # 0x3372e
callq 0x233fb
pushq $0x2
popq %rax
movl %eax, (%r12)
pushq $0x1
popq %rcx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movq 0x10(%rsp), %rdx
movl %ecx, (%rdx)
jmp 0x238b7
movl $0x2, (%r12)
pushq $0x1
popq %rax
jmp 0x23894
leaq 0xfc46(%rip), %rdi      # 0x336ac
callq 0x233fb
leaq 0xfc86(%rip), %rdi      # 0x336f8
callq 0x233fb
leaq 0xfcd1(%rip), %rdi      # 0x3374f
callq 0x233fb
leaq 0xfe2b(%rip), %rdi      # 0x338b5
callq 0x233fb
leaq 0xfe55(%rip), %rdi      # 0x338eb
callq 0x233fb