#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 inb(int);
int /*<<< orphan*/ outb(int, int);
int /*<<< orphan*/ outw(int, int);
void unlockS3(void) {
  int s3_device_id;
  outw(0x3d4, 0x3848);
  outw(0x3d4, 0x39a5);
  outb(0x3d4, 0x2d);
  s3_device_id = inb(0x3d5) << 8;
  outb(0x3d4, 0x2e);
  s3_device_id |= inb(0x3d5);
  if (s3_device_id != 0x8812) {
    outb(0x46E8, 0x10);
    outb(0x3C3, 0x10);
    outb(0x102, 0x01);
    outb(0x46E8, 0x08);
    outb(0x3C3, 0x08);
    outb(0x4AE8, 0x00);
    outb(0x3D4, 0x38);
    outb(0x3D5, 0x48);
    outb(0x3D4, 0x39);
    outb(0x3D5, 0xA5);
    outb(0x3D4, 0x40);
    outb(0x3D5, inb(0x3D5) | 0x01);
    outb(0x3D4, 0x33);
    outb(0x3D5, inb(0x3D5) & ~0x52);
    outb(0x3D4, 0x35);
    outb(0x3D5, inb(0x3D5) & ~0x30);
    outb(0x3D4, 0x3A);
    outb(0x3D5, 0x00);
    outb(0x3D4, 0x53);
    outb(0x3D5, 0x00);
    outb(0x3D4, 0x31);
    outb(0x3D5, inb(0x3D5) & ~0x4B);
    outb(0x3D4, 0x58);
    outb(0x3D5, 0);
    outb(0x3D4, 0x54);
    outb(0x3D5, 0x38);
    outb(0x3D4, 0x60);
    outb(0x3D5, 0x07);
    outb(0x3D4, 0x61);
    outb(0x3D5, 0x80);
    outb(0x3D4, 0x62);
    outb(0x3D5, 0xA1);
    outb(0x3D4, 0x69);
    outb(0x3D5, 0);
    outb(0x3D4, 0x32);
    outb(0x3D5, inb(0x3D5) & ~0x10);
  } else {
    outw(0x3c4, 0x0806);
    outw(0x3c4, 0x1041);
    outw(0x3c4, 0x1128);
    outw(0x3d4, 0x4000);
    outw(0x3d4, 0x3100);
    outw(0x3d4, 0x3a05);
    outw(0x3d4, 0x6688);
    outw(0x3d4, 0x5800);
    outw(0x3d4, 0x4500);
    outw(0x3c4, 0x5410);
    outw(0x3c4, 0x561f);
    outw(0x3c4, 0x1b80);
    outw(0x3d4, 0x3900);
    outw(0x3d4, 0x3800);
  }
}


