#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*/ exit(int);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(double *, int /*<<< orphan*/, int);
int /*<<< orphan*/ morphological_feature_central_moments(double, double, int **,
                                                         int, int, int,
                                                         unsigned char *,
                                                         double *);
double pow(double, double);
int /*<<< orphan*/ printf(char *, ...);
int morphological_feature_central_invariant_moments(
    double p, double q, int **obj_id, int width, int height, int n_object,
    unsigned char *image, double *central_invariant_moment) {
  unsigned int i = 0;
  if (p + q < 2.0) {
    printf("morphological_feature_central_invariant_moments: p+q < 2!!! p+q "
           "should be >=2\n");
    return 0;
  }
  double *mi00 = NULL;
  mi00 = (double *)malloc(n_object * sizeof(double));
  if (mi00 == NULL) {
    printf("Cannot allocate %d bytes for memory.\n",
           (n_object * sizeof(double)));
    exit(-1);
  }
  memset(mi00, 0, (n_object * sizeof(double)));
  double *mipq = NULL;
  mipq = (double *)malloc(n_object * sizeof(double));
  if (mipq == NULL) {
    printf("Cannot allocate %d bytes for memory.\n",
           (n_object * sizeof(double)));
    exit(-1);
  }
  memset(mipq, 0, (n_object * sizeof(double)));
  morphological_feature_central_moments(0.0, 0.0, obj_id, width, height,
                                        n_object, image, mi00);
  morphological_feature_central_moments(p, q, obj_id, width, height, n_object,
                                        image, mipq);
  for (i = 0; i < n_object; i++) {
    central_invariant_moment[i] =
        mipq[i] / pow(mi00[i], (1.0 + ((p + q) / 2.0)));
  }
  free(mi00);
  free(mipq);
  return 1;
}


