#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
double *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ printm(double *, int, int /*<<< orphan*/);
int reverse(double *, double *, int);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ scanm(double *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main() {
  int i, j, n, isbad, itype;
  double *mat;
  double *res;
  char filename[20];
  printf("Please enter type of input\n");
  printf("1: console\n");
  printf("2: file\n");
  scanf("%d", &itype);
  if (itype == 1) {
    printf("Please input size of matrix\n");
    scanf("%d", &n);
    mat = malloc(n * n * sizeof(double *));
    res = malloc(n * n * sizeof(double *));
    if (!(mat && res)) {
      printf("Error1\n");
      return 1;
    }
    printf("Please input matrix\n");
    scanm(mat, n, stdin);
  } else if (itype == 2) {
    n = 20;
    FILE *file;
    printf("Please input filename\n");
    scanf("%s", filename);
    file = fopen(filename, "r");
    if (!file) {
      printf("No such file\n");
      return 1;
    }
    fscanf(file, "%d", &n);
    mat = malloc(n * n * sizeof(double));
    res = malloc(n * n * sizeof(double));
    if (!(mat && res)) {
      printf("Error1\n");
      return 1;
    }
    scanm(mat, n, file);
  } else {
    printf("Wrong option\n");
    return 1;
  }
  isbad = reverse(mat, res, n);
  if (isbad) {
    printf("Bad Determinant\n");
    return 1;
  }
  printf("\n");
  printm(res, n, stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe77(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
cmpl   $0x1,-0x18(%rbp)
jne    1272 <main+0xf2>
lea    0xe5e(%rip),%rdi
call   1050 <printf@plt>
lea    0xe4f(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1233 <main+0xb3>
cmpq   $0x0,-0x28(%rbp)
jne    124b <main+0xcb>
lea    0xe17(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <main+0x259>
lea    0xe07(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    0x2d83(%rip),%rax
mov    (%rax),%rdx
call   10a0 <scanm@plt>
jmp    137c <main+0x1fc>
cmpl   $0x2,-0x18(%rbp)
jne    135f <main+0x1df>
movl   $0x14,-0x10(%rbp)
lea    0xde4(%rip),%rdi
call   1050 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    -0x40(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    12d8 <main+0x158>
lea    0xdc3(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <main+0x259>
mov    -0x48(%rbp),%rdi
lea    0xd4e(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1332 <main+0x1b2>
cmpq   $0x0,-0x28(%rbp)
jne    134a <main+0x1ca>
lea    0xd18(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <main+0x259>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x48(%rbp),%rdx
call   10a0 <scanm@plt>
jmp    1377 <main+0x1f7>
lea    0xd32(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <main+0x259>
jmp    137c <main+0x1fc>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1040 <reverse@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     13b1 <main+0x231>
lea    0xd06(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d9 <main+0x259>
lea    0xc9f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    0x2c0d(%rip),%rax
mov    (%rax),%edx
call   1030 <printm@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
lea    0xe65(%rip),%rdi
call   1060 <puts@plt>
lea    0xe74(%rip),%rdi
call   1060 <puts@plt>
lea    0xe73(%rip),%rdi
call   1060 <puts@plt>
lea    0xe39(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
je     1256 <main+0xc6>
cmp    $0x1,%eax
jne    1306 <main+0x176>
lea    0xe8a(%rip),%rdi
call   1060 <puts@plt>
lea    0xe08(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0x8(%rsp),%ebp
imul   %ebp,%ebp
shl    $0x3,%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1080 <malloc@plt>
test   %rbx,%rbx
je     130f <main+0x17f>
mov    %rax,%r14
test   %rax,%rax
je     130f <main+0x17f>
lea    0xe5e(%rip),%rdi
call   1060 <puts@plt>
mov    0x8(%rsp),%esi
mov    0x2d9d(%rip),%rax
mov    (%rax),%rdx
mov    %rbx,%rdi
jmp    12e5 <main+0x155>
movl   $0x14,0x8(%rsp)
lea    0xdde(%rip),%rdi
call   1060 <puts@plt>
lea    0xd92(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
lea    0xd7f(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1318 <main+0x188>
mov    %rax,%r15
lea    0xd5e(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1070 <fscanf@plt>
mov    0x8(%rsp),%r12d
mov    %r12d,%ebp
imul   %r12d,%ebp
shl    $0x3,%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1080 <malloc@plt>
test   %rbx,%rbx
je     130f <main+0x17f>
mov    %rax,%r14
test   %rax,%rax
je     130f <main+0x17f>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
call   10b0 <scanm@plt>
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <reverse@plt>
test   %eax,%eax
je     1336 <main+0x1a6>
lea    0xd62(%rip),%rdi
jmp    131f <main+0x18f>
lea    0xd29(%rip),%rdi
jmp    131f <main+0x18f>
lea    0xd7c(%rip),%rdi
jmp    131f <main+0x18f>
lea    0xd3a(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    0x8(%rsp),%esi
mov    0x2c8d(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   1030 <printm@plt>
xor    %eax,%eax
jmp    1329 <main+0x199>

LLVM IR (-O0):
@.str = [28 x i8] c"Please enter type of input\0A\00"
@.str.1 = [12 x i8] c"1: console\0A\00"
@.str.2 = [9 x i8] c"2: file\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [29 x i8] c"Please input size of matrix\0A\00"
@.str.5 = [8 x i8] c"Error1\0A\00"
@.str.6 = [21 x i8] c"Please input matrix\0A\00"
@stdin = global i32* null
@.str.7 = [23 x i8] c"Please input filename\0A\00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [2 x i8] c"r\00"
@.str.10 = [14 x i8] c"No such file\0A\00"
@.str.11 = [14 x i8] c"Wrong option\0A\00"
@.str.12 = [17 x i8] c"Bad Determinant\0A\00"
@.str.13 = [2 x i8] c"\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca [20 x i8]
%10 = alloca i32*
store i32 0, i32* %1
%11 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %47
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%20 = load i32, i32* %4
%21 = load i32, i32* %4
%22 = mul nsw i32 %20, %21
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 8
%25 = trunc i64 %24 to i32
%26 = call double* @malloc(i32 %25)
store double* %26, double** %7
%27 = load i32, i32* %4
%28 = load i32, i32* %4
%29 = mul nsw i32 %27, %28
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 8
%32 = trunc i64 %31 to i32
%33 = call double* @malloc(i32 %32)
store double* %33, double** %8
%34 = load double*, double** %7
%35 = icmp ne double* %34, null
br i1 %35, label %36, label %39
36: ; preds = %17
%37 = load double*, double** %8
%38 = icmp ne double* %37, null
br i1 %38, label %41, label %39
39: ; preds = %36, %17
%40 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %107
41: ; preds = %36
%42 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%43 = load double*, double** %7
%44 = load i32, i32* %4
%45 = load i32*, i32** @stdin
%46 = call i32 @scanm(double* %43, i32 %44, i32* %45)
br label %92
47: ; preds = %0
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, 2
br i1 %49, label %50, label %89
50: ; preds = %47
store i32 20, i32* %4
%51 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%53 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %52)
%54 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%55 = call i32* @fopen(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %55, i32** %10
%56 = load i32*, i32** %10
%57 = icmp ne i32* %56, null
br i1 %57, label %60, label %58
58: ; preds = %50
%59 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %1
br label %107
60: ; preds = %50
%61 = load i32*, i32** %10
%62 = call i32 @fscanf(i32* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%63 = load i32, i32* %4
%64 = load i32, i32* %4
%65 = mul nsw i32 %63, %64
%66 = sext i32 %65 to i64
%67 = mul i64 %66, 8
%68 = trunc i64 %67 to i32
%69 = call double* @malloc(i32 %68)
store double* %69, double** %7
%70 = load i32, i32* %4
%71 = load i32, i32* %4
%72 = mul nsw i32 %70, %71
%73 = sext i32 %72 to i64
%74 = mul i64 %73, 8
%75 = trunc i64 %74 to i32
%76 = call double* @malloc(i32 %75)
store double* %76, double** %8
%77 = load double*, double** %7
%78 = icmp ne double* %77, null
br i1 %78, label %79, label %82
79: ; preds = %60
%80 = load double*, double** %8
%81 = icmp ne double* %80, null
br i1 %81, label %84, label %82
82: ; preds = %79, %60
%83 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %107
84: ; preds = %79
%85 = load double*, double** %7
%86 = load i32, i32* %4
%87 = load i32*, i32** %10
%88 = call i32 @scanm(double* %85, i32 %86, i32* %87)
br label %91
89: ; preds = %47
%90 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %1
br label %107
91: ; preds = %84
br label %92
92: ; preds = %91, %41
%93 = load double*, double** %7
%94 = load double*, double** %8
%95 = load i32, i32* %4
%96 = call i32 @reverse(double* %93, double* %94, i32 %95)
store i32 %96, i32* %5
%97 = load i32, i32* %5
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %92
%100 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %1
br label %107
101: ; preds = %92
%102 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%103 = load double*, double** %8
%104 = load i32, i32* %4
%105 = load i32, i32* @stdout
%106 = call i32 @printm(double* %103, i32 %104, i32 %105)
store i32 0, i32* %1
br label %107
107: ; preds = %101, %99, %89, %82, %58, %39
%108 = load i32, i32* %1
ret i32 %108
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"%d\00"
@stdin = global i32* null
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [2 x i8] c"r\00"
@stdout = global i32 0
@str = [27 x i8] c"Please enter type of input\00"
@str.14 = [11 x i8] c"1: console\00"
@str.15 = [8 x i8] c"2: file\00"
@str.16 = [13 x i8] c"Wrong option\00"
@str.17 = [22 x i8] c"Please input filename\00"
@str.18 = [13 x i8] c"No such file\00"
@str.19 = [16 x i8] c"Bad Determinant\00"
@str.21 = [28 x i8] c"Please input size of matrix\00"
@str.22 = [7 x i8] c"Error1\00"
@str.23 = [20 x i8] c"Please input matrix\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [20 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.14, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.15, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
switch i32 %11, label %51 [
i32 1, label %12
i32 2, label %30
]
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.21, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%15 = load i32, i32* %1
%16 = shl i32 %15, 3
%17 = mul i32 %16, %15
%18 = call double* @malloc(i32 %17)
%19 = call double* @malloc(i32 %17)
%20 = icmp ne double* %18, null
%21 = icmp ne double* %19, null
%22 = and i1 %20, %21
br i1 %22, label %25, label %23
23: ; preds = %12
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.22, i64 0, i64 0))
br label %66
25: ; preds = %12
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.23, i64 0, i64 0))
%27 = load i32, i32* %1
%28 = load i32*, i32** @stdin
%29 = call i32 @scanm(double* %18, i32 %27, i32* %28)
br label %53
30: ; preds = %0
store i32 20, i32* %1
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.17, i64 0, i64 0))
%32 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %6)
%33 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.18, i64 0, i64 0))
br label %66
37: ; preds = %30
%38 = call i32 @fscanf(i32* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%39 = load i32, i32* %1
%40 = shl i32 %39, 3
%41 = mul i32 %40, %39
%42 = call double* @malloc(i32 %41)
%43 = call double* @malloc(i32 %41)
%44 = icmp ne double* %42, null
%45 = icmp ne double* %43, null
%46 = and i1 %44, %45
br i1 %46, label %49, label %47
47: ; preds = %37
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.22, i64 0, i64 0))
br label %66
49: ; preds = %37
%50 = call i32 @scanm(double* %42, i32 %39, i32* %33)
br label %53
51: ; preds = %0
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.16, i64 0, i64 0))
br label %66
53: ; preds = %49, %25
%54 = phi double* [ %18, %25 ], [ %42, %49 ]
%55 = phi double* [ %19, %25 ], [ %43, %49 ]
%56 = load i32, i32* %1
%57 = call i32 @reverse(double* %54, double* %55, i32 %56)
%58 = icmp eq i32 %57, 0
br i1 %58, label %61, label %59
59: ; preds = %53
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.19, i64 0, i64 0))
br label %66
61: ; preds = %53
%62 = call i32 @putchar(i32 10)
%63 = load i32, i32* %1
%64 = load i32, i32* @stdout
%65 = call i32 @printm(double* %55, i32 %63, i32 %64)
br label %66
66: ; preds = %35, %47, %61, %59, %51, %23
%67 = phi i32 [ 1, %59 ], [ 0, %61 ], [ 1, %23 ], [ 1, %51 ], [ 1, %47 ], [ 1, %35 ]
ret i32 %67
}