#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 read_whitney(int, unsigned long *);
int write_whitney(int, unsigned long);
int PL_enable_vga(void) {
  int err;
  unsigned long reg;
  err = write_whitney(0x60018, 0);
  if (err)
    return err;
  err = read_whitney(0x6010, &reg);
  if (err)
    return err;
  err = write_whitney(0x6010, reg);
  if (err)
    return err;
  return 0;
}


x86 assembly (clang, -O0):
<PL_enable_vga>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x60018,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <write_whitney@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     114e <PL_enable_vga+0x2e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a1 <PL_enable_vga+0x81>
mov    $0x6010,%edi
lea    -0x10(%rbp),%rsi
call   1040 <read_whitney@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1174 <PL_enable_vga+0x54>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a1 <PL_enable_vga+0x81>
mov    -0x10(%rbp),%rsi
mov    $0x6010,%edi
call   1030 <write_whitney@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     119a <PL_enable_vga+0x7a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a1 <PL_enable_vga+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PL_enable_vga>:
push   %rax
mov    $0x60018,%edi
xor    %esi,%esi
call   1030 <write_whitney@plt>
test   %eax,%eax
je     1133 <PL_enable_vga+0x13>
pop    %rcx
ret
mov    %rsp,%rsi
mov    $0x6010,%edi
call   1040 <read_whitney@plt>
test   %eax,%eax
jne    1131 <PL_enable_vga+0x11>
mov    (%rsp),%rsi
mov    $0x6010,%edi
call   1030 <write_whitney@plt>
pop    %rcx
ret

LLVM IR (-O0):
define i32 @PL_enable_vga() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = call i32 @write_whitney(i32 393240, i64 0)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = load i32, i32* %2
store i32 %8, i32* %1
br label %23
9: ; preds = %0
%10 = call i32 @read_whitney(i32 24592, i64* %3)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load i32, i32* %2
store i32 %14, i32* %1
br label %23
15: ; preds = %9
%16 = load i64, i64* %3
%17 = call i32 @write_whitney(i32 24592, i64 %16)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i32, i32* %2
store i32 %21, i32* %1
br label %23
22: ; preds = %15
store i32 0, i32* %1
br label %23
23: ; preds = %22, %20, %13, %7
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
define i32 @PL_enable_vga() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @write_whitney(i32 393240, i64 0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = call i32 @read_whitney(i32 24592, i64* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i64, i64* %1
%10 = call i32 @write_whitney(i32 24592, i64 %9)
br label %11
11: ; preds = %8, %5, %0
%12 = phi i32 [ %3, %0 ], [ %6, %5 ], [ %10, %8 ]
ret i32 %12
}