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

/* Variables and functions */
int /*<<< orphan*/ _ssdm_RegionBegin(char *);
int /*<<< orphan*/ _ssdm_RegionEnd(char *);
int /*<<< orphan*/ _ssdm_SpecArrayDimSize(int *, int);
int /*<<< orphan*/ _ssdm_op_SpecLoopName(char *);
void vectoradd(volatile int *cmd, volatile int *resp, int a[4096], int b[4096],
               int result[4096]) {
  _ssdm_SpecArrayDimSize(result, 4096);
  _ssdm_SpecArrayDimSize(b, 4096);
  _ssdm_SpecArrayDimSize(a, 4096);
#pragma empty_line
#pragma HLS INTERFACE ap_ctrl_none port = return
#pragma HLS INTERFACE axis port = cmd
#pragma HLS INTERFACE axis port = resp
#pragma HLS INTERFACE bram depth = 1024 port = a
#pragma HLS INTERFACE bram depth = 1024 port = b
#pragma HLS INTERFACE bram depth = 1024 port = result
#pragma empty_line
#pragma HLS RESOURCE variable = a core = RAM_1P_BRAM
#pragma HLS RESOURCE variable = b core = RAM_1P_BRAM
#pragma HLS RESOURCE variable = result core = RAM_1P_BRAM
#pragma empty_line
  int i, op, start, end;
For_Loop:
  while (1) {
    _ssdm_op_SpecLoopName("For_Loop");
    _ssdm_RegionBegin("For_Loop");
    op = *cmd;
    end = *cmd;
    start = *cmd;
    if (op == 1)
    add_Loop:
      for (i = start; i < end; i++) {
        _ssdm_op_SpecLoopName("add_Loop");
        _ssdm_RegionBegin("add_Loop");
        result[i] = a[i] + b[i];
        if (i == end - 1)
          *resp = 1;
        _ssdm_RegionEnd("add_Loop");
      }
    else if (op == 2)
    sub_Loop:
      for (i = start; i < end; i++) {
        _ssdm_op_SpecLoopName("sub_Loop");
        _ssdm_RegionBegin("sub_Loop");
        result[i] = a[i] - b[i];
        if (i == end - 1)
          *resp = 1;
        _ssdm_RegionEnd("sub_Loop");
      }
#pragma empty_line
#pragma empty_line
    _ssdm_RegionEnd("For_Loop");
  }
}


