#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ convolve_id(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *get_matrix_at(int /*<<< orphan*/ *, int, int, int, int,
                                  int);
int /*<<< orphan*/ *malloc(int);
uint8_t *convolve_image_id(uint8_t *data, int height, int width, int size) {
  uint8_t *processed = malloc(width * height);
  int index = 0;
  for (int i = 0; i < height; ++i) {
    for (int j = 0; j < width; ++j) {
      uint8_t *chunk = get_matrix_at(data, i, j, height, width, size);
      processed[index] = convolve_id(chunk, size);
      index++;
      free(chunk);
    }
  }
  return processed;
}


x86 assembly (clang, -O0):
<convolve_image_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%edi
imul   -0xc(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fc <convolve_image_id+0xbc>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e9 <convolve_image_id+0xa9>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0x14(%rbp),%r9d
call   1060 <get_matrix_at@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <convolve_id@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1186 <convolve_image_id+0x46>
jmp    11ee <convolve_image_id+0xae>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1173 <convolve_image_id+0x33>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convolve_image_id>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
mov    %edx,0x4(%rsp)
mov    %edx,%edi
imul   %esi,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %ebp,%ebp
jle    1214 <convolve_image_id+0xd4>
mov    0x4(%rsp),%r13d
xor    %eax,%eax
xor    %ebx,%ebx
mov    %r14d,0xc(%rsp)
mov    %ebp,0x8(%rsp)
mov    0xc(%rsp),%r12d
jmp    1197 <convolve_image_id+0x57>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebp,%ebx
je     1214 <convolve_image_id+0xd4>
cmpl   $0x0,0x4(%rsp)
jle    1190 <convolve_image_id+0x50>
mov    %rax,0x18(%rsp)
cltq
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,4),%rax
mov    %rax,0x20(%rsp)
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %r13d,%r8d
mov    %r12d,%r9d
call   1060 <get_matrix_at@plt>
mov    %r15,%rbp
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12d,%esi
call   1040 <convolve_id@plt>
mov    0x20(%rsp),%rcx
mov    %eax,(%rcx,%r14,4)
mov    %r15,%rdi
mov    %rbp,%r15
mov    0x8(%rsp),%ebp
call   1030 <free@plt>
add    $0x1,%r14
cmp    %r14d,%r13d
jne    11c0 <convolve_image_id+0x80>
mov    0x18(%rsp),%rax
add    %r14d,%eax
jmp    1190 <convolve_image_id+0x50>
mov    0x10(%rsp),%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @convolve_image_id(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = load i32, i32* %7
%15 = load i32, i32* %6
%16 = mul nsw i32 %14, %15
%17 = call i32* @malloc(i32 %16)
store i32* %17, i32** %9
store i32 0, i32* %10
store i32 0, i32* %11
br label %18
18: ; preds = %50, %4
%19 = load i32, i32* %11
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %53
22: ; preds = %18
store i32 0, i32* %12
br label %23
23: ; preds = %46, %22
%24 = load i32, i32* %12
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %49
27: ; preds = %23
%28 = load i32*, i32** %5
%29 = load i32, i32* %11
%30 = load i32, i32* %12
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = call i32* @get_matrix_at(i32* %28, i32 %29, i32 %30, i32 %31, i32 %32, i32 %33)
store i32* %34, i32** %13
%35 = load i32*, i32** %13
%36 = load i32, i32* %8
%37 = call i32 @convolve_id(i32* %35, i32 %36)
%38 = load i32*, i32** %9
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 %37, i32* %41
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
%44 = load i32*, i32** %13
%45 = call i32 @free(i32* %44)
br label %46
46: ; preds = %27
%47 = load i32, i32* %12
%48 = add nsw i32 %47, 1
store i32 %48, i32* %12
br label %23
49: ; preds = %23
br label %50
50: ; preds = %49
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %18
53: ; preds = %18
%54 = load i32*, i32** %9
ret i32* %54
}

LLVM IR (-O2):
define noalias i32* @convolve_image_id(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = mul nsw i32 %2, %1
%6 = tail call i32* @malloc(i32 %5)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %15
8: ; preds = %4
%9 = icmp sgt i32 %2, 0
br label %10
10: ; preds = %8, %18
%11 = phi i32 [ 0, %8 ], [ %19, %18 ]
%12 = phi i32 [ 0, %8 ], [ %20, %18 ]
br i1 %9, label %13, label %18
13: ; preds = %10
%14 = sext i32 %11 to i64
br label %22
15: ; preds = %18, %4
ret i32* %6
16: ; preds = %22
%17 = trunc i64 %28 to i32
br label %18
18: ; preds = %16, %10
%19 = phi i32 [ %11, %10 ], [ %17, %16 ]
%20 = add nuw nsw i32 %12, 1
%21 = icmp eq i32 %20, %1
br i1 %21, label %15, label %10
22: ; preds = %13, %22
%23 = phi i64 [ %14, %13 ], [ %28, %22 ]
%24 = phi i32 [ 0, %13 ], [ %30, %22 ]
%25 = tail call i32* @get_matrix_at(i32* %0, i32 %12, i32 %24, i32 %1, i32 %2, i32 %3)
%26 = tail call i32 @convolve_id(i32* %25, i32 %3)
%27 = getelementptr inbounds i32, i32* %6, i64 %23
store i32 %26, i32* %27
%28 = add nsw i64 %23, 1
%29 = tail call i32 @free(i32* %25)
%30 = add nuw nsw i32 %24, 1
%31 = icmp eq i32 %30, %2
br i1 %31, label %16, label %22
}