#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_inb(int);
int /*<<< orphan*/ gfx_outb(unsigned short, int);
void gu2_vga_extcrtc(char offset, int reset) {
  unsigned short crtcindex, crtcdata;
  crtcindex = (gfx_inb(0x3CC) & 0x01) ? 0x3D4 : 0x3B4;
  crtcdata = crtcindex + 1;
  gfx_outb(crtcindex, 0x30);
  gfx_outb(crtcdata, 0x57);
  gfx_outb(crtcdata, 0x4C);
  gfx_outb(crtcindex, offset);
  gfx_outb(crtcdata, reset);
}


x86 assembly (clang, -O0):
<gu2_vga_extcrtc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
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,-0xa(%rbp)
movzwl -0xa(%rbp),%eax
add    $0x1,%eax
mov    %ax,-0xc(%rbp)
mov    $0x30,%esi
movzwl -0xa(%rbp),%edi
call   1040 <gfx_outb@plt>
mov    $0x57,%esi
movzwl -0xc(%rbp),%edi
call   1040 <gfx_outb@plt>
mov    $0x4c,%esi
movzwl -0xc(%rbp),%edi
call   1040 <gfx_outb@plt>
mov    -0xa(%rbp),%ax
movsbl -0x1(%rbp),%esi
movzwl %ax,%edi
call   1040 <gfx_outb@plt>
mov    -0xc(%rbp),%ax
mov    -0x8(%rbp),%esi
movzwl %ax,%edi
call   1040 <gfx_outb@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gu2_vga_extcrtc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
mov    $0x3cc,%edi
call   1030 <gfx_inb@plt>
mov    %eax,%ebx
shl    $0x5,%ebx
and    $0x20,%ebx
lea    0x3b4(%rbx),%ebp
mov    %ebp,%edi
mov    $0x30,%esi
call   1040 <gfx_outb@plt>
add    $0x3b5,%ebx
mov    %ebx,%edi
mov    $0x57,%esi
call   1040 <gfx_outb@plt>
mov    %ebx,%edi
mov    $0x4c,%esi
call   1040 <gfx_outb@plt>
mov    %ebp,%edi
mov    %r15d,%esi
call   1040 <gfx_outb@plt>
mov    %ebx,%edi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <gfx_outb@plt>

LLVM IR (-O0):
define void @gu2_vga_extcrtc(i8 signext %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i16
%6 = alloca i16
store i8 %0, i8* %3
store i32 %1, i32* %4
%7 = call i32 @gfx_inb(i32 972)
%8 = and i32 %7, 1
%9 = icmp ne i32 %8, 0
%10 = zext i1 %9 to i64
%11 = select i1 %9, i32 980, i32 948
%12 = trunc i32 %11 to i16
store i16 %12, i16* %5
%13 = load i16, i16* %5
%14 = zext i16 %13 to i32
%15 = add nsw i32 %14, 1
%16 = trunc i32 %15 to i16
store i16 %16, i16* %6
%17 = load i16, i16* %5
%18 = call i32 @gfx_outb(i16 zeroext %17, i32 48)
%19 = load i16, i16* %6
%20 = call i32 @gfx_outb(i16 zeroext %19, i32 87)
%21 = load i16, i16* %6
%22 = call i32 @gfx_outb(i16 zeroext %21, i32 76)
%23 = load i16, i16* %5
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = call i32 @gfx_outb(i16 zeroext %23, i32 %25)
%27 = load i16, i16* %6
%28 = load i32, i32* %4
%29 = call i32 @gfx_outb(i16 zeroext %27, i32 %28)
ret void
}

LLVM IR (-O2):
define void @gu2_vga_extcrtc(i8 signext %0, i32 %1) {
%3 = tail call i32 @gfx_inb(i32 972)
%4 = and i32 %3, 1
%5 = icmp eq i32 %4, 0
%6 = select i1 %5, i16 948, i16 980
%7 = or i16 %6, 1
%8 = tail call i32 @gfx_outb(i16 zeroext %6, i32 48)
%9 = tail call i32 @gfx_outb(i16 zeroext %7, i32 87)
%10 = tail call i32 @gfx_outb(i16 zeroext %7, i32 76)
%11 = sext i8 %0 to i32
%12 = tail call i32 @gfx_outb(i16 zeroext %6, i32 %11)
%13 = tail call i32 @gfx_outb(i16 zeroext %7, i32 %1)
ret void
}