x86 assembly (clang, -O0):
<vectoradd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x1000,%esi
call   1050 <_ssdm_SpecArrayDimSize@plt>
mov    -0x20(%rbp),%rdi
mov    $0x1000,%esi
call   1050 <_ssdm_SpecArrayDimSize@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1000,%esi
call   1050 <_ssdm_SpecArrayDimSize@plt>
jmp    118b <vectoradd+0x4b>
lea    0xe6e(%rip),%rdi
call   1030 <_ssdm_op_SpecLoopName@plt>
lea    0xe62(%rip),%rdi
call   1040 <_ssdm_RegionBegin@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x1,-0x30(%rbp)
jne    1252 <vectoradd+0x112>
jmp    11cd <vectoradd+0x8d>
mov    -0x34(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    124d <vectoradd+0x10d>
lea    0xe23(%rip),%rdi
call   1030 <_ssdm_op_SpecLoopName@plt>
lea    0xe17(%rip),%rdi
call   1040 <_ssdm_RegionBegin@plt>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
add    (%rax,%rcx,4),%edx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1233 <vectoradd+0xf3>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
lea    0xdcf(%rip),%rdi
call   1060 <_ssdm_RegionEnd@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d3 <vectoradd+0x93>
jmp    12eb <vectoradd+0x1ab>
cmpl   $0x2,-0x30(%rbp)
jne    12e6 <vectoradd+0x1a6>
jmp    1261 <vectoradd+0x121>
mov    -0x34(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    12e1 <vectoradd+0x1a1>
lea    0xd98(%rip),%rdi
call   1030 <_ssdm_op_SpecLoopName@plt>
lea    0xd8c(%rip),%rdi
call   1040 <_ssdm_RegionBegin@plt>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
sub    (%rax,%rcx,4),%edx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    12c7 <vectoradd+0x187>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
lea    0xd44(%rip),%rdi
call   1060 <_ssdm_RegionEnd@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1267 <vectoradd+0x127>
jmp    12e6 <vectoradd+0x1a6>
jmp    12eb <vectoradd+0x1ab>
lea    0xd0e(%rip),%rdi
call   1060 <_ssdm_RegionEnd@plt>
jmp    118b <vectoradd+0x4b>

x86 assembly (clang, -O2):
<vectoradd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %rsi,0x28(%rsp)
mov    %rdi,0x30(%rsp)
mov    %r8,0x20(%rsp)
mov    %r8,%rdi
mov    $0x1000,%esi
call   1050 <_ssdm_SpecArrayDimSize@plt>
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <_ssdm_SpecArrayDimSize@plt>
mov    %rbp,0x10(%rsp)
mov    %rbp,%rdi
mov    $0x1000,%esi
call   1050 <_ssdm_SpecArrayDimSize@plt>
lea    0xe65(%rip),%rbx
jmp    11af <vectoradd+0x6f>
nopl   (%rax)
lea    0xe59(%rip),%rbx
mov    %rbx,%rdi
call   1060 <_ssdm_RegionEnd@plt>
mov    %rbx,%rdi
call   1030 <_ssdm_op_SpecLoopName@plt>
mov    %rbx,%rdi
call   1040 <_ssdm_RegionBegin@plt>
mov    0x30(%rsp),%rax
mov    (%rax),%ecx
movslq (%rax),%r12
movslq (%rax),%rax
cmp    $0x1,%ecx
je     1270 <vectoradd+0x130>
cmp    $0x2,%ecx
jne    11a0 <vectoradd+0x60>
cmp    %r12d,%eax
jge    11a0 <vectoradd+0x60>
mov    %rax,%rbp
not    %rbp
add    %r12,%rbp
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,4),%rcx
mov    %rcx,0x8(%rsp)
mov    0x18(%rsp),%rcx
lea    (%rcx,%rax,4),%rbx
mov    0x20(%rsp),%rcx
lea    (%rcx,%rax,4),%r14
sub    %eax,%r12d
xor    %r15d,%r15d
jmp    1229 <vectoradd+0xe9>
lea    0xdfb(%rip),%rdi
call   1060 <_ssdm_RegionEnd@plt>
add    $0x1,%r15
cmp    %r15d,%r12d
je     11a0 <vectoradd+0x60>
lea    0xde2(%rip),%r13
mov    %r13,%rdi
call   1030 <_ssdm_op_SpecLoopName@plt>
mov    %r13,%rdi
call   1040 <_ssdm_RegionBegin@plt>
mov    0x8(%rsp),%rax
mov    (%rax,%r15,4),%eax
sub    (%rbx,%r15,4),%eax
mov    %eax,(%r14,%r15,4)
cmp    %r15,%rbp
jne    1210 <vectoradd+0xd0>
mov    0x28(%rsp),%rax
movl   $0x1,(%rax)
jmp    1210 <vectoradd+0xd0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %r12d,%eax
jge    11a0 <vectoradd+0x60>
mov    %rax,%rbp
not    %rbp
add    %r12,%rbp
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,4),%rcx
mov    %rcx,0x8(%rsp)
mov    0x18(%rsp),%rcx
lea    (%rcx,%rax,4),%r13
mov    0x20(%rsp),%rcx
lea    (%rcx,%rax,4),%r15
sub    %eax,%r12d
xor    %ebx,%ebx
jmp    12c9 <vectoradd+0x189>
nopl   0x0(%rax)
lea    0xd52(%rip),%rdi
call   1060 <_ssdm_RegionEnd@plt>
add    $0x1,%rbx
cmp    %ebx,%r12d
je     11a0 <vectoradd+0x60>
lea    0xd39(%rip),%r14
mov    %r14,%rdi
call   1030 <_ssdm_op_SpecLoopName@plt>
mov    %r14,%rdi
call   1040 <_ssdm_RegionBegin@plt>
mov    0x0(%r13,%rbx,4),%eax
mov    0x8(%rsp),%rcx
add    (%rcx,%rbx,4),%eax
mov    %eax,(%r15,%rbx,4)
cmp    %rbx,%rbp
jne    12b0 <vectoradd+0x170>
mov    0x28(%rsp),%rax
movl   $0x1,(%rax)
jmp    12b0 <vectoradd+0x170>

