#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ run_game(int, int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usage(char *);
int cli_main(int argc, char *argv[]) {
  int r, c, m;
  if (argc >= 2 && strcmp(argv[1], "-h") == 0) {
    usage(argv[0]);
    return EXIT_SUCCESS;
  }
  if (argc >= 3) {
    sscanf(argv[1], "%d", &r);
    sscanf(argv[2], "%d", &c);
    if (r <= 0 || c <= 0 || r > 255 || c > 255) {
      fprintf(stderr, "error: bad grid size (%dx%d)\n", r, c);
      return EXIT_FAILURE;
    }
  } else {
    r = c = 10;
  }
  if (argc >= 4) {
    sscanf(argv[3], "%d", &m);
    if (m <= 0 || m > r * c) {
      fprintf(stderr, "error: bad number of mines (%d)\n", m);
      return EXIT_FAILURE;
    }
  } else {
    m = 20;
  }
  run_game(r, c, m);
  return 0;
}


x86 assembly (clang, -O0):
<cli_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11a4 <cli_main+0x54>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe88(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11a4 <cli_main+0x54>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d7 <cli_main+0x187>
cmpl   $0x3,-0x8(%rbp)
jl     123f <cli_main+0xef>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe46(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe2e(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <sscanf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    120c <cli_main+0xbc>
cmpl   $0x0,-0x18(%rbp)
jle    120c <cli_main+0xbc>
cmpl   $0xff,-0x14(%rbp)
jg     120c <cli_main+0xbc>
cmpl   $0xff,-0x18(%rbp)
jle    123a <cli_main+0xea>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d7 <cli_main+0x187>
jmp    124d <cli_main+0xfd>
movl   $0xa,-0x18(%rbp)
movl   $0xa,-0x14(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     12bb <cli_main+0x16b>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd9d(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <sscanf@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    128b <cli_main+0x13b>
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jle    12b6 <cli_main+0x166>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xd86(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d7 <cli_main+0x187>
jmp    12c2 <cli_main+0x172>
movl   $0x14,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1050 <run_game@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cli_main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jl     122c <cli_main+0xdc>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xe8f(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1260 <cli_main+0x110>
cmp    $0x3,%ebp
jb     122c <cli_main+0xdc>
mov    0x8(%rbx),%rdi
lea    0xe70(%rip),%r14
lea    0x8(%rsp),%rdx
mov    %r14,%rsi
call   1060 <sscanf@plt>
mov    0x10(%rbx),%rdi
lea    0x4(%rsp),%rdx
mov    %r14,%rsi
call   1060 <sscanf@plt>
mov    0x8(%rsp),%eax
mov    0x4(%rsp),%ecx
cmp    $0xff,%eax
jg     1271 <cli_main+0x121>
test   %eax,%eax
jle    1271 <cli_main+0x121>
test   %ecx,%ecx
jle    1271 <cli_main+0x121>
cmp    $0x100,%ecx
jge    1271 <cli_main+0x121>
cmp    $0x4,%ebp
jb     1246 <cli_main+0xf6>
mov    0x18(%rbx),%rdi
lea    0xe13(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    1213 <cli_main+0xc3>
mov    0x8(%rsp),%eax
mov    0x4(%rsp),%ecx
mov    %ecx,%esi
imul   %eax,%esi
cmp    %esi,%edx
jle    1253 <cli_main+0x103>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    128a <cli_main+0x13a>
movl   $0xa,0x4(%rsp)
movl   $0xa,0x8(%rsp)
mov    $0xa,%ecx
mov    $0xa,%eax
movl   $0x14,0xc(%rsp)
mov    $0x14,%edx
mov    %eax,%edi
mov    %ecx,%esi
call   1050 <run_game@plt>
xor    %eax,%eax
jmp    1293 <cli_main+0x143>
mov    (%rbx),%rdi
call   1070 <usage@plt>
mov    0x2d61(%rip),%rax
jmp    1291 <cli_main+0x141>
mov    0x2d68(%rip),%rdx
mov    (%rdx),%edi
lea    0xd85(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-h\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"error: bad grid size (%dx%d)\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [33 x i8] c"error: bad number of mines (%d)\0A\00"
define i32 @cli_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 2
br i1 %10, label %11, label %23
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @usage(i8* %20)
%22 = load i32, i32* @EXIT_SUCCESS
store i32 %22, i32* %3
br label %82
23: ; preds = %11, %2
%24 = load i32, i32* %4
%25 = icmp sge i32 %24, 3
br i1 %25, label %26, label %53
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%35 = load i32, i32* %6
%36 = icmp sle i32 %35, 0
br i1 %36, label %46, label %37
37: ; preds = %26
%38 = load i32, i32* %7
%39 = icmp sle i32 %38, 0
br i1 %39, label %46, label %40
40: ; preds = %37
%41 = load i32, i32* %6
%42 = icmp sgt i32 %41, 255
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load i32, i32* %7
%45 = icmp sgt i32 %44, 255
br i1 %45, label %46, label %52
46: ; preds = %43, %40, %37, %26
%47 = load i32, i32* @stderr
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %48, i32 %49)
%51 = load i32, i32* @EXIT_FAILURE
store i32 %51, i32* %3
br label %82
52: ; preds = %43
br label %54
53: ; preds = %23
store i32 10, i32* %7
store i32 10, i32* %6
br label %54
54: ; preds = %53, %52
%55 = load i32, i32* %4
%56 = icmp sge i32 %55, 4
br i1 %56, label %57, label %76
57: ; preds = %54
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 3
%60 = load i8*, i8** %59
%61 = call i32 @sscanf(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%62 = load i32, i32* %8
%63 = icmp sle i32 %62, 0
br i1 %63, label %70, label %64
64: ; preds = %57
%65 = load i32, i32* %8
%66 = load i32, i32* %6
%67 = load i32, i32* %7
%68 = mul nsw i32 %66, %67
%69 = icmp sgt i32 %65, %68
br i1 %69, label %70, label %75
70: ; preds = %64, %57
%71 = load i32, i32* @stderr
%72 = load i32, i32* %8
%73 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %72)
%74 = load i32, i32* @EXIT_FAILURE
store i32 %74, i32* %3
br label %82
75: ; preds = %64
br label %77
76: ; preds = %54
store i32 20, i32* %8
br label %77
77: ; preds = %76, %75
%78 = load i32, i32* %6
%79 = load i32, i32* %7
%80 = load i32, i32* %8
%81 = call i32 @run_game(i32 %78, i32 %79, i32 %80)
store i32 0, i32* %3
br label %82
82: ; preds = %77, %70, %46, %17
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@.str = [3 x i8] c"-h\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"error: bad grid size (%dx%d)\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [33 x i8] c"error: bad number of mines (%d)\0A\00"
define i32 @cli_main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %40
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i8*, i8** %1
%17 = tail call i32 @usage(i8* %16)
%18 = load i32, i32* @EXIT_SUCCESS
br label %66
19: ; preds = %10
%20 = icmp ugt i32 %0, 2
br i1 %20, label %21, label %40
21: ; preds = %19
%22 = load i8*, i8** %11
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 1
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 1
%31 = select i1 %28, i1 true, i1 %30
%32 = icmp sgt i32 %27, 255
%33 = or i1 %32, %31
%34 = icmp sgt i32 %29, 255
%35 = select i1 %33, i1 true, i1 %34
br i1 %35, label %36, label %41
36: ; preds = %21
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %29)
%39 = load i32, i32* @EXIT_FAILURE
br label %66
40: ; preds = %19, %2
store i32 10, i32* %4
store i32 10, i32* %3
br label %58
41: ; preds = %21
%42 = icmp ugt i32 %0, 3
br i1 %42, label %43, label %58
43: ; preds = %41
%44 = getelementptr inbounds i8*, i8** %1, i64 3
%45 = load i8*, i8** %44
%46 = call i32 @sscanf(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%47 = load i32, i32* %5
%48 = icmp slt i32 %47, 1
br i1 %48, label %54, label %49
49: ; preds = %43
%50 = load i32, i32* %3
%51 = load i32, i32* %4
%52 = mul nsw i32 %51, %50
%53 = icmp sgt i32 %47, %52
br i1 %53, label %54, label %61
54: ; preds = %49, %43
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %47)
%57 = load i32, i32* @EXIT_FAILURE
br label %66
58: ; preds = %40, %41
%59 = phi i32 [ 10, %40 ], [ %29, %41 ]
%60 = phi i32 [ 10, %40 ], [ %27, %41 ]
store i32 20, i32* %5
br label %61
61: ; preds = %49, %58
%62 = phi i32 [ %47, %49 ], [ 20, %58 ]
%63 = phi i32 [ %51, %49 ], [ %59, %58 ]
%64 = phi i32 [ %50, %49 ], [ %60, %58 ]
%65 = call i32 @run_game(i32 %64, i32 %63, i32 %62)
br label %66
66: ; preds = %61, %54, %36, %15
%67 = phi i32 [ %18, %15 ], [ %39, %36 ], [ %57, %54 ], [ 0, %61 ]
ret i32 %67
}