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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int run(char const **, int);
int main() {
  const char *prog[] = {
      "MOV(A, 10)", "STR(A, 1)", "MOV(A, 1)", "MOV(B, 1)", "STR(A, 2)",
      "STR(B, 3)",  "LDR(A, 2)", "LDR(B, 3)", "SUM()",     "STR(B, 2)",
      "STR(A, 3)",  "LDR(A, 1)", "SUB(A, 1)", "STR(A, 1)", "CMP(A, 0)",
      "JEQ(17)",    "JMP(6)",    "LDR(A, 2)", "RET()",
  };
  int res = run(prog, sizeof(prog) / sizeof(prog[0]));
  printf("res = %d\n", res);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
lea    -0xa0(%rbp),%rdi
lea    0x2c37(%rip),%rsi
mov    $0x98,%edx
call   1050 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
mov    $0x13,%esi
call   1030 <run@plt>
mov    %eax,-0xa4(%rbp)
mov    -0xa4(%rbp),%esi
lea    0xf27(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xa0,%rsp
lea    0x2c41(%rip),%rsi
mov    %rsp,%rbx
mov    $0x98,%edx
mov    %rbx,%rdi
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    $0x13,%esi
call   1030 <run@plt>
lea    0xf3b(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"MOV(A, 10)\00"
@.str.1 = [10 x i8] c"STR(A, 1)\00"
@.str.2 = [10 x i8] c"MOV(A, 1)\00"
@.str.3 = [10 x i8] c"MOV(B, 1)\00"
@.str.4 = [10 x i8] c"STR(A, 2)\00"
@.str.5 = [10 x i8] c"STR(B, 3)\00"
@.str.6 = [10 x i8] c"LDR(A, 2)\00"
@.str.7 = [10 x i8] c"LDR(B, 3)\00"
@.str.8 = [6 x i8] c"SUM()\00"
@.str.9 = [10 x i8] c"STR(B, 2)\00"
@.str.10 = [10 x i8] c"STR(A, 3)\00"
@.str.11 = [10 x i8] c"LDR(A, 1)\00"
@.str.12 = [10 x i8] c"SUB(A, 1)\00"
@.str.13 = [10 x i8] c"CMP(A, 0)\00"
@.str.14 = [8 x i8] c"JEQ(17)\00"
@.str.15 = [7 x i8] c"JMP(6)\00"
@.str.16 = [6 x i8] c"RET()\00"
@__const.main.prog = [19 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i32 0, i32 0)]
@.str.17 = [10 x i8] c"res = %d\0A\00"
define i32 @main() {
%1 = alloca [19 x i8*]
%2 = alloca i32
%3 = bitcast [19 x i8*]* %1 to i8*
%4 = getelementptr inbounds [19 x i8*], [19 x i8*]* %1, i64 0, i64 0
%5 = call i32 @run(i8** %4, i32 19)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.17, i64 0, i64 0), i32 %6)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"MOV(A, 10)\00"
@.str.1 = [10 x i8] c"STR(A, 1)\00"
@.str.2 = [10 x i8] c"MOV(A, 1)\00"
@.str.3 = [10 x i8] c"MOV(B, 1)\00"
@.str.4 = [10 x i8] c"STR(A, 2)\00"
@.str.5 = [10 x i8] c"STR(B, 3)\00"
@.str.6 = [10 x i8] c"LDR(A, 2)\00"
@.str.7 = [10 x i8] c"LDR(B, 3)\00"
@.str.8 = [6 x i8] c"SUM()\00"
@.str.9 = [10 x i8] c"STR(B, 2)\00"
@.str.10 = [10 x i8] c"STR(A, 3)\00"
@.str.11 = [10 x i8] c"LDR(A, 1)\00"
@.str.12 = [10 x i8] c"SUB(A, 1)\00"
@.str.13 = [10 x i8] c"CMP(A, 0)\00"
@.str.14 = [8 x i8] c"JEQ(17)\00"
@.str.15 = [7 x i8] c"JMP(6)\00"
@.str.16 = [6 x i8] c"RET()\00"
@__const.main.prog = [19 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i32 0, i32 0)]
@.str.17 = [10 x i8] c"res = %d\0A\00"
define i32 @main() {
%1 = alloca [19 x i8*]
%2 = bitcast [19 x i8*]* %1 to i8*
%3 = getelementptr inbounds [19 x i8*], [19 x i8*]* %1, i64 0, i64 0
%4 = call i32 @run(i8** %3, i32 19)
%5 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.17, i64 0, i64 0), i32 %4)
ret i32 0
}