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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int *get_2d_matrix_in_spiral_form(int, int, int **);
scalar_t__ memcmp(int *, int *, int);
int main() {
  int matrix0[][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
  int expected0[] = {1, 2, 3, 6, 9, 8, 7, 4, 5};
  int *actual0 = get_2d_matrix_in_spiral_form(3, 3, matrix0);
  assert(0 == memcmp(expected0, actual0, sizeof(expected0)));
  int matrix1[][3] = {
      {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}, {13, 14, 15}};
  int expected1[] = {1, 2, 3, 6, 9, 12, 15, 14, 13, 10, 7, 4, 5, 8, 11};
  int *actual1 = get_2d_matrix_in_spiral_form(5, 3, matrix1);
  assert(0 == memcmp(expected1, actual1, sizeof(expected1)));
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
lea    -0x60(%rbp),%rdi
lea    0xebe(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
lea    -0x30(%rbp),%rdx
mov    $0x3,%esi
mov    %esi,%edi
call   1060 <get_2d_matrix_in_spiral_form@plt>
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    $0x24,%edx
call   1030 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0xb0(%rbp),%rdi
lea    0xe9b(%rip),%rsi
mov    $0x3c,%edx
call   1050 <memcpy@plt>
lea    -0xf0(%rbp),%rdi
lea    0xec3(%rip),%rsi
mov    $0x3c,%edx
call   1050 <memcpy@plt>
lea    -0xb0(%rbp),%rdx
mov    $0x5,%edi
mov    $0x3,%esi
call   1060 <get_2d_matrix_in_spiral_form@plt>
mov    %rax,-0xf8(%rbp)
lea    -0xf0(%rbp),%rdi
mov    -0xf8(%rbp),%rsi
mov    $0x3c,%edx
call   1030 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0xe8,%rsp
mov    0xee3(%rip),%eax
mov    %eax,0x50(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
mov    0xef1(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xed6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x30(%rsp),%rdx
mov    $0x3,%edi
mov    $0x3,%esi
call   1050 <get_2d_matrix_in_spiral_form@plt>
mov    %rsp,%rdi
mov    %rax,%rsi
mov    $0x24,%edx
call   1030 <memcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
movups 0xed9(%rip),%xmm0
movups %xmm0,0xcc(%rsp)
movaps 0xebe(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xe9f(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xe80(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movups 0xedd(%rip),%xmm0
movups %xmm0,0x8c(%rsp)
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xea3(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe87(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
lea    0xa0(%rsp),%rdx
mov    $0x5,%edi
mov    $0x3,%esi
call   1050 <get_2d_matrix_in_spiral_form@plt>
lea    0x60(%rsp),%rdi
mov    %rax,%rsi
mov    $0x3c,%edx
call   1030 <memcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
add    $0xe8,%rsp
ret

LLVM IR (-O0):
@__const.main.matrix0 = [3 x [3 x i32]] [[3 x i32] [i32 1, i32 2, i32 3], [3 x i32] [i32 4, i32 5, i32 6], [3 x i32] [i32 7, i32 8, i32 9]]
@__const.main.expected0 = [9 x i32] [i32 1, i32 2, i32 3, i32 6, i32 9, i32 8, i32 7, i32 4, i32 5]
@__const.main.matrix1 = [5 x [3 x i32]] [[3 x i32] [i32 1, i32 2, i32 3], [3 x i32] [i32 4, i32 5, i32 6], [3 x i32] [i32 7, i32 8, i32 9], [3 x i32] [i32 10, i32 11, i32 12], [3 x i32] [i32 13, i32 14, i32 15]]
@__const.main.expected1 = [15 x i32] [i32 1, i32 2, i32 3, i32 6, i32 9, i32 12, i32 15, i32 14, i32 13, i32 10, i32 7, i32 4, i32 5, i32 8, i32 11]
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x [3 x i32]]
%3 = alloca [9 x i32]
%4 = alloca i32*
%5 = alloca [5 x [3 x i32]]
%6 = alloca [15 x i32]
%7 = alloca i32*
store i32 0, i32* %1
%8 = bitcast [3 x [3 x i32]]* %2 to i8*
%9 = bitcast [9 x i32]* %3 to i8*
%10 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 0
%11 = bitcast [3 x i32]* %10 to i32**
%12 = call i32* @get_2d_matrix_in_spiral_form(i32 3, i32 3, i32** %11)
store i32* %12, i32** %4
%13 = getelementptr inbounds [9 x i32], [9 x i32]* %3, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = call i64 @memcmp(i32* %13, i32* %14, i32 36)
%16 = icmp eq i64 0, %15
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = bitcast [5 x [3 x i32]]* %5 to i8*
%20 = bitcast [15 x i32]* %6 to i8*
%21 = getelementptr inbounds [5 x [3 x i32]], [5 x [3 x i32]]* %5, i64 0, i64 0
%22 = bitcast [3 x i32]* %21 to i32**
%23 = call i32* @get_2d_matrix_in_spiral_form(i32 5, i32 3, i32** %22)
store i32* %23, i32** %7
%24 = getelementptr inbounds [15 x i32], [15 x i32]* %6, i64 0, i64 0
%25 = load i32*, i32** %7
%26 = call i64 @memcmp(i32* %24, i32* %25, i32 60)
%27 = icmp eq i64 0, %26
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
ret i32 0
}

LLVM IR (-O2):
@__const.main.matrix0 = [3 x [3 x i32]] [[3 x i32] [i32 1, i32 2, i32 3], [3 x i32] [i32 4, i32 5, i32 6], [3 x i32] [i32 7, i32 8, i32 9]]
@__const.main.expected0 = [9 x i32] [i32 1, i32 2, i32 3, i32 6, i32 9, i32 8, i32 7, i32 4, i32 5]
@__const.main.matrix1 = [5 x [3 x i32]] [[3 x i32] [i32 1, i32 2, i32 3], [3 x i32] [i32 4, i32 5, i32 6], [3 x i32] [i32 7, i32 8, i32 9], [3 x i32] [i32 10, i32 11, i32 12], [3 x i32] [i32 13, i32 14, i32 15]]
@__const.main.expected1 = [15 x i32] [i32 1, i32 2, i32 3, i32 6, i32 9, i32 12, i32 15, i32 14, i32 13, i32 10, i32 7, i32 4, i32 5, i32 8, i32 11]
define i32 @main() {
%1 = alloca [3 x [3 x i32]]
%2 = alloca [9 x i32]
%3 = alloca [5 x [3 x i32]]
%4 = alloca [15 x i32]
%5 = bitcast [3 x [3 x i32]]* %1 to i8*
%6 = bitcast [9 x i32]* %2 to i8*
%7 = bitcast [3 x [3 x i32]]* %1 to i32**
%8 = call i32* @get_2d_matrix_in_spiral_form(i32 3, i32 3, i32** %7)
%9 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%10 = call i64 @memcmp(i32* %9, i32* %8, i32 36)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = bitcast [5 x [3 x i32]]* %3 to i8*
%15 = bitcast [15 x i32]* %4 to i8*
%16 = bitcast [5 x [3 x i32]]* %3 to i32**
%17 = call i32* @get_2d_matrix_in_spiral_form(i32 5, i32 3, i32** %16)
%18 = getelementptr inbounds [15 x i32], [15 x i32]* %4, i64 0, i64 0
%19 = call i64 @memcmp(i32* %18, i32* %17, i32 60)
%20 = icmp eq i64 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
ret i32 0
}