#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*/ get2DArrayFromConsole(int, int, int **);
int /*<<< orphan*/ get2DArrayFromFile(int, int, int **);
int /*<<< orphan*/ get2DRandomArray(int, int, int **);
int /*<<< orphan*/ print2DArray(int, int, int **);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ save2DArrayToFile(int, int, int **);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int a[3][3];
  int choice = -1;
  while (choice != 0) {
    printf("1. Get array from console\n");
    printf("2. Fill array randomly\n");
    printf("3. Save array to file\n");
    printf("4. Get array from file\n");
    printf("5. Print array\n");
    printf("0. Exit\n: ");
    scanf("%d", &choice);
    switch (choice) {
    case 1:
      get2DArrayFromConsole(3, 3, a);
      break;
    case 2:
      get2DRandomArray(3, 3, a);
      break;
    case 3:
      save2DArrayToFile(3, 3, a);
      break;
    case 4:
      get2DArrayFromFile(3, 3, a);
      break;
    case 5:
      print2DArray(3, 3, a);
      break;
    case 0:
      printf("The end.\n");
      break;
    default:
      printf("Wrong number, try again\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1298 <main+0x128>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x34(%rbp),%eax
mov    %rax,-0x40(%rbp)
sub    $0x5,%rax
ja     1287 <main+0x117>
mov    -0x40(%rbp),%rax
lea    0xdfc(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x30(%rbp),%rdx
mov    $0x3,%esi
mov    %esi,%edi
call   1090 <get2DArrayFromConsole@plt>
jmp    1293 <main+0x123>
lea    -0x30(%rbp),%rdx
mov    $0x3,%esi
mov    %esi,%edi
call   1060 <get2DRandomArray@plt>
jmp    1293 <main+0x123>
lea    -0x30(%rbp),%rdx
mov    $0x3,%esi
mov    %esi,%edi
call   1070 <save2DArrayToFile@plt>
jmp    1293 <main+0x123>
lea    -0x30(%rbp),%rdx
mov    $0x3,%esi
mov    %esi,%edi
call   1040 <get2DArrayFromFile@plt>
jmp    1293 <main+0x123>
lea    -0x30(%rbp),%rdx
mov    $0x3,%esi
mov    %esi,%edi
call   1050 <print2DArray@plt>
jmp    1293 <main+0x123>
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
jmp    1293 <main+0x123>
lea    0xe14(%rip),%rdi
call   1030 <printf@plt>
jmp    1186 <main+0x16>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xed0(%rip),%r13
lea    0xee0(%rip),%rbx
lea    0xe6d(%rip),%rbp
lea    0xe71(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xe42(%rip),%r12
jmp    11d7 <main+0x57>
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
je     12b7 <main+0x137>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x5,%rax
ja     11c0 <main+0x40>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
lea    0xe5b(%rip),%rdi
jmp    11c7 <main+0x47>
mov    $0x3,%edi
mov    $0x3,%esi
lea    0x10(%rsp),%rdx
call   10a0 <get2DArrayFromConsole@plt>
jmp    11cc <main+0x4c>
mov    $0x3,%edi
mov    $0x3,%esi
lea    0x10(%rsp),%rdx
call   1070 <get2DRandomArray@plt>
jmp    11cc <main+0x4c>
mov    $0x3,%edi
mov    $0x3,%esi
lea    0x10(%rsp),%rdx
call   1080 <save2DArrayToFile@plt>
jmp    11cc <main+0x4c>
mov    $0x3,%edi
mov    $0x3,%esi
lea    0x10(%rsp),%rdx
call   1050 <get2DArrayFromFile@plt>
jmp    11cc <main+0x4c>
mov    $0x3,%edi
mov    $0x3,%esi
lea    0x10(%rsp),%rdx
call   1060 <print2DArray@plt>
jmp    11cc <main+0x4c>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"1. Get array from console\0A\00"
@.str.1 = [24 x i8] c"2. Fill array randomly\0A\00"
@.str.2 = [23 x i8] c"3. Save array to file\0A\00"
@.str.3 = [24 x i8] c"4. Get array from file\0A\00"
@.str.4 = [16 x i8] c"5. Print array\0A\00"
@.str.5 = [11 x i8] c"0. Exit\0A: \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [10 x i8] c"The end.\0A\00"
@.str.8 = [25 x i8] c"Wrong number, try again\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x [3 x i32]]
%3 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %3
br label %4
4: ; preds = %40, %0
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %41
7: ; preds = %4
%8 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%15 = load i32, i32* %3
switch i32 %15, label %38 [
i32 1, label %16
i32 2, label %20
i32 3, label %24
i32 4, label %28
i32 5, label %32
i32 0, label %36
]
16: ; preds = %7
%17 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 0
%18 = bitcast [3 x i32]* %17 to i32**
%19 = call i32 @get2DArrayFromConsole(i32 3, i32 3, i32** %18)
br label %40
20: ; preds = %7
%21 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 0
%22 = bitcast [3 x i32]* %21 to i32**
%23 = call i32 @get2DRandomArray(i32 3, i32 3, i32** %22)
br label %40
24: ; preds = %7
%25 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 0
%26 = bitcast [3 x i32]* %25 to i32**
%27 = call i32 @save2DArrayToFile(i32 3, i32 3, i32** %26)
br label %40
28: ; preds = %7
%29 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 0
%30 = bitcast [3 x i32]* %29 to i32**
%31 = call i32 @get2DArrayFromFile(i32 3, i32 3, i32** %30)
br label %40
32: ; preds = %7
%33 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 0
%34 = bitcast [3 x i32]* %33 to i32**
%35 = call i32 @print2DArray(i32 3, i32 3, i32** %34)
br label %40
36: ; preds = %7
%37 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %40
38: ; preds = %7
%39 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
br label %40
40: ; preds = %38, %36, %32, %28, %24, %20, %16
br label %4
41: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
@.str.5 = [11 x i8] c"0. Exit\0A: \00"
@.str.6 = [3 x i8] c"%d\00"
@str = [26 x i8] c"1. Get array from console\00"
@str.9 = [23 x i8] c"2. Fill array randomly\00"
@str.10 = [22 x i8] c"3. Save array to file\00"
@str.11 = [23 x i8] c"4. Get array from file\00"
@str.12 = [15 x i8] c"5. Print array\00"
@str.13 = [9 x i8] c"The end.\00"
@str.14 = [24 x i8] c"Wrong number, try again\00"
define i32 @main() {
%1 = alloca [3 x [3 x i32]]
%2 = alloca i32
%3 = bitcast [3 x [3 x i32]]* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
%5 = bitcast [3 x [3 x i32]]* %1 to i32**
br label %6
6: ; preds = %0, %29
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.9, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.11, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0))
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%14 = load i32, i32* %2
switch i32 %14, label %27 [
i32 1, label %15
i32 2, label %17
i32 3, label %19
i32 4, label %21
i32 5, label %23
i32 0, label %25
]
15: ; preds = %6
%16 = call i32 @get2DArrayFromConsole(i32 3, i32 3, i32** %5)
br label %29
17: ; preds = %6
%18 = call i32 @get2DRandomArray(i32 3, i32 3, i32** %5)
br label %29
19: ; preds = %6
%20 = call i32 @save2DArrayToFile(i32 3, i32 3, i32** %5)
br label %29
21: ; preds = %6
%22 = call i32 @get2DArrayFromFile(i32 3, i32 3, i32** %5)
br label %29
23: ; preds = %6
%24 = call i32 @print2DArray(i32 3, i32 3, i32** %5)
br label %29
25: ; preds = %6
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.13, i64 0, i64 0))
br label %29
27: ; preds = %6
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.14, i64 0, i64 0))
br label %29
29: ; preds = %27, %25, %23, %21, %19, %17, %15
%30 = load i32, i32* %2
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %6
32: ; preds = %29
ret i32 0
}