#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*/ inb(int);
int /*<<< orphan*/ outb(int, int);
int read_crtc_b(int);
int read_gra_b(int);
int read_seq_b(int);
void vga_set_amode(void) {
  unsigned char byte;
  inb(0x3DA);
  inb(0x80);
  outb(0x10, 0x3C0);
  inb(0x80);
  outb(0x0c, 0x3C0);
  inb(0x80);
  inb(0x3DA);
  inb(0x80);
  outb(0x14, 0x3C0);
  inb(0x80);
  outb(0x0, 0x3C0);
  inb(0x80);
  outb(0x02, 0x3C4);
  outb(0x3, 0x3C5);
  byte = read_seq_b(0x04) & ~0x04;
  outb(0x04, 0x3C4);
  outb(byte, 0x3C5);
  byte = read_gra_b(0x05) & ~0x60;
  outb(0x05, 0x3CE);
  outb(byte | 0x10, 0x3CF);
  outb(0x06, 0x3CE);
  outb(0x0e, 0x3CF);
  outb(0x0A, 0x3D4);
  outb(0x00, 0x3D5);
  outb(0x0B, 0x3D4);
  outb(16 - 1, 0x3D5);
  byte = read_crtc_b(0x17) & ~0xe0;
  outb(0x17, 0x3D4);
  outb(byte | 0xa0, 0x3D5);
  byte = read_crtc_b(9) & ~0x01f;
  outb(9, 0x3D4);
  outb(byte | (16 - 1), 0x3D5);
  inb(0x3DA);
  outb(0x20, 0x3C0);
}


x86 assembly (clang, -O0):
<vga_set_amode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
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>
mov    $0xc,%edi
mov    $0x3c0,%esi
call   1050 <outb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
mov    $0x3da,%edi
call   1060 <inb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
mov    $0x14,%edi
mov    $0x3c0,%esi
call   1050 <outb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
xor    %edi,%edi
mov    $0x3c0,%esi
call   1050 <outb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
mov    $0x2,%edi
mov    $0x3c4,%esi
call   1050 <outb@plt>
mov    $0x3,%edi
mov    $0x3c5,%esi
call   1050 <outb@plt>
mov    $0x4,%edi
call   1040 <read_seq_b@plt>
and    $0xfffffffb,%eax
mov    %al,-0x1(%rbp)
mov    $0x4,%edi
mov    $0x3c4,%esi
call   1050 <outb@plt>
movzbl -0x1(%rbp),%edi
mov    $0x3c5,%esi
call   1050 <outb@plt>
mov    $0x5,%edi
call   1030 <read_gra_b@plt>
and    $0xffffff9f,%eax
mov    %al,-0x1(%rbp)
mov    $0x5,%edi
mov    $0x3ce,%esi
call   1050 <outb@plt>
movzbl -0x1(%rbp),%edi
or     $0x10,%edi
mov    $0x3cf,%esi
call   1050 <outb@plt>
mov    $0x6,%edi
mov    $0x3ce,%esi
call   1050 <outb@plt>
mov    $0xe,%edi
mov    $0x3cf,%esi
call   1050 <outb@plt>
mov    $0xa,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
xor    %edi,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0xb,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
mov    $0xf,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0x17,%edi
call   1070 <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     $0xa0,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0x9,%edi
call   1070 <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
or     $0xf,%edi
mov    $0x3d5,%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_amode>:
push   %rbx
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>
mov    $0xc,%edi
mov    $0x3c0,%esi
call   1050 <outb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
mov    $0x3da,%edi
call   1060 <inb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
mov    $0x14,%edi
mov    $0x3c0,%esi
call   1050 <outb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
xor    %edi,%edi
mov    $0x3c0,%esi
call   1050 <outb@plt>
mov    $0x80,%edi
call   1060 <inb@plt>
mov    $0x2,%edi
mov    $0x3c4,%esi
call   1050 <outb@plt>
mov    $0x3,%edi
mov    $0x3c5,%esi
call   1050 <outb@plt>
mov    $0x4,%edi
call   1040 <read_seq_b@plt>
mov    %eax,%ebx
and    $0xfb,%ebx
mov    $0x4,%edi
mov    $0x3c4,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
mov    $0x3c5,%esi
call   1050 <outb@plt>
mov    $0x5,%edi
call   1030 <read_gra_b@plt>
mov    %eax,%ebx
and    $0x8f,%ebx
mov    $0x5,%edi
mov    $0x3ce,%esi
call   1050 <outb@plt>
or     $0x10,%ebx
mov    %ebx,%edi
mov    $0x3cf,%esi
call   1050 <outb@plt>
mov    $0x6,%edi
mov    $0x3ce,%esi
call   1050 <outb@plt>
mov    $0xe,%edi
mov    $0x3cf,%esi
call   1050 <outb@plt>
mov    $0xa,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
xor    %edi,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0xb,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
mov    $0xf,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0x17,%edi
call   1070 <read_crtc_b@plt>
mov    %eax,%ebx
and    $0x1f,%ebx
mov    $0x17,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
or     $0xa0,%ebx
mov    %ebx,%edi
mov    $0x3d5,%esi
call   1050 <outb@plt>
mov    $0x9,%edi
call   1070 <read_crtc_b@plt>
mov    %eax,%ebx
and    $0xe0,%ebx
mov    $0x9,%edi
mov    $0x3d4,%esi
call   1050 <outb@plt>
or     $0xf,%ebx
mov    %ebx,%edi
mov    $0x3d5,%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_amode() {
%1 = alloca i8
%2 = call i32 @inb(i32 986)
%3 = call i32 @inb(i32 128)
%4 = call i32 @outb(i32 16, i32 960)
%5 = call i32 @inb(i32 128)
%6 = call i32 @outb(i32 12, i32 960)
%7 = call i32 @inb(i32 128)
%8 = call i32 @inb(i32 986)
%9 = call i32 @inb(i32 128)
%10 = call i32 @outb(i32 20, i32 960)
%11 = call i32 @inb(i32 128)
%12 = call i32 @outb(i32 0, i32 960)
%13 = call i32 @inb(i32 128)
%14 = call i32 @outb(i32 2, i32 964)
%15 = call i32 @outb(i32 3, i32 965)
%16 = call i32 @read_seq_b(i32 4)
%17 = and i32 %16, -5
%18 = trunc i32 %17 to i8
store i8 %18, i8* %1
%19 = call i32 @outb(i32 4, i32 964)
%20 = load i8, i8* %1
%21 = zext i8 %20 to i32
%22 = call i32 @outb(i32 %21, i32 965)
%23 = call i32 @read_gra_b(i32 5)
%24 = and i32 %23, -97
%25 = trunc i32 %24 to i8
store i8 %25, i8* %1
%26 = call i32 @outb(i32 5, i32 974)
%27 = load i8, i8* %1
%28 = zext i8 %27 to i32
%29 = or i32 %28, 16
%30 = call i32 @outb(i32 %29, i32 975)
%31 = call i32 @outb(i32 6, i32 974)
%32 = call i32 @outb(i32 14, i32 975)
%33 = call i32 @outb(i32 10, i32 980)
%34 = call i32 @outb(i32 0, i32 981)
%35 = call i32 @outb(i32 11, i32 980)
%36 = call i32 @outb(i32 15, i32 981)
%37 = call i32 @read_crtc_b(i32 23)
%38 = and i32 %37, -225
%39 = trunc i32 %38 to i8
store i8 %39, i8* %1
%40 = call i32 @outb(i32 23, i32 980)
%41 = load i8, i8* %1
%42 = zext i8 %41 to i32
%43 = or i32 %42, 160
%44 = call i32 @outb(i32 %43, i32 981)
%45 = call i32 @read_crtc_b(i32 9)
%46 = and i32 %45, -32
%47 = trunc i32 %46 to i8
store i8 %47, i8* %1
%48 = call i32 @outb(i32 9, i32 980)
%49 = load i8, i8* %1
%50 = zext i8 %49 to i32
%51 = or i32 %50, 15
%52 = call i32 @outb(i32 %51, i32 981)
%53 = call i32 @inb(i32 986)
%54 = call i32 @outb(i32 32, i32 960)
ret void
}

