#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
unsigned int inb(int);
int /*<<< orphan*/ iopl(int);
int /*<<< orphan*/ outb(int, int);
int /*<<< orphan*/ stderr;
unsigned int probe_chip(void) {
  unsigned int ChipType, temp;
  iopl(3);
  outb(0x3D6, 0x00);
  temp = inb(0x3D7);
  ChipType = 0;
  if (temp != 0xA5) {
    if ((temp & 0xF0) == 0x70) {
      ChipType = 0x1;
    }
    if ((temp & 0xF0) == 0x80) {
      ChipType = 0x3;
    }
    if ((temp & 0xF0) == 0xA0) {
      ChipType = 0x4;
    }
    if ((temp & 0xF0) == 0xB0) {
      ChipType = 0x16;
    }
    if ((temp & 0xF0) == 0xC0) {
      ChipType = 0x11;
    }
    if ((temp & 0xF8) == 0xD0) {
      ChipType = 0x12;
    }
    if ((temp & 0xF8) == 0xD8) {
      switch (temp & 0x07) {
      case 3:
        ChipType = 0x14;
        break;
      case 4:
        ChipType = 0x15;
        break;
      default:
        ChipType = 0x13;
      }
    }
  }
  if ((temp != 0) && (ChipType == 0)) {
    outb(0x3D6, 0x02);
    temp = inb(0x03D7);
    if (temp == 0xE0) {
      ChipType = 0x31;
    }
    if (temp == 0xE4) {
      ChipType = 0x32;
    }
    if (temp == 0xE5) {
      ChipType = 0x33;
    }
    if (temp == 0xF4) {
      ChipType = 0x34;
    }
    if (temp == 0xC0) {
      ChipType = 0x35;
    }
    if (temp == 0x30) {
      outb(0x3D6, 0x03);
      temp = inb(0x03D7);
      if (temp == 0x0C)
        ChipType = 0x36;
    }
  }
  iopl(0);
  if (ChipType == 0) {
    fprintf(stderr, "Not a Chips and Technologies Chipset\n");
  }
  return ChipType;
}


