#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ sn76489_data_write(int);
int /*<<< orphan*/ tms9928a_control_write(int);
int /*<<< orphan*/ tms9928a_data_write(int);
void sg_1000_io_write(uint8_t addr, uint8_t data) {
  if (addr >= 0x40 && addr <= 0x7f) {
    sn76489_data_write(data);
  } else if (addr >= 0x80 && addr <= 0xbf) {
    if ((addr & 0x01) == 0x00) {
      tms9928a_data_write(data);
    } else {
      tms9928a_control_write(data);
    }
  }
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x40,-0x4(%rbp)
jl     115f <sg_1000_io_write+0x2f>
cmpl   $0x7f,-0x4(%rbp)
jg     115f <sg_1000_io_write+0x2f>
mov    -0x8(%rbp),%edi
call   1030 <sn76489_data_write@plt>
jmp    11a7 <sg_1000_io_write+0x77>
cmpl   $0x80,-0x4(%rbp)
jl     11a2 <sg_1000_io_write+0x72>
cmpl   $0xbf,-0x4(%rbp)
jg     11a2 <sg_1000_io_write+0x72>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1195 <sg_1000_io_write+0x65>
mov    -0x8(%rbp),%edi
call   1050 <tms9928a_data_write@plt>
jmp    119d <sg_1000_io_write+0x6d>
mov    -0x8(%rbp),%edi
call   1040 <tms9928a_control_write@plt>
jmp    11a2 <sg_1000_io_write+0x72>
jmp    11a7 <sg_1000_io_write+0x77>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
mov    %edi,%eax
and    $0xffffffc0,%eax
cmp    $0x80,%eax
je     1148 <sg_1000_io_write+0x18>
cmp    $0x40,%eax
jne    1155 <sg_1000_io_write+0x25>
mov    %esi,%edi
jmp    1030 <sn76489_data_write@plt>
test   $0x1,%dil
jne    1156 <sg_1000_io_write+0x26>
mov    %esi,%edi
jmp    1050 <tms9928a_data_write@plt>
ret
mov    %esi,%edi
jmp    1040 <tms9928a_control_write@plt>

LLVM IR (-O0):
define void @sg_1000_io_write(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 64
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i32, i32* %3
%9 = icmp sle i32 %8, 127
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* %4
%12 = call i32 @sn76489_data_write(i32 %11)
br label %31
13: ; preds = %7, %2
%14 = load i32, i32* %3
%15 = icmp sge i32 %14, 128
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = load i32, i32* %3
%18 = icmp sle i32 %17, 191
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = load i32, i32* %3
%21 = and i32 %20, 1
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* %4
%25 = call i32 @tms9928a_data_write(i32 %24)
br label %29
26: ; preds = %19
%27 = load i32, i32* %4
%28 = call i32 @tms9928a_control_write(i32 %27)
br label %29
29: ; preds = %26, %23
br label %30
30: ; preds = %29, %16, %13
br label %31
31: ; preds = %30, %10
ret void
}

LLVM IR (-O2):
define void @sg_1000_io_write(i32 %0, i32 %1) {
%3 = and i32 %0, -64
switch i32 %3, label %13 [
i32 64, label %4
i32 128, label %6
]
4: ; preds = %2
%5 = tail call i32 @sn76489_data_write(i32 %1)
br label %13
6: ; preds = %2
%7 = and i32 %0, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @tms9928a_data_write(i32 %1)
br label %13
11: ; preds = %6
%12 = tail call i32 @tms9928a_control_write(i32 %1)
br label %13
13: ; preds = %2, %11, %9, %4
ret void
}