#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*/ printf(char *, int);
int texture_feature_variance(double ***glcm, int n_object, double *variance) {
  unsigned int i = 0, j = 0, k = 0;
  double *mean;
  mean = (double *)malloc(n_object * sizeof(double));
  if (mean == NULL) {
    printf("Cannot allocate %d bytes for memory.\n",
           (n_object * sizeof(double)));
    exit(-1);
  }
  memset(mean, 0, (n_object * sizeof(double)));
  for (i = 0; i < n_object; i++) {
    for (j = 0; j < 256; j++) {
      for (k = 0; k < 256; k++) {
        mean[i] += j * glcm[i][j][k];
      }
    }
  }
  for (i = 0; i < n_object; i++) {
    for (j = 0; j < 256; j++) {
      for (k = 0; k < 256; k++) {
        double tmp = (j - mean[i]);
        variance[i] += tmp * tmp * glcm[i][j][k];
      }
    }
  }
  free(mean);
  return 1;
}


x86 assembly (clang, -O0):
<texture_feature_variance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b6 <texture_feature_variance+0x66>
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x30(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1275 <texture_feature_variance+0x125>
movl   $0x0,-0x20(%rbp)
cmpl   $0x100,-0x20(%rbp)
jae    1262 <texture_feature_variance+0x112>
movl   $0x0,-0x24(%rbp)
cmpl   $0x100,-0x24(%rbp)
jae    124f <texture_feature_variance+0xff>
mov    -0x20(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    -0x24(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f9 <texture_feature_variance+0xa9>
jmp    1254 <texture_feature_variance+0x104>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e5 <texture_feature_variance+0x95>
jmp    1267 <texture_feature_variance+0x117>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d2 <texture_feature_variance+0x82>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    133a <texture_feature_variance+0x1ea>
movl   $0x0,-0x20(%rbp)
cmpl   $0x100,-0x20(%rbp)
jae    1327 <texture_feature_variance+0x1d7>
movl   $0x0,-0x24(%rbp)
cmpl   $0x100,-0x24(%rbp)
jae    1314 <texture_feature_variance+0x1c4>
mov    -0x20(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    -0x24(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12a3 <texture_feature_variance+0x153>
jmp    1319 <texture_feature_variance+0x1c9>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    128f <texture_feature_variance+0x13f>
jmp    132c <texture_feature_variance+0x1dc>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    127c <texture_feature_variance+0x12c>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<texture_feature_variance>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%r14
lea    0x0(,%r12,8),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     12d2 <texture_feature_variance+0x182>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
test   %r12d,%r12d
je     12bc <texture_feature_variance+0x16c>
mov    %r12d,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
mov    (%r14,%rcx,8),%rdx
movsd  (%rbx,%rcx,8),%xmm0
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
mov    %esi,%edi
xorps  %xmm1,%xmm1
cvtsi2sd %rdi,%xmm1
mov    (%rdx,%rsi,8),%rdi
xor    %ebp,%ebp
movsd  (%rdi,%rbp,8),%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rbx,%rcx,8)
movsd  0x8(%rdi,%rbp,8),%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,(%rbx,%rcx,8)
movsd  0x10(%rdi,%rbp,8),%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rbx,%rcx,8)
movsd  0x18(%rdi,%rbp,8),%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,(%rbx,%rcx,8)
add    $0x4,%rbp
cmp    $0x100,%rbp
jne    11c0 <texture_feature_variance+0x70>
add    $0x1,%rsi
cmp    $0x100,%rsi
jne    11b0 <texture_feature_variance+0x60>
add    $0x1,%rcx
cmp    %rax,%rcx
jne    11a0 <texture_feature_variance+0x50>
test   %r12d,%r12d
je     12bc <texture_feature_variance+0x16c>
xor    %ecx,%ecx
nopl   (%rax)
mov    (%r14,%rcx,8),%rdx
movsd  (%r15,%rcx,8),%xmm0
xor    %esi,%esi
nopl   0x0(%rax)
mov    %esi,%edi
xorps  %xmm1,%xmm1
cvtsi2sd %rdi,%xmm1
mov    (%rdx,%rsi,8),%rdi
xor    %ebp,%ebp
movapd %xmm1,%xmm2
subsd  (%rbx,%rcx,8),%xmm2
mulsd  %xmm2,%xmm2
mulsd  (%rdi,%rbp,8),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%r15,%rcx,8)
movapd %xmm1,%xmm0
subsd  (%rbx,%rcx,8),%xmm0
mulsd  %xmm0,%xmm0
mulsd  0x8(%rdi,%rbp,8),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,(%r15,%rcx,8)
add    $0x2,%rbp
cmp    $0x100,%rbp
jne    1260 <texture_feature_variance+0x110>
add    $0x1,%rsi
cmp    $0x100,%rsi
jne    1250 <texture_feature_variance+0x100>
add    $0x1,%rcx
cmp    %rax,%rcx
jne    1240 <texture_feature_variance+0xf0>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd27(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@.str = [38 x i8] c"Cannot allocate %d bytes for memory.\0A\00"
define i32 @texture_feature_variance(double*** nocapture %0, i32 %1, double* nocapture %2) {
%4 = shl i32 %1, 3
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to double*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %4)
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %3
%12 = tail call i32 @memset(double* %6, i32 0, i32 %4)
%13 = icmp eq i32 %1, 0
br i1 %13, label %96, label %14
14: ; preds = %11
%15 = zext i32 %1 to i64
br label %16
16: ; preds = %14, %55
%17 = phi i64 [ 0, %14 ], [ %56, %55 ]
%18 = getelementptr inbounds double**, double*** %0, i64 %17
%19 = load double**, double*** %18
%20 = getelementptr inbounds double, double* %6, i64 %17
%21 = load double, double* %20
br label %25
22: ; preds = %55
br i1 %13, label %96, label %23
23: ; preds = %22
%24 = zext i32 %1 to i64
br label %58
25: ; preds = %16, %52
%26 = phi double [ %21, %16 ], [ %49, %52 ]
%27 = phi i64 [ 0, %16 ], [ %53, %52 ]
%28 = trunc i64 %27 to i32
%29 = uitofp i32 %28 to double
%30 = getelementptr inbounds double*, double** %19, i64 %27
%31 = load double*, double** %30
br label %32
32: ; preds = %32, %25
%33 = phi double [ %26, %25 ], [ %49, %32 ]
%34 = phi i64 [ 0, %25 ], [ %50, %32 ]
%35 = getelementptr inbounds double, double* %31, i64 %34
%36 = load double, double* %35
%37 = tail call double @llvm.fmuladd.f64(double %29, double %36, double %33)
store double %37, double* %20
%38 = or i64 %34, 1
%39 = getelementptr inbounds double, double* %31, i64 %38
%40 = load double, double* %39
%41 = tail call double @llvm.fmuladd.f64(double %29, double %40, double %37)
store double %41, double* %20
%42 = or i64 %34, 2
%43 = getelementptr inbounds double, double* %31, i64 %42
%44 = load double, double* %43
%45 = tail call double @llvm.fmuladd.f64(double %29, double %44, double %41)
store double %45, double* %20
%46 = or i64 %34, 3
%47 = getelementptr inbounds double, double* %31, i64 %46
%48 = load double, double* %47
%49 = tail call double @llvm.fmuladd.f64(double %29, double %48, double %45)
store double %49, double* %20
%50 = add nuw nsw i64 %34, 4
%51 = icmp eq i64 %50, 256
br i1 %51, label %52, label %32
52: ; preds = %32
%53 = add nuw nsw i64 %27, 1
%54 = icmp eq i64 %53, 256
br i1 %54, label %55, label %25
55: ; preds = %52
%56 = add nuw nsw i64 %17, 1
%57 = icmp eq i64 %56, %15
br i1 %57, label %22, label %16
58: ; preds = %23, %93
%59 = phi i64 [ 0, %23 ], [ %94, %93 ]
%60 = getelementptr inbounds double, double* %6, i64 %59
%61 = getelementptr inbounds double**, double*** %0, i64 %59
%62 = load double**, double*** %61
%63 = getelementptr inbounds double, double* %2, i64 %59
%64 = load double, double* %63
br label %65
65: ; preds = %58, %90
%66 = phi double [ %64, %58 ], [ %87, %90 ]
%67 = phi i64 [ 0, %58 ], [ %91, %90 ]
%68 = trunc i64 %67 to i32
%69 = uitofp i32 %68 to double
%70 = getelementptr inbounds double*, double** %62, i64 %67
%71 = load double*, double** %70
br label %72
72: ; preds = %72, %65
%73 = phi double [ %66, %65 ], [ %87, %72 ]
%74 = phi i64 [ 0, %65 ], [ %88, %72 ]
%75 = load double, double* %60
%76 = fsub double %69, %75
%77 = fmul double %76, %76
%78 = getelementptr inbounds double, double* %71, i64 %74
%79 = load double, double* %78
%80 = tail call double @llvm.fmuladd.f64(double %77, double %79, double %73)
store double %80, double* %63
%81 = or i64 %74, 1
%82 = load double, double* %60
%83 = fsub double %69, %82
%84 = fmul double %83, %83
%85 = getelementptr inbounds double, double* %71, i64 %81
%86 = load double, double* %85
%87 = tail call double @llvm.fmuladd.f64(double %84, double %86, double %80)
store double %87, double* %63
%88 = add nuw nsw i64 %74, 2
%89 = icmp eq i64 %88, 256
br i1 %89, label %90, label %72
90: ; preds = %72
%91 = add nuw nsw i64 %67, 1
%92 = icmp eq i64 %91, 256
br i1 %92, label %93, label %65
93: ; preds = %90
%94 = add nuw nsw i64 %59, 1
%95 = icmp eq i64 %94, %24
br i1 %95, label %96, label %58
96: ; preds = %93, %11, %22
%97 = tail call i32 @free(double* %6)
ret i32 1
}