#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*/ printf(char *, ...);
int rand();
int reach(int **, int, int, int);
int /*<<< orphan*/ scanf_s(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int matrix[8][8], x, y, radius;
  srand(time(NULL));
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      matrix[i][j] = rand() % 3;
    }
  }
  do {
    printf("Enter row: ");
    scanf_s("%i", &x);
    printf("Enter column: ");
    scanf_s("%i", &y);
    printf("Enter radius: ");
    scanf_s("%i", &radius);
  } while (x <= 0 && x >= 8 && y <= 0 && y >= 8 && radius > 0);
  printf("The total amount of points gathered is %i.\n\n",
         reach(matrix, x, y, radius));
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0x120(%rbp)
cmpl   $0x8,-0x120(%rbp)
jge    121b <main+0xab>
movl   $0x0,-0x124(%rbp)
cmpl   $0x8,-0x124(%rbp)
jge    1202 <main+0x92>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
movslq -0x120(%rbp),%rcx
lea    -0x110(%rbp),%rax
shl    $0x5,%rcx
add    %rcx,%rax
movslq -0x124(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    11b3 <main+0x43>
jmp    1207 <main+0x97>
mov    -0x120(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x120(%rbp)
jmp    119c <main+0x2c>
jmp    1220 <main+0xb0>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdd7(%rip),%rdi
lea    -0x114(%rbp),%rsi
call   1080 <scanf_s@plt>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdb6(%rip),%rdi
lea    -0x118(%rbp),%rsi
call   1080 <scanf_s@plt>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd95(%rip),%rdi
lea    -0x11c(%rbp),%rsi
call   1080 <scanf_s@plt>
xor    %eax,%eax
cmpl   $0x0,-0x114(%rbp)
mov    %al,-0x125(%rbp)
jg     12e7 <main+0x177>
xor    %eax,%eax
cmpl   $0x8,-0x114(%rbp)
mov    %al,-0x125(%rbp)
jl     12e7 <main+0x177>
xor    %eax,%eax
cmpl   $0x0,-0x118(%rbp)
mov    %al,-0x125(%rbp)
jg     12e7 <main+0x177>
xor    %eax,%eax
cmpl   $0x8,-0x118(%rbp)
mov    %al,-0x125(%rbp)
jl     12e7 <main+0x177>
cmpl   $0x0,-0x11c(%rbp)
setg   %al
mov    %al,-0x125(%rbp)
mov    -0x125(%rbp),%al
test   $0x1,%al
jne    1220 <main+0xb0>
lea    -0x110(%rbp),%rdi
mov    -0x114(%rbp),%esi
mov    -0x118(%rbp),%edx
mov    -0x11c(%rbp),%ecx
call   1070 <reach@plt>
mov    %eax,%esi
lea    0xd11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd30(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x110,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,0x10(%rsp,%rbx,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,0x14(%rsp,%rbx,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,0x18(%rsp,%rbx,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,0x1c(%rsp,%rbx,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,0x20(%rsp,%rbx,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,0x24(%rsp,%rbx,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,0x28(%rsp,%rbx,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,0x2c(%rsp,%rbx,1)
add    $0x20,%rbx
cmp    $0x100,%rbx
jne    1190 <main+0x20>
lea    0xd28(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd26(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf_s@plt>
lea    0xd15(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf_s@plt>
lea    0xd09(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf_s@plt>
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdi
call   1070 <reach@plt>
lea    0xce7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd04(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Enter row: \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [15 x i8] c"Enter column: \00"
@.str.3 = [15 x i8] c"Enter radius: \00"
@.str.4 = [45 x i8] c"The total amount of points gathered is %i.\0A\0A\00"
@.str.5 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x [8 x i32]]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
store i32 0, i32* %6
br label %10
10: ; preds = %30, %0
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 8
br i1 %12, label %13, label %33
13: ; preds = %10
store i32 0, i32* %7
br label %14
14: ; preds = %26, %13
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 8
br i1 %16, label %17, label %29
17: ; preds = %14
%18 = call i32 (...) @rand()
%19 = srem i32 %18, 3
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %2, i64 0, i64 %21
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [8 x i32], [8 x i32]* %22, i64 0, i64 %24
store i32 %19, i32* %25
br label %26
26: ; preds = %17
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %14
29: ; preds = %14
br label %30
30: ; preds = %29
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %10
33: ; preds = %10
br label %34
34: ; preds = %56, %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @scanf_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @scanf_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @scanf_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
br label %41
41: ; preds = %34
%42 = load i32, i32* %3
%43 = icmp sle i32 %42, 0
br i1 %43, label %44, label %56
44: ; preds = %41
%45 = load i32, i32* %3
%46 = icmp sge i32 %45, 8
br i1 %46, label %47, label %56
47: ; preds = %44
%48 = load i32, i32* %4
%49 = icmp sle i32 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %47
%51 = load i32, i32* %4
%52 = icmp sge i32 %51, 8
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* %5
%55 = icmp sgt i32 %54, 0
br label %56
56: ; preds = %53, %50, %47, %44, %41
%57 = phi i1 [ false, %50 ], [ false, %47 ], [ false, %44 ], [ false, %41 ], [ %55, %53 ]
br i1 %57, label %34, label %58
58: ; preds = %56
%59 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %2, i64 0, i64 0
%60 = bitcast [8 x i32]* %59 to i32**
%61 = load i32, i32* %3
%62 = load i32, i32* %4
%63 = load i32, i32* %5
%64 = call i32 @reach(i32** %60, i32 %61, i32 %62, i32 %63)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32 %64)
%66 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Enter row: \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [15 x i8] c"Enter column: \00"
@.str.3 = [15 x i8] c"Enter radius: \00"
@.str.4 = [45 x i8] c"The total amount of points gathered is %i.\0A\0A\00"
@.str.5 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca [8 x [8 x i32]]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast [8 x [8 x i32]]* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 @time(i32* null)
%10 = tail call i32 @srand(i32 %9)
br label %11
11: ; preds = %0, %11
%12 = phi i64 [ 0, %0 ], [ %37, %11 ]
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 3
%15 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %1, i64 0, i64 %12, i64 0
store i32 %14, i32* %15
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, 3
%18 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %1, i64 0, i64 %12, i64 1
store i32 %17, i32* %18
%19 = tail call i32 (...) @rand()
%20 = srem i32 %19, 3
%21 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %1, i64 0, i64 %12, i64 2
store i32 %20, i32* %21
%22 = tail call i32 (...) @rand()
%23 = srem i32 %22, 3
%24 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %1, i64 0, i64 %12, i64 3
store i32 %23, i32* %24
%25 = tail call i32 (...) @rand()
%26 = srem i32 %25, 3
%27 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %1, i64 0, i64 %12, i64 4
store i32 %26, i32* %27
%28 = tail call i32 (...) @rand()
%29 = srem i32 %28, 3
%30 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %1, i64 0, i64 %12, i64 5
store i32 %29, i32* %30
%31 = tail call i32 (...) @rand()
%32 = srem i32 %31, 3
%33 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %1, i64 0, i64 %12, i64 6
store i32 %32, i32* %33
%34 = tail call i32 (...) @rand()
%35 = srem i32 %34, 3
%36 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %1, i64 0, i64 %12, i64 7
store i32 %35, i32* %36
%37 = add nuw nsw i64 %12, 1
%38 = icmp eq i64 %37, 8
br i1 %38, label %39, label %11
39: ; preds = %11
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%41 = call i32 @scanf_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @scanf_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @scanf_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%46 = load i32, i32* %4
%47 = load i32, i32* %3
%48 = load i32, i32* %2
%49 = bitcast [8 x [8 x i32]]* %1 to i32**
%50 = call i32 @reach(i32** %49, i32 %48, i32 %47, i32 %46)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32 %50)
%52 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}