float *grad_horizontal(float *input, int width, int height) {
  float *grad;
  float **u_x;
  grad = (float *)malloc(sizeof(float) * width * height);
  {
    int ml;
    u_x = (float **)malloc(sizeof(float *) * (3));
    u_x[0] = (float *)malloc(sizeof(float) * (3) * (3));
    for (ml = 0; ml < (3); ml++)
      u_x[ml] = &(u_x[0][ml * (3)]);
  };
  u_x[0][0] = 0.25 * -(2.0 - sqrt(2.0));
  u_x[0][1] = 0;
  u_x[0][2] = 0.25 * (2.0 - sqrt(2.0));
  u_x[1][0] = 0.25 * -2.0 * (sqrt(2.0) - 1);
  u_x[1][1] = 0;
  u_x[1][2] = 0.25 * 2.0 * (sqrt(2.0) - 1);
  u_x[2][0] = 0.25 * -(2.0 - sqrt(2.0));
  u_x[2][1] = 0;
  u_x[2][2] = 0.25 * (2.0 - sqrt(2.0));
  aan_mascara_canal(input, grad, width, height, u_x);
  {
    free(u_x[0]);
    free(u_x);
  };
  return grad;
}


x86 assembly (clang, -O0):
<grad_horizontal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movslq -0xc(%rbp),%rdi
shl    $0x2,%rdi
movslq -0x10(%rbp),%rax
imul   %rax,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x18,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x24,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    11cc <grad_horizontal+0x8c>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
imul   $0x3,-0x24(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1194 <grad_horizontal+0x54>
movsd  0xe34(%rip),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe24(%rip),%xmm0
subsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xdf9(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movss  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
movsd  0xdd7(%rip),%xmm0
call   1060 <sqrt@plt>
movsd  0xdca(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  0xdb6(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movss  %xmm0,0x8(%rax)
movsd  0xda2(%rip),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xda2(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xd9e(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
movss  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
movsd  0xd5a(%rip),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xd5a(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xd46(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
movss  %xmm0,0x8(%rax)
movsd  0xd21(%rip),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xd11(%rip),%xmm0
subsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xce6(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
movss  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
movsd  0xcc2(%rip),%xmm0
call   1060 <sqrt@plt>
movsd  0xcb5(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  0xca1(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
movss  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    $0x0,%al
call   1050 <aan_mascara_canal@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grad_horizontal>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
movslq %esi,%r13
movslq %edx,%r15
mov    %r13,%rdi
imul   %r15,%rdi
shl    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0x18,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    $0x24,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
lea    0xc(%rax),%rcx
mov    %rcx,0x8(%rbx)
lea    0x18(%rax),%rcx
mov    %rcx,0x10(%rbx)
movaps 0xe7a(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe80(%rip),%xmm0
movups %xmm0,0x10(%rax)
movl   $0x3e15f61a,0x20(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
mov    %r15d,%ecx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <aan_mascara_canal@plt>
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define float* @grad_horizontal(float* %0, i32 %1, i32 %2) {
%4 = sext i32 %1 to i64
%5 = shl nsw i64 %4, 2
%6 = sext i32 %2 to i64
%7 = mul i64 %5, %6
%8 = tail call i8* @malloc(i64 %7)
%9 = tail call dereferenceable_or_null(24) i8* @malloc(i64 24)
%10 = bitcast i8* %9 to float**
%11 = tail call dereferenceable_or_null(36) i8* @malloc(i64 36)
%12 = bitcast i8* %9 to i8**
%13 = bitcast i8* %11 to float*
%14 = bitcast i8* %9 to i8**
store i8* %11, i8** %14
%15 = getelementptr inbounds float, float* %13, i64 3
%16 = getelementptr inbounds float*, float** %10, i64 1
store float* %15, float** %16
%17 = getelementptr inbounds float, float* %13, i64 6
%18 = getelementptr inbounds float*, float** %10, i64 2
store float* %17, float** %18
%19 = bitcast i8* %8 to float*
%20 = bitcast i8* %11 to <4 x float>*
store <4 x float> <float 0xBFC2BEC340000000, float 0.000000e+00, float 0x3FC2BEC340000000, float 0xBFCA8279A0000000>, <4 x float>* %20
%21 = getelementptr inbounds float, float* %13, i64 4
%22 = bitcast float* %21 to <4 x float>*
store <4 x float> <float 0.000000e+00, float 0x3FCA8279A0000000, float 0xBFC2BEC340000000, float 0.000000e+00>, <4 x float>* %22
%23 = getelementptr inbounds float, float* %13, i64 8
store float 0x3FC2BEC340000000, float* %23
%24 = tail call i32 (float*, float*, i32, i32, float**, ...) bitcast (i32 (...)* @aan_mascara_canal to i32 (float*, float*, i32, i32, float**, ...)*)(float* %0, float* %19, i32 %1, i32 %2, float** %10)
%25 = load i8*, i8** %12
tail call void @free(i8* %25)
tail call void @free(i8* %9)
ret float* %19
}