void sharpen(int width, int height, unsigned char *src_region,
             unsigned char *dest_region, int sharpen_percent) {
  unsigned char *src_rows[4], *src_ptr, *dst_row;
  long int *neg_rows[4], *neg_ptr;
  int i, y, row, count, pitch;
  int img_bpp = 3;
  int neg_lut[256];
  int pos_lut[256];
  compute_luts(sharpen_percent, pos_lut, neg_lut);
  pitch = width * img_bpp;
  for (row = 0; row < 4; row++) {
    src_rows[row] = calloc(pitch, sizeof(unsigned char));
    neg_rows[row] = calloc(pitch, sizeof(long int));
  }
  dst_row = calloc(pitch, sizeof(unsigned char));
  memcpy(src_rows[0], src_region, pitch);
  for (i = pitch, src_ptr = src_rows[0], neg_ptr = neg_rows[0]; i > 0;
       i--, src_ptr++, neg_ptr++)
    *neg_ptr = neg_lut[*src_ptr];
  row = 1;
  count = 1;
  for (y = 0; y < height; y++) {
    if ((y + 1) < height) {
      if (count >= 3)
        count--;
      memcpy(src_rows[row], (src_region + pitch * (y + 1)), pitch);
      for (i = pitch, src_ptr = src_rows[row], neg_ptr = neg_rows[row]; i > 0;
           i--, src_ptr++, neg_ptr++)
        *neg_ptr = neg_lut[*src_ptr];
      count++;
      row = (row + 1) & 3;
    } else {
      count--;
    }
    if (count == 3) {
      rgb_filter(width, pos_lut, neg_lut, src_rows[(row + 2) & 3], dst_row,
                 neg_rows[(row + 1) & 3] + img_bpp,
                 neg_rows[(row + 2) & 3] + img_bpp,
                 neg_rows[(row + 3) & 3] + img_bpp);
      memcpy((dest_region + pitch * y), dst_row, pitch);
    } else if (count == 2) {
      if (y == 0)
        memcpy((dest_region), src_rows[0], pitch);
      else
        memcpy((dest_region + pitch * (y)), src_rows[(height - 1) & 3], pitch);
    }
  }
  for (row = 0; row < 4; row++) {
    free(src_rows[row]);
    free(neg_rows[row]);
  }
  free(dst_row);
}


