#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void print_code_footer(FILE *fp) {
  fputs("\n"
        "  "
        "return EXIT_SUCCESS;\n"
        "}\n\n\n",
        fp);
  fputs("inline static int pop(void)\n"
        "{\n"
        "  "
        "assert(stack_idx < LENGTHOF(stack));\n"
        "  "
        "return stack[--stack_idx];\n"
        "}\n\n\n",
        fp);
  fputs("inline static void push(int e)\n"
        "{\n"
        "  "
        "assert(stack_idx < LENGTHOF(stack));\n"
        "  "
        "stack[stack_idx++] = e;\n"
        "}\n\n\n",
        fp);
  fputs("inline static void dup_n(size_t n)\n"
        "{\n"
        "  "
        "assert(n < stack_idx && stack_idx < LENGTHOF(stack) - 1);\n"
        "  "
        "stack[stack_idx] = stack[stack_idx - (n + 1)];\n"
        "  "
        "stack_idx++;\n"
        "}\n\n\n",
        fp);
  fputs("inline static void slide(size_t n)\n"
        "{\n"
        "  "
        "assert(stack_idx > n);\n"
        "  "
        "stack[stack_idx - (n + 1)] = stack[stack_idx - 1];\n"
        "  "
        "stack_idx -= n;\n"
        "}\n\n\n",
        fp);
  fputs("inline static void swap(void)\n"
        "{\n"
        "  "
        "assert(stack_idx > 1);\n"
        "  "
        "SWAP(int, &stack[stack_idx - 1], &stack[stack_idx - 2]);\n"
        "}\n\n\n",
        fp);
  fputs("inline static void arith_add(void)\n"
        "{\n"
        "  "
        "assert(stack_idx > 1);\n"
        "  "
        "stack_idx--;\n"
        "  "
        "stack[stack_idx - 1] += stack[stack_idx];\n"
        "}\n\n\n",
        fp);
  fputs("inline static void arith_sub(void)\n"
        "{\n"
        "  "
        "assert(stack_idx > 1);\n"
        "  "
        "stack_idx--;\n"
        "  "
        "stack[stack_idx - 1] -= stack[stack_idx];\n"
        "}\n\n\n",
        fp);
  fputs("inline static void arith_mul(void)\n"
        "{\n"
        "  "
        "assert(stack_idx > 1);\n"
        "  "
        "stack_idx--;\n"
        "  "
        "stack[stack_idx - 1] *= stack[stack_idx];\n"
        "}\n\n\n",
        fp);
  fputs("inline static void arith_div(void)\n"
        "{\n"
        "  "
        "assert(stack_idx > 1);\n"
        "  "
        "stack_idx--;\n"
        "  "
        "assert(stack[stack_idx] != 0);\n"
        "  "
        "stack[stack_idx - 1] /= stack[stack_idx];\n"
        "}\n\n\n",
        fp);
  fputs("inline static void arith_mod(void)\n"
        "{\n"
        "  "
        "assert(stack_idx > 1);\n"
        "  "
        "stack_idx--;\n"
        "  "
        "assert(stack[stack_idx] != 0);\n"
        "  "
        "stack[stack_idx - 1] %= stack[stack_idx];\n"
        "}\n\n\n",
        fp);
  fputs("inline static void heap_store(void)\n"
        "{\n"
        "  "
        "int value = pop();\n"
        "  "
        "int addr  = pop();\n"
        "  "
        "assert(0 <= addr && addr < (int) LENGTHOF(heap));\n"
        "  "
        "heap[addr] = value;\n"
        "}\n\n\n",
        fp);
  fputs("inline static void heap_read(void)\n"
        "{\n"
        "  "
        "int addr = pop();\n"
        "  "
        "assert(0 <= addr && addr < (int) LENGTHOF(heap));\n"
        "  "
        "push(heap[addr]);\n"
        "}\n",
        fp);
}


