#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 */
unsigned char inb(int);
int /*<<< orphan*/ outb(int, int);
int read_att_b(int);
int read_crtc_b(int);
int read_gra_b(int);
int read_seq_b(int);
void vga_set_gmode(void) {
  unsigned char byte;
  byte = read_att_b(0x10) & ~0x0f;
  inb(0x3DA);
  inb(0x80);
  outb(0x10, 0x3C0);
  inb(0x80);
  outb(byte | 0x1, 0x3C0);
  inb(0x80);
  byte = read_seq_b(0x02) & ~0xf;
  outb(0x02, 0x3C4);
  outb(byte | 0xf, 0x3C5);
  byte = read_seq_b(0x04);
  outb(0x04, 0x3C4);
  outb(byte | 4, 0x3C5);
  byte = read_gra_b(0x05) & ~0x10;
  outb(0x05, 0x3CE);
  outb(byte, 0x3CF);
  outb(0x06, 0x3CE);
  outb(0x05, 0x3CF);
  outb(0x0A, 0x3D4);
  outb(0x20, 0x3D5);
  outb(0x0B, 0x3D4);
  outb(0x00, 0x3D5);
  byte = read_crtc_b(0x17) & ~0xe0;
  outb(0x17, 0x3D4);
  outb(byte | 0xe0, 0x3D5);
  byte = read_crtc_b(9) & ~0x01f;
  outb(9, 0x3D4);
  outb(byte, 0x3D5);
  byte = inb(0x3CC);
  outb(byte & ~0xc, 0x3C2);
  inb(0x3DA);
  outb(0x20, 0x3C0);
}


x86 assembly (clang, -O0):
<vga_set_gmode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x10,%edi
call   1070 <read_att_b@plt>
and    $0xfffffff0,%eax
mov    %al,-0x1(%rbp)
mov    $0x3da,%edi
call   1060 <inb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
mov    $0x10,%edi
mov    $0x3c0,%esi
call   1050 <outb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
movzbl -0x1(%rbp),%edi
or     $0x1,%edi
mov    $0x3c0,%esi
call   1050 <outb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
mov    $0x2,%edi
call   1040 <read_seq_b@plt>
and    $0xfffffff0,%eax
mov    %al,-0x1(%rbp)
mov    $0x2,%edi
mov    $0x3c4,%esi
call   1050 <outb@plt>
movzbl -0x1(%rbp),%edi
or     $0xf,%edi
mov    $0x3c5,%esi
call   1050 <outb@plt>
mov    $0x4,%edi
call   1040 <read_seq_b@plt>
mov    %al,-0x1(%rbp)
mov    $0x4,%edi
mov    $0x3c4,%esi
call   1050 <outb@plt>
movzbl -0x1(%rbp),%edi
or     $0x4,%edi
mov    $0x3c5,%esi
call   1050 <outb@plt>
mov    $0x5,%edi
call   1030 <read_gra_b@plt>
and    $0xffffffef,%eax
mov    %al,-0x1(%rbp)
mov    $0x5,%edi
mov    $0x3ce,%esi
call   1050 <outb@plt>
movzbl -0x1(%rbp),%edi
mov    $0x3cf,%esi
call   1050 <outb@plt>
mov    $0x6,%edi
mov    $0x3ce,%esi
call   1050 <outb@plt>
mov    $0x5,%edi
mov    $0x3cf,%esi
call   1050 <outb@plt>
mov    $0xa,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
mov    $0x20,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0xb,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
xor    %edi,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0x17,%edi
call   1080 <read_crtc_b@plt>
and    $0xffffff1f,%eax
mov    %al,-0x1(%rbp)
mov    $0x17,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
movzbl -0x1(%rbp),%edi
or     $0xe0,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0x9,%edi
call   1080 <read_crtc_b@plt>
and    $0xffffffe0,%eax
mov    %al,-0x1(%rbp)
mov    $0x9,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
movzbl -0x1(%rbp),%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0x3cc,%edi
call   1060 <inb@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%edi
and    $0xfffffff3,%edi
mov    $0x3c2,%esi
call   1050 <outb@plt>
mov    $0x3da,%edi
call   1060 <inb@plt>
mov    $0x20,%edi
mov    $0x3c0,%esi
call   1050 <outb@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vga_set_gmode>:
push   %rbx
mov    $0x10,%edi
call   1070 <read_att_b@plt>
mov    %eax,%ebx
and    $0xf0,%ebx
mov    $0x3da,%edi
call   1060 <inb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
mov    $0x10,%edi
mov    $0x3c0,%esi
call   1050 <outb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
or     $0x1,%ebx
mov    %ebx,%edi
mov    $0x3c0,%esi
call   1050 <outb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
mov    $0x2,%edi
call   1040 <read_seq_b@plt>
mov    %eax,%ebx
or     $0xf,%ebx
mov    $0x2,%edi
mov    $0x3c4,%esi
call   1050 <outb@plt>
movzbl %bl,%edi
mov    $0x3c5,%esi
call   1050 <outb@plt>
mov    $0x4,%edi
call   1040 <read_seq_b@plt>
mov    %eax,%ebx
mov    $0x4,%edi
mov    $0x3c4,%esi
call   1050 <outb@plt>
or     $0x4,%ebx
movzbl %bl,%edi
mov    $0x3c5,%esi
call   1050 <outb@plt>
mov    $0x5,%edi
call   1030 <read_gra_b@plt>
mov    %eax,%ebx
and    $0xef,%ebx
mov    $0x5,%edi
mov    $0x3ce,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
mov    $0x3cf,%esi
call   1050 <outb@plt>
mov    $0x6,%edi
mov    $0x3ce,%esi
call   1050 <outb@plt>
mov    $0x5,%edi
mov    $0x3cf,%esi
call   1050 <outb@plt>
mov    $0xa,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
mov    $0x20,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0xb,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
xor    %edi,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0x17,%edi
call   1080 <read_crtc_b@plt>
mov    %eax,%ebx
or     $0xe0,%ebx
mov    $0x17,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
movzbl %bl,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0x9,%edi
call   1080 <read_crtc_b@plt>
mov    %eax,%ebx
and    $0xe0,%ebx
mov    $0x9,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0x3cc,%edi
call   1060 <inb@plt>
and    $0xf3,%al
movzbl %al,%edi
mov    $0x3c2,%esi
call   1050 <outb@plt>
mov    $0x3da,%edi
call   1060 <inb@plt>
mov    $0x20,%edi
mov    $0x3c0,%esi
pop    %rbx
jmp    1050 <outb@plt>