x86 assembly (clang, -O0):
<sharpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8a0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movl   $0x3,-0x90(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x890(%rbp),%rsi
lea    -0x490(%rbp),%rdx
mov    $0x0,%al
call   1050 <compute_luts@plt>
mov    -0x4(%rbp),%eax
imul   -0x90(%rbp),%eax
mov    %eax,-0x8c(%rbp)
movl   $0x0,-0x84(%rbp)
cmpl   $0x4,-0x84(%rbp)
jge    120a <sharpen+0xba>
movslq -0x8c(%rbp),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rcx
movslq -0x84(%rbp),%rax
mov    %rcx,-0x40(%rbp,%rax,8)
movslq -0x8c(%rbp),%rdi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%rcx
movslq -0x84(%rbp),%rax
mov    %rcx,-0x70(%rbp,%rax,8)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11a9 <sharpen+0x59>
movslq -0x8c(%rbp),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x8c(%rbp),%rdx
call   1070 <memcpy@plt>
mov    -0x8c(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
cmpl   $0x0,-0x7c(%rbp)
jle    1292 <sharpen+0x142>
mov    -0x48(%rbp),%rax
movzbl (%rax),%eax
movslq -0x490(%rbp,%rax,4),%rcx
ff
mov    -0x78(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x7c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x78(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x78(%rbp)
jmp    124c <sharpen+0xfc>
movl   $0x1,-0x84(%rbp)
movl   $0x1,-0x88(%rbp)
movl   $0x0,-0x80(%rbp)
mov    -0x80(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1504 <sharpen+0x3b4>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jge    13a9 <sharpen+0x259>
cmpl   $0x3,-0x88(%rbp)
jl     12e4 <sharpen+0x194>
mov    -0x88(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x88(%rbp)
movslq -0x84(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8c(%rbp),%eax
mov    -0x80(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
cltq
add    %rax,%rsi
movslq -0x8c(%rbp),%rdx
call   1070 <memcpy@plt>
mov    -0x8c(%rbp),%eax
mov    %eax,-0x7c(%rbp)
movslq -0x84(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rax
mov    %rax,-0x48(%rbp)
movslq -0x84(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rax
mov    %rax,-0x78(%rbp)
cmpl   $0x0,-0x7c(%rbp)
jle    1383 <sharpen+0x233>
mov    -0x48(%rbp),%rax
movzbl (%rax),%eax
movslq -0x490(%rbp,%rax,4),%rcx
ff
mov    -0x78(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x7c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x78(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x78(%rbp)
jmp    133d <sharpen+0x1ed>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
and    $0x3,%eax
mov    %eax,-0x84(%rbp)
jmp    13b8 <sharpen+0x268>
mov    -0x88(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x88(%rbp)
cmpl   $0x3,-0x88(%rbp)
jne    1488 <sharpen+0x338>
mov    -0x4(%rbp),%edi
lea    -0x890(%rbp),%rsi
lea    -0x490(%rbp),%rdx
mov    -0x84(%rbp),%eax
add    $0x2,%eax
and    $0x3,%eax
cltq
mov    -0x40(%rbp,%rax,8),%rcx
mov    -0x50(%rbp),%r8
mov    -0x84(%rbp),%eax
add    $0x1,%eax
and    $0x3,%eax
cltq
mov    -0x70(%rbp,%rax,8),%r9
movslq -0x90(%rbp),%rax
shl    $0x3,%rax
add    %rax,%r9
mov    -0x84(%rbp),%eax
add    $0x2,%eax
and    $0x3,%eax
cltq
mov    -0x70(%rbp,%rax,8),%r10
movslq -0x90(%rbp),%rax
shl    $0x3,%rax
add    %rax,%r10
mov    -0x84(%rbp),%eax
add    $0x3,%eax
and    $0x3,%eax
cltq
mov    -0x70(%rbp,%rax,8),%rax
movslq -0x90(%rbp),%r11
shl    $0x3,%r11
add    %r11,%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1030 <rgb_filter@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8c(%rbp),%eax
imul   -0x80(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x50(%rbp),%rsi
movslq -0x8c(%rbp),%rdx
call   1070 <memcpy@plt>
jmp    14f1 <sharpen+0x3a1>
cmpl   $0x2,-0x88(%rbp)
jne    14ec <sharpen+0x39c>
cmpl   $0x0,-0x80(%rbp)
jne    14b8 <sharpen+0x368>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rsi
movslq -0x8c(%rbp),%rdx
call   1070 <memcpy@plt>
jmp    14e7 <sharpen+0x397>
mov    -0x18(%rbp),%rdi
mov    -0x8c(%rbp),%eax
imul   -0x80(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
and    $0x3,%eax
cltq
mov    -0x40(%rbp,%rax,8),%rsi
movslq -0x8c(%rbp),%rdx
call   1070 <memcpy@plt>
jmp    14ec <sharpen+0x39c>
jmp    14f1 <sharpen+0x3a1>
jmp    14f6 <sharpen+0x3a6>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    12ad <sharpen+0x15d>
movl   $0x0,-0x84(%rbp)
cmpl   $0x4,-0x84(%rbp)
jge    1551 <sharpen+0x401>
movslq -0x84(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
call   1040 <free@plt>
movslq -0x84(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1040 <free@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    150e <sharpen+0x3be>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
add    $0x8a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sharpen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8e8,%rsp
mov    %rcx,0x18(%rsp)
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%r12d
lea    0x4e0(%rsp),%rsi
lea    0xe0(%rsp),%rdx
mov    %r8d,%edi
xor    %eax,%eax
call   1050 <compute_luts@plt>
lea    (%r12,%r12,2),%eax
mov    %rax,0x8(%rsp)
movslq %eax,%r13
mov    $0x1,%esi
mov    %r13,%rdi
call   1060 <calloc@plt>
mov    %rax,%rbp
mov    %rax,0xc0(%rsp)
mov    $0x8,%esi
mov    %r13,%rdi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    %rax,0x40(%rsp)
mov    $0x1,%esi
mov    %r13,%rdi
call   1060 <calloc@plt>
mov    %rax,0x90(%rsp)
mov    %rax,0xc8(%rsp)
mov    $0x8,%esi
mov    %r13,%rdi
call   1060 <calloc@plt>
mov    %rax,0x88(%rsp)
mov    %rax,0x48(%rsp)
mov    $0x1,%esi
mov    %r13,%rdi
call   1060 <calloc@plt>
mov    %rax,0x80(%rsp)
mov    %rax,0xd0(%rsp)
mov    $0x8,%esi
mov    %r13,%rdi
call   1060 <calloc@plt>
mov    %rax,0x78(%rsp)
mov    %rax,0x50(%rsp)
mov    $0x1,%esi
mov    %r13,%rdi
call   1060 <calloc@plt>
mov    %rax,0x70(%rsp)
mov    %rax,0xd8(%rsp)
mov    $0x8,%esi
mov    %r13,%rdi
call   1060 <calloc@plt>
mov    %rax,0x68(%rsp)
mov    %rax,0x58(%rsp)
mov    $0x1,%esi
mov    %r13,%rdi
call   1060 <calloc@plt>
mov    %rax,0x28(%rsp)
mov    %rbp,%rdi
mov    %r14,0xa8(%rsp)
mov    %r14,%rsi
mov    %r13,0x10(%rsp)
mov    %r13,%rdx
call   1070 <memcpy@plt>
mov    %r12,0x30(%rsp)
test   %r12d,%r12d
jle    12bd <sharpen+0x16d>
mov    0x8(%rsp),%rax
add    $0x1,%eax
xor    %ecx,%ecx
nop
movzbl 0x0(%rbp,%rcx,1),%edx
movslq 0xe0(%rsp,%rdx,4),%rdx
mov    %rdx,(%rbx,%rcx,8)
add    $0x1,%rcx
add    $0xffffffff,%eax
cmp    $0x1,%eax
jg     12a0 <sharpen+0x150>
mov    %rbx,0x98(%rsp)
mov    %rbp,0x20(%rsp)
test   %r15d,%r15d
jle    14bb <sharpen+0x36b>
lea    -0x1(%r15),%eax
and    $0x3,%eax
mov    %rax,0xa0(%rsp)
mov    %r15d,%eax
mov    %rax,0x38(%rsp)
mov    0x8(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%ebx
xor    %r13d,%r13d
mov    $0x1,%ebp
jmp    1330 <sharpen+0x1e0>
mov    0x18(%rsp),%rdi
mov    0x20(%rsp),%rsi
mov    0x10(%rsp),%rdx
cs nopw 0x0(%rax,%rax,1)
nop
call   1070 <memcpy@plt>
cmp    0x38(%rsp),%r13
je     14bb <sharpen+0x36b>
mov    %r13,%r15
add    $0x1,%r13
cmp    0x38(%rsp),%r13
jae    1480 <sharpen+0x330>
xor    %r12d,%r12d
mov    %rbx,0xb8(%rsp)
cmp    $0x3,%ebx
setge  %r12b
neg    %r12d
mov    %rbp,0xb0(%rsp)
movslq %ebp,%rbx
mov    0xc0(%rsp,%rbx,8),%r14
mov    %r13,%rsi
mov    0x10(%rsp),%rdx
imul   %rdx,%rsi
add    0xa8(%rsp),%rsi
mov    %r14,%rdi
call   1070 <memcpy@plt>
cmpl   $0x0,0x30(%rsp)
jle    13bd <sharpen+0x26d>
mov    0x40(%rsp,%rbx,8),%rax
mov    0x8(%rsp),%rcx
xor    %edx,%edx
nopl   0x0(%rax)
movzbl (%r14,%rdx,1),%esi
movslq 0xe0(%rsp,%rsi,4),%rsi
mov    %rsi,(%rax,%rdx,8)
add    $0x1,%rdx
add    $0xffffffff,%ecx
cmp    $0x1,%ecx
jg     13a0 <sharpen+0x250>
mov    0xb8(%rsp),%rbx
add    %r12d,%ebx
add    $0x1,%ebx
mov    0xb0(%rsp),%rbp
add    $0x1,%ebp
and    $0x3,%ebp
cmp    $0x2,%ebx
je     148c <sharpen+0x33c>
cmp    $0x3,%ebx
jne    1325 <sharpen+0x1d5>
lea    0x2(%rbp),%eax
and    $0x3,%eax
mov    0xc0(%rsp,%rax,8),%rcx
lea    0x1(%rbp),%edx
and    $0x3,%edx
mov    0x40(%rsp,%rdx,8),%r9
add    $0x18,%r9
mov    %rbx,%r10
mov    0x40(%rsp,%rax,8),%r11
add    $0x18,%r11
lea    -0x1(%rbp),%eax
and    $0x3,%eax
mov    0x40(%rsp,%rax,8),%rbx
add    $0x18,%rbx
mov    0x30(%rsp),%rdi
lea    0x4e0(%rsp),%rsi
lea    0xe0(%rsp),%rdx
mov    %rbp,%r12
mov    0x28(%rsp),%r14
mov    %r14,%r8
xor    %eax,%eax
push   %rbx
mov    0x20(%rsp),%rbp
push   %r11
mov    %r10,%rbx
call   1030 <rgb_filter@plt>
add    $0x10,%rsp
mov    0x10(%rsp),%rdx
imul   %rdx,%r15
add    %rbp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rbp
jmp    1320 <sharpen+0x1d0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffff,%ebx
cmp    $0x2,%ebx
jne    13e2 <sharpen+0x292>
test   %r15,%r15
je     1306 <sharpen+0x1b6>
mov    0x10(%rsp),%rdx
imul   %rdx,%r15
add    0x18(%rsp),%r15
mov    0xa0(%rsp),%rax
mov    0xc0(%rsp,%rax,8),%rsi
mov    %r15,%rdi
jmp    1320 <sharpen+0x1d0>
mov    0x20(%rsp),%rdi
call   1040 <free@plt>
mov    0x98(%rsp),%rdi
call   1040 <free@plt>
mov    0x90(%rsp),%rdi
call   1040 <free@plt>
mov    0x88(%rsp),%rdi
call   1040 <free@plt>
mov    0x80(%rsp),%rdi
call   1040 <free@plt>
mov    0x78(%rsp),%rdi
call   1040 <free@plt>
mov    0x70(%rsp),%rdi
call   1040 <free@plt>
mov    0x68(%rsp),%rdi
call   1040 <free@plt>
mov    0x28(%rsp),%rdi
call   1040 <free@plt>
add    $0x8e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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