x86 assembly (clang, -O0):
<print_code_footer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xed9(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xee6(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xf3d(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xf94(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0x102a(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0x10a4(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0x110d(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0x117b(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0x11e9(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0x1257(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0x12e6(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0x1375(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0x1404(%rip),%rdi
call   1030 <fputs@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_code_footer>:
push   %rbx
mov    %rdi,%rbx
lea    0xee5(%rip),%rdi
mov    $0x1c,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
lea    0xee9(%rip),%rdi
mov    $0x66,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
lea    0xf37(%rip),%rdi
mov    $0x66,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
lea    0xf85(%rip),%rdi
mov    $0xa5,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
lea    0x1012(%rip),%rdi
mov    $0x89,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
lea    0x1083(%rip),%rdi
mov    $0x78,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
lea    0x10e3(%rip),%rdi
mov    $0x7d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
lea    0x1148(%rip),%rdi
mov    $0x7d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
lea    0x11ad(%rip),%rdi
mov    $0x7d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
lea    0x1212(%rip),%rdi
mov    $0x9e,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
lea    0x1298(%rip),%rdi
mov    $0x9e,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
lea    0x131e(%rip),%rdi
mov    $0x9e,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
lea    0x13a4(%rip),%rdi
mov    $0x83,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
pop    %rbx
jmp    1030 <fwrite@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"\0A return EXIT_SUCCESS;\0A}\0A\0A\0A\00"
@.str.1 = [103 x i8] c"inline static int pop(void)\0A{\0A assert(stack_idx < LENGTHOF(stack));\0A return stack[--stack_idx];\0A}\0A\0A\0A\00"
@.str.2 = [103 x i8] c"inline static void push(int e)\0A{\0A assert(stack_idx < LENGTHOF(stack));\0A stack[stack_idx++] = e;\0A}\0A\0A\0A\00"
@.str.3 = [166 x i8] c"inline static void dup_n(size_t n)\0A{\0A assert(n < stack_idx && stack_idx < LENGTHOF(stack) - 1);\0A stack[stack_idx] = stack[stack_idx - (n + 1)];\0A stack_idx++;\0A}\0A\0A\0A\00"
@.str.4 = [138 x i8] c"inline static void slide(size_t n)\0A{\0A assert(stack_idx > n);\0A stack[stack_idx - (n + 1)] = stack[stack_idx - 1];\0A stack_idx -= n;\0A}\0A\0A\0A\00"
@.str.5 = [121 x i8] c"inline static void swap(void)\0A{\0A assert(stack_idx > 1);\0A SWAP(int, &stack[stack_idx - 1], &stack[stack_idx - 2]);\0A}\0A\0A\0A\00"
@.str.6 = [126 x i8] c"inline static void arith_add(void)\0A{\0A assert(stack_idx > 1);\0A stack_idx--;\0A stack[stack_idx - 1] += stack[stack_idx];\0A}\0A\0A\0A\00"
@.str.7 = [126 x i8] c"inline static void arith_sub(void)\0A{\0A assert(stack_idx > 1);\0A stack_idx--;\0A stack[stack_idx - 1] -= stack[stack_idx];\0A}\0A\0A\0A\00"
@.str.8 = [126 x i8] c"inline static void arith_mul(void)\0A{\0A assert(stack_idx > 1);\0A stack_idx--;\0A stack[stack_idx - 1] *= stack[stack_idx];\0A}\0A\0A\0A\00"
@.str.9 = [159 x i8] c"inline static void arith_div(void)\0A{\0A assert(stack_idx > 1);\0A stack_idx--;\0A assert(stack[stack_idx] != 0);\0A stack[stack_idx - 1] /= stack[stack_idx];\0A}\0A\0A\0A\00"
@.str.10 = [159 x i8] c"inline static void arith_mod(void)\0A{\0A assert(stack_idx > 1);\0A stack_idx--;\0A assert(stack[stack_idx] != 0);\0A stack[stack_idx - 1] %= stack[stack_idx];\0A}\0A\0A\0A\00"
@.str.11 = [159 x i8] c"inline static void heap_store(void)\0A{\0A int value = pop();\0A int addr = pop();\0A assert(0 <= addr && addr < (int) LENGTHOF(heap));\0A heap[addr] = value;\0A}\0A\0A\0A\00"
@.str.12 = [132 x i8] c"inline static void heap_read(void)\0A{\0A int addr = pop();\0A assert(0 <= addr && addr < (int) LENGTHOF(heap));\0A push(heap[addr]);\0A}\0A\00"
define void @print_code_footer(i32* %0) {
%2 = alloca i32*
store i32* %0, i32** %2
%3 = load i32*, i32** %2
%4 = call i32 @fputs(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32* %3)
%5 = load i32*, i32** %2
%6 = call i32 @fputs(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%7 = load i32*, i32** %2
%8 = call i32 @fputs(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%9 = load i32*, i32** %2
%10 = call i32 @fputs(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str.3, i64 0, i64 0), i32* %9)
%11 = load i32*, i32** %2
%12 = call i32 @fputs(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.4, i64 0, i64 0), i32* %11)
%13 = load i32*, i32** %2
%14 = call i32 @fputs(i8* getelementptr inbounds ([121 x i8], [121 x i8]* @.str.5, i64 0, i64 0), i32* %13)
%15 = load i32*, i32** %2
%16 = call i32 @fputs(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str.6, i64 0, i64 0), i32* %15)
%17 = load i32*, i32** %2
%18 = call i32 @fputs(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str.7, i64 0, i64 0), i32* %17)
%19 = load i32*, i32** %2
%20 = call i32 @fputs(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str.8, i64 0, i64 0), i32* %19)
%21 = load i32*, i32** %2
%22 = call i32 @fputs(i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.9, i64 0, i64 0), i32* %21)
%23 = load i32*, i32** %2
%24 = call i32 @fputs(i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.10, i64 0, i64 0), i32* %23)
%25 = load i32*, i32** %2
%26 = call i32 @fputs(i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.11, i64 0, i64 0), i32* %25)
%27 = load i32*, i32** %2
%28 = call i32 @fputs(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.12, i64 0, i64 0), i32* %27)
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"\0A return EXIT_SUCCESS;\0A}\0A\0A\0A\00"
@.str.1 = [103 x i8] c"inline static int pop(void)\0A{\0A assert(stack_idx < LENGTHOF(stack));\0A return stack[--stack_idx];\0A}\0A\0A\0A\00"
@.str.2 = [103 x i8] c"inline static void push(int e)\0A{\0A assert(stack_idx < LENGTHOF(stack));\0A stack[stack_idx++] = e;\0A}\0A\0A\0A\00"
@.str.3 = [166 x i8] c"inline static void dup_n(size_t n)\0A{\0A assert(n < stack_idx && stack_idx < LENGTHOF(stack) - 1);\0A stack[stack_idx] = stack[stack_idx - (n + 1)];\0A stack_idx++;\0A}\0A\0A\0A\00"
@.str.4 = [138 x i8] c"inline static void slide(size_t n)\0A{\0A assert(stack_idx > n);\0A stack[stack_idx - (n + 1)] = stack[stack_idx - 1];\0A stack_idx -= n;\0A}\0A\0A\0A\00"
@.str.5 = [121 x i8] c"inline static void swap(void)\0A{\0A assert(stack_idx > 1);\0A SWAP(int, &stack[stack_idx - 1], &stack[stack_idx - 2]);\0A}\0A\0A\0A\00"
@.str.6 = [126 x i8] c"inline static void arith_add(void)\0A{\0A assert(stack_idx > 1);\0A stack_idx--;\0A stack[stack_idx - 1] += stack[stack_idx];\0A}\0A\0A\0A\00"
@.str.7 = [126 x i8] c"inline static void arith_sub(void)\0A{\0A assert(stack_idx > 1);\0A stack_idx--;\0A stack[stack_idx - 1] -= stack[stack_idx];\0A}\0A\0A\0A\00"
@.str.8 = [126 x i8] c"inline static void arith_mul(void)\0A{\0A assert(stack_idx > 1);\0A stack_idx--;\0A stack[stack_idx - 1] *= stack[stack_idx];\0A}\0A\0A\0A\00"
@.str.9 = [159 x i8] c"inline static void arith_div(void)\0A{\0A assert(stack_idx > 1);\0A stack_idx--;\0A assert(stack[stack_idx] != 0);\0A stack[stack_idx - 1] /= stack[stack_idx];\0A}\0A\0A\0A\00"
@.str.10 = [159 x i8] c"inline static void arith_mod(void)\0A{\0A assert(stack_idx > 1);\0A stack_idx--;\0A assert(stack[stack_idx] != 0);\0A stack[stack_idx - 1] %= stack[stack_idx];\0A}\0A\0A\0A\00"
@.str.11 = [159 x i8] c"inline static void heap_store(void)\0A{\0A int value = pop();\0A int addr = pop();\0A assert(0 <= addr && addr < (int) LENGTHOF(heap));\0A heap[addr] = value;\0A}\0A\0A\0A\00"
@.str.12 = [132 x i8] c"inline static void heap_read(void)\0A{\0A int addr = pop();\0A assert(0 <= addr && addr < (int) LENGTHOF(heap));\0A push(heap[addr]);\0A}\0A\00"
define void @print_code_footer(i32* nocapture %0) {
%2 = tail call i64 @fwrite(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 28, i64 1, i32* %0)
%3 = tail call i64 @fwrite(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.1, i64 0, i64 0), i64 102, i64 1, i32* %0)
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.2, i64 0, i64 0), i64 102, i64 1, i32* %0)
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str.3, i64 0, i64 0), i64 165, i64 1, i32* %0)
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.4, i64 0, i64 0), i64 137, i64 1, i32* %0)
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([121 x i8], [121 x i8]* @.str.5, i64 0, i64 0), i64 120, i64 1, i32* %0)
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str.6, i64 0, i64 0), i64 125, i64 1, i32* %0)
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str.7, i64 0, i64 0), i64 125, i64 1, i32* %0)
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str.8, i64 0, i64 0), i64 125, i64 1, i32* %0)
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.9, i64 0, i64 0), i64 158, i64 1, i32* %0)
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.10, i64 0, i64 0), i64 158, i64 1, i32* %0)
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.11, i64 0, i64 0), i64 158, i64 1, i32* %0)
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.12, i64 0, i64 0), i64 131, i64 1, i32* %0)
ret void
}