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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int grid_get_data_from_id(int *, int *, int *, int);
int interface_screen_choices(int *, char **, int, char *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int);
int choose_dimension_bombs(int *row_dim, int *col_dim, int *bombs) {
  int result;
  int retval;
  char *choices[3];
  int lines = sizeof(choices) / sizeof(*choices);
  int i;
  for (i = 0; i < 3; i++) {
    int tmp_row, tmp_col, tmp_bombs;
    char *tmp_name;
    choices[i] = malloc(sizeof(char) * 50);
    retval = grid_get_data_from_id(&tmp_row, &tmp_col, &tmp_bombs, i);
    if (i == 0)
      tmp_name = "Small";
    else if (i == 1)
      tmp_name = "Medium";
    else if (i == 2)
      tmp_name = "Large";
    sprintf(choices[i], "%s\t (%02dx%02d)", tmp_name, tmp_row, tmp_col);
  }
  retval = interface_screen_choices(&result, choices, lines, "Choose the size");
  if (((retval) == (!(0))))
    return (!(0));
  for (i = 0; i < 3; i++)
    free(choices[i]);
  if (result == -1)
    return -1;
  retval = grid_get_data_from_id(row_dim, col_dim, bombs, result);
  if (((retval) == (!(0))))
    return (!(0));
  return (0);
}


