#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 */
size_t coord(int, int, int, int);
int /*<<< orphan*/ printf(char *);
double g(double img[], int x, int y, int cols, int rows, double *g1,
         int g1Dim) {
  int k;
  double out;
  if (x - g1Dim < 0 || x > cols || y < 0 || y > rows) {
    if (0)
      printf("Index outside array.\n");
    return 0.0;
  }
  out = g1[0] * img[coord(x, y, cols, rows)];
  for (k = 1; k < g1Dim; k++) {
    out += g1[k] * ((double)img[coord(x - k, y, cols, rows)] +
                    (double)img[coord(x + k, y, cols, rows)]);
  }
  return out;
}


x86 assembly (clang, -O0):
<g>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x14(%rbp),%eax
sub    0x10(%rbp),%eax
cmp    $0x0,%eax
jl     1161 <g+0x51>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1161 <g+0x51>
cmpl   $0x0,-0x18(%rbp)
jl     1161 <g+0x51>
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    116e <g+0x5e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1258 <g+0x148>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1030 <coord@plt>
movsd  -0x48(%rbp),%xmm0
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    124e <g+0x13e>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x14(%rbp),%edi
sub    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1030 <coord@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x14(%rbp),%edi
add    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1030 <coord@plt>
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm0
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
addsd  (%rax,%rcx,8),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b1 <g+0xa1>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<g>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    0x70(%rsp),%r14d
xorpd  %xmm0,%xmm0
cmp    %r14d,%esi
jl     1225 <g+0x115>
mov    %edx,%ebp
test   %edx,%edx
js     1225 <g+0x115>
mov    %ecx,%r12d
mov    %esi,%ebx
cmp    %ecx,%esi
jg     1225 <g+0x115>
mov    %r8d,%r15d
cmp    %r8d,%ebp
jg     1225 <g+0x115>
mov    %rdi,%r13
mov    %r9,0x10(%rsp)
movsd  (%r9),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1030 <coord@plt>
movsd  0x8(%rsp),%xmm0
mulsd  0x0(%r13,%rax,8),%xmm0
cmp    $0x2,%r14d
jl     1225 <g+0x115>
mov    %r14d,%eax
lea    0x1(%rbx),%ecx
mov    %rcx,0x18(%rsp)
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%rax
mov    %rax,0x20(%rsp)
xor    %r14d,%r14d
mov    0x10(%rsp),%rcx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rcx,%r14,8),%xmm0
movsd  %xmm0,0x30(%rsp)
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1030 <coord@plt>
movsd  0x0(%r13,%rax,8),%xmm0
movsd  %xmm0,0x28(%rsp)
mov    0x18(%rsp),%rax
lea    (%rax,%r14,1),%edi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1030 <coord@plt>
mov    0x10(%rsp),%rcx
movsd  0x8(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
addsd  0x0(%r13,%rax,8),%xmm1
mulsd  0x30(%rsp),%xmm1
addsd  %xmm1,%xmm0
add    $0x1,%r14
add    $0xffffffff,%ebx
cmp    %r14,0x20(%rsp)
jne    11b0 <g+0xa0>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @g(double* %0, i32 %1, i32 %2, i32 %3, i32 %4, double* %5, i32 %6) {
%8 = alloca double
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double*
%15 = alloca i32
%16 = alloca i32
%17 = alloca double
store double* %0, double** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store double* %5, double** %14
store i32 %6, i32* %15
%18 = load i32, i32* %10
%19 = load i32, i32* %15
%20 = sub nsw i32 %18, %19
%21 = icmp slt i32 %20, 0
br i1 %21, label %33, label %22
22: ; preds = %7
%23 = load i32, i32* %10
%24 = load i32, i32* %12
%25 = icmp sgt i32 %23, %24
br i1 %25, label %33, label %26
26: ; preds = %22
%27 = load i32, i32* %11
%28 = icmp slt i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* %11
%31 = load i32, i32* %13
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29, %26, %22, %7
store double 0.000000e+00, double* %8
br label %85
34: ; preds = %29
%35 = load double*, double** %14
%36 = getelementptr inbounds double, double* %35, i64 0
%37 = load double, double* %36
%38 = load double*, double** %9
%39 = load i32, i32* %10
%40 = load i32, i32* %11
%41 = load i32, i32* %12
%42 = load i32, i32* %13
%43 = call i64 @coord(i32 %39, i32 %40, i32 %41, i32 %42)
%44 = getelementptr inbounds double, double* %38, i64 %43
%45 = load double, double* %44
%46 = fmul double %37, %45
store double %46, double* %17
store i32 1, i32* %16
br label %47
47: ; preds = %80, %34
%48 = load i32, i32* %16
%49 = load i32, i32* %15
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %83
51: ; preds = %47
%52 = load double*, double** %14
%53 = load i32, i32* %16
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
%56 = load double, double* %55
%57 = load double*, double** %9
%58 = load i32, i32* %10
%59 = load i32, i32* %16
%60 = sub nsw i32 %58, %59
%61 = load i32, i32* %11
%62 = load i32, i32* %12
%63 = load i32, i32* %13
%64 = call i64 @coord(i32 %60, i32 %61, i32 %62, i32 %63)
%65 = getelementptr inbounds double, double* %57, i64 %64
%66 = load double, double* %65
%67 = load double*, double** %9
%68 = load i32, i32* %10
%69 = load i32, i32* %16
%70 = add nsw i32 %68, %69
%71 = load i32, i32* %11
%72 = load i32, i32* %12
%73 = load i32, i32* %13
%74 = call i64 @coord(i32 %70, i32 %71, i32 %72, i32 %73)
%75 = getelementptr inbounds double, double* %67, i64 %74
%76 = load double, double* %75
%77 = fadd double %66, %76
%78 = load double, double* %17
%79 = call double @llvm.fmuladd.f64(double %56, double %77, double %78)
store double %79, double* %17
br label %80
80: ; preds = %51
%81 = load i32, i32* %16
%82 = add nsw i32 %81, 1
store i32 %82, i32* %16
br label %47
83: ; preds = %47
%84 = load double, double* %17
store double %84, double* %8
br label %85
85: ; preds = %83, %33
%86 = load double, double* %8
ret double %86
}

LLVM IR (-O2):
define double @g(double* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4, double* nocapture %5, i32 %6) {
%8 = icmp slt i32 %1, %6
br i1 %8, label %42, label %9
9: ; preds = %7
%10 = icmp sgt i32 %1, %3
%11 = icmp slt i32 %2, 0
%12 = or i1 %11, %10
%13 = icmp sgt i32 %2, %4
%14 = or i1 %12, %13
br i1 %14, label %42, label %15
15: ; preds = %9
%16 = load double, double* %5
%17 = tail call i64 @coord(i32 %1, i32 %2, i32 %3, i32 %4)
%18 = getelementptr inbounds double, double* %0, i64 %17
%19 = load double, double* %18
%20 = fmul double %16, %19
%21 = icmp sgt i32 %6, 1
br i1 %21, label %22, label %42
22: ; preds = %15
%23 = zext i32 %6 to i64
br label %24
24: ; preds = %22, %24
%25 = phi i64 [ 1, %22 ], [ %40, %24 ]
%26 = phi double [ %20, %22 ], [ %39, %24 ]
%27 = getelementptr inbounds double, double* %5, i64 %25
%28 = load double, double* %27
%29 = trunc i64 %25 to i32
%30 = sub nsw i32 %1, %29
%31 = tail call i64 @coord(i32 %30, i32 %2, i32 %3, i32 %4)
%32 = getelementptr inbounds double, double* %0, i64 %31
%33 = load double, double* %32
%34 = add nsw i32 %29, %1
%35 = tail call i64 @coord(i32 %34, i32 %2, i32 %3, i32 %4)
%36 = getelementptr inbounds double, double* %0, i64 %35
%37 = load double, double* %36
%38 = fadd double %33, %37
%39 = tail call double @llvm.fmuladd.f64(double %28, double %38, double %26)
%40 = add nuw nsw i64 %25, 1
%41 = icmp eq i64 %40, %23
br i1 %41, label %42, label %24
42: ; preds = %24, %15, %7, %9
%43 = phi double [ 0.000000e+00, %9 ], [ 0.000000e+00, %7 ], [ %20, %15 ], [ %39, %24 ]
ret double %43
}