int filter_image(the_image, out_image, rows, cols, bits_per_pixel, filter, type,
                 low_high)
int type;
short filter[3][3], **the_image, **out_image;
char low_high[];
long rows, cols, bits_per_pixel;
{
  int a, b, d, i, j, k, length, max, sum, width;
  setup_filters(type, low_high, filter);
  d = type;
  if (type == 2 || type == 3)
    d = 1;
  max = 255;
  if (bits_per_pixel == 4)
    max = 16;
  printf("\n");
  for (i = 1; i < rows - 1; i++) {
    if ((i % 10) == 0)
      printf("%d ", i);
    for (j = 1; j < cols - 1; j++) {
      sum = 0;
      for (a = -1; a < 2; a++) {
        for (b = -1; b < 2; b++) {
          sum = sum + the_image[i + a][j + b] * filter[a + 1][b + 1];
        }
      }
      sum = sum / d;
      if (sum < 0)
        sum = 0;
      if (sum > max)
        sum = max;
      out_image[i][j] = sum;
    }
  }
  fix_edges(out_image, 1, rows - 1, cols - 1);
  return (1);
}


x86 assembly (clang, -O0):
<filter_image>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    0x10(%rbp),%edi
mov    0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    $0x0,%al
call   1050 <setup_filters@plt>
mov    0x10(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x2,0x10(%rbp)
je     1183 <filter_image+0x53>
cmpl   $0x3,0x10(%rbp)
jne    118a <filter_image+0x5a>
movl   $0x1,-0x3c(%rbp)
movl   $0xff,-0x50(%rbp)
cmpq   $0x4,-0x28(%rbp)
jne    11a3 <filter_image+0x73>
movl   $0x10,-0x50(%rbp)
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x40(%rbp)
movslq -0x40(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jge    130a <filter_image+0x1da>
mov    -0x40(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11f2 <filter_image+0xc2>
mov    -0x40(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x44(%rbp)
movslq -0x44(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jge    12f7 <filter_image+0x1c7>
movl   $0x0,-0x54(%rbp)
movl   $0xffffffff,-0x34(%rbp)
cmpl   $0x2,-0x34(%rbp)
jge    12a2 <filter_image+0x172>
movl   $0xffffffff,-0x38(%rbp)
cmpl   $0x2,-0x38(%rbp)
jge    128f <filter_image+0x15f>
mov    -0x54(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    -0x40(%rbp),%edx
add    -0x34(%rbp),%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,8),%rcx
mov    -0x44(%rbp),%edx
add    -0x38(%rbp),%edx
movslq %edx,%rdx
movswl (%rcx,%rdx,2),%ecx
mov    -0x30(%rbp),%rdx
mov    -0x34(%rbp),%esi
add    $0x1,%esi
movslq %esi,%rsi
imul   $0x6,%rsi,%rsi
add    %rsi,%rdx
mov    -0x38(%rbp),%esi
add    $0x1,%esi
movslq %esi,%rsi
movswl (%rdx,%rsi,2),%edx
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    122d <filter_image+0xfd>
jmp    1294 <filter_image+0x164>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    121c <filter_image+0xec>
mov    -0x54(%rbp),%eax
cltd
idivl  -0x3c(%rbp)
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    12bd <filter_image+0x18d>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x50(%rbp),%eax
jle    12cf <filter_image+0x19f>
mov    -0x50(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %ax,%dx
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x44(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11f9 <filter_image+0xc9>
jmp    12fc <filter_image+0x1cc>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11b8 <filter_image+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <fix_edges@plt>
mov    $0x1,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_image>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %r9,%r12
mov    %r8,%r15
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,0x18(%rsp)
mov    %rdi,0x68(%rsp)
mov    0x160(%rsp),%ebp
mov    0x168(%rsp),%rsi
mov    %ebp,%edi
mov    %r9,%rdx
xor    %eax,%eax
call   1060 <setup_filters@plt>
mov    %ebp,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
mov    $0x1,%r13d
cmovne %ebp,%r13d
cmp    $0x4,%r15
mov    $0x10,%eax
mov    $0xff,%r15d
cmove  %eax,%r15d
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    -0x1(%r14),%rbp
mov    %rbx,0x8(%rsp)
lea    -0x1(%rbx),%rax
mov    %rax,(%rsp)
cmp    $0x3,%r14
jl     1902 <filter_image+0x7c2>
lea    0x12(%r12),%rax
mov    %rax,0x60(%rsp)
mov    0x8(%rsp),%rax
add    $0xfffffffffffffffe,%rax
mov    %rax,0x20(%rsp)
and    $0xfffffffffffffff8,%rax
mov    %rax,0x58(%rsp)
add    $0x1,%rax
mov    %rax,0x50(%rsp)
movd   %r13d,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa %xmm0,0x80(%rsp)
movd   %r15d,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa %xmm0,0x70(%rsp)
mov    $0x1,%r14d
mov    %rbp,0x10(%rsp)
jmp    1243 <filter_image+0x103>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r14
mov    %r14,%rax
mov    %rax,%r14
cmp    %rbp,%rax
je     1902 <filter_image+0x7c2>
imul   $0xcccccccd,%r14d,%eax
ror    %eax
cmp    $0x19999999,%eax
jbe    1260 <filter_image+0x120>
cmpq   $0x2,0x8(%rsp)
jle    1230 <filter_image+0xf0>
jmp    1279 <filter_image+0x139>
nopl   (%rax)
lea    0xd99(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmpq   $0x2,0x8(%rsp)
jle    1230 <filter_image+0xf0>
lea    0x1(%r14),%rcx
mov    0x18(%rsp),%rax
mov    (%rax,%r14,8),%r9
mov    0x68(%rsp),%rax
mov    -0x8(%rax,%r14,8),%r10
mov    (%rax,%r14,8),%r11
mov    0x8(%rax,%r14,8),%r14
mov    $0x1,%eax
cmpq   $0x8,0x20(%rsp)
mov    %rcx,0x28(%rsp)
jae    1390 <filter_image+0x250>
lea    (%r9,%rax,2),%r9
lea    (%r14,%rax,2),%rdi
lea    (%r11,%rax,2),%rcx
lea    (%r10,%rax,2),%rbp
mov    (%rsp),%r10
sub    %rax,%r10
xor    %esi,%esi
xor    %r8d,%r8d
nopl   0x0(%rax,%rax,1)
movswl -0x2(%rbp,%rsi,2),%eax
movswl (%r12),%edx
imul   %eax,%edx
movswl 0x0(%rbp,%rsi,2),%eax
movswl 0x2(%r12),%ebx
imul   %eax,%ebx
add    %edx,%ebx
movswl 0x2(%rbp,%rsi,2),%eax
movswl 0x4(%r12),%edx
imul   %eax,%edx
add    %ebx,%edx
movswl -0x2(%rcx,%rsi,2),%eax
movswl 0x6(%r12),%ebx
imul   %eax,%ebx
add    %edx,%ebx
movswl (%rcx,%rsi,2),%eax
movswl 0x8(%r12),%edx
imul   %eax,%edx
add    %ebx,%edx
movswl 0x2(%rcx,%rsi,2),%eax
movswl 0xa(%r12),%ebx
imul   %eax,%ebx
add    %edx,%ebx
movswl -0x2(%rdi,%rsi,2),%eax
movswl 0xc(%r12),%edx
imul   %eax,%edx
add    %ebx,%edx
movswl (%rdi,%rsi,2),%eax
movswl 0xe(%r12),%ebx
imul   %eax,%ebx
add    %edx,%ebx
movswl 0x2(%rdi,%rsi,2),%edx
movswl 0x10(%r12),%eax
imul   %edx,%eax
add    %ebx,%eax
cltd
idiv   %r13d
test   %eax,%eax
cmovs  %r8d,%eax
cmp    %r15d,%eax
cmovg  %r15d,%eax
mov    %ax,(%r9,%rsi,2)
add    $0x1,%rsi
cmp    %rsi,%r10
jne    12d0 <filter_image+0x190>
mov    0x10(%rsp),%rbp
mov    0x28(%rsp),%rax
jmp    1237 <filter_image+0xf7>
nopl   (%rax)
lea    0x2(%r9),%rsi
mov    (%rsp),%rcx
lea    (%r9,%rcx,2),%rbp
mov    0x8(%rsp),%rdi
lea    (%r10,%rdi,2),%rcx
lea    (%r11,%rdi,2),%rdx
lea    (%r14,%rdi,2),%rbx
cmp    %rcx,%rsi
setb   0x40(%rsp)
cmp    %rbp,%r10
setb   %dil
cmp    0x60(%rsp),%rsi
setb   %cl
cmp    %r12,%rbp
seta   %r8b
cmp    %rdx,%rsi
setb   %dl
cmp    %rbp,%r11
setb   0x30(%rsp)
cmp    %rbx,%rsi
setb   %sil
cmp    %rbp,%r14
setb   %bpl
test   %dil,0x40(%rsp)
jne    12af <filter_image+0x16f>
and    %r8b,%cl
mov    0x58(%rsp),%rbx
jne    12af <filter_image+0x16f>
and    0x30(%rsp),%dl
jne    12af <filter_image+0x16f>
and    %bpl,%sil
jne    12af <filter_image+0x16f>
movzwl (%r12),%eax
movd   %eax,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm1
psrad  $0x10,%xmm1
movdqa %xmm1,0x40(%rsp)
pshufd $0x64,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
psrad  $0x10,%xmm0
movdqa %xmm0,0x30(%rsp)
movzwl 0x2(%r12),%eax
movd   %eax,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm1
psrad  $0x10,%xmm1
movdqa %xmm1,0x110(%rsp)
pshufd $0x64,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
psrad  $0x10,%xmm0
movdqa %xmm0,0x100(%rsp)
movzwl 0x4(%r12),%eax
movd   %eax,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm1
psrad  $0x10,%xmm1
movdqa %xmm1,0xf0(%rsp)
pshufd $0x64,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
psrad  $0x10,%xmm0
movdqa %xmm0,0xe0(%rsp)
movzwl 0x6(%r12),%eax
movd   %eax,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm1
psrad  $0x10,%xmm1
movdqa %xmm1,0xd0(%rsp)
pshufd $0x64,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
psrad  $0x10,%xmm0
movdqa %xmm0,0xc0(%rsp)
movzwl 0x8(%r12),%eax
movd   %eax,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm1
psrad  $0x10,%xmm1
movdqa %xmm1,0xb0(%rsp)
pshufd $0x64,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm0
psrad  $0x10,%xmm0
movdqa %xmm0,0xa0(%rsp)
movzwl 0xa(%r12),%eax
movd   %eax,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm1
psrad  $0x10,%xmm1
movdqa %xmm1,0x90(%rsp)
pshufd $0x64,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm11
psrad  $0x10,%xmm11
movzwl 0xc(%r12),%eax
movd   %eax,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm13
psrad  $0x10,%xmm13
pshufd $0x64,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm12
psrad  $0x10,%xmm12
movzwl 0xe(%r12),%eax
movd   %eax,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm15
psrad  $0x10,%xmm15
pshufd $0x64,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm7
psrad  $0x10,%xmm7
movzwl 0x10(%r12),%eax
movd   %eax,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm10
psrad  $0x10,%xmm10
pshufd $0x64,%xmm0,%xmm0
pshufhw $0xe8,%xmm0,%xmm9
psrad  $0x10,%xmm9
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nop
movdqa 0x40(%rsp),%xmm0
packssdw 0x30(%rsp),%xmm0
movdqu (%r10,%rsi,2),%xmm1
movdqu 0x2(%r10,%rsi,2),%xmm2
movdqu 0x4(%r10,%rsi,2),%xmm3
movdqa %xmm0,%xmm4
pmulhw %xmm1,%xmm4
pmullw %xmm1,%xmm0
movdqa %xmm0,%xmm1
punpcklwd %xmm4,%xmm1
punpckhwd %xmm4,%xmm0
movdqa 0x110(%rsp),%xmm4
packssdw 0x100(%rsp),%xmm4
movdqa %xmm4,%xmm5
pmulhw %xmm2,%xmm5
pmullw %xmm2,%xmm4
movdqa %xmm4,%xmm2
punpcklwd %xmm5,%xmm2
paddd  %xmm1,%xmm2
punpckhwd %xmm5,%xmm4
paddd  %xmm0,%xmm4
movdqa 0xf0(%rsp),%xmm5
packssdw 0xe0(%rsp),%xmm5
movdqa %xmm5,%xmm0
pmulhw %xmm3,%xmm0
pmullw %xmm3,%xmm5
movdqa %xmm5,%xmm3
punpckhwd %xmm0,%xmm3
punpcklwd %xmm0,%xmm5
movdqa 0xd0(%rsp),%xmm0
packssdw 0xc0(%rsp),%xmm0
movdqu (%r11,%rsi,2),%xmm1
movdqa %xmm0,%xmm6
pmulhw %xmm1,%xmm6
pmullw %xmm1,%xmm0
movdqa %xmm0,%xmm1
punpcklwd %xmm6,%xmm1
paddd  %xmm5,%xmm1
movdqu 0x2(%r11,%rsi,2),%xmm5
paddd  %xmm2,%xmm1
movdqu 0x4(%r11,%rsi,2),%xmm2
punpckhwd %xmm6,%xmm0
paddd  %xmm3,%xmm0
paddd  %xmm4,%xmm0
movdqa 0xb0(%rsp),%xmm3
packssdw 0xa0(%rsp),%xmm3
movdqa %xmm3,%xmm4
pmulhw %xmm5,%xmm4
pmullw %xmm5,%xmm3
movdqa %xmm3,%xmm5
punpckhwd %xmm4,%xmm5
punpcklwd %xmm4,%xmm3
movdqa 0x90(%rsp),%xmm6
packssdw %xmm11,%xmm6
movdqa %xmm6,%xmm4
pmulhw %xmm2,%xmm4
pmullw %xmm2,%xmm6
movdqa %xmm6,%xmm2
punpcklwd %xmm4,%xmm2
paddd  %xmm3,%xmm2
punpckhwd %xmm4,%xmm6
paddd  %xmm5,%xmm6
movdqa %xmm13,%xmm4
packssdw %xmm12,%xmm4
movdqu (%r14,%rsi,2),%xmm3
movdqa %xmm4,%xmm5
pmulhw %xmm3,%xmm5
pmullw %xmm3,%xmm4
movdqa %xmm4,%xmm14
punpckhwd %xmm5,%xmm14
paddd  %xmm6,%xmm14
movdqu 0x2(%r14,%rsi,2),%xmm3
paddd  %xmm0,%xmm14
movdqu 0x4(%r14,%rsi,2),%xmm0
punpcklwd %xmm5,%xmm4
paddd  %xmm2,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm15,%xmm2
packssdw %xmm7,%xmm2
movdqa %xmm2,%xmm1
pmulhw %xmm3,%xmm1
pmullw %xmm3,%xmm2
movdqa %xmm2,%xmm3
punpcklwd %xmm1,%xmm3
punpckhwd %xmm1,%xmm2
movdqa %xmm10,%xmm8
packssdw %xmm9,%xmm8
movdqa %xmm8,%xmm5
pmulhw %xmm0,%xmm5
pmullw %xmm0,%xmm8
movdqa %xmm8,%xmm1
punpckhwd %xmm5,%xmm1
paddd  %xmm2,%xmm1
paddd  %xmm14,%xmm1
punpcklwd %xmm5,%xmm8
paddd  %xmm3,%xmm8
paddd  %xmm4,%xmm8
pxor   %xmm4,%xmm4
movdqa 0x80(%rsp),%xmm3
pshufd $0xff,%xmm1,%xmm0
movd   %xmm0,%eax
pshufd $0xff,%xmm3,%xmm0
movd   %xmm0,%ebp
cltd
idiv   %ebp
movd   %eax,%xmm0
pshufd $0xee,%xmm1,%xmm2
movd   %xmm2,%eax
pshufd $0xee,%xmm3,%xmm2
movd   %xmm2,%ecx
cltd
idiv   %ecx
movd   %eax,%xmm2
punpckldq %xmm0,%xmm2
movd   %xmm1,%eax
movd   %xmm3,%edi
cltd
idiv   %edi
movd   %eax,%xmm0
pshufd $0x55,%xmm1,%xmm1
movd   %xmm1,%eax
pshufd $0x55,%xmm3,%xmm1
movd   %xmm1,%r8d
cltd
idiv   %r8d
movd   %eax,%xmm1
punpckldq %xmm1,%xmm0
punpcklqdq %xmm2,%xmm0
pshufd $0xff,%xmm8,%xmm1
movd   %xmm1,%eax
cltd
idiv   %ebp
movd   %eax,%xmm1
pshufd $0xee,%xmm8,%xmm2
movd   %xmm2,%eax
cltd
idiv   %ecx
movd   %eax,%xmm2
punpckldq %xmm1,%xmm2
movd   %xmm8,%eax
cltd
idiv   %edi
movd   %eax,%xmm1
pshufd $0x55,%xmm8,%xmm3
movd   %xmm3,%eax
cltd
idiv   %r8d
movd   %eax,%xmm3
punpckldq %xmm3,%xmm1
movdqa 0x70(%rsp),%xmm3
punpcklqdq %xmm2,%xmm1
movdqa %xmm1,%xmm2
pcmpgtd %xmm4,%xmm2
pand   %xmm1,%xmm2
movdqa %xmm0,%xmm1
pcmpgtd %xmm4,%xmm1
pand   %xmm0,%xmm1
movdqa %xmm3,%xmm0
pcmpgtd %xmm1,%xmm0
pand   %xmm0,%xmm1
pandn  %xmm3,%xmm0
por    %xmm1,%xmm0
movdqa %xmm3,%xmm1
pcmpgtd %xmm2,%xmm1
pand   %xmm1,%xmm2
pandn  %xmm3,%xmm1
por    %xmm2,%xmm1
packuswb %xmm0,%xmm1
movdqu %xmm1,0x2(%r9,%rsi,2)
add    $0x8,%rsi
cmp    %rsi,%rbx
jne    15f0 <filter_image+0x4b0>
mov    0x50(%rsp),%rax
cmp    %rbx,0x20(%rsp)
jne    12af <filter_image+0x16f>
jmp    137e <filter_image+0x23e>
mov    0x18(%rsp),%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    (%rsp),%rcx
xor    %eax,%eax
call   1050 <fix_edges@plt>
mov    $0x1,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%d \00"
define i32 @filter_image(i16** nocapture %0, i16** %1, i64 %2, i64 %3, i64 %4, [3 x i16]* %5, i32 %6, i8* %7) {
%9 = tail call i32 (i32, i8*, [3 x i16]*, ...) bitcast (i32 (...)* @setup_filters to i32 (i32, i8*, [3 x i16]*, ...)*)(i32 %6, i8* %7, [3 x i16]* %5)
%10 = and i32 %6, -2
%11 = icmp eq i32 %10, 2
%12 = select i1 %11, i32 1, i32 %6
%13 = icmp eq i64 %4, 4
%14 = select i1 %13, i32 16, i32 255
%15 = tail call i32 @putchar(i32 10)
%16 = add i64 %2, -1
%17 = icmp sgt i64 %2, 2
%18 = add i64 %3, -1
br i1 %17, label %19, label %267
19: ; preds = %8
%20 = icmp sgt i64 %3, 2
%21 = getelementptr inbounds [3 x i16], [3 x i16]* %5, i64 0, i64 0
%22 = getelementptr inbounds [3 x i16], [3 x i16]* %5, i64 0, i64 1
%23 = getelementptr inbounds [3 x i16], [3 x i16]* %5, i64 0, i64 2
%24 = getelementptr inbounds [3 x i16], [3 x i16]* %5, i64 1, i64 0
%25 = getelementptr inbounds [3 x i16], [3 x i16]* %5, i64 1, i64 1
%26 = getelementptr inbounds [3 x i16], [3 x i16]* %5, i64 1, i64 2
%27 = getelementptr inbounds [3 x i16], [3 x i16]* %5, i64 2, i64 0
%28 = getelementptr inbounds [3 x i16], [3 x i16]* %5, i64 2, i64 1
%29 = getelementptr inbounds [3 x i16], [3 x i16]* %5, i64 2, i64 2
%30 = getelementptr [3 x i16], [3 x i16]* %5, i64 3, i64 0
%31 = add i64 %3, -2
%32 = icmp ult i64 %31, 8
%33 = and i64 %31, -8
%34 = or i64 %33, 1
%35 = insertelement <8 x i32> poison, i32 %12, i64 0
%36 = shufflevector <8 x i32> %35, <8 x i32> poison, <8 x i32> zeroinitializer
%37 = insertelement <8 x i32> poison, i32 %14, i64 0
%38 = shufflevector <8 x i32> %37, <8 x i32> poison, <8 x i32> zeroinitializer
%39 = icmp eq i64 %31, %33
br label %40
40: ; preds = %19, %264
%41 = phi i64 [ 1, %19 ], [ %265, %264 ]
%42 = trunc i64 %41 to i32
%43 = urem i32 %42, 10
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %42)
br label %47
47: ; preds = %45, %40
br i1 %20, label %50, label %48
48: ; preds = %47
%49 = add nuw nsw i64 %41, 1
br label %264
50: ; preds = %47
%51 = getelementptr inbounds i16*, i16** %1, i64 %41
%52 = load i16*, i16** %51
%53 = getelementptr inbounds i16*, i16** %0, i64 %41
%54 = load i16*, i16** %53
%55 = add nsw i64 %41, -1
%56 = getelementptr inbounds i16*, i16** %0, i64 %55
%57 = load i16*, i16** %56
%58 = add nuw nsw i64 %41, 1
%59 = getelementptr inbounds i16*, i16** %0, i64 %58
%60 = load i16*, i16** %59
br i1 %32, label %188, label %61
61: ; preds = %50
%62 = getelementptr i16, i16* %52, i64 1
%63 = getelementptr i16, i16* %52, i64 %18
%64 = getelementptr i16, i16* %57, i64 %3
%65 = getelementptr i16, i16* %54, i64 %3
%66 = getelementptr i16, i16* %60, i64 %3
%67 = icmp ult i16* %62, %64
%68 = icmp ult i16* %57, %63
%69 = and i1 %67, %68
%70 = icmp ult i16* %62, %30
%71 = bitcast i16* %63 to [3 x i16]*
%72 = icmp ugt [3 x i16]* %71, %5
%73 = and i1 %70, %72
%74 = or i1 %69, %73
%75 = icmp ult i16* %62, %65
%76 = icmp ult i16* %54, %63
%77 = and i1 %75, %76
%78 = or i1 %74, %77
%79 = icmp ult i16* %62, %66
%80 = icmp ult i16* %60, %63
%81 = and i1 %79, %80
%82 = or i1 %78, %81
br i1 %82, label %188, label %83
83: ; preds = %61
%84 = load i16, i16* %21
%85 = insertelement <8 x i16> poison, i16 %84, i64 0
%86 = shufflevector <8 x i16> %85, <8 x i16> poison, <8 x i32> zeroinitializer
%87 = sext <8 x i16> %86 to <8 x i32>
%88 = load i16, i16* %22
%89 = insertelement <8 x i16> poison, i16 %88, i64 0
%90 = shufflevector <8 x i16> %89, <8 x i16> poison, <8 x i32> zeroinitializer
%91 = sext <8 x i16> %90 to <8 x i32>
%92 = load i16, i16* %23
%93 = insertelement <8 x i16> poison, i16 %92, i64 0
%94 = shufflevector <8 x i16> %93, <8 x i16> poison, <8 x i32> zeroinitializer
%95 = sext <8 x i16> %94 to <8 x i32>
%96 = load i16, i16* %24
%97 = insertelement <8 x i16> poison, i16 %96, i64 0
%98 = shufflevector <8 x i16> %97, <8 x i16> poison, <8 x i32> zeroinitializer
%99 = sext <8 x i16> %98 to <8 x i32>
%100 = load i16, i16* %25
%101 = insertelement <8 x i16> poison, i16 %100, i64 0
%102 = shufflevector <8 x i16> %101, <8 x i16> poison, <8 x i32> zeroinitializer
%103 = sext <8 x i16> %102 to <8 x i32>
%104 = load i16, i16* %26
%105 = insertelement <8 x i16> poison, i16 %104, i64 0
%106 = shufflevector <8 x i16> %105, <8 x i16> poison, <8 x i32> zeroinitializer
%107 = sext <8 x i16> %106 to <8 x i32>
%108 = load i16, i16* %27
%109 = insertelement <8 x i16> poison, i16 %108, i64 0
%110 = shufflevector <8 x i16> %109, <8 x i16> poison, <8 x i32> zeroinitializer
%111 = sext <8 x i16> %110 to <8 x i32>
%112 = load i16, i16* %28
%113 = insertelement <8 x i16> poison, i16 %112, i64 0
%114 = shufflevector <8 x i16> %113, <8 x i16> poison, <8 x i32> zeroinitializer
%115 = sext <8 x i16> %114 to <8 x i32>
%116 = load i16, i16* %29
%117 = insertelement <8 x i16> poison, i16 %116, i64 0
%118 = shufflevector <8 x i16> %117, <8 x i16> poison, <8 x i32> zeroinitializer
%119 = sext <8 x i16> %118 to <8 x i32>
br label %120
120: ; preds = %120, %83
%121 = phi i64 [ 0, %83 ], [ %185, %120 ]
%122 = or i64 %121, 1
%123 = getelementptr inbounds i16, i16* %57, i64 %121
%124 = bitcast i16* %123 to <8 x i16>*
%125 = load <8 x i16>, <8 x i16>* %124
%126 = sext <8 x i16> %125 to <8 x i32>
%127 = mul nsw <8 x i32> %87, %126
%128 = getelementptr inbounds i16, i16* %57, i64 %122
%129 = bitcast i16* %128 to <8 x i16>*
%130 = load <8 x i16>, <8 x i16>* %129
%131 = sext <8 x i16> %130 to <8 x i32>
%132 = mul nsw <8 x i32> %91, %131
%133 = add nsw <8 x i32> %132, %127
%134 = or i64 %121, 2
%135 = getelementptr inbounds i16, i16* %57, i64 %134
%136 = bitcast i16* %135 to <8 x i16>*
%137 = load <8 x i16>, <8 x i16>* %136
%138 = sext <8 x i16> %137 to <8 x i32>
%139 = mul nsw <8 x i32> %95, %138
%140 = add nsw <8 x i32> %139, %133
%141 = getelementptr inbounds i16, i16* %54, i64 %121
%142 = bitcast i16* %141 to <8 x i16>*
%143 = load <8 x i16>, <8 x i16>* %142
%144 = sext <8 x i16> %143 to <8 x i32>
%145 = mul nsw <8 x i32> %99, %144
%146 = add nsw <8 x i32> %145, %140
%147 = getelementptr inbounds i16, i16* %54, i64 %122
%148 = bitcast i16* %147 to <8 x i16>*
%149 = load <8 x i16>, <8 x i16>* %148
%150 = sext <8 x i16> %149 to <8 x i32>
%151 = mul nsw <8 x i32> %103, %150
%152 = add nsw <8 x i32> %151, %146
%153 = getelementptr inbounds i16, i16* %54, i64 %134
%154 = bitcast i16* %153 to <8 x i16>*
%155 = load <8 x i16>, <8 x i16>* %154
%156 = sext <8 x i16> %155 to <8 x i32>
%157 = mul nsw <8 x i32> %107, %156
%158 = add nsw <8 x i32> %157, %152
%159 = getelementptr inbounds i16, i16* %60, i64 %121
%160 = bitcast i16* %159 to <8 x i16>*
%161 = load <8 x i16>, <8 x i16>* %160
%162 = sext <8 x i16> %161 to <8 x i32>
%163 = mul nsw <8 x i32> %111, %162
%164 = add nsw <8 x i32> %163, %158
%165 = getelementptr inbounds i16, i16* %60, i64 %122
%166 = bitcast i16* %165 to <8 x i16>*
%167 = load <8 x i16>, <8 x i16>* %166
%168 = sext <8 x i16> %167 to <8 x i32>
%169 = mul nsw <8 x i32> %115, %168
%170 = add nsw <8 x i32> %169, %164
%171 = getelementptr inbounds i16, i16* %60, i64 %134
%172 = bitcast i16* %171 to <8 x i16>*
%173 = load <8 x i16>, <8 x i16>* %172
%174 = sext <8 x i16> %173 to <8 x i32>
%175 = mul nsw <8 x i32> %119, %174
%176 = add nsw <8 x i32> %175, %170
%177 = sdiv <8 x i32> %176, %36
%178 = icmp sgt <8 x i32> %177, zeroinitializer
%179 = select <8 x i1> %178, <8 x i32> %177, <8 x i32> zeroinitializer
%180 = icmp sgt <8 x i32> %179, %38
%181 = select <8 x i1> %180, <8 x i32> %38, <8 x i32> %179
%182 = trunc <8 x i32> %181 to <8 x i16>
%183 = getelementptr inbounds i16, i16* %52, i64 %122
%184 = bitcast i16* %183 to <8 x i16>*
store <8 x i16> %182, <8 x i16>* %184
%185 = add nuw i64 %121, 8
%186 = icmp eq i64 %185, %33
br i1 %186, label %187, label %120
187: ; preds = %120
br i1 %39, label %264, label %188
188: ; preds = %61, %50, %187
%189 = phi i64 [ 1, %61 ], [ 1, %50 ], [ %34, %187 ]
br label %190
190: ; preds = %188, %190
%191 = phi i64 [ %206, %190 ], [ %189, %188 ]
%192 = add nsw i64 %191, -1
%193 = getelementptr inbounds i16, i16* %57, i64 %192
%194 = load i16, i16* %193
%195 = sext i16 %194 to i32
%196 = load i16, i16* %21
%197 = sext i16 %196 to i32
%198 = mul nsw i32 %197, %195
%199 = getelementptr inbounds i16, i16* %57, i64 %191
%200 = load i16, i16* %199
%201 = sext i16 %200 to i32
%202 = load i16, i16* %22
%203 = sext i16 %202 to i32
%204 = mul nsw i32 %203, %201
%205 = add nsw i32 %204, %198
%206 = add nuw nsw i64 %191, 1
%207 = getelementptr inbounds i16, i16* %57, i64 %206
%208 = load i16, i16* %207
%209 = sext i16 %208 to i32
%210 = load i16, i16* %23
%211 = sext i16 %210 to i32
%212 = mul nsw i32 %211, %209
%213 = add nsw i32 %212, %205
%214 = getelementptr inbounds i16, i16* %54, i64 %192
%215 = load i16, i16* %214
%216 = sext i16 %215 to i32
%217 = load i16, i16* %24
%218 = sext i16 %217 to i32
%219 = mul nsw i32 %218, %216
%220 = add nsw i32 %219, %213
%221 = getelementptr inbounds i16, i16* %54, i64 %191
%222 = load i16, i16* %221
%223 = sext i16 %222 to i32
%224 = load i16, i16* %25
%225 = sext i16 %224 to i32
%226 = mul nsw i32 %225, %223
%227 = add nsw i32 %226, %220
%228 = getelementptr inbounds i16, i16* %54, i64 %206
%229 = load i16, i16* %228
%230 = sext i16 %229 to i32
%231 = load i16, i16* %26
%232 = sext i16 %231 to i32
%233 = mul nsw i32 %232, %230
%234 = add nsw i32 %233, %227
%235 = getelementptr inbounds i16, i16* %60, i64 %192
%236 = load i16, i16* %235
%237 = sext i16 %236 to i32
%238 = load i16, i16* %27
%239 = sext i16 %238 to i32
%240 = mul nsw i32 %239, %237
%241 = add nsw i32 %240, %234
%242 = getelementptr inbounds i16, i16* %60, i64 %191
%243 = load i16, i16* %242
%244 = sext i16 %243 to i32
%245 = load i16, i16* %28
%246 = sext i16 %245 to i32
%247 = mul nsw i32 %246, %244
%248 = add nsw i32 %247, %241
%249 = getelementptr inbounds i16, i16* %60, i64 %206
%250 = load i16, i16* %249
%251 = sext i16 %250 to i32
%252 = load i16, i16* %29
%253 = sext i16 %252 to i32
%254 = mul nsw i32 %253, %251
%255 = add nsw i32 %254, %248
%256 = sdiv i32 %255, %12
%257 = icmp sgt i32 %256, 0
%258 = select i1 %257, i32 %256, i32 0
%259 = icmp sgt i32 %258, %14
%260 = select i1 %259, i32 %14, i32 %258
%261 = trunc i32 %260 to i16
%262 = getelementptr inbounds i16, i16* %52, i64 %191
store i16 %261, i16* %262
%263 = icmp eq i64 %206, %18
br i1 %263, label %264, label %190
264: ; preds = %190, %187, %48
%265 = phi i64 [ %49, %48 ], [ %58, %187 ], [ %58, %190 ]
%266 = icmp eq i64 %265, %16
br i1 %266, label %267, label %40
267: ; preds = %264, %8
%268 = tail call i32 (i16**, i32, i64, i64, ...) bitcast (i32 (...)* @fix_edges to i32 (i16**, i32, i64, i64, ...)*)(i16** %1, i32 1, i64 %16, i64 %18)
ret i32 1
}