#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_pci_config_read(int);
int /*<<< orphan*/ gfx_pci_config_write(int, unsigned long);
int gfx_vga_test_pci(void) {
  int softvga = 1;
  unsigned long value;
  value = gfx_pci_config_read(0x80009400);
  if ((value & 0x0000FFFF) != 0x1078)
    softvga = 0;
  else {
    value = gfx_pci_config_read(0x80009404);
    gfx_pci_config_write(0x80009404, value | 0x02);
    if (!(gfx_pci_config_read(0x80009404) & 0x02))
      softvga = 0;
    gfx_pci_config_write(0x80009404, value);
  }
  return (softvga);
}


x86 assembly (clang, -O0):
<gfx_vga_test_pci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x4(%rbp)
mov    $0x80009400,%edi
call   1040 <gfx_pci_config_read@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
and    $0xffff,%rax
cmp    $0x1078,%rax
je     1161 <gfx_vga_test_pci+0x41>
movl   $0x0,-0x4(%rbp)
jmp    11ae <gfx_vga_test_pci+0x8e>
mov    $0x80009404,%edi
call   1040 <gfx_pci_config_read@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
or     $0x2,%rsi
mov    $0x80009404,%edi
call   1030 <gfx_pci_config_write@plt>
mov    $0x80009404,%edi
call   1040 <gfx_pci_config_read@plt>
and    $0x2,%eax
cmp    $0x0,%eax
jne    11a0 <gfx_vga_test_pci+0x80>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x80009404,%edi
call   1030 <gfx_pci_config_write@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gfx_vga_test_pci>:
push   %r14
push   %rbx
push   %rax
mov    $0x80009400,%edi
call   1040 <gfx_pci_config_read@plt>
movzwl %ax,%eax
xor    %ebx,%ebx
cmp    $0x1078,%eax
jne    1176 <gfx_vga_test_pci+0x56>
mov    $0x80009404,%edi
call   1040 <gfx_pci_config_read@plt>
movslq %eax,%r14
mov    %r14,%rsi
or     $0x2,%rsi
mov    $0x80009404,%edi
call   1030 <gfx_pci_config_write@plt>
mov    $0x80009404,%edi
call   1040 <gfx_pci_config_read@plt>
mov    %eax,%ebx
shr    %ebx
and    $0x1,%ebx
mov    $0x80009404,%edi
mov    %r14,%rsi
call   1030 <gfx_pci_config_write@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @gfx_vga_test_pci() {
%1 = alloca i32
%2 = alloca i64
store i32 1, i32* %1
%3 = call i32 @gfx_pci_config_read(i32 -2147445760)
%4 = sext i32 %3 to i64
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = and i64 %5, 65535
%7 = icmp ne i64 %6, 4216
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 0, i32* %1
br label %22
9: ; preds = %0
%10 = call i32 @gfx_pci_config_read(i32 -2147445756)
%11 = sext i32 %10 to i64
store i64 %11, i64* %2
%12 = load i64, i64* %2
%13 = or i64 %12, 2
%14 = call i32 @gfx_pci_config_write(i32 -2147445756, i64 %13)
%15 = call i32 @gfx_pci_config_read(i32 -2147445756)
%16 = and i32 %15, 2
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %9
store i32 0, i32* %1
br label %19
19: ; preds = %18, %9
%20 = load i64, i64* %2
%21 = call i32 @gfx_pci_config_write(i32 -2147445756, i64 %20)
br label %22
22: ; preds = %19, %8
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
define i32 @gfx_vga_test_pci() {
%1 = tail call i32 @gfx_pci_config_read(i32 -2147445760)
%2 = and i32 %1, 65535
%3 = icmp eq i32 %2, 4216
br i1 %3, label %4, label %13
4: ; preds = %0
%5 = tail call i32 @gfx_pci_config_read(i32 -2147445756)
%6 = sext i32 %5 to i64
%7 = or i64 %6, 2
%8 = tail call i32 @gfx_pci_config_write(i32 -2147445756, i64 %7)
%9 = tail call i32 @gfx_pci_config_read(i32 -2147445756)
%10 = lshr i32 %9, 1
%11 = and i32 %10, 1
%12 = tail call i32 @gfx_pci_config_write(i32 -2147445756, i64 %6)
br label %13
13: ; preds = %0, %4
%14 = phi i32 [ %11, %4 ], [ 0, %0 ]
ret i32 %14
}