#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ _vram_read(char *, int);
int /*<<< orphan*/ _vram_write(char *, int);
int /*<<< orphan*/ _vram_write_run(int /*<<< orphan*/, int);
int /*<<< orphan*/ delay(int);
int /*<<< orphan*/ vdp_raddr(unsigned int);
int /*<<< orphan*/ vdp_waddr(unsigned int);
void scroll1() {
  char buf[40];
  unsigned int addr = 0x0000;
  delay(65534);
  delay(65534);
  delay(32767);
  for (; addr < (0x0000 + 40 * (24 - 1)); addr += 40) {
    vdp_raddr(addr + 40);
    _vram_read(buf, sizeof(buf));
    vdp_waddr(addr);
    _vram_write(buf, sizeof(buf));
  }
  _vram_write_run(0, 40);
}


x86 assembly (clang, -O0):
<scroll1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x34(%rbp)
mov    $0xfffe,%edi
call   1070 <delay@plt>
mov    $0xfffe,%edi
call   1070 <delay@plt>
mov    $0x7fff,%edi
call   1070 <delay@plt>
cmpl   $0x398,-0x34(%rbp)
jae    11d7 <scroll1+0x77>
mov    -0x34(%rbp),%edi
add    $0x28,%edi
call   1080 <vdp_raddr@plt>
lea    -0x30(%rbp),%rdi
mov    $0x28,%esi
call   1050 <_vram_read@plt>
mov    -0x34(%rbp),%edi
call   1060 <vdp_waddr@plt>
lea    -0x30(%rbp),%rdi
mov    $0x28,%esi
call   1030 <_vram_write@plt>
mov    -0x34(%rbp),%eax
add    $0x28,%eax
mov    %eax,-0x34(%rbp)
jmp    118d <scroll1+0x2d>
xor    %edi,%edi
mov    $0x28,%esi
call   1040 <_vram_write_run@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scroll1>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    $0xfffe,%edi
call   1070 <delay@plt>
mov    $0xfffe,%edi
call   1070 <delay@plt>
mov    $0x7fff,%edi
call   1070 <delay@plt>
mov    $0xffffffd8,%edi
mov    %rsp,%rbx
nopl   0x0(%rax)
lea    0x28(%rdi),%ebp
add    $0x50,%edi
call   1080 <vdp_raddr@plt>
mov    %rbx,%rdi
mov    $0x28,%esi
call   1050 <_vram_read@plt>
mov    %ebp,%edi
call   1060 <vdp_waddr@plt>
mov    %rbx,%rdi
mov    $0x28,%esi
call   1030 <_vram_write@plt>
mov    %ebp,%edi
cmp    $0x370,%ebp
jb     1190 <scroll1+0x30>
xor    %edi,%edi
mov    $0x28,%esi
call   1040 <_vram_write_run@plt>
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @scroll1() {
%1 = alloca [40 x i8]
%2 = alloca i32
store i32 0, i32* %2
%3 = call i32 @delay(i32 65534)
%4 = call i32 @delay(i32 65534)
%5 = call i32 @delay(i32 32767)
br label %6
6: ; preds = %19, %0
%7 = load i32, i32* %2
%8 = icmp ult i32 %7, 920
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = load i32, i32* %2
%11 = add i32 %10, 40
%12 = call i32 @vdp_raddr(i32 %11)
%13 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%14 = call i32 @_vram_read(i8* %13, i32 40)
%15 = load i32, i32* %2
%16 = call i32 @vdp_waddr(i32 %15)
%17 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%18 = call i32 @_vram_write(i8* %17, i32 40)
br label %19
19: ; preds = %9
%20 = load i32, i32* %2
%21 = add i32 %20, 40
store i32 %21, i32* %2
br label %6
22: ; preds = %6
%23 = call i32 @_vram_write_run(i32 0, i32 40)
ret void
}

LLVM IR (-O2):
define void @scroll1() {
%1 = alloca [40 x i8]
%2 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @delay(i32 65534)
%4 = tail call i32 @delay(i32 65534)
%5 = tail call i32 @delay(i32 32767)
br label %6
6: ; preds = %0, %6
%7 = phi i32 [ 0, %0 ], [ %8, %6 ]
%8 = add nuw nsw i32 %7, 40
%9 = call i32 @vdp_raddr(i32 %8)
%10 = call i32 @_vram_read(i8* %2, i32 40)
%11 = call i32 @vdp_waddr(i32 %7)
%12 = call i32 @_vram_write(i8* %2, i32 40)
%13 = icmp ult i32 %7, 880
br i1 %13, label %6, label %14
14: ; preds = %6
%15 = call i32 @_vram_write_run(i32 0, i32 40)
ret void
}