LLVM IR (-O0):
@.str = [9 x i8] c"For_Loop\00"
@.str.1 = [9 x i8] c"add_Loop\00"
@.str.2 = [9 x i8] c"sub_Loop\00"
define void @vectoradd(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%15 = load i32*, i32** %10
%16 = call i32 @_ssdm_SpecArrayDimSize(i32* %15, i32 4096)
%17 = load i32*, i32** %9
%18 = call i32 @_ssdm_SpecArrayDimSize(i32* %17, i32 4096)
%19 = load i32*, i32** %8
%20 = call i32 @_ssdm_SpecArrayDimSize(i32* %19, i32 4096)
br label %21
21: ; preds = %5
br label %22
22: ; preds = %21, %111
%23 = call i32 @_ssdm_op_SpecLoopName(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @_ssdm_RegionBegin(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%25 = load i32*, i32** %6
%26 = load volatile i32, i32* %25
store i32 %26, i32* %12
%27 = load i32*, i32** %6
%28 = load volatile i32, i32* %27
store i32 %28, i32* %14
%29 = load i32*, i32** %6
%30 = load volatile i32, i32* %29
store i32 %30, i32* %13
%31 = load i32, i32* %12
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %70
33: ; preds = %22
br label %34
34: ; preds = %33
%35 = load i32, i32* %13
store i32 %35, i32* %11
br label %36
36: ; preds = %66, %34
%37 = load i32, i32* %11
%38 = load i32, i32* %14
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %69
40: ; preds = %36
%41 = call i32 @_ssdm_op_SpecLoopName(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @_ssdm_RegionBegin(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32*, i32** %8
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = load i32*, i32** %9
%49 = load i32, i32* %11
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %48, i64 %50
%52 = load i32, i32* %51
%53 = add nsw i32 %47, %52
%54 = load i32*, i32** %10
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
store i32 %53, i32* %57
%58 = load i32, i32* %11
%59 = load i32, i32* %14
%60 = sub nsw i32 %59, 1
%61 = icmp eq i32 %58, %60
br i1 %61, label %62, label %64
62: ; preds = %40
%63 = load i32*, i32** %7
store volatile i32 1, i32* %63
br label %64
64: ; preds = %62, %40
%65 = call i32 @_ssdm_RegionEnd(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %66
66: ; preds = %64
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %36
69: ; preds = %36
br label %111
70: ; preds = %22
%71 = load i32, i32* %12
%72 = icmp eq i32 %71, 2
br i1 %72, label %73, label %110
73: ; preds = %70
br label %74
74: ; preds = %73
%75 = load i32, i32* %13
store i32 %75, i32* %11
br label %76
76: ; preds = %106, %74
%77 = load i32, i32* %11
%78 = load i32, i32* %14
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %109
80: ; preds = %76
%81 = call i32 @_ssdm_op_SpecLoopName(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%82 = call i32 @_ssdm_RegionBegin(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%83 = load i32*, i32** %8
%84 = load i32, i32* %11
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i32, i32* %83, i64 %85
%87 = load i32, i32* %86
%88 = load i32*, i32** %9
%89 = load i32, i32* %11
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i32, i32* %88, i64 %90
%92 = load i32, i32* %91
%93 = sub nsw i32 %87, %92
%94 = load i32*, i32** %10
%95 = load i32, i32* %11
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i32, i32* %94, i64 %96
store i32 %93, i32* %97
%98 = load i32, i32* %11
%99 = load i32, i32* %14
%100 = sub nsw i32 %99, 1
%101 = icmp eq i32 %98, %100
br i1 %101, label %102, label %104
102: ; preds = %80
%103 = load i32*, i32** %7
store volatile i32 1, i32* %103
br label %104
104: ; preds = %102, %80
%105 = call i32 @_ssdm_RegionEnd(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %106
106: ; preds = %104
%107 = load i32, i32* %11
%108 = add nsw i32 %107, 1
store i32 %108, i32* %11
br label %76
109: ; preds = %76
br label %110
110: ; preds = %109, %70
br label %111
111: ; preds = %110, %69
%112 = call i32 @_ssdm_RegionEnd(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %22
}

LLVM IR (-O2):
@.str = [9 x i8] c"For_Loop\00"
@.str.1 = [9 x i8] c"add_Loop\00"
@.str.2 = [9 x i8] c"sub_Loop\00"
define void @vectoradd(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = tail call i32 @_ssdm_SpecArrayDimSize(i32* %4, i32 4096)
%7 = tail call i32 @_ssdm_SpecArrayDimSize(i32* %3, i32 4096)
%8 = tail call i32 @_ssdm_SpecArrayDimSize(i32* %2, i32 4096)
br label %9
9: ; preds = %61, %5
%10 = tail call i32 @_ssdm_op_SpecLoopName(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @_ssdm_RegionBegin(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = load volatile i32, i32* %0
%13 = load volatile i32, i32* %0
%14 = load volatile i32, i32* %0
switch i32 %12, label %61 [
i32 1, label %21
i32 2, label %15
]
15: ; preds = %9
%16 = icmp slt i32 %14, %13
br i1 %16, label %17, label %61
17: ; preds = %15
%18 = add nsw i32 %13, -1
%19 = sext i32 %14 to i64
%20 = sext i32 %18 to i64
br label %44
21: ; preds = %9
%22 = icmp slt i32 %14, %13
br i1 %22, label %23, label %61
23: ; preds = %21
%24 = add nsw i32 %13, -1
%25 = sext i32 %14 to i64
%26 = sext i32 %24 to i64
br label %27
27: ; preds = %23, %39
%28 = phi i64 [ %25, %23 ], [ %41, %39 ]
%29 = tail call i32 @_ssdm_op_SpecLoopName(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @_ssdm_RegionBegin(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%31 = getelementptr inbounds i32, i32* %2, i64 %28
%32 = load i32, i32* %31
%33 = getelementptr inbounds i32, i32* %3, i64 %28
%34 = load i32, i32* %33
%35 = add nsw i32 %34, %32
%36 = getelementptr inbounds i32, i32* %4, i64 %28
store i32 %35, i32* %36
%37 = icmp eq i64 %28, %26
br i1 %37, label %38, label %39
38: ; preds = %27
store volatile i32 1, i32* %1
br label %39
39: ; preds = %38, %27
%40 = tail call i32 @_ssdm_RegionEnd(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%41 = add nsw i64 %28, 1
%42 = trunc i64 %41 to i32
%43 = icmp eq i32 %13, %42
br i1 %43, label %61, label %27
44: ; preds = %17, %56
%45 = phi i64 [ %19, %17 ], [ %58, %56 ]
%46 = tail call i32 @_ssdm_op_SpecLoopName(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%47 = tail call i32 @_ssdm_RegionBegin(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%48 = getelementptr inbounds i32, i32* %2, i64 %45
%49 = load i32, i32* %48
%50 = getelementptr inbounds i32, i32* %3, i64 %45
%51 = load i32, i32* %50
%52 = sub nsw i32 %49, %51
%53 = getelementptr inbounds i32, i32* %4, i64 %45
store i32 %52, i32* %53
%54 = icmp eq i64 %45, %20
br i1 %54, label %55, label %56
55: ; preds = %44
store volatile i32 1, i32* %1
br label %56
56: ; preds = %55, %44
%57 = tail call i32 @_ssdm_RegionEnd(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%58 = add nsw i64 %45, 1
%59 = trunc i64 %58 to i32
%60 = icmp eq i32 %13, %59
br i1 %60, label %61, label %44
61: ; preds = %56, %39, %15, %21, %9
%62 = tail call i32 @_ssdm_RegionEnd(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %9
}