LLVM IR (-O2):
define void @vga_set_amode() {
%1 = tail call i32 @inb(i32 986)
%2 = tail call i32 @inb(i32 128)
%3 = tail call i32 @outb(i32 16, i32 960)
%4 = tail call i32 @inb(i32 128)
%5 = tail call i32 @outb(i32 12, i32 960)
%6 = tail call i32 @inb(i32 128)
%7 = tail call i32 @inb(i32 986)
%8 = tail call i32 @inb(i32 128)
%9 = tail call i32 @outb(i32 20, i32 960)
%10 = tail call i32 @inb(i32 128)
%11 = tail call i32 @outb(i32 0, i32 960)
%12 = tail call i32 @inb(i32 128)
%13 = tail call i32 @outb(i32 2, i32 964)
%14 = tail call i32 @outb(i32 3, i32 965)
%15 = tail call i32 @read_seq_b(i32 4)
%16 = and i32 %15, 251
%17 = tail call i32 @outb(i32 4, i32 964)
%18 = tail call i32 @outb(i32 %16, i32 965)
%19 = tail call i32 @read_gra_b(i32 5)
%20 = and i32 %19, 143
%21 = tail call i32 @outb(i32 5, i32 974)
%22 = or i32 %20, 16
%23 = tail call i32 @outb(i32 %22, i32 975)
%24 = tail call i32 @outb(i32 6, i32 974)
%25 = tail call i32 @outb(i32 14, i32 975)
%26 = tail call i32 @outb(i32 10, i32 980)
%27 = tail call i32 @outb(i32 0, i32 981)
%28 = tail call i32 @outb(i32 11, i32 980)
%29 = tail call i32 @outb(i32 15, 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, 160
%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 = or i32 %36, 15
%39 = tail call i32 @outb(i32 %38, i32 981)
%40 = tail call i32 @inb(i32 986)
%41 = tail call i32 @outb(i32 32, i32 960)
ret void
}