#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 */
unsigned char mMax(unsigned char *, unsigned char *, unsigned char *,
                   unsigned char *, unsigned char *);
int ProcessImage(unsigned char *pMatrix, unsigned char *pResultMatrix, int *pN,
                 int *pM) {
  int i;
  for (i = 0; i < *pN; i = i + 1) {
    *pResultMatrix = *pMatrix;
    pMatrix++;
    pResultMatrix++;
    *pResultMatrix = *pMatrix;
    pMatrix++;
    pResultMatrix++;
    int j;
    for (j = 2; j < *pM - 2; j = j + 1) {
      *pResultMatrix = mMax(pMatrix - 0x2, pMatrix - 0x1, pMatrix,
                            pMatrix + 0x1, pMatrix + 0x2);
      pMatrix++;
      pResultMatrix++;
    }
    *pResultMatrix = *pMatrix;
    pMatrix++;
    pResultMatrix++;
    *pResultMatrix = *pMatrix;
    pMatrix++;
    pResultMatrix++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<ProcessImage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    124e <ProcessImage+0x13e>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movl   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    11f8 <ProcessImage+0xe8>
mov    -0x8(%rbp),%rdi
add    $0xfffffffffffffffe,%rdi
mov    -0x8(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
mov    -0x8(%rbp),%rdx
mov    -0x8(%rbp),%rcx
add    $0x1,%rcx
mov    -0x8(%rbp),%r8
add    $0x2,%r8
call   1030 <mMax@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    118d <ProcessImage+0x7d>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112f <ProcessImage+0x1f>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ProcessImage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmpl   $0x0,(%rdx)
jle    11cd <ProcessImage+0xbd>
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
xor    %r13d,%r13d
jmp    1163 <ProcessImage+0x53>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x2,%rbx
mov    (%rbx),%al
mov    %al,(%r12)
mov    0x1(%rbx),%al
mov    %al,0x1(%r12)
add    $0x2,%rbx
add    $0x2,%r12
add    $0x1,%r13d
cmp    (%r14),%r13d
jge    11cd <ProcessImage+0xbd>
mov    (%rbx),%al
mov    %al,(%r12)
mov    0x1(%rbx),%al
mov    %al,0x1(%r12)
add    $0x2,%r12
cmpl   $0x5,(%r15)
jl     1140 <ProcessImage+0x30>
xor    %ebp,%ebp
nopl   (%rax)
lea    (%rbx,%rbp,1),%rdi
lea    (%rbx,%rbp,1),%rdx
add    $0x2,%rdx
lea    (%rbx,%rbp,1),%rsi
add    $0x1,%rsi
lea    (%rbx,%rbp,1),%rcx
add    $0x3,%rcx
lea    (%rbx,%rbp,1),%r8
add    $0x4,%r8
call   1030 <mMax@plt>
mov    %al,(%r12,%rbp,1)
mov    (%r15),%eax
add    $0xfffffffe,%eax
add    $0x1,%rbp
lea    0x2(%rbp),%ecx
cmp    %eax,%ecx
jl     1180 <ProcessImage+0x70>
add    %rbp,%rbx
add    $0x2,%rbx
add    %rbp,%r12
jmp    1144 <ProcessImage+0x34>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ProcessImage(i8* %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 0, i32* %9
br label %11
11: ; preds = %71, %4
%12 = load i32, i32* %9
%13 = load i32*, i32** %7
%14 = load i32, i32* %13
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %74
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = load i8*, i8** %6
store i8 %18, i8* %19
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %6
%24 = load i8*, i8** %5
%25 = load i8, i8* %24
%26 = load i8*, i8** %6
store i8 %25, i8* %26
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %6
store i32 2, i32* %10
br label %31
31: ; preds = %53, %16
%32 = load i32, i32* %10
%33 = load i32*, i32** %8
%34 = load i32, i32* %33
%35 = sub nsw i32 %34, 2
%36 = icmp slt i32 %32, %35
br i1 %36, label %37, label %56
37: ; preds = %31
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 -2
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i64 -1
%42 = load i8*, i8** %5
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i64 2
%47 = call zeroext i8 @mMax(i8* %39, i8* %41, i8* %42, i8* %44, i8* %46)
%48 = load i8*, i8** %6
store i8 %47, i8* %48
%49 = load i8*, i8** %5
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %5
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %6
br label %53
53: ; preds = %37
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %31
56: ; preds = %31
%57 = load i8*, i8** %5
%58 = load i8, i8* %57
%59 = load i8*, i8** %6
store i8 %58, i8* %59
%60 = load i8*, i8** %5
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %5
%62 = load i8*, i8** %6
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %6
%64 = load i8*, i8** %5
%65 = load i8, i8* %64
%66 = load i8*, i8** %6
store i8 %65, i8* %66
%67 = load i8*, i8** %5
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %5
%69 = load i8*, i8** %6
%70 = getelementptr inbounds i8, i8* %69, i32 1
store i8* %70, i8** %6
br label %71
71: ; preds = %56
%72 = load i32, i32* %9
%73 = add nsw i32 %72, 1
store i32 %73, i32* %9
br label %11
74: ; preds = %11
ret i32 1
}

LLVM IR (-O2):
define i32 @ProcessImage(i8* %0, i8* nocapture writeonly %1, i32* nocapture %2, i32* nocapture %3) {
%5 = load i32, i32* %2
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %45
7: ; preds = %4, %33
%8 = phi i32 [ %42, %33 ], [ 0, %4 ]
%9 = phi i8* [ %40, %33 ], [ %0, %4 ]
%10 = phi i8* [ %41, %33 ], [ %1, %4 ]
%11 = load i8, i8* %9
store i8 %11, i8* %10
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = load i8, i8* %12
store i8 %14, i8* %13
%15 = getelementptr inbounds i8, i8* %9, i64 2
%16 = getelementptr inbounds i8, i8* %10, i64 2
%17 = load i32, i32* %3
%18 = icmp sgt i32 %17, 4
br i1 %18, label %19, label %33
19: ; preds = %7, %19
%20 = phi i32 [ %29, %19 ], [ 2, %7 ]
%21 = phi i8* [ %25, %19 ], [ %15, %7 ]
%22 = phi i8* [ %28, %19 ], [ %16, %7 ]
%23 = getelementptr inbounds i8, i8* %21, i64 -2
%24 = getelementptr inbounds i8, i8* %21, i64 -1
%25 = getelementptr inbounds i8, i8* %21, i64 1
%26 = getelementptr inbounds i8, i8* %21, i64 2
%27 = tail call zeroext i8 @mMax(i8* %23, i8* %24, i8* %21, i8* %25, i8* %26)
store i8 %27, i8* %22
%28 = getelementptr inbounds i8, i8* %22, i64 1
%29 = add nuw nsw i32 %20, 1
%30 = load i32, i32* %3
%31 = add nsw i32 %30, -2
%32 = icmp slt i32 %29, %31
br i1 %32, label %19, label %33
33: ; preds = %19, %7
%34 = phi i8* [ %16, %7 ], [ %28, %19 ]
%35 = phi i8* [ %15, %7 ], [ %25, %19 ]
%36 = load i8, i8* %35
store i8 %36, i8* %34
%37 = getelementptr inbounds i8, i8* %35, i64 1
%38 = getelementptr inbounds i8, i8* %34, i64 1
%39 = load i8, i8* %37
store i8 %39, i8* %38
%40 = getelementptr inbounds i8, i8* %35, i64 2
%41 = getelementptr inbounds i8, i8* %34, i64 2
%42 = add nuw nsw i32 %8, 1
%43 = load i32, i32* %2
%44 = icmp slt i32 %42, %43
br i1 %44, label %7, label %45
45: ; preds = %33, %4
ret i32 1
}