#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 */
struct image {
  int dummy;
};
struct Rule {
  int dummy;
};
struct Program {
  int dummy;
};
struct DrawObj {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ builder_init();
struct DrawObj *builder_make(struct Program *, struct Rule *);
int /*<<< orphan*/ builder_stop();
int /*<<< orphan*/ css_eval_start();
int /*<<< orphan*/ css_eval_stop();
int /*<<< orphan*/ css_free_program(struct Program *);
struct Program *css_parse_file(char *);
struct Program *css_parse_file_as_stream(int /*<<< orphan*/);
int /*<<< orphan*/ destroy_image(struct image *);
int /*<<< orphan*/ draw(struct DrawObj *, struct Rule *, struct image *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
struct Rule *find_world(struct Program *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct image *make_img(struct Rule *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ write_png_file(int /*<<< orphan*/ *, struct image *);
int main(int argc, char **argv) {
  char *in_filename = argc > 1 ? argv[1] : "-";
  char *out_filename = argc > 2 ? argv[2] : "out.png";
  builder_init();
  css_eval_start();
  struct Program *program;
  if (!strcmp(in_filename, "-")) {
    program = css_parse_file_as_stream(stdin);
  } else {
    program = css_parse_file(in_filename);
  }
  struct Rule *world_rule = find_world(program);
  if (!world_rule) {
    fprintf(stderr, "world rule not found! :(\n");
  }
  struct DrawObj *draw_obj = builder_make(program, world_rule);
  struct image *img = make_img(world_rule);
  draw(draw_obj, world_rule, img);
  FILE *fp = strcmp(out_filename, "-") ? fopen(out_filename, "wb") : stdout;
  if (!fp) {
    fprintf(stderr, "Problem with creating file %s\n", out_filename);
    return -1;
  }
  write_png_file(fp, img);
  fclose(fp);
  builder_stop();
  css_eval_stop();
  css_free_program(program);
  destroy_image(img);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1241 <main+0x31>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    1251 <main+0x41>
lea    0xdb8(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    1251 <main+0x41>
mov    -0x50(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1274 <main+0x64>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    1284 <main+0x74>
lea    0xd87(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    1284 <main+0x74>
mov    -0x58(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <builder_init@plt>
mov    $0x0,%al
call   1090 <css_eval_start@plt>
mov    -0x18(%rbp),%rdi
lea    0xd5b(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    12cb <main+0xbb>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
call   10a0 <css_parse_file_as_stream@plt>
mov    %rax,-0x28(%rbp)
jmp    12d8 <main+0xc8>
mov    -0x18(%rbp),%rdi
call   1060 <css_parse_file@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <find_world@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1307 <main+0xf7>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd0a(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10f0 <builder_make@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   10e0 <make_img@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1040 <draw@plt>
mov    -0x20(%rbp),%rdi
lea    0xcbf(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
je     1369 <main+0x159>
mov    -0x20(%rbp),%rdi
lea    0xcc9(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x60(%rbp)
jmp    1377 <main+0x167>
mov    0x2c60(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    13b1 <main+0x1a1>
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xc89(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ee <main+0x1de>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1130 <write_png_file@plt>
mov    -0x48(%rbp),%rdi
call   1080 <fclose@plt>
mov    $0x0,%al
call   1050 <builder_stop@plt>
mov    $0x0,%al
call   1110 <css_eval_stop@plt>
mov    -0x28(%rbp),%rdi
call   1100 <css_free_program@plt>
mov    -0x40(%rbp),%rdi
call   1030 <destroy_image@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xde2(%rip),%r14
cmp    $0x2,%edi
jl     1231 <main+0x21>
mov    0x8(%rsi),%rbx
je     1238 <main+0x28>
mov    0x10(%rsi),%r14
jmp    1238 <main+0x28>
lea    0xdc8(%rip),%rbx
xor    %eax,%eax
call   1070 <builder_init@plt>
xor    %eax,%eax
call   1090 <css_eval_start@plt>
lea    0xdb3(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1264 <main+0x54>
mov    %rbx,%rdi
call   1060 <css_parse_file@plt>
jmp    1272 <main+0x62>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   10a0 <css_parse_file_as_stream@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   10b0 <find_world@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    129c <main+0x8c>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xd75(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10f0 <builder_make@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   10e0 <make_img@plt>
mov    %rax,%r12
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <draw@plt>
lea    0xd36(%rip),%rsi
mov    %r14,%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1323 <main+0x113>
lea    0xd46(%rip),%rsi
mov    %r14,%rdi
call   1120 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
je     1332 <main+0x122>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1130 <write_png_file@plt>
mov    %rbx,%rdi
call   1080 <fclose@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <builder_stop@plt>
xor    %eax,%eax
call   1110 <css_eval_stop@plt>
mov    %r15,%rdi
call   1100 <css_free_program@plt>
mov    %r12,%rdi
call   1030 <destroy_image@plt>
jmp    1351 <main+0x141>
mov    0x2ca6(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    12ee <main+0xde>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
lea    0xce5(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.Program = type { i32 }
%struct.Rule = type { i32 }
%struct.DrawObj = type { i32 }
%struct.image = type { i32 }
@.str = [2 x i8] c"-\00"
@.str.1 = [8 x i8] c"out.png\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"world rule not found! :(\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@stdout = global i32* null
@.str.4 = [31 x i8] c"Problem with creating file %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.Program*
%9 = alloca %struct.Rule*
%10 = alloca %struct.DrawObj*
%11 = alloca %struct.image*
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
br label %20
19: ; preds = %2
br label %20
20: ; preds = %19, %15
%21 = phi i8* [ %18, %15 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %19 ]
store i8* %21, i8** %6
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, 2
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
br label %29
28: ; preds = %20
br label %29
29: ; preds = %28, %24
%30 = phi i8* [ %27, %24 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %28 ]
store i8* %30, i8** %7
%31 = call i32 (...) @builder_init()
%32 = call i32 (...) @css_eval_start()
%33 = load i8*, i8** %6
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %29
%37 = load i32, i32* @stdin
%38 = call %struct.Program* @css_parse_file_as_stream(i32 %37)
store %struct.Program* %38, %struct.Program** %8
br label %42
39: ; preds = %29
%40 = load i8*, i8** %6
%41 = call %struct.Program* @css_parse_file(i8* %40)
store %struct.Program* %41, %struct.Program** %8
br label %42
42: ; preds = %39, %36
%43 = load %struct.Program*, %struct.Program** %8
%44 = call %struct.Rule* @find_world(%struct.Program* %43)
store %struct.Rule* %44, %struct.Rule** %9
%45 = load %struct.Rule*, %struct.Rule** %9
%46 = icmp ne %struct.Rule* %45, null
br i1 %46, label %50, label %47
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %47, %42
%51 = load %struct.Program*, %struct.Program** %8
%52 = load %struct.Rule*, %struct.Rule** %9
%53 = call %struct.DrawObj* @builder_make(%struct.Program* %51, %struct.Rule* %52)
store %struct.DrawObj* %53, %struct.DrawObj** %10
%54 = load %struct.Rule*, %struct.Rule** %9
%55 = call %struct.image* @make_img(%struct.Rule* %54)
store %struct.image* %55, %struct.image** %11
%56 = load %struct.DrawObj*, %struct.DrawObj** %10
%57 = load %struct.Rule*, %struct.Rule** %9
%58 = load %struct.image*, %struct.image** %11
%59 = call i32 @draw(%struct.DrawObj* %56, %struct.Rule* %57, %struct.image* %58)
%60 = load i8*, i8** %7
%61 = call i64 @strcmp(i8* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %50
%64 = load i8*, i8** %7
%65 = call i32* @fopen(i8* %64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %68
66: ; preds = %50
%67 = load i32*, i32** @stdout
br label %68
68: ; preds = %66, %63
%69 = phi i32* [ %65, %63 ], [ %67, %66 ]
store i32* %69, i32** %12
%70 = load i32*, i32** %12
%71 = icmp ne i32* %70, null
br i1 %71, label %76, label %72
72: ; preds = %68
%73 = load i32, i32* @stderr
%74 = load i8*, i8** %7
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %74)
store i32 -1, i32* %3
br label %88
76: ; preds = %68
%77 = load i32*, i32** %12
%78 = load %struct.image*, %struct.image** %11
%79 = call i32 @write_png_file(i32* %77, %struct.image* %78)
%80 = load i32*, i32** %12
%81 = call i32 @fclose(i32* %80)
%82 = call i32 (...) @builder_stop()
%83 = call i32 (...) @css_eval_stop()
%84 = load %struct.Program*, %struct.Program** %8
%85 = call i32 @css_free_program(%struct.Program* %84)
%86 = load %struct.image*, %struct.image** %11
%87 = call i32 @destroy_image(%struct.image* %86)
store i32 0, i32* %3
br label %88
88: ; preds = %76, %72
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
%struct.Program = type { i32 }
%struct.Rule = type { i32 }
%struct.DrawObj = type { i32 }
%struct.image = type { i32 }
@.str = [2 x i8] c"-\00"
@.str.1 = [8 x i8] c"out.png\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"world rule not found! :(\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@stdout = global i32* null
@.str.4 = [31 x i8] c"Problem with creating file %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
br label %11
11: ; preds = %2, %4, %8
%12 = phi i8* [ %6, %8 ], [ %6, %4 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %2 ]
%13 = phi i8* [ %10, %8 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %2 ]
%14 = tail call i32 (...) @builder_init()
%15 = tail call i32 (...) @css_eval_start()
%16 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32, i32* @stdin
%20 = tail call %struct.Program* @css_parse_file_as_stream(i32 %19)
br label %23
21: ; preds = %11
%22 = tail call %struct.Program* @css_parse_file(i8* %12)
br label %23
23: ; preds = %21, %18
%24 = phi %struct.Program* [ %22, %21 ], [ %20, %18 ]
%25 = tail call %struct.Rule* @find_world(%struct.Program* %24)
%26 = icmp eq %struct.Rule* %25, null
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %27, %23
%31 = tail call %struct.DrawObj* @builder_make(%struct.Program* %24, %struct.Rule* %25)
%32 = tail call %struct.image* @make_img(%struct.Rule* %25)
%33 = tail call i32 @draw(%struct.DrawObj* %31, %struct.Rule* %25, %struct.image* %32)
%34 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %30
%37 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %40
38: ; preds = %30
%39 = load i32*, i32** @stdout
br label %40
40: ; preds = %38, %36
%41 = phi i32* [ %37, %36 ], [ %39, %38 ]
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %13)
br label %53
46: ; preds = %40
%47 = tail call i32 @write_png_file(i32* %41, %struct.image* %32)
%48 = tail call i32 @fclose(i32* %41)
%49 = tail call i32 (...) @builder_stop()
%50 = tail call i32 (...) @css_eval_stop()
%51 = tail call i32 @css_free_program(%struct.Program* %24)
%52 = tail call i32 @destroy_image(%struct.image* %32)
br label %53
53: ; preds = %46, %43
%54 = phi i32 [ 0, %46 ], [ -1, %43 ]
ret i32 %54
}