LLVM IR (-O0):
define void @vga_set_gmode() {
%1 = alloca i8
%2 = call i32 @read_att_b(i32 16)
%3 = and i32 %2, -16
%4 = trunc i32 %3 to i8
store i8 %4, i8* %1
%5 = call zeroext i8 @inb(i32 986)
%6 = call zeroext i8 @inb(i32 128)
%7 = call i32 @outb(i32 16, i32 960)
%8 = call zeroext i8 @inb(i32 128)
%9 = load i8, i8* %1
%10 = zext i8 %9 to i32
%11 = or i32 %10, 1
%12 = call i32 @outb(i32 %11, i32 960)
%13 = call zeroext i8 @inb(i32 128)
%14 = call i32 @read_seq_b(i32 2)
%15 = and i32 %14, -16
%16 = trunc i32 %15 to i8
store i8 %16, i8* %1
%17 = call i32 @outb(i32 2, i32 964)
%18 = load i8, i8* %1
%19 = zext i8 %18 to i32
%20 = or i32 %19, 15
%21 = call i32 @outb(i32 %20, i32 965)
%22 = call i32 @read_seq_b(i32 4)
%23 = trunc i32 %22 to i8
store i8 %23, i8* %1
%24 = call i32 @outb(i32 4, i32 964)
%25 = load i8, i8* %1
%26 = zext i8 %25 to i32
%27 = or i32 %26, 4
%28 = call i32 @outb(i32 %27, i32 965)
%29 = call i32 @read_gra_b(i32 5)
%30 = and i32 %29, -17
%31 = trunc i32 %30 to i8
store i8 %31, i8* %1
%32 = call i32 @outb(i32 5, i32 974)
%33 = load i8, i8* %1
%34 = zext i8 %33 to i32
%35 = call i32 @outb(i32 %34, i32 975)
%36 = call i32 @outb(i32 6, i32 974)
%37 = call i32 @outb(i32 5, i32 975)
%38 = call i32 @outb(i32 10, i32 980)
%39 = call i32 @outb(i32 32, i32 981)
%40 = call i32 @outb(i32 11, i32 980)
%41 = call i32 @outb(i32 0, i32 981)
%42 = call i32 @read_crtc_b(i32 23)
%43 = and i32 %42, -225
%44 = trunc i32 %43 to i8
store i8 %44, i8* %1
%45 = call i32 @outb(i32 23, i32 980)
%46 = load i8, i8* %1
%47 = zext i8 %46 to i32
%48 = or i32 %47, 224
%49 = call i32 @outb(i32 %48, i32 981)
%50 = call i32 @read_crtc_b(i32 9)
%51 = and i32 %50, -32
%52 = trunc i32 %51 to i8
store i8 %52, i8* %1
%53 = call i32 @outb(i32 9, i32 980)
%54 = load i8, i8* %1
%55 = zext i8 %54 to i32
%56 = call i32 @outb(i32 %55, i32 981)
%57 = call zeroext i8 @inb(i32 972)
store i8 %57, i8* %1
%58 = load i8, i8* %1
%59 = zext i8 %58 to i32
%60 = and i32 %59, -13
%61 = call i32 @outb(i32 %60, i32 962)
%62 = call zeroext i8 @inb(i32 986)
%63 = call i32 @outb(i32 32, i32 960)
ret void
}

