#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 */
double grad_x(unsigned char *, int const, int const, int const, int const,
              int const, int const);
double grad_y(unsigned char *, int const, int const, int const, int const,
              int const, int const);
double grad_z(unsigned char *, int const, int const, int const, int const,
              int const, int const);
double grad_mag(unsigned char *in_im, const int dimx, const int dimy,
                const int dimz, const int i, const int j, const int k) {
  return (grad_x(in_im, dimx, dimy, dimz, i, j, k) *
              grad_x(in_im, dimx, dimy, dimz, i, j, k) +
          grad_y(in_im, dimx, dimy, dimz, i, j, k) *
              grad_y(in_im, dimx, dimy, dimz, i, j, k) +
          grad_z(in_im, dimx, dimy, dimz, i, j, k) *
              grad_z(in_im, dimx, dimy, dimz, i, j, k));
}


x86 assembly (clang, -O0):
<grad_mag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1050 <grad_x@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1050 <grad_x@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <grad_y@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <grad_y@plt>
movsd  -0x48(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1040 <grad_z@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1040 <grad_z@plt>
movsd  -0x30(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grad_mag>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r14d
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %esi,%ebx
mov    %rdi,%rbp
mov    0x60(%rsp),%eax
mov    %eax,(%rsp)
call   1050 <grad_x@plt>
movsd  %xmm0,0x18(%rsp)
mov    0x60(%rsp),%eax
mov    %eax,(%rsp)
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    %r14d,%r9d
call   1050 <grad_x@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x60(%rsp),%eax
mov    %eax,(%rsp)
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    %r14d,%r9d
call   1030 <grad_y@plt>
movsd  %xmm0,0x20(%rsp)
mov    0x60(%rsp),%eax
mov    %eax,(%rsp)
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    %r14d,%r9d
call   1030 <grad_y@plt>
mulsd  0x20(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  0x18(%rsp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    0x60(%rsp),%eax
mov    %eax,(%rsp)
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    %r14d,%r9d
call   1040 <grad_z@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x60(%rsp),%eax
mov    %eax,(%rsp)
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    %r14d,%r9d
call   1040 <grad_z@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @grad_mag(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%15 = load i8*, i8** %8
%16 = load i32, i32* %9
%17 = load i32, i32* %10
%18 = load i32, i32* %11
%19 = load i32, i32* %12
%20 = load i32, i32* %13
%21 = load i32, i32* %14
%22 = call double @grad_x(i8* %15, i32 %16, i32 %17, i32 %18, i32 %19, i32 %20, i32 %21)
%23 = load i8*, i8** %8
%24 = load i32, i32* %9
%25 = load i32, i32* %10
%26 = load i32, i32* %11
%27 = load i32, i32* %12
%28 = load i32, i32* %13
%29 = load i32, i32* %14
%30 = call double @grad_x(i8* %23, i32 %24, i32 %25, i32 %26, i32 %27, i32 %28, i32 %29)
%31 = load i8*, i8** %8
%32 = load i32, i32* %9
%33 = load i32, i32* %10
%34 = load i32, i32* %11
%35 = load i32, i32* %12
%36 = load i32, i32* %13
%37 = load i32, i32* %14
%38 = call double @grad_y(i8* %31, i32 %32, i32 %33, i32 %34, i32 %35, i32 %36, i32 %37)
%39 = load i8*, i8** %8
%40 = load i32, i32* %9
%41 = load i32, i32* %10
%42 = load i32, i32* %11
%43 = load i32, i32* %12
%44 = load i32, i32* %13
%45 = load i32, i32* %14
%46 = call double @grad_y(i8* %39, i32 %40, i32 %41, i32 %42, i32 %43, i32 %44, i32 %45)
%47 = fmul double %38, %46
%48 = call double @llvm.fmuladd.f64(double %22, double %30, double %47)
%49 = load i8*, i8** %8
%50 = load i32, i32* %9
%51 = load i32, i32* %10
%52 = load i32, i32* %11
%53 = load i32, i32* %12
%54 = load i32, i32* %13
%55 = load i32, i32* %14
%56 = call double @grad_z(i8* %49, i32 %50, i32 %51, i32 %52, i32 %53, i32 %54, i32 %55)
%57 = load i8*, i8** %8
%58 = load i32, i32* %9
%59 = load i32, i32* %10
%60 = load i32, i32* %11
%61 = load i32, i32* %12
%62 = load i32, i32* %13
%63 = load i32, i32* %14
%64 = call double @grad_z(i8* %57, i32 %58, i32 %59, i32 %60, i32 %61, i32 %62, i32 %63)
%65 = call double @llvm.fmuladd.f64(double %56, double %64, double %48)
ret double %65
}

LLVM IR (-O2):
define double @grad_mag(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = tail call double @grad_x(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6)
%9 = tail call double @grad_x(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6)
%10 = tail call double @grad_y(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6)
%11 = tail call double @grad_y(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6)
%12 = fmul double %10, %11
%13 = tail call double @llvm.fmuladd.f64(double %8, double %9, double %12)
%14 = tail call double @grad_z(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6)
%15 = tail call double @grad_z(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6)
%16 = tail call double @llvm.fmuladd.f64(double %14, double %15, double %13)
ret double %16
}