x86 assembly (clang, -O0):
<probe_chip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3,%edi
call   1030 <iopl@plt>
mov    $0x3d6,%edi
xor    %esi,%esi
call   1040 <outb@plt>
mov    $0x3d7,%edi
call   1060 <inb@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0xa5,-0x8(%rbp)
je     127d <probe_chip+0x13d>
mov    -0x8(%rbp),%eax
and    $0xf0,%eax
cmp    $0x70,%eax
jne    1197 <probe_chip+0x57>
movl   $0x1,-0x4(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf0,%eax
cmp    $0x80,%eax
jne    11b1 <probe_chip+0x71>
movl   $0x3,-0x4(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf0,%eax
cmp    $0xa0,%eax
jne    11cb <probe_chip+0x8b>
movl   $0x4,-0x4(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf0,%eax
cmp    $0xb0,%eax
jne    11e5 <probe_chip+0xa5>
movl   $0x16,-0x4(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf0,%eax
cmp    $0xc0,%eax
jne    11ff <probe_chip+0xbf>
movl   $0x11,-0x4(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf8,%eax
cmp    $0xd0,%eax
jne    1219 <probe_chip+0xd9>
movl   $0x12,-0x4(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf8,%eax
cmp    $0xd8,%eax
jne    1278 <probe_chip+0x138>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
mov    %eax,-0xc(%rbp)
sub    $0x3,%eax
je     1254 <probe_chip+0x114>
jmp    1243 <probe_chip+0x103>
mov    -0xc(%rbp),%eax
sub    $0x4,%eax
je     1260 <probe_chip+0x120>
jmp    126c <probe_chip+0x12c>
movl   $0x14,-0x4(%rbp)
jmp    1273 <probe_chip+0x133>
movl   $0x15,-0x4(%rbp)
jmp    1273 <probe_chip+0x133>
movl   $0x13,-0x4(%rbp)
jmp    1278 <probe_chip+0x138>
jmp    127d <probe_chip+0x13d>
cmpl   $0x0,-0x8(%rbp)
je     1352 <probe_chip+0x212>
cmpl   $0x0,-0x4(%rbp)
jne    1352 <probe_chip+0x212>
mov    $0x3d6,%edi
mov    $0x2,%esi
call   1040 <outb@plt>
mov    $0x3d7,%edi
call   1060 <inb@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xe0,-0x8(%rbp)
jne    12c1 <probe_chip+0x181>
movl   $0x31,-0x4(%rbp)
cmpl   $0xe4,-0x8(%rbp)
jne    12d5 <probe_chip+0x195>
movl   $0x32,-0x4(%rbp)
cmpl   $0xe5,-0x8(%rbp)
jne    12e9 <probe_chip+0x1a9>
movl   $0x33,-0x4(%rbp)
cmpl   $0xf4,-0x8(%rbp)
jne    12fd <probe_chip+0x1bd>
movl   $0x34,-0x4(%rbp)
cmpl   $0xc0,-0x8(%rbp)
jne    1311 <probe_chip+0x1d1>
movl   $0x35,-0x4(%rbp)
cmpl   $0x30,-0x8(%rbp)
jne    134d <probe_chip+0x20d>
mov    $0x3d6,%edi
mov    $0x3,%esi
call   1040 <outb@plt>
mov    $0x3d7,%edi
call   1060 <inb@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xc,-0x8(%rbp)
jne    1348 <probe_chip+0x208>
movl   $0x36,-0x4(%rbp)
jmp    134d <probe_chip+0x20d>
jmp    1352 <probe_chip+0x212>
xor    %edi,%edi
call   1030 <iopl@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1378 <probe_chip+0x238>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
lea    0xc8d(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<probe_chip>:
push   %rbp
push   %rbx
push   %rax
mov    $0x3,%ebp
mov    $0x3,%edi
call   1030 <iopl@plt>
xor    %ebx,%ebx
mov    $0x3d6,%edi
xor    %esi,%esi
call   1040 <outb@plt>
mov    $0x3d7,%edi
call   1060 <inb@plt>
cmp    $0xa5,%eax
je     11f6 <probe_chip+0xb6>
mov    %eax,%ecx
and    $0xf0,%ecx
xor    %edx,%edx
cmp    $0x70,%ecx
sete   %dl
cmp    $0x80,%ecx
cmove  %ebp,%edx
cmp    $0xa0,%ecx
mov    $0x4,%esi
cmovne %edx,%esi
cmp    $0xb0,%ecx
mov    $0x16,%edx
cmovne %esi,%edx
cmp    $0xc0,%ecx
mov    $0x11,%ecx
cmovne %edx,%ecx
mov    %eax,%edx
and    $0xf8,%edx
cmp    $0xd0,%edx
mov    $0x12,%ebx
cmovne %ecx,%ebx
cmp    $0xd8,%edx
jne    11f6 <probe_chip+0xb6>
and    $0x7,%eax
xor    %ecx,%ecx
cmp    $0x4,%eax
sete   %cl
add    %ecx,%ecx
add    $0x13,%ecx
cmp    $0x3,%eax
mov    $0x14,%ebp
cmovne %ecx,%ebp
jmp    128a <probe_chip+0x14a>
test   %eax,%eax
je     1295 <probe_chip+0x155>
test   %ebx,%ebx
jne    1295 <probe_chip+0x155>
mov    $0x3d6,%edi
mov    $0x2,%esi
call   1040 <outb@plt>
mov    $0x3d7,%edi
call   1060 <inb@plt>
xor    %ecx,%ecx
cmp    $0xe0,%eax
mov    $0x31,%edx
cmovne %ecx,%edx
cmp    $0xe4,%eax
mov    $0x32,%ecx
cmovne %edx,%ecx
cmp    $0xe5,%eax
mov    $0x33,%edx
cmovne %ecx,%edx
cmp    $0xf4,%eax
mov    $0x34,%ecx
cmovne %edx,%ecx
cmp    $0xc0,%eax
mov    $0x35,%ebx
cmovne %ecx,%ebx
cmp    $0x30,%eax
jne    1295 <probe_chip+0x155>
mov    $0x3d6,%edi
mov    $0x3,%esi
call   1040 <outb@plt>
mov    $0x3d7,%edi
call   1060 <inb@plt>
mov    $0x36,%ebp
cmp    $0xc,%eax
jne    1295 <probe_chip+0x155>
xor    %edi,%edi
call   1030 <iopl@plt>
mov    %ebp,%ebx
jmp    12b7 <probe_chip+0x177>
xor    %edi,%edi
call   1030 <iopl@plt>
test   %ebx,%ebx
jne    12b7 <probe_chip+0x177>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xd50(%rip),%rsi
call   1050 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"Not a Chips and Technologies Chipset\0A\00"
define i32 @probe_chip() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @iopl(i32 3)
%4 = call i32 @outb(i32 982, i32 0)
%5 = call i32 @inb(i32 983)
store i32 %5, i32* %2
store i32 0, i32* %1
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 165
br i1 %7, label %8, label %50
8: ; preds = %0
%9 = load i32, i32* %2
%10 = and i32 %9, 240
%11 = icmp eq i32 %10, 112
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 1, i32* %1
br label %13
13: ; preds = %12, %8
%14 = load i32, i32* %2
%15 = and i32 %14, 240
%16 = icmp eq i32 %15, 128
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 3, i32* %1
br label %18
18: ; preds = %17, %13
%19 = load i32, i32* %2
%20 = and i32 %19, 240
%21 = icmp eq i32 %20, 160
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 4, i32* %1
br label %23
23: ; preds = %22, %18
%24 = load i32, i32* %2
%25 = and i32 %24, 240
%26 = icmp eq i32 %25, 176
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 22, i32* %1
br label %28
28: ; preds = %27, %23
%29 = load i32, i32* %2
%30 = and i32 %29, 240
%31 = icmp eq i32 %30, 192
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 17, i32* %1
br label %33
33: ; preds = %32, %28
%34 = load i32, i32* %2
%35 = and i32 %34, 248
%36 = icmp eq i32 %35, 208
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 18, i32* %1
br label %38
38: ; preds = %37, %33
%39 = load i32, i32* %2
%40 = and i32 %39, 248
%41 = icmp eq i32 %40, 216
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = load i32, i32* %2
%44 = and i32 %43, 7
switch i32 %44, label %47 [
i32 3, label %45
i32 4, label %46
]
45: ; preds = %42
store i32 20, i32* %1
br label %48
46: ; preds = %42
store i32 21, i32* %1
br label %48
47: ; preds = %42
store i32 19, i32* %1
br label %48
48: ; preds = %47, %46, %45
br label %49
49: ; preds = %48, %38
br label %50
50: ; preds = %49, %0
%51 = load i32, i32* %2
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %89
53: ; preds = %50
%54 = load i32, i32* %1
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %89
56: ; preds = %53
%57 = call i32 @outb(i32 982, i32 2)
%58 = call i32 @inb(i32 983)
store i32 %58, i32* %2
%59 = load i32, i32* %2
%60 = icmp eq i32 %59, 224
br i1 %60, label %61, label %62
61: ; preds = %56
store i32 49, i32* %1
br label %62
62: ; preds = %61, %56
%63 = load i32, i32* %2
%64 = icmp eq i32 %63, 228
br i1 %64, label %65, label %66
65: ; preds = %62
store i32 50, i32* %1
br label %66
66: ; preds = %65, %62
%67 = load i32, i32* %2
%68 = icmp eq i32 %67, 229
br i1 %68, label %69, label %70
69: ; preds = %66
store i32 51, i32* %1
br label %70
70: ; preds = %69, %66
%71 = load i32, i32* %2
%72 = icmp eq i32 %71, 244
br i1 %72, label %73, label %74
73: ; preds = %70
store i32 52, i32* %1
br label %74
74: ; preds = %73, %70
%75 = load i32, i32* %2
%76 = icmp eq i32 %75, 192
br i1 %76, label %77, label %78
77: ; preds = %74
store i32 53, i32* %1
br label %78
78: ; preds = %77, %74
%79 = load i32, i32* %2
%80 = icmp eq i32 %79, 48
br i1 %80, label %81, label %88
81: ; preds = %78
%82 = call i32 @outb(i32 982, i32 3)
%83 = call i32 @inb(i32 983)
store i32 %83, i32* %2
%84 = load i32, i32* %2
%85 = icmp eq i32 %84, 12
br i1 %85, label %86, label %87
86: ; preds = %81
store i32 54, i32* %1
br label %87
87: ; preds = %86, %81
br label %88
88: ; preds = %87, %78
br label %89
89: ; preds = %88, %53, %50
%90 = call i32 @iopl(i32 0)
%91 = load i32, i32* %1
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %89
%94 = load i32, i32* @stderr
%95 = call i32 @fprintf(i32 %94, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %96
96: ; preds = %93, %89
%97 = load i32, i32* %1
ret i32 %97
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"Not a Chips and Technologies Chipset\0A\00"
define i32 @probe_chip() {
%1 = tail call i32 @iopl(i32 3)
%2 = tail call i32 @outb(i32 982, i32 0)
%3 = tail call i32 @inb(i32 983)
%4 = icmp eq i32 %3, 165
br i1 %4, label %27, label %5
5: ; preds = %0
%6 = and i32 %3, 240
%7 = icmp eq i32 %6, 112
%8 = zext i1 %7 to i32
%9 = icmp eq i32 %6, 128
%10 = select i1 %9, i32 3, i32 %8
%11 = icmp eq i32 %6, 160
%12 = select i1 %11, i32 4, i32 %10
%13 = icmp eq i32 %6, 176
%14 = select i1 %13, i32 22, i32 %12
%15 = icmp eq i32 %6, 192
%16 = select i1 %15, i32 17, i32 %14
%17 = and i32 %3, 248
%18 = icmp eq i32 %17, 208
%19 = select i1 %18, i32 18, i32 %16
%20 = icmp eq i32 %17, 216
br i1 %20, label %21, label %27
21: ; preds = %5
%22 = and i32 %3, 7
%23 = icmp eq i32 %22, 4
%24 = select i1 %23, i32 21, i32 19
%25 = icmp eq i32 %22, 3
%26 = select i1 %25, i32 20, i32 %24
br label %50
27: ; preds = %5, %0
%28 = phi i32 [ %19, %5 ], [ 0, %0 ]
%29 = icmp ne i32 %3, 0
%30 = icmp eq i32 %28, 0
%31 = select i1 %29, i1 %30, i1 false
br i1 %31, label %32, label %53
32: ; preds = %27
%33 = tail call i32 @outb(i32 982, i32 2)
%34 = tail call i32 @inb(i32 983)
%35 = icmp eq i32 %34, 224
%36 = select i1 %35, i32 49, i32 0
%37 = icmp eq i32 %34, 228
%38 = select i1 %37, i32 50, i32 %36
%39 = icmp eq i32 %34, 229
%40 = select i1 %39, i32 51, i32 %38
%41 = icmp eq i32 %34, 244
%42 = select i1 %41, i32 52, i32 %40
%43 = icmp eq i32 %34, 192
%44 = select i1 %43, i32 53, i32 %42
%45 = icmp eq i32 %34, 48
br i1 %45, label %46, label %53
46: ; preds = %32
%47 = tail call i32 @outb(i32 982, i32 3)
%48 = tail call i32 @inb(i32 983)
%49 = icmp eq i32 %48, 12
br i1 %49, label %50, label %53
50: ; preds = %21, %46
%51 = phi i32 [ %26, %21 ], [ 54, %46 ]
%52 = tail call i32 @iopl(i32 0)
br label %60
53: ; preds = %46, %32, %27
%54 = phi i32 [ %44, %32 ], [ %28, %27 ], [ %44, %46 ]
%55 = tail call i32 @iopl(i32 0)
%56 = icmp eq i32 %54, 0
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = tail call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %60
60: ; preds = %50, %57, %53
%61 = phi i32 [ %51, %50 ], [ 0, %57 ], [ %54, %53 ]
ret i32 %61
}