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

/* Variables and functions */
scalar_t__ ece391_vidmap(int /*<<< orphan*/ **);
int /*<<< orphan*/ printf(char *);
int main() {
  uint8_t *vmem;
  if (ece391_vidmap(&vmem) != 0) {
    printf("cannot open video memory\n");
    return -1;
  }
  while (1) {
    for (int i = 0; i < 80 * 24; i++)
      vmem[i * 2]++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <ece391_vidmap@plt>
cmp    $0x0,%rax
je     1159 <main+0x39>
lea    0xeb7(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    115e <main+0x3e>
movl   $0x0,-0x14(%rbp)
cmpl   $0x780,-0x14(%rbp)
jge    1196 <main+0x76>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <main+0x45>
jmp    115e <main+0x3e>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1040 <ece391_vidmap@plt>
test   %rax,%rax
je     1141 <main+0x21>
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
mov    (%rsp),%rax
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x3,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
addl   $0x1,-0x18(%rax,%rcx,8)
addl   $0x1,-0x10(%rax,%rcx,8)
addl   $0x1,-0x8(%rax,%rcx,8)
addl   $0x1,(%rax,%rcx,8)
add    $0x4,%rcx
cmp    $0x783,%rcx
jne    1160 <main+0x40>
jmp    1150 <main+0x30>

LLVM IR (-O0):
@.str = [26 x i8] c"cannot open video memory\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 @ece391_vidmap(i32** %2)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
ret i32 -1
8: ; preds = %0
br label %9
9: ; preds = %8, %24
store i32 0, i32* %3
br label %10
10: ; preds = %21, %9
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 1920
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = load i32*, i32** %2
%15 = load i32, i32* %3
%16 = mul nsw i32 %15, 2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %14, i64 %17
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %18
br label %21
21: ; preds = %13
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %10
24: ; preds = %10
br label %9
}

LLVM IR (-O2):
@str = [25 x i8] c"cannot open video memory\00"
define i32 @main() {
%1 = alloca i32*
%2 = bitcast i32** %1 to i8*
%3 = call i64 @ece391_vidmap(i32** %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = load i32*, i32** %1
br label %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
ret i32 -1
9: ; preds = %10, %5
br label %10
10: ; preds = %10, %9
%11 = phi i64 [ 0, %9 ], [ %31, %10 ]
%12 = shl nuw nsw i64 %11, 1
%13 = getelementptr inbounds i32, i32* %6, i64 %12
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
store i32 %15, i32* %13
%16 = shl nuw i64 %11, 1
%17 = or i64 %16, 2
%18 = getelementptr inbounds i32, i32* %6, i64 %17
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %18
%21 = shl nuw i64 %11, 1
%22 = or i64 %21, 4
%23 = getelementptr inbounds i32, i32* %6, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
store i32 %25, i32* %23
%26 = shl nuw i64 %11, 1
%27 = or i64 %26, 6
%28 = getelementptr inbounds i32, i32* %6, i64 %27
%29 = load i32, i32* %28
%30 = add nsw i32 %29, 1
store i32 %30, i32* %28
%31 = add nuw nsw i64 %11, 4
%32 = icmp eq i64 %31, 1920
br i1 %32, label %9, label %10
}