#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 */
void *calloc(int, int);
int /*<<< orphan*/ printf(char *, int);
int *spiralOrder(int **, int, int);
int main(int argc, char const *argv[]) {
  int **matrix;
  matrix = calloc(50, sizeof(int *));
  for (int i = 0; i < 50; ++i) {
    matrix[i] = calloc(20, sizeof(int));
    for (int j = 0; j < 20; ++j)
      matrix[i][j] = j;
  }
  int *result = spiralOrder(matrix, 50, 20);
  for (int i = 0; i < 50 * 20; ++i)
    printf("%d ", result[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x32,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x32,-0x1c(%rbp)
jge    11d0 <main+0xa0>
mov    $0x14,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x20(%rbp)
cmpl   $0x14,-0x20(%rbp)
jge    11bd <main+0x8d>
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118f <main+0x5f>
jmp    11c2 <main+0x92>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1160 <main+0x30>
mov    -0x18(%rbp),%rdi
mov    $0x32,%esi
mov    $0x14,%edx
call   1040 <spiralOrder@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3e8,-0x2c(%rbp)
jge    1220 <main+0xf0>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ee <main+0xbe>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x32,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    $0x14,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,(%r14,%rbx,8)
movaps 0xe96(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe9c(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xea1(%rip),%xmm0
movups %xmm0,0x20(%rax)
movaps 0xea6(%rip),%xmm0
movups %xmm0,0x30(%rax)
movaps 0xeab(%rip),%xmm0
movups %xmm0,0x40(%rax)
add    $0x1,%rbx
cmp    $0x32,%rbx
jne    1150 <main+0x20>
mov    %r14,%rdi
mov    $0x32,%esi
mov    $0x14,%edx
call   1040 <spiralOrder@plt>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xe8f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    11d0 <main+0xa0>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i8* @calloc(i32 50, i32 8)
%12 = bitcast i8* %11 to i32**
store i32** %12, i32*** %6
store i32 0, i32* %7
br label %13
13: ; preds = %40, %2
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 50
br i1 %15, label %16, label %43
16: ; preds = %13
%17 = call i8* @calloc(i32 20, i32 4)
%18 = bitcast i8* %17 to i32*
%19 = load i32**, i32*** %6
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32*, i32** %19, i64 %21
store i32* %18, i32** %22
store i32 0, i32* %8
br label %23
23: ; preds = %36, %16
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 20
br i1 %25, label %26, label %39
26: ; preds = %23
%27 = load i32, i32* %8
%28 = load i32**, i32*** %6
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32*, i32** %28, i64 %30
%32 = load i32*, i32** %31
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 %27, i32* %35
br label %36
36: ; preds = %26
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %23
39: ; preds = %23
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %13
43: ; preds = %13
%44 = load i32**, i32*** %6
%45 = call i32* @spiralOrder(i32** %44, i32 50, i32 20)
store i32* %45, i32** %9
store i32 0, i32* %10
br label %46
46: ; preds = %56, %43
%47 = load i32, i32* %10
%48 = icmp slt i32 %47, 1000
br i1 %48, label %49, label %59
49: ; preds = %46
%50 = load i32*, i32** %9
%51 = load i32, i32* %10
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
%54 = load i32, i32* %53
%55 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %49
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 1
store i32 %58, i32* %10
br label %46
59: ; preds = %46
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(400) i8* @calloc(i32 50, i32 8)
%4 = bitcast i8* %3 to i32**
br label %7
5: ; preds = %7
%6 = tail call i32* @spiralOrder(i32** %4, i32 50, i32 20)
br label %25
7: ; preds = %2, %7
%8 = phi i64 [ 0, %2 ], [ %22, %7 ]
%9 = tail call dereferenceable_or_null(80) i8* @calloc(i32 20, i32 4)
%10 = getelementptr inbounds i32*, i32** %4, i64 %8
%11 = bitcast i32** %10 to i8**
store i8* %9, i8** %11
%12 = bitcast i8* %9 to i32*
%13 = bitcast i8* %9 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %13
%14 = getelementptr inbounds i32, i32* %12, i64 4
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %15
%16 = getelementptr inbounds i32, i32* %12, i64 8
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 8, i32 9, i32 10, i32 11>, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %12, i64 12
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> <i32 12, i32 13, i32 14, i32 15>, <4 x i32>* %19
%20 = getelementptr inbounds i32, i32* %12, i64 16
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> <i32 16, i32 17, i32 18, i32 19>, <4 x i32>* %21
%22 = add nuw nsw i64 %8, 1
%23 = icmp eq i64 %22, 50
br i1 %23, label %5, label %7
24: ; preds = %25
ret i32 0
25: ; preds = %5, %25
%26 = phi i64 [ 0, %5 ], [ %30, %25 ]
%27 = getelementptr inbounds i32, i32* %6, i64 %26
%28 = load i32, i32* %27
%29 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = add nuw nsw i64 %26, 1
%31 = icmp eq i64 %30, 1000
br i1 %31, label %24, label %25
}