#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ write_register(int, int);
void plot_point(uint32_t x, uint32_t y, uint32_t color) {
  static int last_bank = 0;
  if (last_bank != y / (768 / ((1024 * 768 * 32 / 8) / (64 * 1024)))) {
    last_bank = y / (768 / ((1024 * 768 * 32 / 8) / (64 * 1024)));
    write_register(0x5, last_bank);
  }
  *(((uint32_t *)0xA0000) + x +
    y % (768 / ((1024 * 768 * 32 / 8) / (64 * 1024))) * 1024) = color;
}


x86 assembly (clang, -O0):
<plot_point>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    0x2f05(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
je     1163 <plot_point+0x53>
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,0x2ed9(%rip)
mov    0x2ed3(%rip),%esi
mov    $0x5,%edi
call   1030 <write_register@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movslq -0x4(%rbp),%rcx
mov    $0xa0000,%eax
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
mov    %edx,%ecx
mov    -0x14(%rbp),%edx
shl    $0xa,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plot_point>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xf(%rbx),%eax
test   %esi,%esi
cmovns %esi,%eax
mov    %eax,%esi
sar    $0x4,%esi
and    $0xfffffff0,%eax
sub    %eax,%ebx
cmp    %esi,0x2ef9(%rip)
je     1145 <plot_point+0x35>
mov    %esi,0x2ef1(%rip)
mov    $0x5,%edi
call   1030 <write_register@plt>
movslq %ebp,%rax
shl    $0xa,%ebx
movslq %ebx,%rcx
shl    $0x2,%rcx
mov    %r14d,0xa0000(%rcx,%rax,4)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@plot_point.last_bank = internal global i32 0
define void @plot_point(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* @plot_point.last_bank
%8 = load i32, i32* %5
%9 = sdiv i32 %8, 16
%10 = icmp ne i32 %7, %9
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = load i32, i32* %5
%13 = sdiv i32 %12, 16
store i32 %13, i32* @plot_point.last_bank
%14 = load i32, i32* @plot_point.last_bank
%15 = call i32 @write_register(i32 5, i32 %14)
br label %16
16: ; preds = %11, %3
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* inttoptr (i64 655360 to i32*), i64 %19
%21 = load i32, i32* %5
%22 = srem i32 %21, 16
%23 = mul nsw i32 %22, 1024
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %20, i64 %24
store i32 %17, i32* %25
ret void
}

LLVM IR (-O2):
@plot_point.last_bank = internal unnamed_addr global i32 0
define void @plot_point(i32 %0, i32 %1, i32 %2) {
%4 = load i32, i32* @plot_point.last_bank
%5 = sdiv i32 %1, 16
%6 = srem i32 %1, 16
%7 = icmp eq i32 %4, %5
br i1 %7, label %10, label %8
8: ; preds = %3
store i32 %5, i32* @plot_point.last_bank
%9 = tail call i32 @write_register(i32 5, i32 %5)
br label %10
10: ; preds = %8, %3
%11 = sext i32 %0 to i64
%12 = getelementptr inbounds i32, i32* inttoptr (i64 655360 to i32*), i64 %11
%13 = shl nsw i32 %6, 10
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
store i32 %2, i32* %15
ret void
}