#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*/ c_show_map(int **, int, int, int);
int /*<<< orphan*/ copy_map(int **, int **, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free_map(int **, int);
int **get_map(int);
char get_opt();
int /*<<< orphan*/ initial_map(int **, int, int);
int num_counts(int **, int, int, int);
int /*<<< orphan*/ open_all_ctn_unit(int **, int **, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ set_mine_counts(int **, int);
int /*<<< orphan*/ set_mines(int **, int, int);
int /*<<< orphan*/ system(char *);
int main() {
  printf("Please input map's size(size*size):__\b\b");
  int length;
  scanf("%d", &length);
  printf("Please input mine's counts:__\b\b");
  int mine_counts;
  scanf("%d", &mine_counts);
  if (length * length < mine_counts) {
    printf(
        "can you go to dead, I have no much time to play with you!\nbyebye!\n");
    exit(0);
  }
  int **user_map = get_map(length);
  int **real_map = get_map(length);
  int **tmp_map = get_map(length);
  initial_map(real_map, length, 0);
  initial_map(user_map, length, 123);
  set_mines(real_map, length, mine_counts);
  set_mine_counts(real_map, length);
  int x = 0, y = 0, ret, flag_counts = 0;
  char dir, ok = 0;
  system("clear");
  c_show_map(user_map, length, x, y);
  while ((dir = get_opt()) && (dir != 'q')) {
    switch (dir) {
    case 'u':
      if (x <= 0) {
        x = 0;
      } else {
        x--;
      }
      break;
    case 'd':
      if (x >= length - 1) {
        x = length - 1;
      } else {
        x++;
      }
      break;
    case 'l':
      if (y <= 0) {
        y = 0;
      } else {
        y--;
      }
      break;
    case 'r':
      if (y >= length - 1) {
        y = length - 1;
      } else {
        y++;
      }
      break;
    case 'o':
      if (*(*(user_map + x) + y) == 123) {
        *(*(user_map + x) + y) = *(*(real_map + x) + y);
        ok = 1;
      }
      break;
    case 'f':
      if (*(*(user_map + x) + y) == 123) {
        if (flag_counts < mine_counts) {
          *(*(user_map + x) + y) = 456;
          flag_counts++;
        }
      } else if (*(*(user_map + x) + y) == 456) {
        *(*(user_map + x) + y) = 123;
        flag_counts--;
      }
      break;
    }
    if (ok == 1) {
      printf("x = %d, y = %d\n", x, y);
      if (*(*(user_map + x) + y) == 0) {
        copy_map(tmp_map, real_map, length);
        open_all_ctn_unit(tmp_map, user_map, x, y, length);
      } else if (*(*(user_map + x) + y) == 1000) {
        printf("You failed! Game Over\n");
        break;
      }
      if (mine_counts == (num_counts(user_map, length, length, 123) +
                          num_counts(user_map, length, length, 456))) {
        system("clear");
        printf("You Win! Game Over\n");
        break;
      }
      ok = 0;
    }
    system("clear");
    c_show_map(user_map, length, x, y);
  }
  c_show_map(real_map, length, x, y);
  free_map(real_map, length);
  free_map(user_map, length);
  free_map(tmp_map, length);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe6c(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   10c0 <scanf@plt>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe4e(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   10c0 <scanf@plt>
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1250 <main+0x70>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x8(%rbp),%edi
call   1040 <get_map@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <get_map@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <get_map@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
xor    %edx,%edx
call   10b0 <initial_map@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x7b,%edx
call   10b0 <initial_map@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1080 <set_mines@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <set_mine_counts@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
movb   $0x0,-0x3a(%rbp)
lea    0xe08(%rip),%rdi
call   1050 <system@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
call   10a0 <c_show_map@plt>
mov    $0x0,%al
call   1100 <get_opt@plt>
mov    %al,-0x39(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x3b(%rbp)
je     130d <main+0x12d>
movsbl -0x39(%rbp),%eax
cmp    $0x71,%eax
setne  %al
mov    %al,-0x3b(%rbp)
mov    -0x3b(%rbp),%al
test   $0x1,%al
jne    131d <main+0x13d>
jmp    15e9 <main+0x409>
movsbl -0x39(%rbp),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x11,%eax
ja     14c4 <main+0x2e4>
mov    -0x48(%rbp),%rax
lea    0xcc2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x0,-0x2c(%rbp)
jg     135d <main+0x17d>
movl   $0x0,-0x2c(%rbp)
jmp    1366 <main+0x186>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    14c4 <main+0x2e4>
mov    -0x2c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     138a <main+0x1aa>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1393 <main+0x1b3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    14c4 <main+0x2e4>
cmpl   $0x0,-0x30(%rbp)
jg     13ae <main+0x1ce>
movl   $0x0,-0x30(%rbp)
jmp    13b7 <main+0x1d7>
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    14c4 <main+0x2e4>
mov    -0x30(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     13db <main+0x1fb>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    13e4 <main+0x204>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    14c4 <main+0x2e4>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
cmpl   $0x7b,(%rax,%rcx,4)
jne    142d <main+0x24d>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movb   $0x1,-0x3a(%rbp)
jmp    14c4 <main+0x2e4>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
cmpl   $0x7b,(%rax,%rcx,4)
jne    147d <main+0x29d>
mov    -0x38(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1478 <main+0x298>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movl   $0x1c8,(%rax,%rcx,4)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    14bf <main+0x2df>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
cmpl   $0x1c8,(%rax,%rcx,4)
jne    14ba <main+0x2da>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movl   $0x7b,(%rax,%rcx,4)
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    14bf <main+0x2df>
jmp    14c4 <main+0x2e4>
movsbl -0x3a(%rbp),%eax
cmp    $0x1,%eax
jne    15c6 <main+0x3e6>
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
lea    0xbfe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    152b <main+0x34b>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1070 <copy_map@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x8(%rbp),%r8d
call   10f0 <open_all_ctn_unit@plt>
jmp    1560 <main+0x380>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
cmpl   $0x3e8,(%rax,%rcx,4)
jne    155b <main+0x37b>
lea    0xb9d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15e9 <main+0x409>
jmp    1560 <main+0x380>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    $0x7b,%ecx
call   1090 <num_counts@plt>
mov    %eax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    $0x1c8,%ecx
call   1090 <num_counts@plt>
mov    -0x50(%rbp),%ecx
mov    %eax,%edx
mov    -0x4c(%rbp),%eax
add    %edx,%ecx
cmp    %ecx,%eax
jne    15c2 <main+0x3e2>
lea    0xb2c(%rip),%rdi
call   1050 <system@plt>
lea    0xb4d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15e9 <main+0x409>
movb   $0x0,-0x3a(%rbp)
lea    0xb09(%rip),%rdi
call   1050 <system@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
call   10a0 <c_show_map@plt>
jmp    12e5 <main+0x105>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
call   10a0 <c_show_map@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10d0 <free_map@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10d0 <free_map@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10d0 <free_map@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe43(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe5a(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   10d0 <scanf@plt>
lea    0xe49(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   10d0 <scanf@plt>
mov    0xc(%rsp),%edi
mov    %edi,%eax
imul   %edi,%eax
cmp    0x10(%rsp),%eax
jl     151b <main+0x32b>
call   1040 <get_map@plt>
mov    %rax,%r12
mov    0xc(%rsp),%edi
call   1040 <get_map@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%edi
call   1040 <get_map@plt>
mov    %rax,0x20(%rsp)
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   10c0 <initial_map@plt>
mov    0xc(%rsp),%esi
mov    %r12,%rdi
mov    $0x7b,%edx
call   10c0 <initial_map@plt>
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%edx
mov    %rbx,%rdi
call   1090 <set_mines@plt>
mov    0xc(%rsp),%esi
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdi
call   1030 <set_mine_counts@plt>
lea    0xdd9(%rip),%rbx
mov    %rbx,%rdi
call   1060 <system@plt>
mov    0xc(%rsp),%esi
mov    %r12,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   10b0 <c_show_map@plt>
lea    0xd27(%rip),%rbp
xor    %r15d,%r15d
movl   $0x0,0x14(%rsp)
xor    %r13d,%r13d
jmp    131a <main+0x12a>
test   %r13d,%r13d
lea    -0x1(%r13),%eax
cmovle %r14d,%eax
mov    %eax,%r13d
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <system@plt>
mov    0xc(%rsp),%esi
mov    %r12,%rdi
mov    %r13d,%edx
mov    %r15d,%ecx
call   10b0 <c_show_map@plt>
xor    %eax,%eax
call   1110 <get_opt@plt>
test   %al,%al
je     14cd <main+0x2dd>
cmp    $0x71,%al
je     14cd <main+0x2dd>
movsbl %al,%eax
add    $0xffffff9c,%eax
cmp    $0x11,%eax
ja     1300 <main+0x110>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    %eax,%r13d
lea    0x1(%r13),%ecx
cmovge %eax,%ecx
mov    %ecx,%r13d
jmp    1300 <main+0x110>
movslq %r13d,%rax
mov    (%r12,%rax,8),%rax
movslq %r15d,%rcx
mov    (%rax,%rcx,4),%edx
cmp    $0x1c8,%edx
je     1429 <main+0x239>
cmp    $0x7b,%edx
jne    1300 <main+0x110>
mov    0x14(%rsp),%edx
cmp    0x10(%rsp),%edx
jge    1300 <main+0x110>
movl   $0x1c8,(%rax,%rcx,4)
add    $0x1,%edx
mov    %edx,0x14(%rsp)
jmp    1300 <main+0x110>
test   %r15d,%r15d
lea    -0x1(%r15),%eax
cmovle %r14d,%eax
mov    %eax,%r15d
jmp    1300 <main+0x110>
mov    %rbp,%r14
movslq %r13d,%rbp
mov    (%r12,%rbp,8),%rax
movslq %r15d,%rbx
cmpl   $0x7b,(%rax,%rbx,4)
jne    1417 <main+0x227>
mov    0x18(%rsp),%rcx
mov    (%rcx,%rbp,8),%rcx
mov    (%rcx,%rbx,4),%ecx
mov    %ecx,(%rax,%rbx,4)
lea    0xcc2(%rip),%rdi
mov    %r13d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r12,%rbp,8),%rax
mov    (%rax,%rbx,4),%eax
test   %eax,%eax
je     143a <main+0x24a>
cmp    $0x3e8,%eax
mov    %r14,%rbp
jne    1469 <main+0x279>
jmp    14c1 <main+0x2d1>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    %eax,%r15d
lea    0x1(%r15),%ecx
cmovge %eax,%ecx
mov    %ecx,%r15d
jmp    1300 <main+0x110>
lea    0xc75(%rip),%rbx
mov    %r14,%rbp
xor    %r14d,%r14d
jmp    1300 <main+0x110>
movl   $0x7b,(%rax,%rcx,4)
addl   $0xffffffff,0x14(%rsp)
jmp    1300 <main+0x110>
mov    0xc(%rsp),%edx
mov    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    0x18(%rsp),%rsi
call   1080 <copy_map@plt>
mov    0xc(%rsp),%r8d
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
mov    %r15d,%ecx
call   1100 <open_all_ctn_unit@plt>
mov    %r14,%rbp
mov    0x10(%rsp),%ebx
mov    0xc(%rsp),%edx
mov    %r12,%rdi
mov    %edx,%esi
mov    $0x7b,%ecx
call   10a0 <num_counts@plt>
mov    %eax,%r14d
mov    0xc(%rsp),%edx
mov    %r12,%rdi
mov    %edx,%esi
mov    $0x1c8,%ecx
call   10a0 <num_counts@plt>
add    %r14d,%eax
cmp    %eax,%ebx
je     14ac <main+0x2bc>
xor    %r14d,%r14d
lea    0xbec(%rip),%rbx
jmp    1300 <main+0x110>
lea    0xbe0(%rip),%rdi
call   1060 <system@plt>
lea    0xbea(%rip),%rdi
jmp    14c8 <main+0x2d8>
lea    0xbf4(%rip),%rdi
call   1050 <puts@plt>
mov    0xc(%rsp),%esi
mov    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13d,%edx
mov    %r15d,%ecx
call   10b0 <c_show_map@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   10e0 <free_map@plt>
mov    0xc(%rsp),%esi
mov    %r12,%rdi
call   10e0 <free_map@plt>
mov    0xc(%rsp),%esi
mov    0x20(%rsp),%rdi
call   10e0 <free_map@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbb0(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"Please input map's size(size*size):__\08\08\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"Please input mine's counts:__\08\08\00"
@.str.3 = [67 x i8] c"can you go to dead, I have no much time to play with you!\0Abyebye!\0A\00"
@.str.4 = [6 x i8] c"clear\00"
@.str.5 = [16 x i8] c"x = %d, y = %d\0A\00"
@.str.6 = [23 x i8] c"You failed! Game Over\0A\00"
@.str.7 = [20 x i8] c"You Win! Game Over\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i32**
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i8
store i32 0, i32* %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%17 = load i32, i32* %2
%18 = load i32, i32* %2
%19 = mul nsw i32 %17, %18
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %0
%26 = load i32, i32* %2
%27 = call i32** @get_map(i32 %26)
store i32** %27, i32*** %4
%28 = load i32, i32* %2
%29 = call i32** @get_map(i32 %28)
store i32** %29, i32*** %5
%30 = load i32, i32* %2
%31 = call i32** @get_map(i32 %30)
store i32** %31, i32*** %6
%32 = load i32**, i32*** %5
%33 = load i32, i32* %2
%34 = call i32 @initial_map(i32** %32, i32 %33, i32 0)
%35 = load i32**, i32*** %4
%36 = load i32, i32* %2
%37 = call i32 @initial_map(i32** %35, i32 %36, i32 123)
%38 = load i32**, i32*** %5
%39 = load i32, i32* %2
%40 = load i32, i32* %3
%41 = call i32 @set_mines(i32** %38, i32 %39, i32 %40)
%42 = load i32**, i32*** %5
%43 = load i32, i32* %2
%44 = call i32 @set_mine_counts(i32** %42, i32 %43)
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %10
store i8 0, i8* %12
%45 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%46 = load i32**, i32*** %4
%47 = load i32, i32* %2
%48 = load i32, i32* %7
%49 = load i32, i32* %8
%50 = call i32 @c_show_map(i32** %46, i32 %47, i32 %48, i32 %49)
br label %51
51: ; preds = %244, %25
%52 = call signext i8 (...) @get_opt()
store i8 %52, i8* %11
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = load i8, i8* %11
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %57, 113
br label %59
59: ; preds = %55, %51
%60 = phi i1 [ false, %51 ], [ %58, %55 ]
br i1 %60, label %61, label %251
61: ; preds = %59
%62 = load i8, i8* %11
%63 = sext i8 %62 to i32
switch i32 %63, label %185 [
i32 117, label %64
i32 100, label %72
i32 108, label %84
i32 114, label %92
i32 111, label %104
i32 102, label %134
]
64: ; preds = %61
%65 = load i32, i32* %7
%66 = icmp sle i32 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %64
store i32 0, i32* %7
br label %71
68: ; preds = %64
%69 = load i32, i32* %7
%70 = add nsw i32 %69, -1
store i32 %70, i32* %7
br label %71
71: ; preds = %68, %67
br label %185
72: ; preds = %61
%73 = load i32, i32* %7
%74 = load i32, i32* %2
%75 = sub nsw i32 %74, 1
%76 = icmp sge i32 %73, %75
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = load i32, i32* %2
%79 = sub nsw i32 %78, 1
store i32 %79, i32* %7
br label %83
80: ; preds = %72
%81 = load i32, i32* %7
%82 = add nsw i32 %81, 1
store i32 %82, i32* %7
br label %83
83: ; preds = %80, %77
br label %185
84: ; preds = %61
%85 = load i32, i32* %8
%86 = icmp sle i32 %85, 0
br i1 %86, label %87, label %88
87: ; preds = %84
store i32 0, i32* %8
br label %91
88: ; preds = %84
%89 = load i32, i32* %8
%90 = add nsw i32 %89, -1
store i32 %90, i32* %8
br label %91
91: ; preds = %88, %87
br label %185
92: ; preds = %61
%93 = load i32, i32* %8
%94 = load i32, i32* %2
%95 = sub nsw i32 %94, 1
%96 = icmp sge i32 %93, %95
br i1 %96, label %97, label %100
97: ; preds = %92
%98 = load i32, i32* %2
%99 = sub nsw i32 %98, 1
store i32 %99, i32* %8
br label %103
100: ; preds = %92
%101 = load i32, i32* %8
%102 = add nsw i32 %101, 1
store i32 %102, i32* %8
br label %103
103: ; preds = %100, %97
br label %185
104: ; preds = %61
%105 = load i32**, i32*** %4
%106 = load i32, i32* %7
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i32*, i32** %105, i64 %107
%109 = load i32*, i32** %108
%110 = load i32, i32* %8
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i32, i32* %109, i64 %111
%113 = load i32, i32* %112
%114 = icmp eq i32 %113, 123
br i1 %114, label %115, label %133
115: ; preds = %104
%116 = load i32**, i32*** %5
%117 = load i32, i32* %7
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds i32*, i32** %116, i64 %118
%120 = load i32*, i32** %119
%121 = load i32, i32* %8
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i32, i32* %120, i64 %122
%124 = load i32, i32* %123
%125 = load i32**, i32*** %4
%126 = load i32, i32* %7
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i32*, i32** %125, i64 %127
%129 = load i32*, i32** %128
%130 = load i32, i32* %8
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds i32, i32* %129, i64 %131
store i32 %124, i32* %132
store i8 1, i8* %12
br label %133
133: ; preds = %115, %104
br label %185
134: ; preds = %61
%135 = load i32**, i32*** %4
%136 = load i32, i32* %7
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds i32*, i32** %135, i64 %137
%139 = load i32*, i32** %138
%140 = load i32, i32* %8
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds i32, i32* %139, i64 %141
%143 = load i32, i32* %142
%144 = icmp eq i32 %143, 123
br i1 %144, label %145, label %161
145: ; preds = %134
%146 = load i32, i32* %10
%147 = load i32, i32* %3
%148 = icmp slt i32 %146, %147
br i1 %148, label %149, label %160
149: ; preds = %145
%150 = load i32**, i32*** %4
%151 = load i32, i32* %7
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds i32*, i32** %150, i64 %152
%154 = load i32*, i32** %153
%155 = load i32, i32* %8
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds i32, i32* %154, i64 %156
store i32 456, i32* %157
%158 = load i32, i32* %10
%159 = add nsw i32 %158, 1
store i32 %159, i32* %10
br label %160
160: ; preds = %149, %145
br label %184
161: ; preds = %134
%162 = load i32**, i32*** %4
%163 = load i32, i32* %7
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds i32*, i32** %162, i64 %164
%166 = load i32*, i32** %165
%167 = load i32, i32* %8
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds i32, i32* %166, i64 %168
%170 = load i32, i32* %169
%171 = icmp eq i32 %170, 456
br i1 %171, label %172, label %183
172: ; preds = %161
%173 = load i32**, i32*** %4
%174 = load i32, i32* %7
%175 = sext i32 %174 to i64
%176 = getelementptr inbounds i32*, i32** %173, i64 %175
%177 = load i32*, i32** %176
%178 = load i32, i32* %8
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds i32, i32* %177, i64 %179
store i32 123, i32* %180
%181 = load i32, i32* %10
%182 = add nsw i32 %181, -1
store i32 %182, i32* %10
br label %183
183: ; preds = %172, %161
br label %184
184: ; preds = %183, %160
br label %185
185: ; preds = %61, %184, %133, %103, %91, %83, %71
%186 = load i8, i8* %12
%187 = sext i8 %186 to i32
%188 = icmp eq i32 %187, 1
br i1 %188, label %189, label %244
189: ; preds = %185
%190 = load i32, i32* %7
%191 = load i32, i32* %8
%192 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %190, i32 %191)
%193 = load i32**, i32*** %4
%194 = load i32, i32* %7
%195 = sext i32 %194 to i64
%196 = getelementptr inbounds i32*, i32** %193, i64 %195
%197 = load i32*, i32** %196
%198 = load i32, i32* %8
%199 = sext i32 %198 to i64
%200 = getelementptr inbounds i32, i32* %197, i64 %199
%201 = load i32, i32* %200
%202 = icmp eq i32 %201, 0
br i1 %202, label %203, label %214
203: ; preds = %189
%204 = load i32**, i32*** %6
%205 = load i32**, i32*** %5
%206 = load i32, i32* %2
%207 = call i32 @copy_map(i32** %204, i32** %205, i32 %206)
%208 = load i32**, i32*** %6
%209 = load i32**, i32*** %4
%210 = load i32, i32* %7
%211 = load i32, i32* %8
%212 = load i32, i32* %2
%213 = call i32 @open_all_ctn_unit(i32** %208, i32** %209, i32 %210, i32 %211, i32 %212)
br label %228
214: ; preds = %189
%215 = load i32**, i32*** %4
%216 = load i32, i32* %7
%217 = sext i32 %216 to i64
%218 = getelementptr inbounds i32*, i32** %215, i64 %217
%219 = load i32*, i32** %218
%220 = load i32, i32* %8
%221 = sext i32 %220 to i64
%222 = getelementptr inbounds i32, i32* %219, i64 %221
%223 = load i32, i32* %222
%224 = icmp eq i32 %223, 1000
br i1 %224, label %225, label %227
225: ; preds = %214
%226 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %251
227: ; preds = %214
br label %228
228: ; preds = %227, %203
%229 = load i32, i32* %3
%230 = load i32**, i32*** %4
%231 = load i32, i32* %2
%232 = load i32, i32* %2
%233 = call i32 @num_counts(i32** %230, i32 %231, i32 %232, i32 123)
%234 = load i32**, i32*** %4
%235 = load i32, i32* %2
%236 = load i32, i32* %2
%237 = call i32 @num_counts(i32** %234, i32 %235, i32 %236, i32 456)
%238 = add nsw i32 %233, %237
%239 = icmp eq i32 %229, %238
br i1 %239, label %240, label %243
240: ; preds = %228
%241 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%242 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
br label %251
243: ; preds = %228
store i8 0, i8* %12
br label %244
244: ; preds = %243, %185
%245 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%246 = load i32**, i32*** %4
%247 = load i32, i32* %2
%248 = load i32, i32* %7
%249 = load i32, i32* %8
%250 = call i32 @c_show_map(i32** %246, i32 %247, i32 %248, i32 %249)
br label %51
251: ; preds = %240, %225, %59
%252 = load i32**, i32*** %5
%253 = load i32, i32* %2
%254 = load i32, i32* %7
%255 = load i32, i32* %8
%256 = call i32 @c_show_map(i32** %252, i32 %253, i32 %254, i32 %255)
%257 = load i32**, i32*** %5
%258 = load i32, i32* %2
%259 = call i32 @free_map(i32** %257, i32 %258)
%260 = load i32**, i32*** %4
%261 = load i32, i32* %2
%262 = call i32 @free_map(i32** %260, i32 %261)
%263 = load i32**, i32*** %6
%264 = load i32, i32* %2
%265 = call i32 @free_map(i32** %263, i32 %264)
%266 = load i32, i32* %1
ret i32 %266
}

LLVM IR (-O2):
@.str = [40 x i8] c"Please input map's size(size*size):__\08\08\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"Please input mine's counts:__\08\08\00"
@.str.4 = [6 x i8] c"clear\00"
@.str.5 = [16 x i8] c"x = %d, y = %d\0A\00"
@str = [19 x i8] c"You Win! Game Over\00"
@str.8 = [22 x i8] c"You failed! Game Over\00"
@str.9 = [66 x i8] c"can you go to dead, I have no much time to play with you!\0Abyebye!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%7 = bitcast i32* %2 to i8*
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %1
%10 = mul nsw i32 %9, %9
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str.9, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %0
%17 = call i32** @get_map(i32 %9)
%18 = load i32, i32* %1
%19 = call i32** @get_map(i32 %18)
%20 = load i32, i32* %1
%21 = call i32** @get_map(i32 %20)
%22 = load i32, i32* %1
%23 = call i32 @initial_map(i32** %19, i32 %22, i32 0)
%24 = load i32, i32* %1
%25 = call i32 @initial_map(i32** %17, i32 %24, i32 123)
%26 = load i32, i32* %1
%27 = load i32, i32* %2
%28 = call i32 @set_mines(i32** %19, i32 %26, i32 %27)
%29 = load i32, i32* %1
%30 = call i32 @set_mine_counts(i32** %19, i32 %29)
%31 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32, i32* %1
%33 = call i32 @c_show_map(i32** %17, i32 %32, i32 0, i32 0)
br label %34
34: ; preds = %107, %16
%35 = phi i32 [ 0, %16 ], [ %110, %107 ]
%36 = phi i32 [ 0, %16 ], [ %109, %107 ]
%37 = phi i32 [ 0, %16 ], [ %108, %107 ]
%38 = call signext i8 (...) @get_opt()
switch i8 %38, label %39 [
i8 113, label %117
i8 0, label %117
]
39: ; preds = %34
%40 = sext i8 %38 to i32
switch i32 %40, label %107 [
i32 117, label %41
i32 100, label %45
i32 108, label %51
i32 114, label %55
i32 111, label %61
i32 102, label %69
]
41: ; preds = %39
%42 = add nsw i32 %37, -1
%43 = icmp sgt i32 %37, 0
%44 = select i1 %43, i32 %42, i32 0
br label %107
45: ; preds = %39
%46 = load i32, i32* %1
%47 = add nsw i32 %46, -1
%48 = icmp slt i32 %37, %47
%49 = add nsw i32 %37, 1
%50 = select i1 %48, i32 %49, i32 %47
br label %107
51: ; preds = %39
%52 = add nsw i32 %35, -1
%53 = icmp sgt i32 %35, 0
%54 = select i1 %53, i32 %52, i32 0
br label %107
55: ; preds = %39
%56 = load i32, i32* %1
%57 = add nsw i32 %56, -1
%58 = icmp slt i32 %35, %57
%59 = add nsw i32 %35, 1
%60 = select i1 %58, i32 %59, i32 %57
br label %107
61: ; preds = %39
%62 = sext i32 %37 to i64
%63 = getelementptr inbounds i32*, i32** %17, i64 %62
%64 = load i32*, i32** %63
%65 = sext i32 %35 to i64
%66 = getelementptr inbounds i32, i32* %64, i64 %65
%67 = load i32, i32* %66
%68 = icmp eq i32 %67, 123
br i1 %68, label %83, label %107
69: ; preds = %39
%70 = sext i32 %37 to i64
%71 = getelementptr inbounds i32*, i32** %17, i64 %70
%72 = load i32*, i32** %71
%73 = sext i32 %35 to i64
%74 = getelementptr inbounds i32, i32* %72, i64 %73
%75 = load i32, i32* %74
switch i32 %75, label %107 [
i32 123, label %76
i32 456, label %81
]
76: ; preds = %69
%77 = load i32, i32* %2
%78 = icmp slt i32 %36, %77
br i1 %78, label %79, label %107
79: ; preds = %76
store i32 456, i32* %74
%80 = add nsw i32 %36, 1
br label %107
81: ; preds = %69
store i32 123, i32* %74
%82 = add nsw i32 %36, -1
br label %107
83: ; preds = %61
%84 = getelementptr inbounds i32*, i32** %19, i64 %62
%85 = load i32*, i32** %84
%86 = getelementptr inbounds i32, i32* %85, i64 %65
%87 = load i32, i32* %86
store i32 %87, i32* %66
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %37, i32 %35)
%89 = load i32*, i32** %63
%90 = getelementptr inbounds i32, i32* %89, i64 %65
%91 = load i32, i32* %90
switch i32 %91, label %97 [
i32 0, label %92
i32 1000, label %114
]
92: ; preds = %83
%93 = load i32, i32* %1
%94 = call i32 @copy_map(i32** %21, i32** %19, i32 %93)
%95 = load i32, i32* %1
%96 = call i32 @open_all_ctn_unit(i32** %21, i32** %17, i32 %37, i32 %35, i32 %95)
br label %97
97: ; preds = %83, %92
%98 = load i32, i32* %2
%99 = load i32, i32* %1
%100 = call i32 @num_counts(i32** %17, i32 %99, i32 %99, i32 123)
%101 = load i32, i32* %1
%102 = call i32 @num_counts(i32** %17, i32 %101, i32 %101, i32 456)
%103 = add nsw i32 %102, %100
%104 = icmp eq i32 %98, %103
br i1 %104, label %105, label %107
105: ; preds = %97
%106 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %114
107: ; preds = %55, %51, %45, %41, %69, %61, %81, %76, %79, %39, %97
%108 = phi i32 [ %37, %97 ], [ %37, %55 ], [ %37, %51 ], [ %50, %45 ], [ %44, %41 ], [ %37, %69 ], [ %37, %61 ], [ %37, %81 ], [ %37, %76 ], [ %37, %79 ], [ %37, %39 ]
%109 = phi i32 [ %36, %97 ], [ %36, %55 ], [ %36, %51 ], [ %36, %45 ], [ %36, %41 ], [ %36, %69 ], [ %36, %61 ], [ %82, %81 ], [ %36, %76 ], [ %80, %79 ], [ %36, %39 ]
%110 = phi i32 [ %35, %97 ], [ %60, %55 ], [ %54, %51 ], [ %35, %45 ], [ %35, %41 ], [ %35, %69 ], [ %35, %61 ], [ %35, %81 ], [ %35, %76 ], [ %35, %79 ], [ %35, %39 ]
%111 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%112 = load i32, i32* %1
%113 = call i32 @c_show_map(i32** %17, i32 %112, i32 %108, i32 %110)
br label %34
114: ; preds = %83, %105
%115 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0), %105 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0), %83 ]
%116 = call i32 @puts(i8* dereferenceable(1) %115)
br label %117
117: ; preds = %34, %34, %114
%118 = load i32, i32* %1
%119 = call i32 @c_show_map(i32** %19, i32 %118, i32 %37, i32 %35)
%120 = load i32, i32* %1
%121 = call i32 @free_map(i32** %19, i32 %120)
%122 = load i32, i32* %1
%123 = call i32 @free_map(i32** %17, i32 %122)
%124 = load i32, i32* %1
%125 = call i32 @free_map(i32** %21, i32 %124)
ret i32 0
}