#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 /*<<< orphan*/ memory_copy(unsigned char *, unsigned char *, int);
int handle_scrolling(int cursor_offset) {
  int i;
  unsigned char *video_memory = (unsigned char *)0xb8000;
  for (i = 0; i < 25; i++) {
    memory_copy((video_memory + 160), video_memory, 160);
    video_memory += 160;
  }
  cursor_offset -= 80;
  return cursor_offset;
}


x86 assembly (clang, -O0):
<handle_scrolling>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0xb8000,%eax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x19,-0x8(%rbp)
jge    116a <handle_scrolling+0x5a>
mov    -0x10(%rbp),%rdi
add    $0xa0,%rdi
mov    -0x10(%rbp),%rsi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    -0x10(%rbp),%rax
add    $0xa0,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112b <handle_scrolling+0x1b>
mov    -0x4(%rbp),%eax
sub    $0x50,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_scrolling>:
push   %rbx
mov    %edi,%ebx
mov    $0xb80a0,%edi
mov    $0xb8000,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8140,%edi
mov    $0xb80a0,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb81e0,%edi
mov    $0xb8140,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8280,%edi
mov    $0xb81e0,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8320,%edi
mov    $0xb8280,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb83c0,%edi
mov    $0xb8320,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8460,%edi
mov    $0xb83c0,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8500,%edi
mov    $0xb8460,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb85a0,%edi
mov    $0xb8500,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8640,%edi
mov    $0xb85a0,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb86e0,%edi
mov    $0xb8640,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8780,%edi
mov    $0xb86e0,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8820,%edi
mov    $0xb8780,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb88c0,%edi
mov    $0xb8820,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8960,%edi
mov    $0xb88c0,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8a00,%edi
mov    $0xb8960,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8aa0,%edi
mov    $0xb8a00,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8b40,%edi
mov    $0xb8aa0,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8be0,%edi
mov    $0xb8b40,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8c80,%edi
mov    $0xb8be0,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8d20,%edi
mov    $0xb8c80,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8dc0,%edi
mov    $0xb8d20,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8e60,%edi
mov    $0xb8dc0,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8f00,%edi
mov    $0xb8e60,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
mov    $0xb8fa0,%edi
mov    $0xb8f00,%esi
mov    $0xa0,%edx
call   1030 <memory_copy@plt>
add    $0xffffffb0,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @handle_scrolling(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
store i8* inttoptr (i64 753664 to i8*), i8** %4
store i32 0, i32* %3
br label %5
5: ; preds = %15, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 25
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i64 160
%11 = load i8*, i8** %4
%12 = call i32 @memory_copy(i8* %10, i8* %11, i32 160)
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 160
store i8* %14, i8** %4
br label %15
15: ; preds = %8
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %5
18: ; preds = %5
%19 = load i32, i32* %2
%20 = sub nsw i32 %19, 80
store i32 %20, i32* %2
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
define i32 @handle_scrolling(i32 %0) {
%2 = tail call i32 @memory_copy(i8* inttoptr (i64 753824 to i8*), i8* inttoptr (i64 753664 to i8*), i32 160)
%3 = tail call i32 @memory_copy(i8* inttoptr (i64 753984 to i8*), i8* inttoptr (i64 753824 to i8*), i32 160)
%4 = tail call i32 @memory_copy(i8* inttoptr (i64 754144 to i8*), i8* inttoptr (i64 753984 to i8*), i32 160)
%5 = tail call i32 @memory_copy(i8* inttoptr (i64 754304 to i8*), i8* inttoptr (i64 754144 to i8*), i32 160)
%6 = tail call i32 @memory_copy(i8* inttoptr (i64 754464 to i8*), i8* inttoptr (i64 754304 to i8*), i32 160)
%7 = tail call i32 @memory_copy(i8* inttoptr (i64 754624 to i8*), i8* inttoptr (i64 754464 to i8*), i32 160)
%8 = tail call i32 @memory_copy(i8* inttoptr (i64 754784 to i8*), i8* inttoptr (i64 754624 to i8*), i32 160)
%9 = tail call i32 @memory_copy(i8* inttoptr (i64 754944 to i8*), i8* inttoptr (i64 754784 to i8*), i32 160)
%10 = tail call i32 @memory_copy(i8* inttoptr (i64 755104 to i8*), i8* inttoptr (i64 754944 to i8*), i32 160)
%11 = tail call i32 @memory_copy(i8* inttoptr (i64 755264 to i8*), i8* inttoptr (i64 755104 to i8*), i32 160)
%12 = tail call i32 @memory_copy(i8* inttoptr (i64 755424 to i8*), i8* inttoptr (i64 755264 to i8*), i32 160)
%13 = tail call i32 @memory_copy(i8* inttoptr (i64 755584 to i8*), i8* inttoptr (i64 755424 to i8*), i32 160)
%14 = tail call i32 @memory_copy(i8* inttoptr (i64 755744 to i8*), i8* inttoptr (i64 755584 to i8*), i32 160)
%15 = tail call i32 @memory_copy(i8* inttoptr (i64 755904 to i8*), i8* inttoptr (i64 755744 to i8*), i32 160)
%16 = tail call i32 @memory_copy(i8* inttoptr (i64 756064 to i8*), i8* inttoptr (i64 755904 to i8*), i32 160)
%17 = tail call i32 @memory_copy(i8* inttoptr (i64 756224 to i8*), i8* inttoptr (i64 756064 to i8*), i32 160)
%18 = tail call i32 @memory_copy(i8* inttoptr (i64 756384 to i8*), i8* inttoptr (i64 756224 to i8*), i32 160)
%19 = tail call i32 @memory_copy(i8* inttoptr (i64 756544 to i8*), i8* inttoptr (i64 756384 to i8*), i32 160)
%20 = tail call i32 @memory_copy(i8* inttoptr (i64 756704 to i8*), i8* inttoptr (i64 756544 to i8*), i32 160)
%21 = tail call i32 @memory_copy(i8* inttoptr (i64 756864 to i8*), i8* inttoptr (i64 756704 to i8*), i32 160)
%22 = tail call i32 @memory_copy(i8* inttoptr (i64 757024 to i8*), i8* inttoptr (i64 756864 to i8*), i32 160)
%23 = tail call i32 @memory_copy(i8* inttoptr (i64 757184 to i8*), i8* inttoptr (i64 757024 to i8*), i32 160)
%24 = tail call i32 @memory_copy(i8* inttoptr (i64 757344 to i8*), i8* inttoptr (i64 757184 to i8*), i32 160)
%25 = tail call i32 @memory_copy(i8* inttoptr (i64 757504 to i8*), i8* inttoptr (i64 757344 to i8*), i32 160)
%26 = tail call i32 @memory_copy(i8* inttoptr (i64 757664 to i8*), i8* inttoptr (i64 757504 to i8*), i32 160)
%27 = add nsw i32 %0, -80
ret i32 %27
}