#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*/ retro_init(int, char **);
unsigned char *retro_video_get_framebuffer();
scalar_t__ retro_video_get_vsync_signal();
int /*<<< orphan*/ retro_video_set_fps(int);
int /*<<< orphan*/ retro_video_set_framebuffer_size(int);
int /*<<< orphan*/ retro_video_set_framebuffer_width(int);
int /*<<< orphan*/ retro_video_set_viewport_position(int /*<<< orphan*/,
                                                     int /*<<< orphan*/);
int /*<<< orphan*/ retro_video_set_viewport_size(int, int);
int /*<<< orphan*/ sleep(int);
int main(int argc, char **argv) {
  retro_init(argc, argv);
  retro_video_set_framebuffer_size(128000);
  retro_video_set_framebuffer_width(640);
  retro_video_set_fps(60);
  retro_video_set_viewport_position(0, 0);
  retro_video_set_viewport_size(320, 200);
  unsigned char *screen = retro_video_get_framebuffer();
  int i, x, y, offset;
  for (i = 0; i < 100000; i += 10) {
    for (y = 0; y < 200; ++y) {
      for (x = 0; x < 320; ++x) {
        offset = y * 640 + x;
        screen[offset * 3 + 0] = i % 255;
        screen[offset * 3 + 1] = i % 255;
        screen[offset * 3 + 2] = 0;
      }
    }
    while (retro_video_get_vsync_signal())
      ;
    while (!retro_video_get_vsync_signal())
      ;
  }
  sleep(20);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <retro_init@plt>
mov    $0x1f400,%edi
call   1050 <retro_video_set_framebuffer_size@plt>
mov    $0x280,%edi
call   1090 <retro_video_set_framebuffer_width@plt>
mov    $0x3c,%edi
call   1060 <retro_video_set_fps@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1030 <retro_video_set_viewport_position@plt>
mov    $0x140,%edi
mov    $0xc8,%esi
call   1080 <retro_video_set_viewport_size@plt>
mov    $0x0,%al
call   1040 <retro_video_get_framebuffer@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x186a0,-0x1c(%rbp)
jge    12fc <main+0x16c>
movl   $0x0,-0x24(%rbp)
cmpl   $0xc8,-0x24(%rbp)
jge    12a7 <main+0x117>
movl   $0x0,-0x20(%rbp)
cmpl   $0x140,-0x20(%rbp)
jge    1294 <main+0x104>
imul   $0x280,-0x24(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
imul   $0x3,-0x28(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
imul   $0x3,-0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
imul   $0x3,-0x28(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1222 <main+0x92>
jmp    1299 <main+0x109>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    120e <main+0x7e>
jmp    12ac <main+0x11c>
mov    $0x0,%al
call   10a0 <retro_video_get_vsync_signal@plt>
cmp    $0x0,%rax
je     12c2 <main+0x132>
jmp    12ac <main+0x11c>
jmp    12c7 <main+0x137>
mov    $0x0,%al
call   10a0 <retro_video_get_vsync_signal@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12e4 <main+0x154>
jmp    12e9 <main+0x159>
jmp    12c7 <main+0x137>
jmp    12ee <main+0x15e>
mov    -0x1c(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x1c(%rbp)
jmp    11fa <main+0x6a>
mov    $0x14,%edi
call   10b0 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
call   1070 <retro_init@plt>
mov    $0x1f400,%edi
call   1050 <retro_video_set_framebuffer_size@plt>
mov    $0x280,%edi
call   1090 <retro_video_set_framebuffer_width@plt>
mov    $0x3c,%edi
call   1060 <retro_video_set_fps@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <retro_video_set_viewport_position@plt>
mov    $0x140,%edi
mov    $0xc8,%esi
call   1080 <retro_video_set_viewport_size@plt>
xor    %eax,%eax
call   1040 <retro_video_get_framebuffer@plt>
mov    %rax,%r15
mov    $0x80808081,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%eax
imul   %r14,%rax
shr    $0x27,%rax
add    %ebx,%eax
mov    %r15,%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x5,%esi
cs nopw 0x0(%rax,%rax,1)
nop
mov    %al,-0x5(%rcx,%rsi,1)
mov    %al,-0x4(%rcx,%rsi,1)
movb   $0x0,-0x3(%rcx,%rsi,1)
mov    %al,-0x2(%rcx,%rsi,1)
mov    %al,-0x1(%rcx,%rsi,1)
movb   $0x0,(%rcx,%rsi,1)
add    $0x6,%rsi
cmp    $0x3c5,%rsi
jne    1220 <main+0x90>
add    $0x1,%rdx
add    $0x780,%rcx
cmp    $0xc8,%rdx
jne    1210 <main+0x80>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <retro_video_get_vsync_signal@plt>
test   %rax,%rax
jne    1260 <main+0xd0>
nopl   0x0(%rax)
xor    %eax,%eax
call   10a0 <retro_video_get_vsync_signal@plt>
test   %rax,%rax
je     1270 <main+0xe0>
lea    0xa(%rbx),%eax
cmp    $0x18696,%ebx
mov    %eax,%ebx
jb     11f0 <main+0x60>
mov    $0x14,%edi
call   10b0 <sleep@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @retro_init(i32 %11, i8** %12)
%14 = call i32 @retro_video_set_framebuffer_size(i32 128000)
%15 = call i32 @retro_video_set_framebuffer_width(i32 640)
%16 = call i32 @retro_video_set_fps(i32 60)
%17 = call i32 @retro_video_set_viewport_position(i32 0, i32 0)
%18 = call i32 @retro_video_set_viewport_size(i32 320, i32 200)
%19 = call i8* (...) @retro_video_get_framebuffer()
store i8* %19, i8** %6
store i32 0, i32* %7
br label %20
20: ; preds = %79, %2
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 100000
br i1 %22, label %23, label %82
23: ; preds = %20
store i32 0, i32* %9
br label %24
24: ; preds = %64, %23
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 200
br i1 %26, label %27, label %67
27: ; preds = %24
store i32 0, i32* %8
br label %28
28: ; preds = %60, %27
%29 = load i32, i32* %8
%30 = icmp slt i32 %29, 320
br i1 %30, label %31, label %63
31: ; preds = %28
%32 = load i32, i32* %9
%33 = mul nsw i32 %32, 640
%34 = load i32, i32* %8
%35 = add nsw i32 %33, %34
store i32 %35, i32* %10
%36 = load i32, i32* %7
%37 = srem i32 %36, 255
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %6
%40 = load i32, i32* %10
%41 = mul nsw i32 %40, 3
%42 = add nsw i32 %41, 0
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %39, i64 %43
store i8 %38, i8* %44
%45 = load i32, i32* %7
%46 = srem i32 %45, 255
%47 = trunc i32 %46 to i8
%48 = load i8*, i8** %6
%49 = load i32, i32* %10
%50 = mul nsw i32 %49, 3
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %48, i64 %52
store i8 %47, i8* %53
%54 = load i8*, i8** %6
%55 = load i32, i32* %10
%56 = mul nsw i32 %55, 3
%57 = add nsw i32 %56, 2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %54, i64 %58
store i8 0, i8* %59
br label %60
60: ; preds = %31
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %28
63: ; preds = %28
br label %64
64: ; preds = %63
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %24
67: ; preds = %24
br label %68
68: ; preds = %71, %67
%69 = call i64 (...) @retro_video_get_vsync_signal()
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %68
br label %68
72: ; preds = %68
br label %73
73: ; preds = %77, %72
%74 = call i64 (...) @retro_video_get_vsync_signal()
%75 = icmp ne i64 %74, 0
%76 = xor i1 %75, true
br i1 %76, label %77, label %78
77: ; preds = %73
br label %73
78: ; preds = %73
br label %79
79: ; preds = %78
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 10
store i32 %81, i32* %7
br label %20
82: ; preds = %20
%83 = call i32 @sleep(i32 20)
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @retro_init(i32 %0, i8** %1)
%4 = tail call i32 @retro_video_set_framebuffer_size(i32 128000)
%5 = tail call i32 @retro_video_set_framebuffer_width(i32 640)
%6 = tail call i32 @retro_video_set_fps(i32 60)
%7 = tail call i32 @retro_video_set_viewport_position(i32 0, i32 0)
%8 = tail call i32 @retro_video_set_viewport_size(i32 320, i32 200)
%9 = tail call i8* (...) @retro_video_get_framebuffer()
br label %10
10: ; preds = %2, %45
%11 = phi i32 [ 0, %2 ], [ %46, %45 ]
%12 = urem i32 %11, 255
%13 = trunc i32 %12 to i8
br label %14
14: ; preds = %10, %36
%15 = phi i64 [ 0, %10 ], [ %37, %36 ]
%16 = mul nuw nsw i64 %15, 640
br label %17
17: ; preds = %17, %14
%18 = phi i64 [ 0, %14 ], [ %34, %17 ]
%19 = add nuw nsw i64 %18, %16
%20 = mul nuw nsw i64 %19, 3
%21 = getelementptr inbounds i8, i8* %9, i64 %20
store i8 %13, i8* %21
%22 = or i64 %20, 1
%23 = getelementptr inbounds i8, i8* %9, i64 %22
store i8 %13, i8* %23
%24 = add nuw nsw i64 %20, 2
%25 = getelementptr inbounds i8, i8* %9, i64 %24
store i8 0, i8* %25
%26 = or i64 %18, 1
%27 = add nuw nsw i64 %26, %16
%28 = mul nuw nsw i64 %27, 3
%29 = getelementptr inbounds i8, i8* %9, i64 %28
store i8 %13, i8* %29
%30 = add nuw nsw i64 %28, 1
%31 = getelementptr inbounds i8, i8* %9, i64 %30
store i8 %13, i8* %31
%32 = add nuw nsw i64 %28, 2
%33 = getelementptr inbounds i8, i8* %9, i64 %32
store i8 0, i8* %33
%34 = add nuw nsw i64 %18, 2
%35 = icmp eq i64 %34, 320
br i1 %35, label %36, label %17
36: ; preds = %17
%37 = add nuw nsw i64 %15, 1
%38 = icmp eq i64 %37, 200
br i1 %38, label %39, label %14
39: ; preds = %36, %39
%40 = tail call i64 (...) @retro_video_get_vsync_signal()
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %39
42: ; preds = %39, %42
%43 = tail call i64 (...) @retro_video_get_vsync_signal()
%44 = icmp eq i64 %43, 0
br i1 %44, label %42, label %45
45: ; preds = %42
%46 = add nuw nsw i32 %11, 10
%47 = icmp ult i32 %11, 99990
br i1 %47, label %10, label %48
48: ; preds = %45
%49 = tail call i32 @sleep(i32 20)
ret i32 0
}