#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 */
int /*<<< orphan*/ loop(int **, int /*<<< orphan*/, int /*<<< orphan*/, int,
                        int, int /*<<< orphan*/, int *, int *);
scalar_t__ malloc(int);
int *spiralOrder(int **matrix, int matrixRowSize, int matrixColSize) {
  int *res = (int *)malloc((matrixRowSize * matrixColSize) * sizeof(int));
  if (matrixRowSize == 0)
    return res;
  int rSize = 0;
  loop(matrix, 0, 0, matrixRowSize, matrixColSize, 0, res, &rSize);
  return res;
}


x86 assembly (clang, -O0):
<spiralOrder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1161 <spiralOrder+0x41>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119a <spiralOrder+0x7a>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x20(%rbp),%r10
xor    %r9d,%r9d
lea    -0x24(%rbp),%rax
mov    %r9d,%esi
mov    %r9d,%edx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <loop@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spiralOrder>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
mov    %esi,%edi
imul   %edx,%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %ebp,%ebp
je     116a <spiralOrder+0x4a>
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rax
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
xor    %r9d,%r9d
push   %rax
push   %rbx
call   1030 <loop@plt>
add    $0x10,%rsp
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32* @spiralOrder(i32** %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = shl i32 %1, 2
%6 = mul i32 %5, %2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = icmp eq i32 %1, 0
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%12 = call i32 @loop(i32** %0, i32 0, i32 0, i32 %1, i32 %2, i32 0, i32* %8, i32* %4)
br label %13
13: ; preds = %3, %10
ret i32* %8
}