#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 */
float dGauss(float, double);
int /*<<< orphan*/ dxy_separable_convolution(float *, int, int, int, float *,
                                             int, float *, int);
int /*<<< orphan*/ free(float *);
scalar_t__ malloc(int);
float meanGauss(float, double);
int /*<<< orphan*/ nonmax_suppress(float *, float *, int, int, int, int *);
int /*<<< orphan*/ separable_convolution(int *, int, int, int, float *, int,
                                         float *, float *);
void canny_aux(int *image, int width, int height, int depth, double s,
               int *mag) {
  int gau_width = 0;
  float *smx, *smy, *dx, *dy;
  int i;
  float gau[20], dgau[20];
  for (i = 0; i < 20; i++) {
    gau[i] = meanGauss((float)i, s);
    if (gau[i] < 0.005) {
      gau_width = i;
      break;
    }
    dgau[i] = dGauss((float)i, s);
  }
  smx = (float *)malloc(width * height * depth * sizeof(float));
  smy = (float *)malloc(width * height * depth * sizeof(float));
  separable_convolution(image, width, height, depth, gau, gau_width, smx, smy);
  dx = (float *)malloc(width * height * depth * sizeof(float));
  dxy_separable_convolution(smx, height, width, depth, dgau, gau_width, dx, 1);
  free(smx);
  dy = (float *)malloc(width * height * depth * sizeof(float));
  dxy_separable_convolution(smy, height, width, depth, dgau, gau_width, dy, 0);
  free(smy);
  nonmax_suppress(dx, dy, height, width, depth, mag);
  free(dx);
  free(dy);
}


