#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 rect_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ index_to_xy(int, int *, int *, int);
scalar_t__ is_rect_full(struct rect_t *, int, int, int);
int /*<<< orphan*/ set_full(struct rect_t *, int, int, int);
int check_and_set_full(struct rect_t *prect, int num, int index) {
  int x, y;
  index_to_xy(index, &x, &y, num);
  if (y == 0 || is_rect_full(prect, num, x - 1, y) ||
      is_rect_full(prect, num, x + 1, y) ||
      is_rect_full(prect, num, x, y - 1) ||
      is_rect_full(prect, num, x, y + 1)) {
    set_full(prect, num, x, y);
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_and_set_full>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%ecx
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <index_to_xy@plt>
cmpl   $0x0,-0x18(%rbp)
je     11db <check_and_set_full+0xab>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1050 <is_rect_full@plt>
cmp    $0x0,%rax
jne    11db <check_and_set_full+0xab>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1050 <is_rect_full@plt>
cmp    $0x0,%rax
jne    11db <check_and_set_full+0xab>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
call   1050 <is_rect_full@plt>
cmp    $0x0,%rax
jne    11db <check_and_set_full+0xab>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
call   1050 <is_rect_full@plt>
cmp    $0x0,%rax
je     11ed <check_and_set_full+0xbd>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <set_full@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_and_set_full>:
push   %r14
push   %rbx
push   %rax
mov    %edx,%eax
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %eax,%edi
mov    %ebx,%ecx
call   1030 <index_to_xy@plt>
mov    (%rsp),%ecx
test   %ecx,%ecx
je     11b4 <check_and_set_full+0x84>
mov    0x4(%rsp),%edx
add    $0xffffffff,%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <is_rect_full@plt>
test   %rax,%rax
jne    11b4 <check_and_set_full+0x84>
mov    0x4(%rsp),%edx
add    $0x1,%edx
mov    (%rsp),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <is_rect_full@plt>
test   %rax,%rax
jne    11b4 <check_and_set_full+0x84>
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
add    $0xffffffff,%ecx
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <is_rect_full@plt>
test   %rax,%rax
jne    11b4 <check_and_set_full+0x84>
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
add    $0x1,%ecx
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <is_rect_full@plt>
test   %rax,%rax
je     11c5 <check_and_set_full+0x95>
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <set_full@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rect_t = type { i32 }
define i32 @check_and_set_full(%struct.rect_t* %0, i32 %1, i32 %2) {
%4 = alloca %struct.rect_t*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.rect_t* %0, %struct.rect_t** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = load i32, i32* %5
%11 = call i32 @index_to_xy(i32 %9, i32* %7, i32* %8, i32 %10)
%12 = load i32, i32* %8
%13 = icmp eq i32 %12, 0
br i1 %13, label %46, label %14
14: ; preds = %3
%15 = load %struct.rect_t*, %struct.rect_t** %4
%16 = load i32, i32* %5
%17 = load i32, i32* %7
%18 = sub nsw i32 %17, 1
%19 = load i32, i32* %8
%20 = call i64 @is_rect_full(%struct.rect_t* %15, i32 %16, i32 %18, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %46, label %22
22: ; preds = %14
%23 = load %struct.rect_t*, %struct.rect_t** %4
%24 = load i32, i32* %5
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
%27 = load i32, i32* %8
%28 = call i64 @is_rect_full(%struct.rect_t* %23, i32 %24, i32 %26, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %46, label %30
30: ; preds = %22
%31 = load %struct.rect_t*, %struct.rect_t** %4
%32 = load i32, i32* %5
%33 = load i32, i32* %7
%34 = load i32, i32* %8
%35 = sub nsw i32 %34, 1
%36 = call i64 @is_rect_full(%struct.rect_t* %31, i32 %32, i32 %33, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %46, label %38
38: ; preds = %30
%39 = load %struct.rect_t*, %struct.rect_t** %4
%40 = load i32, i32* %5
%41 = load i32, i32* %7
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
%44 = call i64 @is_rect_full(%struct.rect_t* %39, i32 %40, i32 %41, i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %38, %30, %22, %14, %3
%47 = load %struct.rect_t*, %struct.rect_t** %4
%48 = load i32, i32* %5
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = call i32 @set_full(%struct.rect_t* %47, i32 %48, i32 %49, i32 %50)
br label %52
52: ; preds = %46, %38
ret i32 0
}

LLVM IR (-O2):
%struct.rect_t = type { i32 }
define i32 @check_and_set_full(%struct.rect_t* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = call i32 @index_to_xy(i32 %2, i32* %4, i32* %5, i32 %1)
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %34, label %11
11: ; preds = %3
%12 = load i32, i32* %4
%13 = add nsw i32 %12, -1
%14 = call i64 @is_rect_full(%struct.rect_t* %0, i32 %1, i32 %13, i32 %9)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %11
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
%19 = load i32, i32* %5
%20 = call i64 @is_rect_full(%struct.rect_t* %0, i32 %1, i32 %18, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %16
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = add nsw i32 %24, -1
%26 = call i64 @is_rect_full(%struct.rect_t* %0, i32 %1, i32 %23, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
%32 = call i64 @is_rect_full(%struct.rect_t* %0, i32 %1, i32 %29, i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %28, %22, %16, %11, %3
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = call i32 @set_full(%struct.rect_t* %0, i32 %1, i32 %35, i32 %36)
br label %38
38: ; preds = %34, %28
ret i32 0
}