#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*/ getMatrix(int **, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, i, j, a[101][101] = {0};
  printf("Please input order of the snake matrix:");
  scanf("%d", &n);
  for (i = 0; i <= n; i++)
    a[i][n] = a[n][i] = -1;
  getMatrix(a, n);
  printf("The snake matrix is:\n");
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++)
      printf("%d ", a[j][i]);
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9f80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x9f80(%rbp),%rdi
xor    %esi,%esi
mov    $0x9f64,%edx
call   1040 <memset@plt>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11e4 <main+0xa4>
movslq -0x8(%rbp),%rcx
lea    -0x9f80(%rbp),%rax
imul   $0x194,%rcx,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
movslq -0xc(%rbp),%rcx
lea    -0x9f80(%rbp),%rax
imul   $0x194,%rcx,%rcx
add    %rcx,%rax
movslq -0x8(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118a <main+0x4a>
lea    -0x9f80(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <getMatrix@plt>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127b <main+0x13b>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    125f <main+0x11f>
movslq -0x10(%rbp),%rcx
lea    -0x9f80(%rbp),%rax
imul   $0x194,%rcx,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    121b <main+0xdb>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1208 <main+0xc8>
xor    %eax,%eax
add    $0x9f80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x9f80,%rsp
lea    0x10(%rsp),%rdi
mov    $0x9f64,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe92(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
js     123d <main+0xdd>
lea    0x1(%rsi),%rax
test   %rsi,%rsi
je     12d8 <main+0x178>
mov    %eax,%edx
and    $0xfffffffe,%edx
imul   $0x194,%rsi,%rcx
lea    (%rsp,%rcx,1),%rdi
add    $0x14,%rdi
lea    (%rsp,%rsi,4),%rbx
add    $0x10,%rbx
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movl   $0xffffffff,-0x4(%rdi,%rcx,4)
ff
movl   $0xffffffff,(%rbx)
movl   $0xffffffff,(%rdi,%rcx,4)
movl   $0xffffffff,0x194(%rbx)
ff ff ff
add    $0x2,%rcx
add    $0x328,%rbx
cmp    %rcx,%rdx
jne    11e0 <main+0x80>
test   $0x1,%al
je     123d <main+0xdd>
imul   $0x194,%rsi,%rax
add    %rsp,%rax
add    $0x10,%rax
movl   $0xffffffff,(%rax,%rcx,4)
imul   $0x194,%rcx,%rax
add    %rsp,%rax
add    $0x10,%rax
movl   $0xffffffff,(%rax,%rsi,4)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1080 <getMatrix@plt>
lea    0xdde(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    12c5 <main+0x165>
lea    0xdc6(%rip),%r12
xor    %r15d,%r15d
jmp    128c <main+0x12c>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r15
movslq 0xc(%rsp),%rax
add    $0x4,%r14
cmp    %rax,%r15
jge    12c5 <main+0x165>
test   %eax,%eax
jle    1270 <main+0x110>
mov    %r14,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x194,%r13
cmp    %rax,%rbx
jl     12a0 <main+0x140>
jmp    1270 <main+0x110>
xor    %eax,%eax
add    $0x9f80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %ecx,%ecx
test   $0x1,%al
jne    1213 <main+0xb3>
jmp    123d <main+0xdd>

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

LLVM IR (-O2):
@.str = [40 x i8] c"Please input order of the snake matrix:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d \00"
@str = [21 x i8] c"The snake matrix is:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [101 x [101 x i32]]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [101 x [101 x i32]]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 0
br i1 %8, label %34, label %9
9: ; preds = %0
%10 = zext i32 %7 to i64
%11 = add nuw i32 %7, 1
%12 = zext i32 %11 to i64
%13 = and i64 %12, 1
%14 = icmp eq i32 %7, 0
br i1 %14, label %28, label %15
15: ; preds = %9
%16 = and i64 %12, 4294967294
br label %17
17: ; preds = %17, %15
%18 = phi i64 [ 0, %15 ], [ %25, %17 ]
%19 = phi i64 [ 0, %15 ], [ %26, %17 ]
%20 = getelementptr inbounds [101 x [101 x i32]], [101 x [101 x i32]]* %2, i64 0, i64 %10, i64 %18
store i32 -1, i32* %20
%21 = getelementptr inbounds [101 x [101 x i32]], [101 x [101 x i32]]* %2, i64 0, i64 %18, i64 %10
store i32 -1, i32* %21
%22 = or i64 %18, 1
%23 = getelementptr inbounds [101 x [101 x i32]], [101 x [101 x i32]]* %2, i64 0, i64 %10, i64 %22
store i32 -1, i32* %23
%24 = getelementptr inbounds [101 x [101 x i32]], [101 x [101 x i32]]* %2, i64 0, i64 %22, i64 %10
store i32 -1, i32* %24
%25 = add nuw nsw i64 %18, 2
%26 = add i64 %19, 2
%27 = icmp eq i64 %26, %16
br i1 %27, label %28, label %17
28: ; preds = %17, %9
%29 = phi i64 [ 0, %9 ], [ %25, %17 ]
%30 = icmp eq i64 %13, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = getelementptr inbounds [101 x [101 x i32]], [101 x [101 x i32]]* %2, i64 0, i64 %10, i64 %29
store i32 -1, i32* %32
%33 = getelementptr inbounds [101 x [101 x i32]], [101 x [101 x i32]]* %2, i64 0, i64 %29, i64 %10
store i32 -1, i32* %33
br label %34
34: ; preds = %31, %28, %0
%35 = bitcast [101 x [101 x i32]]* %2 to i32**
%36 = call i32 @getMatrix(i32** %35, i32 %7)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%38 = load i32, i32* %1
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %59
40: ; preds = %34, %53
%41 = phi i32 [ %56, %53 ], [ %38, %34 ]
%42 = phi i64 [ %55, %53 ], [ 0, %34 ]
%43 = icmp sgt i32 %41, 0
br i1 %43, label %44, label %53
44: ; preds = %40, %44
%45 = phi i64 [ %49, %44 ], [ 0, %40 ]
%46 = getelementptr inbounds [101 x [101 x i32]], [101 x [101 x i32]]* %2, i64 0, i64 %45, i64 %42
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %47)
%49 = add nuw nsw i64 %45, 1
%50 = load i32, i32* %1
%51 = sext i32 %50 to i64
%52 = icmp slt i64 %49, %51
br i1 %52, label %44, label %53
53: ; preds = %44, %40
%54 = call i32 @putchar(i32 10)
%55 = add nuw nsw i64 %42, 1
%56 = load i32, i32* %1
%57 = sext i32 %56 to i64
%58 = icmp slt i64 %55, %57
br i1 %58, label %40, label %59
59: ; preds = %53, %34
ret i32 0
}