#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 gfx_get_vsa2_softvga_enable();
int gfx_inb(unsigned short);
int /*<<< orphan*/ gfx_outb(unsigned short, int);
scalar_t__ gu1_detect_vsa2();
int gfx_get_softvga_active(void) {
  unsigned short crtcindex, crtcdata;
  if (gu1_detect_vsa2())
    return (gfx_get_vsa2_softvga_enable());
  crtcindex = (gfx_inb(0x3CC) & 0x01) ? 0x3D4 : 0x3B4;
  crtcdata = crtcindex + 1;
  gfx_outb(crtcindex, 0x3F);
  return (gfx_inb(crtcdata) & 0x1);
}


x86 assembly (clang, -O0):
<gfx_get_softvga_active>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <gu1_detect_vsa2@plt>
cmp    $0x0,%rax
je     1168 <gfx_get_softvga_active+0x28>
mov    $0x0,%al
call   1060 <gfx_get_vsa2_softvga_enable@plt>
mov    %eax,-0x4(%rbp)
jmp    11b3 <gfx_get_softvga_active+0x73>
mov    $0x3cc,%edi
call   1030 <gfx_inb@plt>
mov    %eax,%edx
and    $0x1,%edx
mov    $0x3b4,%eax
mov    $0x3d4,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %ax,-0x6(%rbp)
movzwl -0x6(%rbp),%eax
add    $0x1,%eax
mov    %ax,-0x8(%rbp)
mov    $0x3f,%esi
movzwl -0x6(%rbp),%edi
call   1040 <gfx_outb@plt>
movzwl -0x8(%rbp),%edi
call   1030 <gfx_inb@plt>
and    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gfx_get_softvga_active>:
push   %rbx
xor    %eax,%eax
call   1050 <gu1_detect_vsa2@plt>
test   %rax,%rax
je     1155 <gfx_get_softvga_active+0x15>
xor    %eax,%eax
pop    %rbx
jmp    1060 <gfx_get_vsa2_softvga_enable@plt>
mov    $0x3cc,%edi
call   1030 <gfx_inb@plt>
mov    %eax,%ebx
shl    $0x5,%ebx
and    $0x20,%ebx
lea    0x3b4(%rbx),%edi
mov    $0x3f,%esi
call   1040 <gfx_outb@plt>
add    $0x3b5,%ebx
mov    %ebx,%edi
call   1030 <gfx_inb@plt>
and    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @gfx_get_softvga_active() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i16
%4 = call i64 (...) @gu1_detect_vsa2()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (...) @gfx_get_vsa2_softvga_enable()
store i32 %7, i32* %1
br label %24
8: ; preds = %0
%9 = call i32 @gfx_inb(i16 zeroext 972)
%10 = and i32 %9, 1
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i32 980, i32 948
%14 = trunc i32 %13 to i16
store i16 %14, i16* %2
%15 = load i16, i16* %2
%16 = zext i16 %15 to i32
%17 = add nsw i32 %16, 1
%18 = trunc i32 %17 to i16
store i16 %18, i16* %3
%19 = load i16, i16* %2
%20 = call i32 @gfx_outb(i16 zeroext %19, i32 63)
%21 = load i16, i16* %3
%22 = call i32 @gfx_inb(i16 zeroext %21)
%23 = and i32 %22, 1
store i32 %23, i32* %1
br label %24
24: ; preds = %8, %6
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
define i32 @gfx_get_softvga_active() {
%1 = tail call i64 (...) @gu1_detect_vsa2()
%2 = icmp eq i64 %1, 0
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 (...) @gfx_get_vsa2_softvga_enable()
br label %14
5: ; preds = %0
%6 = tail call i32 @gfx_inb(i16 zeroext 972)
%7 = and i32 %6, 1
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i16 948, i16 980
%10 = or i16 %9, 1
%11 = tail call i32 @gfx_outb(i16 zeroext %9, i32 63)
%12 = tail call i32 @gfx_inb(i16 zeroext %10)
%13 = and i32 %12, 1
br label %14
14: ; preds = %5, %3
%15 = phi i32 [ %4, %3 ], [ %13, %5 ]
ret i32 %15
}