#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*/ Window;
typedef int /*<<< orphan*/ GC;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ RootWindow(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XCreateGC(int /*<<< orphan*/ *, int /*<<< orphan*/,
                             int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ XCreateSimpleWindow(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                       int, int, int, int, int,
                                       int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ XDrawPoint(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              int /*<<< orphan*/, int, int);
int /*<<< orphan*/ XFlush(int /*<<< orphan*/ *);
int /*<<< orphan*/ XMapWindow(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XSetForeground(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                  int /*<<< orphan*/);
int /*<<< orphan*/ XWhitePixel(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ get_gs_pixel(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "usage: %s <filename>\n", argv[0]);
    exit(1);
  }
  Display *disp = XOpenDisplay(NULL);
  Window win =
      XCreateSimpleWindow(disp, RootWindow(disp, 0), 200, 50, 400, 300, 2,
                          XWhitePixel(disp, 0), XWhitePixel(disp, 0));
  XMapWindow(disp, win);
  GC gc = XCreateGC(disp, win, 0, 0);
  FILE *fp = fopen(argv[1], "rb");
  if (fp) {
    for (int y = 0; y < 240; y++) {
      for (int x = 0; x < 640; x++) {
        XSetForeground(disp, gc, get_gs_pixel(disp, fgetc(fp)));
        XDrawPoint(disp, win, gc, x, y);
      }
    }
    fclose(fp);
  } else {
    fprintf(stderr, "ERROR: failed to open a file, '%s'\n", argv[1]);
    exit(1);
  }
  XFlush(disp);
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1246 <main+0x46>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc9(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   10a0 <RootWindow@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <XWhitePixel@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <XWhitePixel@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%r10d
mov    $0xc8,%edx
mov    $0x32,%ecx
mov    $0x190,%r8d
mov    $0x12c,%r9d
movl   $0x2,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   10c0 <XCreateSimpleWindow@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1110 <XMapWindow@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   10b0 <XCreateGC@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd2d(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     13a2 <main+0x1a2>
movl   $0x0,-0x2c(%rbp)
cmpl   $0xf0,-0x2c(%rbp)
jge    1394 <main+0x194>
movl   $0x0,-0x30(%rbp)
cmpl   $0x280,-0x30(%rbp)
jge    1381 <main+0x181>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <fgetc@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
call   10d0 <get_gs_pixel@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    %eax,%edx
call   10e0 <XSetForeground@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
call   1040 <XDrawPoint@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1318 <main+0x118>
jmp    1386 <main+0x186>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1304 <main+0x104>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
jmp    13c9 <main+0x1c9>
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc5f(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x18(%rbp),%rdi
call   10f0 <XFlush@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
cmp    $0x2,%edi
jne    1330 <main+0x130>
xor    %r14d,%r14d
xor    %edi,%edi
call   1080 <XOpenDisplay@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
call   10a0 <RootWindow@plt>
mov    %eax,%ebp
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <XWhitePixel@plt>
mov    %eax,%ebx
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <XWhitePixel@plt>
sub    $0x8,%rsp
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0xc8,%edx
mov    $0x32,%ecx
mov    $0x190,%r8d
mov    $0x12c,%r9d
push   %rax
push   %rbx
push   $0x2
call   10c0 <XCreateSimpleWindow@plt>
add    $0x20,%rsp
mov    %eax,%r12d
mov    %r15,%rdi
mov    %eax,%esi
call   1110 <XMapWindow@plt>
mov    %r15,%rdi
mov    %r12d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10b0 <XCreateGC@plt>
mov    %eax,%ebp
mov    %r13,%rbx
mov    0x8(%r13),%rdi
lea    0xd78(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     1346 <main+0x146>
mov    %rax,%r13
nop
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
call   1060 <fgetc@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   10d0 <get_gs_pixel@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   10e0 <XSetForeground@plt>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r14d,%r8d
call   1040 <XDrawPoint@plt>
add    $0x1,%ebx
cmp    $0x280,%ebx
jne    12c0 <main+0xc0>
add    $0x1,%r14d
cmp    $0xf0,%r14d
jne    12b0 <main+0xb0>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   10f0 <XFlush@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ca9(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xcbc(%rip),%rsi
jmp    135a <main+0x15a>
mov    0x2c93(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xcbf(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"usage: %s <filename>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [36 x i8] c"ERROR: failed to open a file, '%s'\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 i32*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = call i32* @XOpenDisplay(i32* null)
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = load i32*, i32** %6
%25 = call i32 @RootWindow(i32* %24, i32 0)
%26 = load i32*, i32** %6
%27 = call i32 @XWhitePixel(i32* %26, i32 0)
%28 = load i32*, i32** %6
%29 = call i32 @XWhitePixel(i32* %28, i32 0)
%30 = call i32 @XCreateSimpleWindow(i32* %23, i32 %25, i32 200, i32 50, i32 400, i32 300, i32 2, i32 %27, i32 %29)
store i32 %30, i32* %7
%31 = load i32*, i32** %6
%32 = load i32, i32* %7
%33 = call i32 @XMapWindow(i32* %31, i32 %32)
%34 = load i32*, i32** %6
%35 = load i32, i32* %7
%36 = call i32 @XCreateGC(i32* %34, i32 %35, i32 0, i32 0)
store i32 %36, i32* %8
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %40, i32** %9
%41 = load i32*, i32** %9
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %75
43: ; preds = %21
store i32 0, i32* %10
br label %44
44: ; preds = %69, %43
%45 = load i32, i32* %10
%46 = icmp slt i32 %45, 240
br i1 %46, label %47, label %72
47: ; preds = %44
store i32 0, i32* %11
br label %48
48: ; preds = %65, %47
%49 = load i32, i32* %11
%50 = icmp slt i32 %49, 640
br i1 %50, label %51, label %68
51: ; preds = %48
%52 = load i32*, i32** %6
%53 = load i32, i32* %8
%54 = load i32*, i32** %6
%55 = load i32*, i32** %9
%56 = call i32 @fgetc(i32* %55)
%57 = call i32 @get_gs_pixel(i32* %54, i32 %56)
%58 = call i32 @XSetForeground(i32* %52, i32 %53, i32 %57)
%59 = load i32*, i32** %6
%60 = load i32, i32* %7
%61 = load i32, i32* %8
%62 = load i32, i32* %11
%63 = load i32, i32* %10
%64 = call i32 @XDrawPoint(i32* %59, i32 %60, i32 %61, i32 %62, i32 %63)
br label %65
65: ; preds = %51
%66 = load i32, i32* %11
%67 = add nsw i32 %66, 1
store i32 %67, i32* %11
br label %48
68: ; preds = %48
br label %69
69: ; preds = %68
%70 = load i32, i32* %10
%71 = add nsw i32 %70, 1
store i32 %71, i32* %10
br label %44
72: ; preds = %44
%73 = load i32*, i32** %9
%74 = call i32 @fclose(i32* %73)
br label %82
75: ; preds = %21
%76 = load i32, i32* @stderr
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 1
%79 = load i8*, i8** %78
%80 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %79)
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %72
%83 = load i32*, i32** %6
%84 = call i32 @XFlush(i32* %83)
%85 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"usage: %s <filename>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [36 x i8] c"ERROR: failed to open a file, '%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i32* @XOpenDisplay(i32* null)
%11 = tail call i32 @RootWindow(i32* %10, i32 0)
%12 = tail call i32 @XWhitePixel(i32* %10, i32 0)
%13 = tail call i32 @XWhitePixel(i32* %10, i32 0)
%14 = tail call i32 @XCreateSimpleWindow(i32* %10, i32 %11, i32 200, i32 50, i32 400, i32 300, i32 2, i32 %12, i32 %13)
%15 = tail call i32 @XMapWindow(i32* %10, i32 %14)
%16 = tail call i32 @XCreateGC(i32* %10, i32 %14, i32 0, i32 0)
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %38, label %21
21: ; preds = %9, %27
%22 = phi i32 [ %28, %27 ], [ 0, %9 ]
br label %30
23: ; preds = %27
%24 = tail call i32 @fclose(i32* %19)
%25 = tail call i32 @XFlush(i32* %10)
%26 = tail call i32 (...) @getchar()
ret i32 0
27: ; preds = %30
%28 = add nuw nsw i32 %22, 1
%29 = icmp eq i32 %28, 240
br i1 %29, label %23, label %21
30: ; preds = %21, %30
%31 = phi i32 [ 0, %21 ], [ %36, %30 ]
%32 = tail call i32 @fgetc(i32* %19)
%33 = tail call i32 @get_gs_pixel(i32* %10, i32 %32)
%34 = tail call i32 @XSetForeground(i32* %10, i32 %16, i32 %33)
%35 = tail call i32 @XDrawPoint(i32* %10, i32 %14, i32 %16, i32 %31, i32 %22)
%36 = add nuw nsw i32 %31, 1
%37 = icmp eq i32 %36, 640
br i1 %37, label %27, label %30
38: ; preds = %9
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %17
%41 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = tail call i32 @exit(i32 1)
unreachable
}