#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 */
char gfx_inb(unsigned short);
int /*<<< orphan*/ gfx_outb(unsigned short, int);
int gu1_detect_vsa2(void) {
  unsigned short crtcindex, crtcdata;
  crtcindex = (gfx_inb(0x3CC) & 0x01) ? 0x3D4 : 0x3B4;
  crtcdata = crtcindex + 1;
  gfx_outb(crtcindex, 0x35);
  if (gfx_inb(crtcdata) != 'C')
    return (0);
  gfx_outb(crtcindex, 0x36);
  if (gfx_inb(crtcdata) != 'X')
    return (0);
  return (1);
}


x86 assembly (clang, -O0):
<gu1_detect_vsa2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3cc,%edi
call   1030 <gfx_inb@plt>
movsbl %al,%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    $0x35,%esi
movzwl -0x6(%rbp),%edi
call   1040 <gfx_outb@plt>
movzwl -0x8(%rbp),%edi
call   1030 <gfx_inb@plt>
movsbl %al,%eax
cmp    $0x43,%eax
je     1186 <gu1_detect_vsa2+0x66>
movl   $0x0,-0x4(%rbp)
jmp    11bc <gu1_detect_vsa2+0x9c>
mov    $0x36,%esi
movzwl -0x6(%rbp),%edi
call   1040 <gfx_outb@plt>
movzwl -0x8(%rbp),%edi
call   1030 <gfx_inb@plt>
movsbl %al,%eax
cmp    $0x58,%eax
je     11b5 <gu1_detect_vsa2+0x95>
movl   $0x0,-0x4(%rbp)
jmp    11bc <gu1_detect_vsa2+0x9c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gu1_detect_vsa2>:
push   %rbp
push   %rbx
push   %rax
mov    $0x3cc,%edi
call   1030 <gfx_inb@plt>
and    $0x1,%al
movzbl %al,%ebx
shl    $0x5,%ebx
lea    0x3b4(%rbx),%ebp
add    $0x3b5,%ebx
mov    %ebp,%edi
mov    $0x35,%esi
call   1040 <gfx_outb@plt>
mov    %ebx,%edi
call   1030 <gfx_inb@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x43,%cl
jne    117c <gu1_detect_vsa2+0x5c>
movzwl %bp,%edi
mov    $0x36,%esi
call   1040 <gfx_outb@plt>
movzwl %bx,%edi
call   1030 <gfx_inb@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x58,%cl
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gu1_detect_vsa2() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i16
%4 = call signext i8 @gfx_inb(i16 zeroext 972)
%5 = sext i8 %4 to i32
%6 = and i32 %5, 1
%7 = icmp ne i32 %6, 0
%8 = zext i1 %7 to i64
%9 = select i1 %7, i32 980, i32 948
%10 = trunc i32 %9 to i16
store i16 %10, i16* %2
%11 = load i16, i16* %2
%12 = zext i16 %11 to i32
%13 = add nsw i32 %12, 1
%14 = trunc i32 %13 to i16
store i16 %14, i16* %3
%15 = load i16, i16* %2
%16 = call i32 @gfx_outb(i16 zeroext %15, i32 53)
%17 = load i16, i16* %3
%18 = call signext i8 @gfx_inb(i16 zeroext %17)
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 67
br i1 %20, label %21, label %22
21: ; preds = %0
store i32 0, i32* %1
br label %31
22: ; preds = %0
%23 = load i16, i16* %2
%24 = call i32 @gfx_outb(i16 zeroext %23, i32 54)
%25 = load i16, i16* %3
%26 = call signext i8 @gfx_inb(i16 zeroext %25)
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 88
br i1 %28, label %29, label %30
29: ; preds = %22
store i32 0, i32* %1
br label %31
30: ; preds = %22
store i32 1, i32* %1
br label %31
31: ; preds = %30, %29, %21
%32 = load i32, i32* %1
ret i32 %32
}

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