x86 assembly (clang, -O0):
<unlockS3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3d4,%edi
mov    $0x3848,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x39a5,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x2d,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
shl    $0x8,%eax
mov    %eax,-0x4(%rbp)
mov    $0x3d4,%edi
mov    $0x2e,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x8812,-0x4(%rbp)
je     13e5 <unlockS3+0x2b5>
mov    $0x46e8,%edi
mov    $0x10,%esi
call   1030 <outb@plt>
mov    $0x3c3,%edi
mov    $0x10,%esi
call   1030 <outb@plt>
mov    $0x102,%edi
mov    $0x1,%esi
call   1030 <outb@plt>
mov    $0x46e8,%edi
mov    $0x8,%esi
call   1030 <outb@plt>
mov    $0x3c3,%edi
mov    $0x8,%esi
call   1030 <outb@plt>
mov    $0x4ae8,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x38,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
mov    $0x48,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x39,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
mov    $0xa5,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x40,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
mov    %eax,%esi
or     $0x1,%esi
mov    $0x3d5,%edi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x33,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
mov    %eax,%esi
and    $0xffffffad,%esi
mov    $0x3d5,%edi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x35,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
mov    %eax,%esi
and    $0xffffffcf,%esi
mov    $0x3d5,%edi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x3a,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x53,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x31,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
mov    %eax,%esi
and    $0xffffffb4,%esi
mov    $0x3d5,%edi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x58,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x54,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
mov    $0x38,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x60,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
mov    $0x7,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x61,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
mov    $0x80,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x62,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
mov    $0xa1,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x69,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x32,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
mov    %eax,%esi
and    $0xffffffef,%esi
mov    $0x3d5,%edi
call   1030 <outb@plt>
jmp    14b7 <unlockS3+0x387>
mov    $0x3c4,%edi
mov    $0x806,%esi
call   1050 <outw@plt>
mov    $0x3c4,%edi
mov    $0x1041,%esi
call   1050 <outw@plt>
mov    $0x3c4,%edi
mov    $0x1128,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x4000,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x3100,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x3a05,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x6688,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x5800,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x4500,%esi
call   1050 <outw@plt>
mov    $0x3c4,%edi
mov    $0x5410,%esi
call   1050 <outw@plt>
mov    $0x3c4,%edi
mov    $0x561f,%esi
call   1050 <outw@plt>
mov    $0x3c4,%edi
mov    $0x1b80,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x3900,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x3800,%esi
call   1050 <outw@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unlockS3>:
push   %rbx
mov    $0x3d4,%edi
mov    $0x3848,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x39a5,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x2d,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
mov    $0x3d4,%edi
mov    $0x2e,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
or     %ebx,%eax
cmp    $0x8812,%eax
jne    1266 <unlockS3+0x136>
mov    $0x3c4,%edi
mov    $0x806,%esi
call   1050 <outw@plt>
mov    $0x3c4,%edi
mov    $0x1041,%esi
call   1050 <outw@plt>
mov    $0x3c4,%edi
mov    $0x1128,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x4000,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x3100,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x3a05,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x6688,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x5800,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x4500,%esi
call   1050 <outw@plt>
mov    $0x3c4,%edi
mov    $0x5410,%esi
call   1050 <outw@plt>
mov    $0x3c4,%edi
mov    $0x561f,%esi
call   1050 <outw@plt>
mov    $0x3c4,%edi
mov    $0x1b80,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x3900,%esi
call   1050 <outw@plt>
mov    $0x3d4,%edi
mov    $0x3800,%esi
pop    %rbx
jmp    1050 <outw@plt>
mov    $0x46e8,%edi
mov    $0x10,%esi
call   1030 <outb@plt>
mov    $0x3c3,%edi
mov    $0x10,%esi
call   1030 <outb@plt>
mov    $0x102,%edi
mov    $0x1,%esi
call   1030 <outb@plt>
mov    $0x46e8,%edi
mov    $0x8,%esi
call   1030 <outb@plt>
mov    $0x3c3,%edi
mov    $0x8,%esi
call   1030 <outb@plt>
mov    $0x4ae8,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x38,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
mov    $0x48,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x39,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
mov    $0xa5,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x40,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
or     $0x1,%eax
mov    $0x3d5,%edi
mov    %eax,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x33,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
and    $0xffffffad,%eax
mov    $0x3d5,%edi
mov    %eax,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x35,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
and    $0xffffffcf,%eax
mov    $0x3d5,%edi
mov    %eax,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x3a,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x53,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x31,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
and    $0xffffffb4,%eax
mov    $0x3d5,%edi
mov    %eax,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x58,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x54,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
mov    $0x38,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x60,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
mov    $0x7,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x61,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
mov    $0x80,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x62,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
mov    $0xa1,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x69,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
xor    %esi,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0x32,%esi
call   1030 <outb@plt>
mov    $0x3d5,%edi
call   1040 <inb@plt>
and    $0xffffffef,%eax
mov    $0x3d5,%edi
mov    %eax,%esi
pop    %rbx
jmp    1030 <outb@plt>

