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

/* Variables and functions */
int /*<<< orphan*/ CompileForth(char *, int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  static char ForthSource[(32 * 1024)];
  if (argc < 2) {
    fgets(ForthSource, sizeof ForthSource, stdin);
  } else {
    FILE *InputFile = fopen(argv[1], "r");
    fread(ForthSource, 1, sizeof ForthSource, InputFile);
    fclose(InputFile);
  }
  static char BytecodeStream[(64 * 1024)];
  uint32_t BytecodeStreamSize =
      CompileForth(ForthSource, sizeof ForthSource, BytecodeStream);
  FILE *BytecodeFile = fopen("bytecode", "wb");
  fwrite(BytecodeStream, BytecodeStreamSize, 1, BytecodeFile);
  fclose(BytecodeFile);
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    119f <main+0x3f>
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
lea    0x2ed0(%rip),%rdi
mov    $0x8000,%esi
call   1050 <fgets@plt>
jmp    11da <main+0x7a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe52(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
lea    0x2e9e(%rip),%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0x2e7f(%rip),%rdi
mov    $0x8000,%esi
lea    0xae83(%rip),%rdx
call   1060 <CompileForth@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe06(%rip),%rdi
lea    0xe08(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rcx
lea    0xae56(%rip),%rdi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x1,%edi
jg     1185 <main+0x25>
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
lea    0x2ee7(%rip),%rdi
mov    $0x8000,%esi
call   1050 <fgets@plt>
jmp    11b9 <main+0x59>
mov    0x8(%rsi),%rdi
lea    0xe70(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0x2ec1(%rip),%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0x2ea0(%rip),%rdi
lea    0xaea9(%rip),%r14
mov    $0x8000,%esi
mov    %r14,%rdx
call   1060 <CompileForth@plt>
mov    %eax,%ebp
lea    0xe25(%rip),%rdi
lea    0xe27(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@main.ForthSource = internal global [32768 x i8] zeroinitializer
@stdin = global i32 0
@.str = [2 x i8] c"r\00"
@main.BytecodeStream = internal global [65536 x i8] zeroinitializer
@.str.1 = [9 x i8] c"bytecode\00"
@.str.2 = [3 x i8] c"wb\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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* getelementptr inbounds ([32768 x i8], [32768 x i8]* @main.ForthSource, i64 0, i64 0), i32 32768, i32 %12)
br label %23
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = call i32 @fread(i8* getelementptr inbounds ([32768 x i8], [32768 x i8]* @main.ForthSource, i64 0, i64 0), i32 1, i32 32768, i32* %19)
%21 = load i32*, i32** %6
%22 = call i32 @fclose(i32* %21)
br label %23
23: ; preds = %14, %11
%24 = call i32 @CompileForth(i8* getelementptr inbounds ([32768 x i8], [32768 x i8]* @main.ForthSource, i64 0, i64 0), i32 32768, i8* getelementptr inbounds ([65536 x i8], [65536 x i8]* @main.BytecodeStream, i64 0, i64 0))
store i32 %24, i32* %7
%25 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %25, i32** %8
%26 = load i32, i32* %7
%27 = load i32*, i32** %8
%28 = call i32 @fwrite(i8* getelementptr inbounds ([65536 x i8], [65536 x i8]* @main.BytecodeStream, i64 0, i64 0), i32 %26, i32 1, i32* %27)
%29 = load i32*, i32** %8
%30 = call i32 @fclose(i32* %29)
ret i32 0
}

LLVM IR (-O2):
@main.ForthSource = internal global [32768 x i8] zeroinitializer
@stdin = global i32 0
@.str = [2 x i8] c"r\00"
@main.BytecodeStream = internal global [65536 x i8] zeroinitializer
@.str.1 = [9 x i8] c"bytecode\00"
@.str.2 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stdin
%6 = tail call i32 @fgets(i8* getelementptr inbounds ([32768 x i8], [32768 x i8]* @main.ForthSource, i64 0, i64 0), i32 32768, i32 %5)
br label %13
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @fread(i8* getelementptr inbounds ([32768 x i8], [32768 x i8]* @main.ForthSource, i64 0, i64 0), i32 1, i32 32768, i32* %10)
%12 = tail call i32 @fclose(i32* %10)
br label %13
13: ; preds = %7, %4
%14 = tail call i32 @CompileForth(i8* getelementptr inbounds ([32768 x i8], [32768 x i8]* @main.ForthSource, i64 0, i64 0), i32 32768, i8* getelementptr inbounds ([65536 x i8], [65536 x i8]* @main.BytecodeStream, i64 0, i64 0))
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @fwrite(i8* getelementptr inbounds ([65536 x i8], [65536 x i8]* @main.BytecodeStream, i64 0, i64 0), i32 %14, i32 1, i32* %15)
%17 = tail call i32 @fclose(i32* %15)
ret i32 0
}