#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 O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ draw_hline(int, int, int, int);
int /*<<< orphan*/ draw_point(int, int, int);
int /*<<< orphan*/ draw_vline(int, int, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ init_draw(int);
int open(char *, int, int);
int /*<<< orphan*/ sscanf(char *, char *, char *, int *, int *, int *);
int /*<<< orphan*/ stderr;
int main(void) {
  int a, b, c, i = 0;
  char ch;
  int fd = open("image", O_WRONLY | O_CREAT | O_TRUNC, 0644);
  if (fd < 0) {
    fprintf(stderr, "Cannot open file\n");
    exit(1);
  }
  init_draw(fd);
  char *icode[] = {"v 1 1 11",   "v 11 7 11",  "v 14 5 11", "v 18 6 11",
                   "v 21 5 10",  "v 25 5 10",  "v 29 5 6",  "v 33 5 6",
                   "v 29 10 11", "v 33 10 11", "h 11 1 8",  "h 5 16 17",
                   "h 11 22 24", "p 11 5 0",   "p 15 6 0",  "p 26 11 0",
                   "p 30 7 0",   "p 32 7 0",   "p 31 8 0",  "p 30 9 0",
                   "p 32 9 0",   NULL};
  while (icode[i] != NULL) {
    sscanf(icode[i], "%c %d %d %d", &ch, &a, &b, &c);
    switch (ch) {
    case 'v':
      draw_vline(fd, a, b, c);
      break;
    case 'h':
      draw_hline(fd, a, b, c);
      break;
    case 'p':
      draw_point(fd, a, b);
      break;
    default:
      abort();
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
mov    0x2e2f(%rip),%rax
or     (%rax),%esi
mov    0x2e1e(%rip),%rax
or     (%rax),%esi
lea    0xe25(%rip),%rdi
mov    $0x1a4,%edx
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1211 <main+0x71>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <init_draw@plt>
lea    -0xd0(%rbp),%rdi
lea    0x2b29(%rip),%rsi
mov    $0xb0,%edx
call   1080 <memcpy@plt>
movslq -0x14(%rbp),%rax
cmpq   $0x0,-0xd0(%rbp,%rax,8)
je     12f7 <main+0x157>
movslq -0x14(%rbp),%rax
mov    -0xd0(%rbp,%rax,8),%rdi
ff
lea    0xe8b(%rip),%rsi
lea    -0x15(%rbp),%rdx
lea    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%r8
lea    -0x10(%rbp),%r9
call   1090 <sscanf@plt>
movsbl -0x15(%rbp),%eax
mov    %eax,-0xd4(%rbp)
sub    $0x68,%eax
je     12c2 <main+0x122>
jmp    1284 <main+0xe4>
mov    -0xd4(%rbp),%eax
sub    $0x70,%eax
je     12d8 <main+0x138>
jmp    1298 <main+0xf8>
mov    -0xd4(%rbp),%eax
sub    $0x76,%eax
jne    12eb <main+0x14b>
jmp    12ac <main+0x10c>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1060 <draw_vline@plt>
jmp    12f2 <main+0x152>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1050 <draw_hline@plt>
jmp    12f2 <main+0x152>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <draw_point@plt>
jmp    12f2 <main+0x152>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    1231 <main+0x91>
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e1b(%rip),%rax
mov    0x2e4c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e39(%rip),%rax
or     (%rax),%esi
lea    0xe40(%rip),%rdi
mov    $0x1a4,%edx
call   10a0 <open@plt>
test   %eax,%eax
jns    11ed <main+0x5d>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1090 <init_draw@plt>
lea    0xe24(%rip),%r15
lea    0xb(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%rbp
lea    0x14(%rsp),%r14
jmp    122f <main+0x9f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %ebx,%edi
call   1030 <draw_point@plt>
lea    0xde2(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
mov    %r14,%r9
call   1080 <sscanf@plt>
movsbl 0xb(%rsp),%eax
cmp    $0x68,%eax
je     1280 <main+0xf0>
cmp    $0x70,%eax
je     1220 <main+0x90>
cmp    $0x76,%eax
jne    1295 <main+0x105>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %ebx,%edi
call   1060 <draw_vline@plt>
jmp    122f <main+0x9f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %ebx,%edi
call   1050 <draw_hline@plt>
jmp    122f <main+0x9f>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"image\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@stderr = global i32 0
@.str.1 = [18 x i8] c"Cannot open file\0A\00"
@.str.2 = [9 x i8] c"v 1 1 11\00"
@.str.3 = [10 x i8] c"v 11 7 11\00"
@.str.4 = [10 x i8] c"v 14 5 11\00"
@.str.5 = [10 x i8] c"v 18 6 11\00"
@.str.6 = [10 x i8] c"v 21 5 10\00"
@.str.7 = [10 x i8] c"v 25 5 10\00"
@.str.8 = [9 x i8] c"v 29 5 6\00"
@.str.9 = [9 x i8] c"v 33 5 6\00"
@.str.10 = [11 x i8] c"v 29 10 11\00"
@.str.11 = [11 x i8] c"v 33 10 11\00"
@.str.12 = [9 x i8] c"h 11 1 8\00"
@.str.13 = [10 x i8] c"h 5 16 17\00"
@.str.14 = [11 x i8] c"h 11 22 24\00"
@.str.15 = [9 x i8] c"p 11 5 0\00"
@.str.16 = [9 x i8] c"p 15 6 0\00"
@.str.17 = [10 x i8] c"p 26 11 0\00"
@.str.18 = [9 x i8] c"p 30 7 0\00"
@.str.19 = [9 x i8] c"p 32 7 0\00"
@.str.20 = [9 x i8] c"p 31 8 0\00"
@.str.21 = [9 x i8] c"p 30 9 0\00"
@.str.22 = [9 x i8] c"p 32 9 0\00"
@__const.main.icode = [22 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.18, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.20, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.21, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.22, i32 0, i32 0), i8* null]
@.str.23 = [12 x i8] c"%c %d %d %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca [22 x i8*]
store i32 0, i32* %1
store i32 0, i32* %5
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %13, i32 420)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %0
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %0
%22 = load i32, i32* %7
%23 = call i32 @init_draw(i32 %22)
%24 = bitcast [22 x i8*]* %8 to i8*
br label %25
25: ; preds = %58, %21
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [22 x i8*], [22 x i8*]* %8, i64 0, i64 %27
%29 = load i8*, i8** %28
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %59
31: ; preds = %25
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [22 x i8*], [22 x i8*]* %8, i64 0, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.23, i64 0, i64 0), i8* %6, i32* %2, i32* %3, i32* %4)
%37 = load i8, i8* %6
%38 = sext i8 %37 to i32
switch i32 %38, label %56 [
i32 118, label %39
i32 104, label %45
i32 112, label %51
]
39: ; preds = %31
%40 = load i32, i32* %7
%41 = load i32, i32* %2
%42 = load i32, i32* %3
%43 = load i32, i32* %4
%44 = call i32 @draw_vline(i32 %40, i32 %41, i32 %42, i32 %43)
br label %58
45: ; preds = %31
%46 = load i32, i32* %7
%47 = load i32, i32* %2
%48 = load i32, i32* %3
%49 = load i32, i32* %4
%50 = call i32 @draw_hline(i32 %46, i32 %47, i32 %48, i32 %49)
br label %58
51: ; preds = %31
%52 = load i32, i32* %7
%53 = load i32, i32* %2
%54 = load i32, i32* %3
%55 = call i32 @draw_point(i32 %52, i32 %53, i32 %54)
br label %58
56: ; preds = %31
%57 = call i32 (...) @abort()
unreachable
58: ; preds = %51, %45, %39
br label %25
59: ; preds = %25
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@.str = [6 x i8] c"image\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@stderr = global i32 0
@.str.1 = [18 x i8] c"Cannot open file\0A\00"
@.str.2 = [9 x i8] c"v 1 1 11\00"
@.str.23 = [12 x i8] c"%c %d %d %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %8
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %12, i32 420)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = tail call i32 @init_draw(i32 %13)
br label %21
21: ; preds = %39, %19
%22 = call i32 @sscanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.23, i64 0, i64 0), i8* %4, i32* %1, i32* %2, i32* %3)
%23 = load i8, i8* %4
%24 = sext i8 %23 to i32
switch i32 %24, label %40 [
i32 118, label %25
i32 104, label %30
i32 112, label %35
]
25: ; preds = %21
%26 = load i32, i32* %1
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = call i32 @draw_vline(i32 %13, i32 %26, i32 %27, i32 %28)
br label %39
30: ; preds = %21
%31 = load i32, i32* %1
%32 = load i32, i32* %2
%33 = load i32, i32* %3
%34 = call i32 @draw_hline(i32 %13, i32 %31, i32 %32, i32 %33)
br label %39
35: ; preds = %21
%36 = load i32, i32* %1
%37 = load i32, i32* %2
%38 = call i32 @draw_point(i32 %13, i32 %36, i32 %37)
br label %39
39: ; preds = %35, %30, %25
br label %21
40: ; preds = %21
%41 = call i32 (...) @abort()
unreachable
}