#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*/ corner_row_left(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int, int, int, int *);
int /*<<< orphan*/ *malloc(int);
uint8_t *corner_matrix_tl(uint8_t *data, int y, int x, int width, int size) {
  int median = size / 2;
  int index = 0;
  int yl = y * width;
  int yh = (y + median) * width;
  int xh = x + median;
  uint8_t *matrix = malloc(size * size);
  if (!matrix) {
    return NULL;
  }
  while (index < median * size) {
    corner_row_left(data, matrix, yl + x, yl + xh, median, &index);
  }
  for (int row = yl; row <= yh; row += width) {
    corner_row_left(data, matrix, row + x, row + xh, median, &index);
  }
  return matrix;
}


x86 assembly (clang, -O0):
<corner_matrix_tl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
add    -0x24(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%edi
imul   -0x20(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1196 <corner_matrix_tl+0x76>
movq   $0x0,-0x8(%rbp)
jmp    121c <corner_matrix_tl+0xfc>
jmp    119b <corner_matrix_tl+0x7b>
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
imul   -0x20(%rbp),%ecx
cmp    %ecx,%eax
jge    11d3 <corner_matrix_tl+0xb3>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x2c(%rbp),%edx
add    -0x18(%rbp),%edx
mov    -0x2c(%rbp),%ecx
add    -0x34(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    -0x28(%rbp),%r9
call   1030 <corner_row_left@plt>
jmp    119b <corner_matrix_tl+0x7b>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x30(%rbp),%eax
jg     1214 <corner_matrix_tl+0xf4>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
add    -0x18(%rbp),%edx
mov    -0x44(%rbp),%ecx
add    -0x34(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    -0x28(%rbp),%r9
call   1030 <corner_row_left@plt>
mov    -0x1c(%rbp),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    11d9 <corner_matrix_tl+0xb9>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<corner_matrix_tl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r13
movl   $0x0,0x8(%rsp)
mov    %r8d,%edi
imul   %r8d,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
je     123c <corner_matrix_tl+0x11c>
mov    %ebx,%ecx
mov    %r14d,%ebx
shr    $0x1f,%ebx
add    %r14d,%ebx
sar    %ebx
mov    %r14d,%edx
mov    %r15d,%r14d
imul   %ecx,%r14d
add    %ebx,%ecx
mov    %r15d,0x18(%rsp)
imul   %r15d,%ecx
mov    %ecx,0xc(%rsp)
mov    %r12,0x10(%rsp)
lea    (%rbx,%r12,1),%eax
mov    %rax,0x20(%rsp)
imul   %ebx,%edx
test   %edx,%edx
jle    11da <corner_matrix_tl+0xba>
mov    0x10(%rsp),%rax
add    %r14d,%eax
mov    %eax,0x1c(%rsp)
mov    0x20(%rsp),%rax
lea    (%rax,%r14,1),%r12d
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbp,%r15
mov    %edx,%ebp
mov    0x1c(%rsp),%edx
mov    %r12d,%ecx
mov    %ebx,%r8d
lea    0x8(%rsp),%r9
call   1030 <corner_row_left@plt>
mov    %ebp,%edx
mov    %r15,%rbp
cmp    %edx,0x8(%rsp)
jl     11b0 <corner_matrix_tl+0x90>
cmp    0xc(%rsp),%r14d
mov    0x18(%rsp),%eax
mov    0x10(%rsp),%rcx
mov    0x20(%rsp),%rdi
jg     123c <corner_matrix_tl+0x11c>
mov    %r13,%rsi
mov    %rbx,%r13
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rcx,%r14,1),%edx
lea    (%rdi,%r14,1),%ecx
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %rbp,%rsi
mov    %r13d,%r8d
lea    0x8(%rsp),%r9
mov    %eax,%r15d
call   1030 <corner_row_left@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    0x10(%rsp),%rcx
mov    %r15d,%eax
add    %r15d,%r14d
cmp    0xc(%rsp),%r14d
jle    1200 <corner_matrix_tl+0xe0>
mov    %rbp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32* @corner_matrix_tl(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = sdiv i32 %4, 2
%8 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%9 = mul nsw i32 %3, %1
%10 = add nsw i32 %7, %1
%11 = mul nsw i32 %10, %3
%12 = add nsw i32 %7, %2
%13 = mul nsw i32 %4, %4
%14 = tail call i32* @malloc(i32 %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %35, label %16
16: ; preds = %5
%17 = mul nsw i32 %7, %4
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = add nsw i32 %9, %2
%21 = add nsw i32 %12, %9
br label %24
22: ; preds = %24, %16
%23 = icmp sgt i32 %9, %11
br i1 %23, label %35, label %28
24: ; preds = %19, %24
%25 = call i32 @corner_row_left(i32* %0, i32* %14, i32 %20, i32 %21, i32 %7, i32* %6)
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, %17
br i1 %27, label %24, label %22
28: ; preds = %22, %28
%29 = phi i32 [ %33, %28 ], [ %9, %22 ]
%30 = add nsw i32 %29, %2
%31 = add nsw i32 %29, %12
%32 = call i32 @corner_row_left(i32* %0, i32* %14, i32 %30, i32 %31, i32 %7, i32* %6)
%33 = add nsw i32 %29, %3
%34 = icmp sgt i32 %33, %11
br i1 %34, label %35, label %28
35: ; preds = %28, %22, %5
ret i32* %14
}