#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ find_result_array(int *, int, int, int /*<<< orphan*/,
                                     int /*<<< orphan*/, int **, int);
int *spiral(int rows, int columns, int **input_array) {
  int *result_array = NULL;
  if (rows * columns) {
    result_array = (int *)calloc(rows * columns, sizeof(int));
    find_result_array(result_array, rows, columns, 0, 0, input_array,
                      rows * columns - 1);
    return result_array;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<spiral>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
cmp    $0x0,%eax
je     1192 <spiral+0x72>
mov    -0xc(%rbp),%edi
imul   -0x10(%rbp),%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%r9
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
sub    $0x1,%eax
xor    %r8d,%r8d
mov    %r8d,%ecx
mov    %eax,(%rsp)
call   1040 <find_result_array@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119a <spiral+0x7a>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spiral>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
imul   %edi,%ebx
test   %ebx,%ebx
je     1169 <spiral+0x49>
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebp
mov    %ebx,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,%r12
add    $0xffffffff,%ebx
mov    %ebx,(%rsp)
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r14,%r9
call   1040 <find_result_array@plt>
jmp    116c <spiral+0x4c>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @spiral(i32 %0, i32 %1, i32** %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32**
%8 = alloca i32*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32** %2, i32*** %7
store i32* null, i32** %8
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = mul nsw i32 %9, %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %3
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = mul nsw i32 %14, %15
%17 = call i64 @calloc(i32 %16, i32 4)
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %8
%19 = load i32*, i32** %8
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = load i32**, i32*** %7
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = mul nsw i32 %23, %24
%26 = sub nsw i32 %25, 1
%27 = call i32 @find_result_array(i32* %19, i32 %20, i32 %21, i32 0, i32 0, i32** %22, i32 %26)
%28 = load i32*, i32** %8
store i32* %28, i32** %4
br label %30
29: ; preds = %3
store i32* null, i32** %4
br label %30
30: ; preds = %29, %13
%31 = load i32*, i32** %4
ret i32* %31
}

LLVM IR (-O2):
define i32* @spiral(i32 %0, i32 %1, i32** %2) {
%4 = mul nsw i32 %1, %0
%5 = icmp eq i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i64 @calloc(i32 %4, i32 4)
%8 = inttoptr i64 %7 to i32*
%9 = add nsw i32 %4, -1
%10 = tail call i32 @find_result_array(i32* %8, i32 %0, i32 %1, i32 0, i32 0, i32** %2, i32 %9)
br label %11
11: ; preds = %3, %6
%12 = phi i32* [ %8, %6 ], [ null, %3 ]
ret i32* %12
}