LLVM IR (-O2):
define void @vga_set_gmode() {
%1 = tail call i32 @read_att_b(i32 16)
%2 = and i32 %1, 240
%3 = tail call zeroext i8 @inb(i32 986)
%4 = tail call zeroext i8 @inb(i32 128)
%5 = tail call i32 @outb(i32 16, i32 960)
%6 = tail call zeroext i8 @inb(i32 128)
%7 = or i32 %2, 1
%8 = tail call i32 @outb(i32 %7, i32 960)
%9 = tail call zeroext i8 @inb(i32 128)
%10 = tail call i32 @read_seq_b(i32 2)
%11 = and i32 %10, 240
%12 = tail call i32 @outb(i32 2, i32 964)
%13 = or i32 %11, 15
%14 = tail call i32 @outb(i32 %13, i32 965)
%15 = tail call i32 @read_seq_b(i32 4)
%16 = tail call i32 @outb(i32 4, i32 964)
%17 = and i32 %15, 251
%18 = or i32 %17, 4
%19 = tail call i32 @outb(i32 %18, i32 965)
%20 = tail call i32 @read_gra_b(i32 5)
%21 = and i32 %20, 239
%22 = tail call i32 @outb(i32 5, i32 974)
%23 = tail call i32 @outb(i32 %21, i32 975)
%24 = tail call i32 @outb(i32 6, i32 974)
%25 = tail call i32 @outb(i32 5, i32 975)
%26 = tail call i32 @outb(i32 10, i32 980)
%27 = tail call i32 @outb(i32 32, i32 981)
%28 = tail call i32 @outb(i32 11, i32 980)
%29 = tail call i32 @outb(i32 0, i32 981)
%30 = tail call i32 @read_crtc_b(i32 23)
%31 = and i32 %30, 31
%32 = tail call i32 @outb(i32 23, i32 980)
%33 = or i32 %31, 224
%34 = tail call i32 @outb(i32 %33, i32 981)
%35 = tail call i32 @read_crtc_b(i32 9)
%36 = and i32 %35, 224
%37 = tail call i32 @outb(i32 9, i32 980)
%38 = tail call i32 @outb(i32 %36, i32 981)
%39 = tail call zeroext i8 @inb(i32 972)
%40 = and i8 %39, -13
%41 = zext i8 %40 to i32
%42 = tail call i32 @outb(i32 %41, i32 962)
%43 = tail call zeroext i8 @inb(i32 986)
%44 = tail call i32 @outb(i32 32, i32 960)
ret void
}