x86 assembly (clang, -O0):
<morphological_feature_central_invariant_moments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %esi,-0x24(%rbp)
mov    %edx,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    %r8,-0x38(%rbp)
mov    %r9,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movsd  -0x10(%rbp),%xmm1
addsd  -0x18(%rbp),%xmm1
movsd  0xe50(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d4 <morphological_feature_central_invariant_moments+0x64>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1364 <morphological_feature_central_invariant_moments+0x1f4>
movq   $0x0,-0x50(%rbp)
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    121a <morphological_feature_central_invariant_moments+0xaa>
movslq -0x2c(%rbp),%rsi
shl    $0x3,%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x50(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movq   $0x0,-0x58(%rbp)
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1275 <morphological_feature_central_invariant_moments+0x105>
movslq -0x2c(%rbp),%rsi
shl    $0x3,%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x58(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    -0x50(%rbp),%r9
xorps  %xmm1,%xmm1
movaps %xmm1,%xmm0
call   1060 <morphological_feature_central_moments@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    -0x58(%rbp),%r9
call   1060 <morphological_feature_central_moments@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jae    134b <morphological_feature_central_invariant_moments+0x1db>
mov    -0x58(%rbp),%rax
mov    -0x44(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x50(%rbp),%rax
mov    -0x44(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x10(%rbp),%xmm2
addsd  -0x18(%rbp),%xmm2
movsd  0xcf0(%rip),%xmm1
divsd  %xmm1,%xmm2
movsd  0xcec(%rip),%xmm1
addsd  %xmm2,%xmm1
call   1080 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    -0x40(%rbp),%rax
mov    -0x44(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12d5 <morphological_feature_central_invariant_moments+0x165>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<morphological_feature_central_invariant_moments>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movapd %xmm0,%xmm2
addsd  %xmm1,%xmm2
movsd  0xe62(%rip),%xmm3
ucomisd %xmm2,%xmm3
jbe    11b7 <morphological_feature_central_invariant_moments+0x37>
lea    0xe93(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    136b <morphological_feature_central_invariant_moments+0x1eb>
mov    %r9,%r14
movsd  %xmm0,0x28(%rsp)
movsd  %xmm1,0x30(%rsp)
mov    %rdi,%rbp
mov    %esi,%r13d
mov    %edx,0x1c(%rsp)
mov    %r8,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
mov    %ecx,0x18(%rsp)
movslq %ecx,%r12
shl    $0x3,%r12
mov    %r12d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     137a <morphological_feature_central_invariant_moments+0x1fa>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1060 <memset@plt>
mov    %r12d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     137a <morphological_feature_central_invariant_moments+0x1fa>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1060 <memset@plt>
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
mov    %rbp,0x20(%rsp)
mov    %rbp,%rdi
mov    %r13d,%esi
mov    0x1c(%rsp),%r12d
mov    %r12d,%edx
mov    0x18(%rsp),%ebp
mov    %ebp,%ecx
mov    0x8(%rsp),%r8
mov    %r15,%r9
call   1070 <morphological_feature_central_moments@plt>
movsd  0x28(%rsp),%xmm0
movsd  0x30(%rsp),%xmm1
mov    0x20(%rsp),%rdi
mov    %r13d,%esi
mov    %r12d,%edx
mov    %ebp,%ecx
mov    0x8(%rsp),%r8
mov    %rbx,%r9
call   1070 <morphological_feature_central_moments@plt>
test   %ebp,%ebp
je     1356 <morphological_feature_central_invariant_moments+0x1d6>
movsd  0x10(%rsp),%xmm0
mulsd  0xd76(%rip),%xmm0
addsd  0xd76(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %ebp,%r12d
cmp    $0x1,%ebp
jne    12ac <morphological_feature_central_invariant_moments+0x12c>
xor    %ebp,%ebp
jmp    1324 <morphological_feature_central_invariant_moments+0x1a4>
mov    %r12d,%r13d
and    $0xfffffffe,%r13d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%rbx,%rbp,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%r15,%rbp,8),%xmm0
movsd  0x10(%rsp),%xmm1
call   1090 <pow@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r14,%rbp,8)
movsd  0x8(%rbx,%rbp,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%r15,%rbp,8),%xmm0
movsd  0x10(%rsp),%xmm1
call   1090 <pow@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%r14,%rbp,8)
add    $0x2,%rbp
cmp    %rbp,%r13
jne    12c0 <morphological_feature_central_invariant_moments+0x140>
test   $0x1,%r12b
je     1356 <morphological_feature_central_invariant_moments+0x1d6>
movsd  (%rbx,%rbp,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%r15,%rbp,8),%xmm0
movsd  0x10(%rsp),%xmm1
call   1090 <pow@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r14,%rbp,8)
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc97(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [79 x i8] c"morphological_feature_central_invariant_moments: p+q < 2!!! p+q should be >=2\0A\00"
@.str.1 = [38 x i8] c"Cannot allocate %d bytes for memory.\0A\00"
define i32 @morphological_feature_central_invariant_moments(double %0, double %1, i32** %2, i32 %3, i32 %4, i32 %5, i8* %6, double* %7) {
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca i32**
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca double*
%18 = alloca i32
%19 = alloca double*
%20 = alloca double*
store double %0, double* %10
store double %1, double* %11
store i32** %2, i32*** %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store i8* %6, i8** %16
store double* %7, double** %17
store i32 0, i32* %18
%21 = load double, double* %10
%22 = load double, double* %11
%23 = fadd double %21, %22
%24 = fcmp olt double %23, 2.000000e+00
br i1 %24, label %25, label %27
25: ; preds = %8
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %9
br label %120
27: ; preds = %8
store double* null, double** %19
%28 = load i32, i32* %15
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 8
%31 = trunc i64 %30 to i32
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to double*
store double* %33, double** %19
%34 = load double*, double** %19
%35 = icmp eq double* %34, null
br i1 %35, label %36, label %42
36: ; preds = %27
%37 = load i32, i32* %15
%38 = sext i32 %37 to i64
%39 = mul i64 %38, 8
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %39)
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %27
%43 = load double*, double** %19
%44 = load i32, i32* %15
%45 = sext i32 %44 to i64
%46 = mul i64 %45, 8
%47 = trunc i64 %46 to i32
%48 = call i32 @memset(double* %43, i32 0, i32 %47)
store double* null, double** %20
%49 = load i32, i32* %15
%50 = sext i32 %49 to i64
%51 = mul i64 %50, 8
%52 = trunc i64 %51 to i32
%53 = call i64 @malloc(i32 %52)
%54 = inttoptr i64 %53 to double*
store double* %54, double** %20
%55 = load double*, double** %20
%56 = icmp eq double* %55, null
br i1 %56, label %57, label %63
57: ; preds = %42
%58 = load i32, i32* %15
%59 = sext i32 %58 to i64
%60 = mul i64 %59, 8
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %60)
%62 = call i32 @exit(i32 -1)
unreachable
63: ; preds = %42
%64 = load double*, double** %20
%65 = load i32, i32* %15
%66 = sext i32 %65 to i64
%67 = mul i64 %66, 8
%68 = trunc i64 %67 to i32
%69 = call i32 @memset(double* %64, i32 0, i32 %68)
%70 = load i32**, i32*** %12
%71 = load i32, i32* %13
%72 = load i32, i32* %14
%73 = load i32, i32* %15
%74 = load i8*, i8** %16
%75 = load double*, double** %19
%76 = call i32 @morphological_feature_central_moments(double 0.000000e+00, double 0.000000e+00, i32** %70, i32 %71, i32 %72, i32 %73, i8* %74, double* %75)
%77 = load double, double* %10
%78 = load double, double* %11
%79 = load i32**, i32*** %12
%80 = load i32, i32* %13
%81 = load i32, i32* %14
%82 = load i32, i32* %15
%83 = load i8*, i8** %16
%84 = load double*, double** %20
%85 = call i32 @morphological_feature_central_moments(double %77, double %78, i32** %79, i32 %80, i32 %81, i32 %82, i8* %83, double* %84)
store i32 0, i32* %18
br label %86
86: ; preds = %112, %63
%87 = load i32, i32* %18
%88 = load i32, i32* %15
%89 = icmp ult i32 %87, %88
br i1 %89, label %90, label %115
90: ; preds = %86
%91 = load double*, double** %20
%92 = load i32, i32* %18
%93 = zext i32 %92 to i64
%94 = getelementptr inbounds double, double* %91, i64 %93
%95 = load double, double* %94
%96 = load double*, double** %19
%97 = load i32, i32* %18
%98 = zext i32 %97 to i64
%99 = getelementptr inbounds double, double* %96, i64 %98
%100 = load double, double* %99
%101 = load double, double* %10
%102 = load double, double* %11
%103 = fadd double %101, %102
%104 = fdiv double %103, 2.000000e+00
%105 = fadd double 1.000000e+00, %104
%106 = call double @pow(double %100, double %105)
%107 = fdiv double %95, %106
%108 = load double*, double** %17
%109 = load i32, i32* %18
%110 = zext i32 %109 to i64
%111 = getelementptr inbounds double, double* %108, i64 %110
store double %107, double* %111
br label %112
112: ; preds = %90
%113 = load i32, i32* %18
%114 = add i32 %113, 1
store i32 %114, i32* %18
br label %86
115: ; preds = %86
%116 = load double*, double** %19
%117 = call i32 @free(double* %116)
%118 = load double*, double** %20
%119 = call i32 @free(double* %118)
store i32 1, i32* %9
br label %120
120: ; preds = %115, %25
%121 = load i32, i32* %9
ret i32 %121
}

LLVM IR (-O2):
@.str.1 = [38 x i8] c"Cannot allocate %d bytes for memory.\0A\00"
@str = [78 x i8] c"morphological_feature_central_invariant_moments: p+q < 2!!! p+q should be >=2\00"
define i32 @morphological_feature_central_invariant_moments(double %0, double %1, i32** %2, i32 %3, i32 %4, i32 %5, i8* %6, double* nocapture writeonly %7) {
%9 = fadd double %0, %1
%10 = fcmp olt double %9, 2.000000e+00
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str, i64 0, i64 0))
br label %79
13: ; preds = %8
%14 = sext i32 %5 to i64
%15 = shl nsw i64 %14, 3
%16 = trunc i64 %15 to i32
%17 = tail call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to double*
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %15)
%22 = tail call i32 @exit(i32 -1)
unreachable
23: ; preds = %13
%24 = tail call i32 @memset(double* %18, i32 0, i32 %16)
%25 = tail call i64 @malloc(i32 %16)
%26 = inttoptr i64 %25 to double*
%27 = icmp eq i64 %25, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %15)
%30 = tail call i32 @exit(i32 -1)
unreachable
31: ; preds = %23
%32 = tail call i32 @memset(double* %26, i32 0, i32 %16)
%33 = tail call i32 @morphological_feature_central_moments(double 0.000000e+00, double 0.000000e+00, i32** %2, i32 %3, i32 %4, i32 %5, i8* %6, double* %18)
%34 = tail call i32 @morphological_feature_central_moments(double %0, double %1, i32** %2, i32 %3, i32 %4, i32 %5, i8* %6, double* %26)
%35 = icmp eq i32 %5, 0
br i1 %35, label %76, label %36
36: ; preds = %31
%37 = fmul double %9, 5.000000e-01
%38 = fadd double %37, 1.000000e+00
%39 = zext i32 %5 to i64
%40 = and i64 %39, 1
%41 = icmp eq i32 %5, 1
br i1 %41, label %65, label %42
42: ; preds = %36
%43 = and i64 %39, 4294967294
br label %44
44: ; preds = %44, %42
%45 = phi i64 [ 0, %42 ], [ %62, %44 ]
%46 = phi i64 [ 0, %42 ], [ %63, %44 ]
%47 = getelementptr inbounds double, double* %26, i64 %45
%48 = load double, double* %47
%49 = getelementptr inbounds double, double* %18, i64 %45
%50 = load double, double* %49
%51 = tail call double @pow(double %50, double %38)
%52 = fdiv double %48, %51
%53 = getelementptr inbounds double, double* %7, i64 %45
store double %52, double* %53
%54 = or i64 %45, 1
%55 = getelementptr inbounds double, double* %26, i64 %54
%56 = load double, double* %55
%57 = getelementptr inbounds double, double* %18, i64 %54
%58 = load double, double* %57
%59 = tail call double @pow(double %58, double %38)
%60 = fdiv double %56, %59
%61 = getelementptr inbounds double, double* %7, i64 %54
store double %60, double* %61
%62 = add nuw nsw i64 %45, 2
%63 = add i64 %46, 2
%64 = icmp eq i64 %63, %43
br i1 %64, label %65, label %44
65: ; preds = %44, %36
%66 = phi i64 [ 0, %36 ], [ %62, %44 ]
%67 = icmp eq i64 %40, 0
br i1 %67, label %76, label %68
68: ; preds = %65
%69 = getelementptr inbounds double, double* %26, i64 %66
%70 = load double, double* %69
%71 = getelementptr inbounds double, double* %18, i64 %66
%72 = load double, double* %71
%73 = tail call double @pow(double %72, double %38)
%74 = fdiv double %70, %73
%75 = getelementptr inbounds double, double* %7, i64 %66
store double %74, double* %75
br label %76
76: ; preds = %68, %65, %31
%77 = tail call i32 @free(double* %18)
%78 = tail call i32 @free(double* %26)
br label %79
79: ; preds = %76, %11
%80 = phi i32 [ 0, %11 ], [ 1, %76 ]
ret i32 %80
}