#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 */
struct llk_info {
  int dummy;
};

/* Variables and functions */
int llkfinder_find(struct llk_info *, int *, int *, int *, int *);
int /*<<< orphan*/ print_map(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove_elem(int *, int, int, int);
void play_game(struct llk_info *info, int *map, int rows, int cols) {
  int i, result;
  int max_try = rows * cols / 2 + 1;
  for (i = 0; i < max_try; ++i) {
    int row1, col1, row2, col2;
    printf("\ntry %d: ", i);
    result = llkfinder_find(info, &row1, &col1, &row2, &col2);
    switch (result) {
    case 0:
      printf("found: (%d, %d), (%d, %d):\n", row1, col1, row2, col2);
      print_map(map, rows * cols, cols);
      remove_elem(map, cols, row1, col1);
      remove_elem(map, cols, row2, col2);
      break;
    case -1:
      printf("found failed\n");
      break;
    case 1:
      printf("win!\n");
      print_map(map, rows * cols, cols);
      break;
    default:
      printf("Invalid result\n");
    }
  }
  if (result == -1) {
    printf("\nmap is in error state\n");
  }
}


x86 assembly (clang, -O0):
<play_game>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1291 <play_game+0x151>
mov    -0x1c(%rbp),%esi
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r8
call   1030 <llkfinder_find@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0xffffffff,%eax
je     1237 <play_game+0xf7>
jmp    11bf <play_game+0x7f>
mov    -0x38(%rbp),%eax
test   %eax,%eax
je     11e0 <play_game+0xa0>
jmp    11cf <play_game+0x8f>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
je     124a <play_game+0x10a>
jmp    1270 <play_game+0x130>
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x34(%rbp),%r8d
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
imul   -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <print_map@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
call   1060 <remove_elem@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
call   1060 <remove_elem@plt>
jmp    127e <play_game+0x13e>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127e <play_game+0x13e>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
imul   -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <print_map@plt>
jmp    127e <play_game+0x13e>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1283 <play_game+0x143>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1172 <play_game+0x32>
cmpl   $0xffffffff,-0x20(%rbp)
jne    12a9 <play_game+0x169>
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<play_game>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
imul   %ecx,%edx
mov    %edx,0x4(%rsp)
cmp    $0xffffffff,%edx
jl     1295 <play_game+0x145>
mov    %ecx,%ebx
mov    %rsi,%r15
mov    %rdi,%rbp
mov    0x4(%rsp),%eax
mov    %eax,%r14d
shr    $0x1f,%r14d
add    %eax,%r14d
sar    %r14d
xor    %r13d,%r13d
jmp    11a9 <play_game+0x59>
nopl   0x0(%rax)
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
cmp    %r13d,%r14d
je     128f <play_game+0x13f>
add    $0x1,%r13d
lea    0xe50(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1040 <llkfinder_find@plt>
cmp    $0xffffffff,%eax
je     1250 <play_game+0x100>
mov    %eax,%r12d
cmp    $0x1,%eax
je     1270 <play_game+0x120>
test   %r12d,%r12d
jne    1190 <play_game+0x40>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    0x4(%rsp),%esi
mov    %ebx,%edx
call   1060 <print_map@plt>
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    %r15,%rdi
mov    %ebx,%esi
call   1070 <remove_elem@plt>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    %r15,%rdi
mov    %ebx,%esi
call   1070 <remove_elem@plt>
jmp    119c <play_game+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xdeb(%rip),%rdi
call   1030 <puts@plt>
cmp    %r13d,%r14d
jne    11a5 <play_game+0x55>
jmp    1295 <play_game+0x145>
nopw   0x0(%rax,%rax,1)
lea    0xdc6(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    0x4(%rsp),%esi
mov    %ebx,%edx
call   1060 <print_map@plt>
jmp    119c <play_game+0x4c>
cmp    $0xffffffff,%r12d
jne    12a1 <play_game+0x151>
lea    0xd8a(%rip),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.llk_info = type { i32 }
@.str = [10 x i8] c"\0Atry %d: \00"
@.str.1 = [28 x i8] c"found: (%d, %d), (%d, %d):\0A\00"
@.str.2 = [14 x i8] c"found failed\0A\00"
@.str.3 = [6 x i8] c"win!\0A\00"
@.str.4 = [16 x i8] c"Invalid result\0A\00"
@.str.5 = [24 x i8] c"\0Amap is in error state\0A\00"
define void @play_game(%struct.llk_info* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca %struct.llk_info*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store %struct.llk_info* %0, %struct.llk_info** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = mul nsw i32 %16, %17
%19 = sdiv i32 %18, 2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %11
store i32 0, i32* %9
br label %21
21: ; preds = %66, %4
%22 = load i32, i32* %9
%23 = load i32, i32* %11
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %69
25: ; preds = %21
%26 = load i32, i32* %9
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load %struct.llk_info*, %struct.llk_info** %5
%29 = call i32 @llkfinder_find(%struct.llk_info* %28, i32* %12, i32* %13, i32* %14, i32* %15)
store i32 %29, i32* %10
%30 = load i32, i32* %10
switch i32 %30, label %63 [
i32 0, label %31
i32 -1, label %53
i32 1, label %55
]
31: ; preds = %25
%32 = load i32, i32* %12
%33 = load i32, i32* %13
%34 = load i32, i32* %14
%35 = load i32, i32* %15
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %33, i32 %34, i32 %35)
%37 = load i32*, i32** %6
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = mul nsw i32 %38, %39
%41 = load i32, i32* %8
%42 = call i32 @print_map(i32* %37, i32 %40, i32 %41)
%43 = load i32*, i32** %6
%44 = load i32, i32* %8
%45 = load i32, i32* %12
%46 = load i32, i32* %13
%47 = call i32 @remove_elem(i32* %43, i32 %44, i32 %45, i32 %46)
%48 = load i32*, i32** %6
%49 = load i32, i32* %8
%50 = load i32, i32* %14
%51 = load i32, i32* %15
%52 = call i32 @remove_elem(i32* %48, i32 %49, i32 %50, i32 %51)
br label %65
53: ; preds = %25
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %65
55: ; preds = %25
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%57 = load i32*, i32** %6
%58 = load i32, i32* %7
%59 = load i32, i32* %8
%60 = mul nsw i32 %58, %59
%61 = load i32, i32* %8
%62 = call i32 @print_map(i32* %57, i32 %60, i32 %61)
br label %65
63: ; preds = %25
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %65
65: ; preds = %63, %55, %53, %31
br label %66
66: ; preds = %65
%67 = load i32, i32* %9
%68 = add nsw i32 %67, 1
store i32 %68, i32* %9
br label %21
69: ; preds = %21
%70 = load i32, i32* %10
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %74
74: ; preds = %72, %69
ret void
}

LLVM IR (-O2):
%struct.llk_info = type { i32 }
@.str = [10 x i8] c"\0Atry %d: \00"
@.str.1 = [28 x i8] c"found: (%d, %d), (%d, %d):\0A\00"
@str = [23 x i8] c"\0Amap is in error state\00"
@str.6 = [5 x i8] c"win!\00"
@str.7 = [13 x i8] c"found failed\00"
@str.8 = [15 x i8] c"Invalid result\00"
define void @play_game(%struct.llk_info* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = mul nsw i32 %3, %2
%10 = icmp slt i32 %9, -1
br i1 %10, label %48, label %11
11: ; preds = %4
%12 = sdiv i32 %9, 2
%13 = bitcast i32* %5 to i8*
%14 = bitcast i32* %6 to i8*
%15 = bitcast i32* %7 to i8*
%16 = bitcast i32* %8 to i8*
br label %17
17: ; preds = %41, %11
%18 = phi i32 [ 0, %11 ], [ %42, %41 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 @llkfinder_find(%struct.llk_info* %0, i32* %5, i32* %6, i32* %7, i32* %8)
switch i32 %20, label %37 [
i32 0, label %21
i32 -1, label %43
i32 1, label %34
]
21: ; preds = %17
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %23, i32 %24, i32 %25)
%27 = call i32 @print_map(i32* %1, i32 %9, i32 %3)
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = call i32 @remove_elem(i32* %1, i32 %3, i32 %28, i32 %29)
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = call i32 @remove_elem(i32* %1, i32 %3, i32 %31, i32 %32)
br label %39
34: ; preds = %17
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.6, i64 0, i64 0))
%36 = call i32 @print_map(i32* %1, i32 %9, i32 %3)
br label %39
37: ; preds = %17
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
br label %39
39: ; preds = %37, %34, %21
%40 = icmp eq i32 %18, %12
br i1 %40, label %46, label %41
41: ; preds = %39, %43
%42 = add nuw nsw i32 %18, 1
br label %17
43: ; preds = %17
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
%45 = icmp eq i32 %18, %12
br i1 %45, label %48, label %41
46: ; preds = %39
%47 = icmp eq i32 %20, -1
br i1 %47, label %48, label %50
48: ; preds = %43, %4, %46
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %50
50: ; preds = %48, %46
ret void
}