LLVM IR (-O0):
define void @unlockS3() {
%1 = alloca i32
%2 = call i32 @outw(i32 980, i32 14408)
%3 = call i32 @outw(i32 980, i32 14757)
%4 = call i32 @outb(i32 980, i32 45)
%5 = call i32 @inb(i32 981)
%6 = shl i32 %5, 8
store i32 %6, i32* %1
%7 = call i32 @outb(i32 980, i32 46)
%8 = call i32 @inb(i32 981)
%9 = load i32, i32* %1
%10 = or i32 %9, %8
store i32 %10, i32* %1
%11 = load i32, i32* %1
%12 = icmp ne i32 %11, 34834
br i1 %12, label %13, label %60
13: ; preds = %0
%14 = call i32 @outb(i32 18152, i32 16)
%15 = call i32 @outb(i32 963, i32 16)
%16 = call i32 @outb(i32 258, i32 1)
%17 = call i32 @outb(i32 18152, i32 8)
%18 = call i32 @outb(i32 963, i32 8)
%19 = call i32 @outb(i32 19176, i32 0)
%20 = call i32 @outb(i32 980, i32 56)
%21 = call i32 @outb(i32 981, i32 72)
%22 = call i32 @outb(i32 980, i32 57)
%23 = call i32 @outb(i32 981, i32 165)
%24 = call i32 @outb(i32 980, i32 64)
%25 = call i32 @inb(i32 981)
%26 = or i32 %25, 1
%27 = call i32 @outb(i32 981, i32 %26)
%28 = call i32 @outb(i32 980, i32 51)
%29 = call i32 @inb(i32 981)
%30 = and i32 %29, -83
%31 = call i32 @outb(i32 981, i32 %30)
%32 = call i32 @outb(i32 980, i32 53)
%33 = call i32 @inb(i32 981)
%34 = and i32 %33, -49
%35 = call i32 @outb(i32 981, i32 %34)
%36 = call i32 @outb(i32 980, i32 58)
%37 = call i32 @outb(i32 981, i32 0)
%38 = call i32 @outb(i32 980, i32 83)
%39 = call i32 @outb(i32 981, i32 0)
%40 = call i32 @outb(i32 980, i32 49)
%41 = call i32 @inb(i32 981)
%42 = and i32 %41, -76
%43 = call i32 @outb(i32 981, i32 %42)
%44 = call i32 @outb(i32 980, i32 88)
%45 = call i32 @outb(i32 981, i32 0)
%46 = call i32 @outb(i32 980, i32 84)
%47 = call i32 @outb(i32 981, i32 56)
%48 = call i32 @outb(i32 980, i32 96)
%49 = call i32 @outb(i32 981, i32 7)
%50 = call i32 @outb(i32 980, i32 97)
%51 = call i32 @outb(i32 981, i32 128)
%52 = call i32 @outb(i32 980, i32 98)
%53 = call i32 @outb(i32 981, i32 161)
%54 = call i32 @outb(i32 980, i32 105)
%55 = call i32 @outb(i32 981, i32 0)
%56 = call i32 @outb(i32 980, i32 50)
%57 = call i32 @inb(i32 981)
%58 = and i32 %57, -17
%59 = call i32 @outb(i32 981, i32 %58)
br label %75
60: ; preds = %0
%61 = call i32 @outw(i32 964, i32 2054)
%62 = call i32 @outw(i32 964, i32 4161)
%63 = call i32 @outw(i32 964, i32 4392)
%64 = call i32 @outw(i32 980, i32 16384)
%65 = call i32 @outw(i32 980, i32 12544)
%66 = call i32 @outw(i32 980, i32 14853)
%67 = call i32 @outw(i32 980, i32 26248)
%68 = call i32 @outw(i32 980, i32 22528)
%69 = call i32 @outw(i32 980, i32 17664)
%70 = call i32 @outw(i32 964, i32 21520)
%71 = call i32 @outw(i32 964, i32 22047)
%72 = call i32 @outw(i32 964, i32 7040)
%73 = call i32 @outw(i32 980, i32 14592)
%74 = call i32 @outw(i32 980, i32 14336)
br label %75
75: ; preds = %60, %13
ret void
}

