#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*/ options;
typedef int /*<<< orphan*/ data_in;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
double *malloc(unsigned int);
int /*<<< orphan*/ print_array(double const *, int const);
int /*<<< orphan*/ printf(char *, ...);
int ti_sma(int const, double const **, double const *, double **);
int ti_sma_start(double const *);
int main() {
  const double data_in[] = {5, 8, 12, 11, 9, 8, 7, 10, 11, 13};
  const int input_length = sizeof(data_in) / sizeof(double);
  printf("We have %d bars of input data.\n", input_length);
  print_array(data_in, input_length);
  const double options[] = {3};
  printf("Our option array is: ");
  print_array(options, sizeof(options) / sizeof(double));
  const int start = ti_sma_start(options);
  printf("The start amount is: %d\n", start);
  const int output_length = input_length - start;
  double *data_out = malloc((unsigned int)output_length * sizeof(double));
  assert(data_out != 0);
  printf("The output length is: %d\n", output_length);
  const double *all_inputs[] = {data_in};
  double *all_outputs[] = {data_out};
  int error = ti_sma(input_length, all_inputs, options, all_outputs);
  assert(error == 0);
  printf("The output data is: ");
  print_array(data_out, output_length);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe73(%rip),%rsi
mov    $0x50,%edx
call   1060 <memcpy@plt>
movl   $0xa,-0x64(%rbp)
lea    0xeab(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0xa,%esi
call   1030 <print_array@plt>
mov    0xf0a(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    $0x1,%esi
call   1030 <print_array@plt>
lea    -0x70(%rbp),%rdi
call   1090 <ti_sma_start@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%eax
sub    -0x74(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x78(%rbp),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x88(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    -0x90(%rbp),%rcx
mov    $0xa,%edi
call   1080 <ti_sma@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%esi
call   1030 <print_array@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x78,%rsp
movaps 0xece(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe96(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe7a(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe5e(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xea2(%rip),%rdi
mov    $0xa,%r12d
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0xa,%esi
call   1030 <print_array@plt>
movabs $0x4008000000000000,%rax
mov    %rax,0x18(%rsp)
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x18(%rsp),%r15
mov    %r15,%rdi
mov    $0x1,%esi
call   1030 <print_array@plt>
mov    %r15,%rdi
call   1080 <ti_sma_start@plt>
mov    %eax,%ebx
lea    0xe74(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
sub    %ebx,%r12d
lea    0x0(,%r12,8),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
lea    0xe5c(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,0x10(%rsp)
mov    %rbx,0x8(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rcx
mov    $0xa,%edi
mov    %r15,%rdx
call   1070 <ti_sma@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1030 <print_array@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.data_in = [10 x double] [double 5.000000e+00, double 8.000000e+00, double 1.200000e+01, double 1.100000e+01, double 9.000000e+00, double 8.000000e+00, double 7.000000e+00, double 1.000000e+01, double 1.100000e+01, double 1.300000e+01]
@.str = [32 x i8] c"We have %d bars of input data.\0A\00"
@__const.main.options = [1 x double] [double 3.000000e+00]
@.str.1 = [22 x i8] c"Our option array is: \00"
@.str.2 = [25 x i8] c"The start amount is: %d\0A\00"
@.str.3 = [26 x i8] c"The output length is: %d\0A\00"
@.str.4 = [21 x i8] c"The output data is: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x double]
%3 = alloca i32
%4 = alloca [1 x double]
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca [1 x double*]
%9 = alloca [1 x double*]
%10 = alloca i32
store i32 0, i32* %1
%11 = bitcast [10 x double]* %2 to i8*
store i32 10, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 10)
%13 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 0
%14 = call i32 @print_array(double* %13, i32 10)
%15 = bitcast [1 x double]* %4 to i8*
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [1 x double], [1 x double]* %4, i64 0, i64 0
%18 = call i32 @print_array(double* %17, i32 1)
%19 = getelementptr inbounds [1 x double], [1 x double]* %4, i64 0, i64 0
%20 = call i32 @ti_sma_start(double* %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %5
%24 = sub nsw i32 10, %23
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = zext i32 %25 to i64
%27 = mul i64 %26, 8
%28 = trunc i64 %27 to i32
%29 = call double* @malloc(i32 %28)
store double* %29, double** %7
%30 = load double*, double** %7
%31 = icmp ne double* %30, null
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i32, i32* %6
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds [1 x double*], [1 x double*]* %8, i64 0, i64 0
%37 = getelementptr inbounds [10 x double], [10 x double]* %2, i64 0, i64 0
store double* %37, double** %36
%38 = getelementptr inbounds [1 x double*], [1 x double*]* %9, i64 0, i64 0
%39 = load double*, double** %7
store double* %39, double** %38
%40 = getelementptr inbounds [1 x double*], [1 x double*]* %8, i64 0, i64 0
%41 = getelementptr inbounds [1 x double], [1 x double]* %4, i64 0, i64 0
%42 = getelementptr inbounds [1 x double*], [1 x double*]* %9, i64 0, i64 0
%43 = call i32 @ti_sma(i32 10, double** %40, double* %41, double** %42)
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = icmp eq i32 %44, 0
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%49 = load double*, double** %7
%50 = load i32, i32* %6
%51 = call i32 @print_array(double* %49, i32 %50)
ret i32 0
}

LLVM IR (-O2):
@__const.main.data_in = [10 x double] [double 5.000000e+00, double 8.000000e+00, double 1.200000e+01, double 1.100000e+01, double 9.000000e+00, double 8.000000e+00, double 7.000000e+00, double 1.000000e+01, double 1.100000e+01, double 1.300000e+01]
@.str = [32 x i8] c"We have %d bars of input data.\0A\00"
@.str.1 = [22 x i8] c"Our option array is: \00"
@.str.2 = [25 x i8] c"The start amount is: %d\0A\00"
@.str.3 = [26 x i8] c"The output length is: %d\0A\00"
@.str.4 = [21 x i8] c"The output data is: \00"
define i32 @main() {
%1 = alloca [10 x double]
%2 = alloca [1 x double]
%3 = alloca [1 x double*]
%4 = alloca [1 x double*]
%5 = bitcast [10 x double]* %1 to i8*
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 10)
%7 = getelementptr inbounds [10 x double], [10 x double]* %1, i64 0, i64 0
%8 = call i32 @print_array(double* %7, i32 10)
%9 = bitcast [1 x double]* %2 to i8*
%10 = bitcast [1 x double]* %2 to i64*
store i64 4613937818241073152, i64* %10
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds [1 x double], [1 x double]* %2, i64 0, i64 0
%13 = call i32 @print_array(double* %12, i32 1)
%14 = call i32 @ti_sma_start(double* %12)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = sub nsw i32 10, %14
%17 = shl i32 %16, 3
%18 = call double* @malloc(i32 %17)
%19 = icmp ne double* %18, null
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%23 = bitcast [1 x double*]* %3 to i8*
%24 = getelementptr inbounds [1 x double*], [1 x double*]* %3, i64 0, i64 0
store double* %7, double** %24
%25 = bitcast [1 x double*]* %4 to i8*
%26 = getelementptr inbounds [1 x double*], [1 x double*]* %4, i64 0, i64 0
store double* %18, double** %26
%27 = call i32 @ti_sma(i32 10, double** %24, double* %12, double** %26)
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @print_array(double* %18, i32 %16)
ret i32 0
}