x86 assembly (clang, -O0):
<canny_aux>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x14,-0x54(%rbp)
jge    121d <canny_aux+0xad>
cvtsi2ssl -0x54(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1090 <meanGauss@plt>
movslq -0x54(%rbp),%rax
movss  %xmm0,-0xb0(%rbp,%rax,4)
ff ff
movslq -0x54(%rbp),%rax
movss  -0xb0(%rbp,%rax,4),%xmm0
ff ff
cvtss2sd %xmm0,%xmm1
movsd  0xe22(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11f3 <canny_aux+0x83>
mov    -0x54(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    121d <canny_aux+0xad>
cvtsi2ssl -0x54(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1040 <dGauss@plt>
movslq -0x54(%rbp),%rax
movss  %xmm0,-0x100(%rbp,%rax,4)
ff ff
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    119f <canny_aux+0x2f>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    -0xb0(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    -0x38(%rbp),%r10
mov    -0x40(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <separable_convolution@plt>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    -0x100(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    -0x48(%rbp),%rax
mov    %rax,(%rsp)
movl   $0x1,0x8(%rsp)
call   1050 <dxy_separable_convolution@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    -0x100(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    -0x50(%rbp),%rax
xor    %r10d,%r10d
mov    %rax,(%rsp)
movl   $0x0,0x8(%rsp)
call   1050 <dxy_separable_convolution@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x28(%rbp),%r9
call   1080 <nonmax_suppress@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canny_aux>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %r8,0x18(%rsp)
movsd  %xmm0,(%rsp)
mov    %ecx,%ebp
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,0x10(%rsp)
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
movss  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm1
call   1090 <meanGauss@plt>
movss  %xmm0,0x70(%rsp,%rbx,4)
cvtss2sd %xmm0,%xmm0
movsd  0xe37(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     11f1 <canny_aux+0x81>
movss  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1040 <dGauss@plt>
movss  %xmm0,0x20(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x14,%rbx
jne    11a0 <canny_aux+0x30>
xor    %ebx,%ebx
mov    %r14d,%r12d
imul   %r15d,%r12d
imul   %ebp,%r12d
shl    $0x2,%r12d
mov    %r12d,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
mov    %r12d,%edi
call   1070 <malloc@plt>
mov    %rax,(%rsp)
lea    0x70(%rsp),%r8
mov    0x10(%rsp),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %ebx,%r9d
push   %rax
push   %r13
call   1060 <separable_convolution@plt>
add    $0x10,%rsp
mov    %r12d,%edi
call   1070 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0x20(%rsp),%r8
mov    %r13,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %ebx,%r9d
push   $0x1
push   %rax
call   1050 <dxy_separable_convolution@plt>
add    $0x10,%rsp
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12d,%edi
call   1070 <malloc@plt>
mov    %ebp,%r12d
mov    %rax,%r13
mov    (%rsp),%rbp
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %r12d,%ecx
lea    0x20(%rsp),%r8
mov    %ebx,%r9d
push   $0x0
push   %rax
call   1050 <dxy_separable_convolution@plt>
add    $0x10,%rsp
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
mov    %r12d,%r8d
mov    0x18(%rsp),%r9
call   1080 <nonmax_suppress@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @canny_aux(i32* %0, i32 %1, i32 %2, i32 %3, double %4, i32* %5) {
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca i32*
%13 = alloca i32
%14 = alloca float*
%15 = alloca float*
%16 = alloca float*
%17 = alloca float*
%18 = alloca i32
%19 = alloca [20 x float]
%20 = alloca [20 x float]
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store double %4, double* %11
store i32* %5, i32** %12
store i32 0, i32* %13
store i32 0, i32* %18
br label %21
21: ; preds = %48, %6
%22 = load i32, i32* %18
%23 = icmp slt i32 %22, 20
br i1 %23, label %24, label %51
24: ; preds = %21
%25 = load i32, i32* %18
%26 = sitofp i32 %25 to float
%27 = load double, double* %11
%28 = call float @meanGauss(float %26, double %27)
%29 = load i32, i32* %18
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20 x float], [20 x float]* %19, i64 0, i64 %30
store float %28, float* %31
%32 = load i32, i32* %18
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [20 x float], [20 x float]* %19, i64 0, i64 %33
%35 = load float, float* %34
%36 = fpext float %35 to double
%37 = fcmp olt double %36, 5.000000e-03
br i1 %37, label %38, label %40
38: ; preds = %24
%39 = load i32, i32* %18
store i32 %39, i32* %13
br label %51
40: ; preds = %24
%41 = load i32, i32* %18
%42 = sitofp i32 %41 to float
%43 = load double, double* %11
%44 = call float @dGauss(float %42, double %43)
%45 = load i32, i32* %18
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [20 x float], [20 x float]* %20, i64 0, i64 %46
store float %44, float* %47
br label %48
48: ; preds = %40
%49 = load i32, i32* %18
%50 = add nsw i32 %49, 1
store i32 %50, i32* %18
br label %21
51: ; preds = %38, %21
%52 = load i32, i32* %8
%53 = load i32, i32* %9
%54 = mul nsw i32 %52, %53
%55 = load i32, i32* %10
%56 = mul nsw i32 %54, %55
%57 = sext i32 %56 to i64
%58 = mul i64 %57, 4
%59 = trunc i64 %58 to i32
%60 = call i64 @malloc(i32 %59)
%61 = inttoptr i64 %60 to float*
store float* %61, float** %14
%62 = load i32, i32* %8
%63 = load i32, i32* %9
%64 = mul nsw i32 %62, %63
%65 = load i32, i32* %10
%66 = mul nsw i32 %64, %65
%67 = sext i32 %66 to i64
%68 = mul i64 %67, 4
%69 = trunc i64 %68 to i32
%70 = call i64 @malloc(i32 %69)
%71 = inttoptr i64 %70 to float*
store float* %71, float** %15
%72 = load i32*, i32** %7
%73 = load i32, i32* %8
%74 = load i32, i32* %9
%75 = load i32, i32* %10
%76 = getelementptr inbounds [20 x float], [20 x float]* %19, i64 0, i64 0
%77 = load i32, i32* %13
%78 = load float*, float** %14
%79 = load float*, float** %15
%80 = call i32 @separable_convolution(i32* %72, i32 %73, i32 %74, i32 %75, float* %76, i32 %77, float* %78, float* %79)
%81 = load i32, i32* %8
%82 = load i32, i32* %9
%83 = mul nsw i32 %81, %82
%84 = load i32, i32* %10
%85 = mul nsw i32 %83, %84
%86 = sext i32 %85 to i64
%87 = mul i64 %86, 4
%88 = trunc i64 %87 to i32
%89 = call i64 @malloc(i32 %88)
%90 = inttoptr i64 %89 to float*
store float* %90, float** %16
%91 = load float*, float** %14
%92 = load i32, i32* %9
%93 = load i32, i32* %8
%94 = load i32, i32* %10
%95 = getelementptr inbounds [20 x float], [20 x float]* %20, i64 0, i64 0
%96 = load i32, i32* %13
%97 = load float*, float** %16
%98 = call i32 @dxy_separable_convolution(float* %91, i32 %92, i32 %93, i32 %94, float* %95, i32 %96, float* %97, i32 1)
%99 = load float*, float** %14
%100 = call i32 @free(float* %99)
%101 = load i32, i32* %8
%102 = load i32, i32* %9
%103 = mul nsw i32 %101, %102
%104 = load i32, i32* %10
%105 = mul nsw i32 %103, %104
%106 = sext i32 %105 to i64
%107 = mul i64 %106, 4
%108 = trunc i64 %107 to i32
%109 = call i64 @malloc(i32 %108)
%110 = inttoptr i64 %109 to float*
store float* %110, float** %17
%111 = load float*, float** %15
%112 = load i32, i32* %9
%113 = load i32, i32* %8
%114 = load i32, i32* %10
%115 = getelementptr inbounds [20 x float], [20 x float]* %20, i64 0, i64 0
%116 = load i32, i32* %13
%117 = load float*, float** %17
%118 = call i32 @dxy_separable_convolution(float* %111, i32 %112, i32 %113, i32 %114, float* %115, i32 %116, float* %117, i32 0)
%119 = load float*, float** %15
%120 = call i32 @free(float* %119)
%121 = load float*, float** %16
%122 = load float*, float** %17
%123 = load i32, i32* %9
%124 = load i32, i32* %8
%125 = load i32, i32* %10
%126 = load i32*, i32** %12
%127 = call i32 @nonmax_suppress(float* %121, float* %122, i32 %123, i32 %124, i32 %125, i32* %126)
%128 = load float*, float** %16
%129 = call i32 @free(float* %128)
%130 = load float*, float** %17
%131 = call i32 @free(float* %130)
ret void
}

LLVM IR (-O2):
define void @canny_aux(i32* %0, i32 %1, i32 %2, i32 %3, double %4, i32* %5) {
%7 = alloca [20 x float]
%8 = alloca [20 x float]
%9 = bitcast [20 x float]* %7 to i8*
%10 = bitcast [20 x float]* %8 to i8*
br label %11
11: ; preds = %6, %19
%12 = phi i64 [ 0, %6 ], [ %22, %19 ]
%13 = trunc i64 %12 to i32
%14 = sitofp i32 %13 to float
%15 = tail call float @meanGauss(float %14, double %4)
%16 = getelementptr inbounds [20 x float], [20 x float]* %7, i64 0, i64 %12
store float %15, float* %16
%17 = fpext float %15 to double
%18 = fcmp olt double %17, 5.000000e-03
br i1 %18, label %24, label %19
19: ; preds = %11
%20 = tail call float @dGauss(float %14, double %4)
%21 = getelementptr inbounds [20 x float], [20 x float]* %8, i64 0, i64 %12
store float %20, float* %21
%22 = add nuw nsw i64 %12, 1
%23 = icmp eq i64 %22, 20
br i1 %23, label %26, label %11
24: ; preds = %11
%25 = trunc i64 %12 to i32
br label %26
26: ; preds = %19, %24
%27 = phi i32 [ %25, %24 ], [ 0, %19 ]
%28 = shl i32 %1, 2
%29 = mul i32 %28, %2
%30 = mul i32 %29, %3
%31 = tail call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to float*
%33 = tail call i64 @malloc(i32 %30)
%34 = inttoptr i64 %33 to float*
%35 = getelementptr inbounds [20 x float], [20 x float]* %7, i64 0, i64 0
%36 = call i32 @separable_convolution(i32* %0, i32 %1, i32 %2, i32 %3, float* %35, i32 %27, float* %32, float* %34)
%37 = call i64 @malloc(i32 %30)
%38 = inttoptr i64 %37 to float*
%39 = getelementptr inbounds [20 x float], [20 x float]* %8, i64 0, i64 0
%40 = call i32 @dxy_separable_convolution(float* %32, i32 %2, i32 %1, i32 %3, float* %39, i32 %27, float* %38, i32 1)
%41 = call i32 @free(float* %32)
%42 = call i64 @malloc(i32 %30)
%43 = inttoptr i64 %42 to float*
%44 = call i32 @dxy_separable_convolution(float* %34, i32 %2, i32 %1, i32 %3, float* %39, i32 %27, float* %43, i32 0)
%45 = call i32 @free(float* %34)
%46 = call i32 @nonmax_suppress(float* %38, float* %43, i32 %2, i32 %1, i32 %3, i32* %5)
%47 = call i32 @free(float* %38)
%48 = call i32 @free(float* %43)
ret void
}