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

/* Variables and functions */
int /*<<< orphan*/ R_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ newFilename(char const *, char **);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ svgcfree();
int /*<<< orphan*/ svgcinit();
int /*<<< orphan*/ svgcstring(char **, char *);
int main(int argc, const char *argv[]) {
  const char *filename;
  char *outFilename;
  FILE *inFile = NULL;
  FILE *outFile = NULL;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  if (argc < 2) {
    puts("Usage: SVGC <path to your svg file>\n\tOutput filename: file.svg -> "
         "file.svgc.svg\n\n"
         "Searches and executes any operation inside <!--- ---> blocks\n"
         "Examples:\n"
         "\t<!--- 5 * 5 ---> is replaced by 25\n"
         "\t<!--- var val1 = 10 + 15; ---> stores the value 25 in the heap and "
         "can be accessed using val1\n"
         "\t<!--- val1 ---> is replaced by 25\n"
         "\t<!--- var val2 = 10; val1 = val2 + 10; ---> creates val2 and val1 "
         "value is now 45.\n");
    return 1;
  }
  filename = argv[1];
  if (access(filename, R_OK) != 0) {
    printf("SVGC: The file (%s) doesn't exists or you don't have read "
           "permissions.\n",
           filename);
    return 1;
  }
  newFilename(filename, &outFilename);
  if ((outFile = fopen(outFilename, "w"))) {
    if ((inFile = fopen(filename, "r"))) {
      svgcinit();
      while ((read = getline(&line, &len, inFile)) != -1) {
        char *output = NULL;
        svgcstring(&output, line);
        if (output) {
          fputs(output, outFile);
        }
        free(output);
      }
      svgcfree();
      fclose(inFile);
    }
    fclose(outFile);
  }
  free(outFilename);
  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)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1218 <main+0x58>