x86 assembly (clang, -O0):
<choose_dimension_bombs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x3,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
cmpl   $0x3,-0x48(%rbp)
jge    122a <choose_dimension_bombs+0xda>
mov    $0x32,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
movslq -0x48(%rbp),%rax
mov    %rcx,-0x40(%rbp,%rax,8)
mov    -0x48(%rbp),%ecx
lea    -0x4c(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x54(%rbp),%rdx
call   1060 <grid_get_data_from_id@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x48(%rbp)
jne    11c3 <choose_dimension_bombs+0x73>
lea    0xe46(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    11fc <choose_dimension_bombs+0xac>
cmpl   $0x1,-0x48(%rbp)
jne    11dd <choose_dimension_bombs+0x8d>
lea    0xe32(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    11f7 <choose_dimension_bombs+0xa7>
cmpl   $0x2,-0x48(%rbp)
jne    11f2 <choose_dimension_bombs+0xa2>
lea    0xe1f(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    11f7 <choose_dimension_bombs+0xa7>
jmp    11fc <choose_dimension_bombs+0xac>
movslq -0x48(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
mov    -0x60(%rbp),%rdx
mov    -0x4c(%rbp),%ecx
mov    -0x50(%rbp),%r8d
lea    0xdfc(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1172 <choose_dimension_bombs+0x22>
lea    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
lea    -0x24(%rbp),%rdi
lea    0xde7(%rip),%rcx
call   1050 <interface_screen_choices@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
jne    125a <choose_dimension_bombs+0x10a>
movl   $0x1,-0x4(%rbp)
jmp    12d1 <choose_dimension_bombs+0x181>
movl   $0x0,-0x48(%rbp)
cmpl   $0x3,-0x48(%rbp)
jge    1287 <choose_dimension_bombs+0x137>
movslq -0x48(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1261 <choose_dimension_bombs+0x111>
cmpl   $0xffffffff,-0x24(%rbp)
jne    129d <choose_dimension_bombs+0x14d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d1 <choose_dimension_bombs+0x181>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1060 <grid_get_data_from_id@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
jne    12ca <choose_dimension_bombs+0x17a>
movl   $0x1,-0x4(%rbp)
jmp    12d1 <choose_dimension_bombs+0x181>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<choose_dimension_bombs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,0x38(%rsp)
mov    %rsi,0x30(%rsp)
mov    %rdi,0x28(%rsp)
mov    $0x32,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rbx
lea    0xc(%rsp),%r13
lea    0x44(%rsp),%r14
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1060 <grid_get_data_from_id@plt>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
lea    0xe65(%rip),%r15
lea    0xe4b(%rip),%rdx
mov    %rbp,%rdi
mov    %r15,%rsi
call   1070 <sprintf@plt>
mov    $0x32,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    %rax,0x18(%rsp)
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    $0x1,%ecx
call   1060 <grid_get_data_from_id@plt>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
lea    0xe0c(%rip),%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <sprintf@plt>
mov    $0x32,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x20(%rsp)
lea    0x8(%rsp),%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    $0x2,%ecx
call   1060 <grid_get_data_from_id@plt>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
lea    0xdd1(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <sprintf@plt>
lea    0xdd5(%rip),%rcx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x3,%edx
call   1050 <interface_screen_choices@plt>
cmp    $0x1,%eax
je     12b2 <choose_dimension_bombs+0x162>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%ecx
cmp    $0xffffffff,%ecx
je     12ad <choose_dimension_bombs+0x15d>
mov    0x28(%rsp),%rdi
mov    0x30(%rsp),%rsi
mov    0x38(%rsp),%rdx
call   1060 <grid_get_data_from_id@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
sete   %bpl
jmp    12b2 <choose_dimension_bombs+0x162>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Small\00"
@.str.1 = [7 x i8] c"Medium\00"
@.str.2 = [6 x i8] c"Large\00"
@.str.3 = [16 x i8] c"%s\09 (%02dx%02d)\00"
@.str.4 = [16 x i8] c"Choose the size\00"
define i32 @choose_dimension_bombs(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [3 x i8*]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 3, i32* %11
store i32 0, i32* %12
br label %17
17: ; preds = %49, %3
%18 = load i32, i32* %12
%19 = icmp slt i32 %18, 3
br i1 %19, label %20, label %52
20: ; preds = %17
%21 = call i8* @malloc(i32 50)
%22 = load i32, i32* %12
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 %23
store i8* %21, i8** %24
%25 = load i32, i32* %12
%26 = call i32 @grid_get_data_from_id(i32* %13, i32* %14, i32* %15, i32 %25)
store i32 %26, i32* %9
%27 = load i32, i32* %12
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %20
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %16
br label %40
30: ; preds = %20
%31 = load i32, i32* %12
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %34
33: ; preds = %30
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %16
br label %39
34: ; preds = %30
%35 = load i32, i32* %12
%36 = icmp eq i32 %35, 2
br i1 %36, label %37, label %38
37: ; preds = %34
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %16
br label %38
38: ; preds = %37, %34
br label %39
39: ; preds = %38, %33
br label %40
40: ; preds = %39, %29
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 %42
%44 = load i8*, i8** %43
%45 = load i8*, i8** %16
%46 = load i32, i32* %13
%47 = load i32, i32* %14
%48 = call i32 @sprintf(i8* %44, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %45, i32 %46, i32 %47)
br label %49
49: ; preds = %40
%50 = load i32, i32* %12
%51 = add nsw i32 %50, 1
store i32 %51, i32* %12
br label %17
52: ; preds = %17
%53 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 0
%54 = load i32, i32* %11
%55 = call i32 @interface_screen_choices(i32* %8, i8** %53, i32 %54, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i32 %55, i32* %9
%56 = load i32, i32* %9
%57 = icmp eq i32 %56, 1
br i1 %57, label %58, label %59
58: ; preds = %52
store i32 1, i32* %4
br label %86
59: ; preds = %52
store i32 0, i32* %12
br label %60
60: ; preds = %69, %59
%61 = load i32, i32* %12
%62 = icmp slt i32 %61, 3
br i1 %62, label %63, label %72
63: ; preds = %60
%64 = load i32, i32* %12
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 %65
%67 = load i8*, i8** %66
%68 = call i32 @free(i8* %67)
br label %69
69: ; preds = %63
%70 = load i32, i32* %12
%71 = add nsw i32 %70, 1
store i32 %71, i32* %12
br label %60
72: ; preds = %60
%73 = load i32, i32* %8
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %76
75: ; preds = %72
store i32 -1, i32* %4
br label %86
76: ; preds = %72
%77 = load i32*, i32** %5
%78 = load i32*, i32** %6
%79 = load i32*, i32** %7
%80 = load i32, i32* %8
%81 = call i32 @grid_get_data_from_id(i32* %77, i32* %78, i32* %79, i32 %80)
store i32 %81, i32* %9
%82 = load i32, i32* %9
%83 = icmp eq i32 %82, 1
br i1 %83, label %84, label %85
84: ; preds = %76
store i32 1, i32* %4
br label %86
85: ; preds = %76
store i32 0, i32* %4
br label %86
86: ; preds = %85, %84, %75, %58
%87 = load i32, i32* %4
ret i32 %87
}

LLVM IR (-O2):
@.str = [6 x i8] c"Small\00"
@.str.1 = [7 x i8] c"Medium\00"
@.str.2 = [6 x i8] c"Large\00"
@.str.3 = [16 x i8] c"%s\09 (%02dx%02d)\00"
@.str.4 = [16 x i8] c"Choose the size\00"
define i32 @choose_dimension_bombs(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca [3 x i8*]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast i32* %4 to i8*
%10 = bitcast [3 x i8*]* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = bitcast i32* %8 to i8*
%14 = call dereferenceable_or_null(50) i8* @malloc(i32 50)
%15 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
store i8* %14, i8** %15
%16 = call i32 @grid_get_data_from_id(i32* %6, i32* %7, i32* %8, i32 0)
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = call i32 @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18)
%20 = call dereferenceable_or_null(50) i8* @malloc(i32 50)
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 1
store i8* %20, i8** %21
%22 = call i32 @grid_get_data_from_id(i32* %6, i32* %7, i32* %8, i32 1)
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = call i32 @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %24)
%26 = call dereferenceable_or_null(50) i8* @malloc(i32 50)
%27 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 2
store i8* %26, i8** %27
%28 = call i32 @grid_get_data_from_id(i32* %6, i32* %7, i32* %8, i32 2)
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = call i32 @sprintf(i8* dereferenceable(1) %26, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %30)
%32 = call i32 @interface_screen_choices(i32* %4, i8** %15, i32 3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp eq i32 %32, 1
br i1 %33, label %47, label %34
34: ; preds = %3
%35 = load i8*, i8** %15
%36 = call i32 @free(i8* %35)
%37 = load i8*, i8** %21
%38 = call i32 @free(i8* %37)
%39 = load i8*, i8** %27
%40 = call i32 @free(i8* %39)
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, -1
br i1 %42, label %47, label %43
43: ; preds = %34
%44 = call i32 @grid_get_data_from_id(i32* %0, i32* %1, i32* %2, i32 %41)
%45 = icmp eq i32 %44, 1
%46 = zext i1 %45 to i32
br label %47
47: ; preds = %43, %34, %3
%48 = phi i32 [ 1, %3 ], [ -1, %34 ], [ %46, %43 ]
ret i32 %48
}