LLVM IR (-O2):
define void @unlockS3() {
%1 = tail call i32 @outw(i32 980, i32 14408)
%2 = tail call i32 @outw(i32 980, i32 14757)
%3 = tail call i32 @outb(i32 980, i32 45)
%4 = tail call i32 @inb(i32 981)
%5 = shl i32 %4, 8
%6 = tail call i32 @outb(i32 980, i32 46)
%7 = tail call i32 @inb(i32 981)
%8 = or i32 %7, %5
%9 = icmp eq i32 %8, 34834
br i1 %9, label %57, label %10
10: ; preds = %0
%11 = tail call i32 @outb(i32 18152, i32 16)
%12 = tail call i32 @outb(i32 963, i32 16)
%13 = tail call i32 @outb(i32 258, i32 1)
%14 = tail call i32 @outb(i32 18152, i32 8)
%15 = tail call i32 @outb(i32 963, i32 8)
%16 = tail call i32 @outb(i32 19176, i32 0)
%17 = tail call i32 @outb(i32 980, i32 56)
%18 = tail call i32 @outb(i32 981, i32 72)
%19 = tail call i32 @outb(i32 980, i32 57)
%20 = tail call i32 @outb(i32 981, i32 165)
%21 = tail call i32 @outb(i32 980, i32 64)
%22 = tail call i32 @inb(i32 981)
%23 = or i32 %22, 1
%24 = tail call i32 @outb(i32 981, i32 %23)
%25 = tail call i32 @outb(i32 980, i32 51)
%26 = tail call i32 @inb(i32 981)
%27 = and i32 %26, -83
%28 = tail call i32 @outb(i32 981, i32 %27)
%29 = tail call i32 @outb(i32 980, i32 53)
%30 = tail call i32 @inb(i32 981)
%31 = and i32 %30, -49
%32 = tail call i32 @outb(i32 981, i32 %31)
%33 = tail call i32 @outb(i32 980, i32 58)
%34 = tail call i32 @outb(i32 981, i32 0)
%35 = tail call i32 @outb(i32 980, i32 83)
%36 = tail call i32 @outb(i32 981, i32 0)
%37 = tail call i32 @outb(i32 980, i32 49)
%38 = tail call i32 @inb(i32 981)
%39 = and i32 %38, -76
%40 = tail call i32 @outb(i32 981, i32 %39)
%41 = tail call i32 @outb(i32 980, i32 88)
%42 = tail call i32 @outb(i32 981, i32 0)
%43 = tail call i32 @outb(i32 980, i32 84)
%44 = tail call i32 @outb(i32 981, i32 56)
%45 = tail call i32 @outb(i32 980, i32 96)
%46 = tail call i32 @outb(i32 981, i32 7)
%47 = tail call i32 @outb(i32 980, i32 97)
%48 = tail call i32 @outb(i32 981, i32 128)
%49 = tail call i32 @outb(i32 980, i32 98)
%50 = tail call i32 @outb(i32 981, i32 161)
%51 = tail call i32 @outb(i32 980, i32 105)
%52 = tail call i32 @outb(i32 981, i32 0)
%53 = tail call i32 @outb(i32 980, i32 50)
%54 = tail call i32 @inb(i32 981)
%55 = and i32 %54, -17
%56 = tail call i32 @outb(i32 981, i32 %55)
br label %72
57: ; preds = %0
%58 = tail call i32 @outw(i32 964, i32 2054)
%59 = tail call i32 @outw(i32 964, i32 4161)
%60 = tail call i32 @outw(i32 964, i32 4392)
%61 = tail call i32 @outw(i32 980, i32 16384)
%62 = tail call i32 @outw(i32 980, i32 12544)
%63 = tail call i32 @outw(i32 980, i32 14853)
%64 = tail call i32 @outw(i32 980, i32 26248)
%65 = tail call i32 @outw(i32 980, i32 22528)
%66 = tail call i32 @outw(i32 980, i32 17664)
%67 = tail call i32 @outw(i32 964, i32 21520)
%68 = tail call i32 @outw(i32 964, i32 22047)
%69 = tail call i32 @outw(i32 964, i32 7040)
%70 = tail call i32 @outw(i32 980, i32 14592)
%71 = tail call i32 @outw(i32 980, i32 14336)
br label %72
72: ; preds = %57, %10
ret void
}