#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*/ exit(int);
int getchar();
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int vmwLoadPCX(char *, char *);
int /*<<< orphan*/ vmwos_framebuffer_load(int, int, int, char *);
char *vmwos_malloc(int);
int main(int argc, char **argv) {
  int result;
  int slide = 0;
  int ch;
  char filename[32];
  char *pixels;
  printf("Starting slide show!\n");
  pixels = vmwos_malloc(800 * 600 * 3);
  printf("Memsetting %p\n", pixels);
  memset(pixels, 0xff, 800 * 600 * 3);
  while (1) {
    sprintf(filename, "out-%d.pcx", slide);
    result = vmwLoadPCX(filename, pixels);
    if (result < 0) {
      printf("Error opening %s\n", filename);
      exit(1);
    }
    vmwos_framebuffer_load(800, 600, 24, pixels);
    printf("About to get character\n");
    ch = getchar();
    printf("Read character %x\n", ch);
    if (ch == ' ')
      slide++;
    if (ch == 'q')
      break;
    if (ch == 'b') {
      slide--;
      if (slide < 0)
        slide = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x15f900,%edi
call   1030 <vmwos_malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rdi
mov    $0xff,%esi
mov    $0x15f900,%edx
call   1050 <memset@plt>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe39(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1070 <vmwLoadPCX@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1227 <main+0xa7>
lea    -0x40(%rbp),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x48(%rbp),%rcx
mov    $0x320,%edi
mov    $0x258,%esi
mov    $0x18,%edx
call   10a0 <vmwos_framebuffer_load@plt>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x20,-0x1c(%rbp)
jne    127b <main+0xfb>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x71,-0x1c(%rbp)
jne    128a <main+0x10a>
jmp    12b8 <main+0x138>
cmpl   $0x62,-0x1c(%rbp)
jne    12b3 <main+0x133>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12ae <main+0x12e>
movl   $0x0,-0x18(%rbp)
jmp    12b3 <main+0x133>
jmp    11de <main+0x5e>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe9a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x15f900,%edi
call   1030 <vmwos_malloc@plt>
mov    %rax,%rbx
lea    0xe42(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    $0x15f900,%edx
call   1060 <memset@plt>
lea    0xe2e(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %edx,%edx
call   1090 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <vmwLoadPCX@plt>
test   %eax,%eax
js     12b3 <main+0x123>
lea    0xe24(%rip),%r15
mov    %rsp,%r13
xor    %r12d,%r12d
jmp    1236 <main+0xa6>
add    $0xffffffff,%ebp
mov    %r13,%rdi
lea    0xdf2(%rip),%rsi
mov    %ebp,%edx
call   1090 <sprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <vmwLoadPCX@plt>
mov    %ebp,%r12d
test   %eax,%eax
js     12b3 <main+0x123>
mov    $0x320,%edi
mov    $0x258,%esi
mov    $0x18,%edx
mov    %rbx,%rcx
call   10b0 <vmwos_framebuffer_load@plt>
lea    0xe00(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%r14d
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
cmp    $0x20,%r14d
sete   %bpl
add    %r12d,%ebp
cmp    $0x62,%r14d
je     1290 <main+0x100>
cmp    $0x71,%r14d
jne    1213 <main+0x83>
jmp    12a2 <main+0x112>
nopw   0x0(%rax,%rax,1)
test   %ebp,%ebp
jg     1210 <main+0x80>
mov    $0x1,%ebp
jmp    1210 <main+0x80>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd60(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Starting slide show!\0A\00"
@.str.1 = [15 x i8] c"Memsetting %p\0A\00"
@.str.2 = [11 x i8] c"out-%d.pcx\00"
@.str.3 = [18 x i8] c"Error opening %s\0A\00"
@.str.4 = [24 x i8] c"About to get character\0A\00"
@.str.5 = [19 x i8] c"Read character %x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [32 x i8]
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%12 = call i8* @vmwos_malloc(i32 1440000)
store i8* %12, i8** %10
%13 = load i8*, i8** %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %10
%16 = call i32 @memset(i8* %15, i32 255, i32 1440000)
br label %17
17: ; preds = %2, %56
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%19 = load i32, i32* %7
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%22 = load i8*, i8** %10
%23 = call i32 @vmwLoadPCX(i8* %21, i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %17
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = load i8*, i8** %10
%32 = call i32 @vmwos_framebuffer_load(i32 800, i32 600, i32 24, i8* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 (...) @getchar()
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %8
%38 = icmp eq i32 %37, 32
br i1 %38, label %39, label %42
39: ; preds = %30
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %42
42: ; preds = %39, %30
%43 = load i32, i32* %8
%44 = icmp eq i32 %43, 113
br i1 %44, label %45, label %46
45: ; preds = %42
br label %57
46: ; preds = %42
%47 = load i32, i32* %8
%48 = icmp eq i32 %47, 98
br i1 %48, label %49, label %56
49: ; preds = %46
%50 = load i32, i32* %7
%51 = add nsw i32 %50, -1
store i32 %51, i32* %7
%52 = load i32, i32* %7
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %49
store i32 0, i32* %7
br label %55
55: ; preds = %54, %49
br label %56
56: ; preds = %55, %46
br label %17
57: ; preds = %45
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"Memsetting %p\0A\00"
@.str.2 = [11 x i8] c"out-%d.pcx\00"
@.str.3 = [18 x i8] c"Error opening %s\0A\00"
@.str.5 = [19 x i8] c"Read character %x\0A\00"
@str = [21 x i8] c"Starting slide show!\00"
@str.6 = [23 x i8] c"About to get character\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%6 = tail call i8* @vmwos_malloc(i32 1440000)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = tail call i32 @memset(i8* %6, i32 255, i32 1440000)
%9 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 0)
%10 = call i32 @vmwLoadPCX(i8* %4, i8* %6)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %28, %2
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2, %28
%16 = phi i32 [ %29, %28 ], [ 0, %2 ]
%17 = call i32 @vmwos_framebuffer_load(i32 800, i32 600, i32 24, i8* %6)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
%19 = call i32 (...) @getchar()
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = icmp eq i32 %19, 32
%22 = zext i1 %21 to i32
%23 = add nsw i32 %16, %22
switch i32 %19, label %28 [
i32 113, label %33
i32 98, label %24
]
24: ; preds = %15
%25 = icmp sgt i32 %23, 1
%26 = select i1 %25, i32 %23, i32 1
%27 = add nsw i32 %26, -1
br label %28
28: ; preds = %15, %24
%29 = phi i32 [ %27, %24 ], [ %23, %15 ]
%30 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = call i32 @vmwLoadPCX(i8* %4, i8* %6)
%32 = icmp slt i32 %31, 0
br i1 %32, label %12, label %15
33: ; preds = %15
ret i32 0
}