#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 curve_monotonity(double *, int);
int line_monotonity(double *, int);
int tensor_dimension_monotonity(const double *T0, const double *T1, int ii,
                                int i0, double *pole, int p_offset,
                                int pole_step, int pole_step_i, int order) {
  if (ii < 0) {
    if (order == 3)
      return curve_monotonity(pole + p_offset, pole_step_i);
    else
      return line_monotonity(pole + p_offset, pole_step_i);
  } else if (i0 == ii) {
    return tensor_dimension_monotonity(T0, T1, ii - 1, i0, pole, p_offset,
                                       pole_step / 4, pole_step, order);
  } else {
    int j, ei = (T0[ii] == T1[ii] ? 1 : order + 1), m = 0, mm;
    for (j = 0; j < ei; j++) {
      mm = tensor_dimension_monotonity(T0, T1, ii - 1, i0, pole,
                                       p_offset + j * pole_step, pole_step / 4,
                                       pole_step_i, order);
      m |= mm << (j * 3);
      if (mm == 3) {
        break;
      }
    }
    return m;
  }
}


x86 assembly (clang, -O0):
<tensor_dimension_monotonity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11a9 <tensor_dimension_monotonity+0x79>
cmpl   $0x3,0x20(%rbp)
jne    118a <tensor_dimension_monotonity+0x5a>
mov    -0x28(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    0x18(%rbp),%esi
call   1040 <curve_monotonity@plt>
mov    %eax,-0x4(%rbp)
jmp    12ed <tensor_dimension_monotonity+0x1bd>
mov    -0x28(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    0x18(%rbp),%esi
call   1030 <line_monotonity@plt>
mov    %eax,-0x4(%rbp)
jmp    12ed <tensor_dimension_monotonity+0x1bd>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1205 <tensor_dimension_monotonity+0xd5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    $0x4,%r10d
cltd
idiv   %r10d
mov    -0x40(%rbp),%edx
mov    %eax,%r11d
mov    0x10(%rbp),%r10d
mov    0x20(%rbp),%eax
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1050 <tensor_dimension_monotonity@plt>
mov    %eax,-0x4(%rbp)
jmp    12ed <tensor_dimension_monotonity+0x1bd>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jne    1238 <tensor_dimension_monotonity+0x108>
jp     1238 <tensor_dimension_monotonity+0x108>
mov    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1241 <tensor_dimension_monotonity+0x111>
mov    0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    12e7 <tensor_dimension_monotonity+0x1b7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%eax
imul   0x10(%rbp),%eax
add    %eax,%r9d
mov    0x10(%rbp),%eax
mov    $0x4,%r10d
cltd
idiv   %r10d
mov    -0x48(%rbp),%edx
mov    %eax,%r11d
mov    0x18(%rbp),%r10d
mov    0x20(%rbp),%eax
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1050 <tensor_dimension_monotonity@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
imul   $0x3,-0x30(%rbp),%ecx
shl    %cl,%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x3,-0x3c(%rbp)
jne    12d4 <tensor_dimension_monotonity+0x1a4>
jmp    12e7 <tensor_dimension_monotonity+0x1b7>
jmp    12d9 <tensor_dimension_monotonity+0x1a9>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1255 <tensor_dimension_monotonity+0x125>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tensor_dimension_monotonity>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9d,%r12d
mov    %r8,0x28(%rsp)
mov    %rsi,0x38(%rsp)
mov    %rdi,0x30(%rsp)
mov    0x90(%rsp),%eax
mov    %rax,0x18(%rsp)
mov    0x88(%rsp),%eax
mov    %rax,0x10(%rsp)
test   %edx,%edx
js     127f <tensor_dimension_monotonity+0x14f>
mov    %edx,%ebx
mov    0x80(%rsp),%eax
mov    %rax,0x8(%rsp)
cmp    %ecx,%edx
jne    11a7 <tensor_dimension_monotonity+0x77>
test   %ecx,%ecx
jle    1275 <tensor_dimension_monotonity+0x145>
lea    -0x1(%rcx),%ebx
mov    0x8(%rsp),%rdx
lea    0x3(%rdx),%eax
test   %edx,%edx
cmovns %edx,%eax
sar    $0x2,%eax
mov    %rdx,0x10(%rsp)
mov    %rax,0x8(%rsp)
mov    %ebx,%eax
mov    0x30(%rsp),%rdx
movsd  (%rdx,%rax,8),%xmm0
mov    0x38(%rsp),%rdx
ucomisd (%rdx,%rax,8),%xmm0
mov    0x18(%rsp),%rax
lea    0x1(%rax),%eax
mov    $0x1,%edx
cmovne %eax,%edx
mov    $0x1,%r14d
cmovp  %eax,%edx
mov    %edx,0x20(%rsp)
test   %edx,%edx
jle    1264 <tensor_dimension_monotonity+0x134>
add    $0xffffffff,%ebx
mov    0x8(%rsp),%rax
lea    0x3(%rax),%edx
test   %eax,%eax
cmovns %eax,%edx
sar    $0x2,%edx
mov    %rdx,0x40(%rsp)
xor    %r15d,%r15d
xor    %eax,%eax
nop
mov    %eax,0x24(%rsp)
sub    $0x8,%rsp
mov    0x38(%rsp),%rdi
mov    0x40(%rsp),%rsi
mov    %ebx,%ebp
mov    %ebx,%edx
mov    %rcx,%r13
mov    0x30(%rsp),%r8
mov    %r12d,%r9d
push   0x20(%rsp)
push   0x20(%rsp)
push   0x58(%rsp)
call   1050 <tensor_dimension_monotonity@plt>
add    $0x20,%rsp
mov    %eax,%edx
mov    %r15d,%ecx
shl    %cl,%eax
or     0x24(%rsp),%eax
cmp    $0x3,%edx
je     1266 <tensor_dimension_monotonity+0x136>
lea    0x1(%r14),%ecx
add    $0x3,%r15d
add    0x8(%rsp),%r12d
cmp    0x20(%rsp),%r14d
mov    %ecx,%r14d
mov    %r13,%rcx
mov    %ebp,%ebx
jl     1200 <tensor_dimension_monotonity+0xd0>
jmp    1266 <tensor_dimension_monotonity+0x136>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rax
mov    %rax,0x10(%rsp)
movslq %r12d,%rax
mov    0x28(%rsp),%rcx
lea    (%rcx,%rax,8),%rdi
cmpl   $0x3,0x18(%rsp)
jne    12aa <tensor_dimension_monotonity+0x17a>
mov    0x10(%rsp),%rsi
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <curve_monotonity@plt>
mov    0x10(%rsp),%rsi
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <line_monotonity@plt>

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

LLVM IR (-O2):
define i32 @tensor_dimension_monotonity(double* %0, double* %1, i32 %2, i32 %3, double* %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = icmp slt i32 %2, 0
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = add nsw i32 %3, -1
%13 = icmp eq i32 %2, %3
br i1 %13, label %23, label %27
14: ; preds = %23, %9
%15 = phi i32 [ %7, %9 ], [ %6, %23 ]
%16 = icmp eq i32 %8, 3
%17 = sext i32 %5 to i64
%18 = getelementptr inbounds double, double* %4, i64 %17
br i1 %16, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @curve_monotonity(double* %18, i32 %15)
br label %56
21: ; preds = %14
%22 = tail call i32 @line_monotonity(double* %18, i32 %15)
br label %56
23: ; preds = %11
%24 = icmp slt i32 %3, 1
br i1 %24, label %14, label %25
25: ; preds = %23
%26 = sdiv i32 %6, 4
br label %27
27: ; preds = %25, %11
%28 = phi i32 [ %6, %25 ], [ %7, %11 ]
%29 = phi i32 [ %26, %25 ], [ %6, %11 ]
%30 = phi i32 [ %12, %25 ], [ %2, %11 ]
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds double, double* %0, i64 %31
%33 = load double, double* %32
%34 = getelementptr inbounds double, double* %1, i64 %31
%35 = load double, double* %34
%36 = fcmp oeq double %33, %35
%37 = add nsw i32 %8, 1
%38 = select i1 %36, i32 1, i32 %37
%39 = add nsw i32 %30, -1
%40 = icmp sgt i32 %38, 0
br i1 %40, label %41, label %56
41: ; preds = %27
%42 = sdiv i32 %29, 4
br label %43
43: ; preds = %43, %41
%44 = phi i32 [ 0, %41 ], [ %51, %43 ]
%45 = phi i32 [ 0, %41 ], [ %53, %43 ]
%46 = mul nsw i32 %45, %29
%47 = add nsw i32 %46, %5
%48 = tail call i32 @tensor_dimension_monotonity(double* %0, double* %1, i32 %39, i32 %3, double* %4, i32 %47, i32 %42, i32 %28, i32 %8)
%49 = mul nsw i32 %45, 3
%50 = shl i32 %48, %49
%51 = or i32 %50, %44
%52 = icmp ne i32 %48, 3
%53 = add nuw nsw i32 %45, 1
%54 = icmp slt i32 %53, %38
%55 = select i1 %52, i1 %54, i1 false
br i1 %55, label %43, label %56
56: ; preds = %43, %27, %21, %19
%57 = phi i32 [ %20, %19 ], [ %22, %21 ], [ 0, %27 ], [ %51, %43 ]
ret i32 %57
}