lea    0xdf9(%rip),%rdi
call   1050 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    132d <main+0x16d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
call   10a0 <access@plt>
cmp    $0x0,%rax
je     125c <main+0x9c>
mov    -0x18(%rbp),%rsi
lea    0xf48(%rip),%rdi
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    132d <main+0x16d>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10e0 <newFilename@plt>
mov    -0x20(%rbp),%rdi
lea    0xf67(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     131d <main+0x15d>
mov    -0x18(%rbp),%rdi
lea    0xf4b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1314 <main+0x154>
mov    $0x0,%al
call   1060 <svgcinit@plt>
mov    -0x28(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10d0 <getline@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
je     1304 <main+0x144>
movq   $0x0,-0x50(%rbp)
mov    -0x38(%rbp),%rsi
lea    -0x50(%rbp),%rdi
call   10c0 <svgcstring@plt>
cmpq   $0x0,-0x50(%rbp)
je     12f6 <main+0x136>
mov    -0x50(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <fputs@plt>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
jmp    12ac <main+0xec>
mov    $0x0,%al
call   1030 <svgcfree@plt>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
cmp    $0x1,%edi
jg     11fa <main+0x3a>
lea    0xe15(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
jmp    1309 <main+0x149>
mov    0x8(%rsi),%rbx
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <access@plt>
test   %rax,%rax
je     122d <main+0x6d>
lea    0xf78(%rip),%rdi
mov    %rbx,%rsi
call   1080 <printf@plt>
mov    $0x1,%eax
jmp    1309 <main+0x149>
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
call   10e0 <newFilename@plt>
mov    0x18(%rsp),%rdi
lea    0xf95(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12fd <main+0x13d>
mov    %rax,%r14
lea    0xf7f(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12f5 <main+0x135>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <svgcinit@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   10d0 <getline@plt>
cmp    $0xffffffff,%eax
je     12e6 <main+0x126>
mov    %rsp,%r15
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%r13
jmp    12c4 <main+0x104>
nop
mov    %r14,%rsi
call   1090 <fputs@plt>
mov    (%rsp),%rdi
call   1040 <free@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   10d0 <getline@plt>
cmp    $0xffffffff,%eax
je     12e6 <main+0x126>
movq   $0x0,(%rsp)
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
call   10c0 <svgcstring@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
jne    12a0 <main+0xe0>
xor    %edi,%edi
jmp    12ac <main+0xec>
xor    %eax,%eax
call   1030 <svgcfree@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %r14,%rdi
call   1070 <fclose@plt>
mov    0x18(%rsp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [403 x i8] c"Usage: SVGC <path to your svg file>\0A\09Output filename: file.svg -> file.svgc.svg\0A\0ASearches and executes any operation inside <!--- ---> blocks\0AExamples:\0A\09<!--- 5 * 5 ---> is replaced by 25\0A\09<!--- var val1 = 10 + 15; ---> stores the value 25 in the heap and can be accessed using val1\0A\09<!--- val1 ---> is replaced by 25\0A\09<!--- var val2 = 10; val1 = val2 + 10; ---> creates val2 and val1 value is now 45.\0A\00"
@R_OK = global i32 0
@.str.1 = [72 x i8] c"SVGC: The file (%s) doesn't exists or you don't have read permissions.\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [2 x i8] c"r\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 i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %8
store i32* null, i32** %9
store i8* null, i8** %10
store i64 0, i64* %11
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @puts(i8* getelementptr inbounds ([403 x i8], [403 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %67
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = load i32, i32* @R_OK
%24 = call i64 @access(i8* %22, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = load i8*, i8** %6
%28 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i8* %27)
store i32 1, i32* %3
br label %67
29: ; preds = %18
%30 = load i8*, i8** %6
%31 = call i32 @newFilename(i8* %30, i8** %7)
%32 = load i8*, i8** %7
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %9
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %64
35: ; preds = %29
%36 = load i8*, i8** %6
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %37, i32** %8
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %61
39: ; preds = %35
%40 = call i32 (...) @svgcinit()
br label %41
41: ; preds = %54, %39
%42 = load i32*, i32** %8
%43 = call i32 @getline(i8** %10, i64* %11, i32* %42)
store i32 %43, i32* %12
%44 = icmp ne i32 %43, -1
br i1 %44, label %45, label %57
45: ; preds = %41
store i8* null, i8** %13
%46 = load i8*, i8** %10
%47 = call i32 @svgcstring(i8** %13, i8* %46)
%48 = load i8*, i8** %13
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %54
50: ; preds = %45
%51 = load i8*, i8** %13
%52 = load i32*, i32** %9
%53 = call i32 @fputs(i8* %51, i32* %52)
br label %54
54: ; preds = %50, %45
%55 = load i8*, i8** %13
%56 = call i32 @free(i8* %55)
br label %41
57: ; preds = %41
%58 = call i32 (...) @svgcfree()
%59 = load i32*, i32** %8
%60 = call i32 @fclose(i32* %59)
br label %61
61: ; preds = %57, %35
%62 = load i32*, i32** %9
%63 = call i32 @fclose(i32* %62)
br label %64
64: ; preds = %61, %29
%65 = load i8*, i8** %7
%66 = call i32 @free(i8* %65)
store i32 0, i32* %3
br label %67
67: ; preds = %64, %26, %16
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@.str = [403 x i8] c"Usage: SVGC <path to your svg file>\0A\09Output filename: file.svg -> file.svgc.svg\0A\0ASearches and executes any operation inside <!--- ---> blocks\0AExamples:\0A\09<!--- 5 * 5 ---> is replaced by 25\0A\09<!--- var val1 = 10 + 15; ---> stores the value 25 in the heap and can be accessed using val1\0A\09<!--- val1 ---> is replaced by 25\0A\09<!--- var val2 = 10; val1 = val2 + 10; ---> creates val2 and val1 value is now 45.\0A\00"
@R_OK = global i32 0
@.str.1 = [72 x i8] c"SVGC: The file (%s) doesn't exists or you don't have read permissions.\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = bitcast i8** %3 to i8*
%8 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%9 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%10 = icmp slt i32 %0, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([403 x i8], [403 x i8]* @.str, i64 0, i64 0))
br label %56
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @R_OK
%17 = tail call i64 @access(i8* %15, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %13
%20 = tail call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %56
21: ; preds = %13
%22 = call i32 @newFilename(i8* %15, i8** %3)
%23 = load i8*, i8** %3
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %53, label %26
26: ; preds = %21
%27 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %51, label %29
29: ; preds = %26
%30 = call i32 (...) @svgcinit()
%31 = call i32 @getline(i8** %4, i64* %5, i32* %27)
%32 = icmp eq i32 %31, -1
br i1 %32, label %48, label %33
33: ; preds = %29
%34 = bitcast i8** %6 to i8*
br label %35
35: ; preds = %33, %43
store i8* null, i8** %6
%36 = load i8*, i8** %4
%37 = call i32 @svgcstring(i8** %6, i8* %36)
%38 = load i8*, i8** %6
%39 = icmp eq i8* %38, null
br i1 %39, label %43, label %40
40: ; preds = %35
%41 = call i32 @fputs(i8* %38, i32* %24)
%42 = load i8*, i8** %6
br label %43
43: ; preds = %40, %35
%44 = phi i8* [ %42, %40 ], [ null, %35 ]
%45 = call i32 @free(i8* %44)
%46 = call i32 @getline(i8** %4, i64* %5, i32* %27)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %35
48: ; preds = %43, %29
%49 = call i32 (...) @svgcfree()
%50 = call i32 @fclose(i32* %27)
br label %51
51: ; preds = %48, %26
%52 = call i32 @fclose(i32* %24)
br label %53
53: ; preds = %51, %21
%54 = load i8*, i8** %3
%55 = call i32 @free(i8* %54)
br label %56
56: ; preds = %53, %19, %11
%57 = phi i32 [ 1, %11 ], [ 1, %19 ], [ 0, %53 ]
ret i32 %57
}