#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 stat {
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
char *extension(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int argcheck = 0;
  switch (argc) {
  case 3:
    argcheck++;
  case 2:
    argcheck++;
    break;
  default:
    printf("Usage: cthulhu src.c OR cthulhu run un.cth\n");
  }
  if (argcheck < 1) {
    return (EXIT_FAILURE);
  } else if (argcheck == 1 && strcmp(extension(argv[1]), ".c") == 0) {
    printf("Compile: %s\n", argv[1]);
    struct stat fs;
    if (stat(argv[1], &fs) != 0) {
      fprintf(stderr, "stat");
      return (EXIT_FAILURE);
    }
    printf("%lld\n", (long long int)fs.st_size);
    char *sc = malloc((fs.st_size + 1) * sizeof(char));
    FILE *sf = fopen(argv[1], "rb");
    fread(sc, sizeof(char), (int)fs.st_size, sf);
    fclose(sf);
    printf("%lld\n", (long long int)sc);
  } else if (argcheck == 2) {
    if (strcmp(argv[1], "run") != 0 ||
        strcmp(extension(argv[2]), ".cth") != 0) {
      printf("Usage: cthulhu src.c OR cthulhu run un.cth\n");
      return (EXIT_FAILURE);
    } else {
      printf("RUN MODE\n");
    }
  }
  return (EXIT_SUCCESS);
}


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)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x2,%eax
je     11db <main+0x4b>
jmp    11c1 <main+0x31>
mov    -0x2c(%rbp),%eax
sub    $0x3,%eax
jne    11e9 <main+0x59>
jmp    11d2 <main+0x42>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f7 <main+0x67>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x1,-0x14(%rbp)
jge    1212 <main+0x82>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13a5 <main+0x215>
cmpl   $0x1,-0x14(%rbp)
jne    130f <main+0x17f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <extension@plt>
mov    %rax,%rdi
lea    0xdf9(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    130f <main+0x17f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
je     1299 <main+0x109>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13a5 <main+0x215>
movslq -0x18(%rbp),%rsi
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd76(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rsi
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1394 <main+0x204>
cmpl   $0x2,-0x14(%rbp)
jne    138f <main+0x1ff>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd22(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    135d <main+0x1cd>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <extension@plt>
mov    %rax,%rdi
lea    0xd00(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     137c <main+0x1ec>
lea    0xc9c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2c66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13a5 <main+0x215>
lea    0xcd0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    138f <main+0x1ff>
jmp    1394 <main+0x204>
jmp    1399 <main+0x209>
mov    0x2c30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1201 <main+0x61>
cmp    $0x3,%edi
jne    11ec <main+0x4c>
mov    0x8(%rbx),%rdi
lea    0xe5d(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    11ec <main+0x4c>
mov    0x10(%rbx),%rdi
call   1060 <extension@plt>
lea    0xe76(%rip),%rsi
mov    %rax,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     126d <main+0xcd>
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dd9(%rip),%rax
jmp    1225 <main+0x85>
mov    0x8(%rbx),%rdi
call   1060 <extension@plt>
lea    0xdef(%rip),%rsi
mov    %rax,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1231 <main+0x91>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x8(%rbx),%rsi
lea    0xdc7(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   10a0 <stat@plt>
test   %rax,%rax
je     127b <main+0xdb>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
call   1090 <fprintf@plt>
jmp    11f8 <main+0x58>
lea    0xdae(%rip),%rdi
call   1030 <puts@plt>
jmp    121e <main+0x7e>
movslq 0x8(%rsp),%rsi
lea    0xd8e(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rsp),%edi
add    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
lea    0xd70(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%edx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    121e <main+0x7e>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [44 x i8] c"Usage: cthulhu src.c OR cthulhu run un.cth\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c".c\00"
@.str.2 = [13 x i8] c"Compile: %s\0A\00"
@stderr = global i32 0
@.str.3 = [5 x i8] c"stat\00"
@.str.4 = [6 x i8] c"%lld\0A\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [4 x i8] c"run\00"
@.str.7 = [5 x i8] c".cth\00"
@.str.8 = [10 x i8] c"RUN MODE\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca i8*
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%10 = load i32, i32* %4
switch i32 %10, label %17 [
i32 3, label %11
i32 2, label %14
]
11: ; preds = %2
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 1
store i32 %13, i32* %6
br label %14
14: ; preds = %2, %11
%15 = load i32, i32* %6
%16 = add nsw i32 %15, 1
store i32 %16, i32* %6
br label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i32, i32* @EXIT_FAILURE
store i32 %23, i32* %3
br label %100
24: ; preds = %19
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %74
27: ; preds = %24
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i8* @extension(i8* %30)
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %74
34: ; preds = %27
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i64 @stat(i8* %41, %struct.stat* %7)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %34
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
store i32 %47, i32* %3
br label %100
48: ; preds = %34
%49 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%50 = load i32, i32* %49
%51 = sext i32 %50 to i64
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 %51)
%53 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%54 = load i32, i32* %53
%55 = add nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = mul i64 %56, 1
%58 = trunc i64 %57 to i32
%59 = call i8* @malloc(i32 %58)
store i8* %59, i8** %8
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 1
%62 = load i8*, i8** %61
%63 = call i32* @fopen(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %63, i32** %9
%64 = load i8*, i8** %8
%65 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%66 = load i32, i32* %65
%67 = load i32*, i32** %9
%68 = call i32 @fread(i8* %64, i32 1, i32 %66, i32* %67)
%69 = load i32*, i32** %9
%70 = call i32 @fclose(i32* %69)
%71 = load i8*, i8** %8
%72 = ptrtoint i8* %71 to i64
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 %72)
br label %97
74: ; preds = %27, %24
%75 = load i32, i32* %6
%76 = icmp eq i32 %75, 2
br i1 %76, label %77, label %96
77: ; preds = %74
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 1
%80 = load i8*, i8** %79
%81 = call i64 @strcmp(i8* %80, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%82 = icmp ne i64 %81, 0
br i1 %82, label %90, label %83
83: ; preds = %77
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 2
%86 = load i8*, i8** %85
%87 = call i8* @extension(i8* %86)
%88 = call i64 @strcmp(i8* %87, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %93
90: ; preds = %83, %77
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%92 = load i32, i32* @EXIT_FAILURE
store i32 %92, i32* %3
br label %100
93: ; preds = %83
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
br label %95
95: ; preds = %93
br label %96
96: ; preds = %95, %74
br label %97
97: ; preds = %96, %48
br label %98
98: ; preds = %97
%99 = load i32, i32* @EXIT_SUCCESS
store i32 %99, i32* %3
br label %100
100: ; preds = %98, %90, %44, %22
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c".c\00"
@.str.2 = [13 x i8] c"Compile: %s\0A\00"
@stderr = global i32 0
@.str.3 = [5 x i8] c"stat\00"
@.str.4 = [6 x i8] c"%lld\0A\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [4 x i8] c"run\00"
@.str.7 = [5 x i8] c".cth\00"
@EXIT_SUCCESS = global i32 0
@str = [9 x i8] c"RUN MODE\00"
@str.10 = [43 x i8] c"Usage: cthulhu src.c OR cthulhu run un.cth\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
switch i32 %0, label %4 [
i32 3, label %39
i32 2, label %7
]
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.10, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
br label %57
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i8* @extension(i8* %9)
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %55
13: ; preds = %7
%14 = load i8*, i8** %8
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = bitcast %struct.stat* %3 to i8*
%17 = load i8*, i8** %8
%18 = call i64 @stat(i8* %17, %struct.stat* %3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %13
%21 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 %23)
%25 = load i32, i32* %21
%26 = add nsw i32 %25, 1
%27 = call i8* @malloc(i32 %26)
%28 = load i8*, i8** %8
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32, i32* %21
%31 = call i32 @fread(i8* %27, i32 1, i32 %30, i32* %29)
%32 = call i32 @fclose(i32* %29)
%33 = ptrtoint i8* %27 to i64
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 %33)
br label %55
35: ; preds = %13
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
br label %57
39: ; preds = %2
%40 = getelementptr inbounds i8*, i8** %1, i64 1
%41 = load i8*, i8** %40
%42 = tail call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %39
%45 = getelementptr inbounds i8*, i8** %1, i64 2
%46 = load i8*, i8** %45
%47 = tail call i8* @extension(i8* %46)
%48 = tail call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %44, %39
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.10, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
br label %57
53: ; preds = %44
%54 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %55
55: ; preds = %7, %20, %53
%56 = load i32, i32* @EXIT_SUCCESS
br label %57
57: ; preds = %35, %55, %50, %4
%58 = phi i32 [ %6, %4 ], [ %56, %55 ], [ %38, %35 ], [ %52, %50 ]
ret i32 %58
}