#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*/ memcpy(int **, int **, int);
int /*<<< orphan*/ printf(char *, ...);
int reachable_size(int *, int, int, int, int);
void test_reachable_size() {
  printf("TESTING PROBLEM 5: reachable_size\n\n");
  int test1[4][5] = {
      {1, 1, 1, 1, 1}, {1, 0, 1, 0, 1}, {1, 0, 1, 1, 1}, {1, 1, 1, 0, 1}};
  int vals[4][5];
  memcpy(vals, test1, sizeof(int) * 4 * 5);
  int result1 = reachable_size((int *)vals, 4, 5, 1, 1);
  int answer1 = 3;
  printf("Test 1 of reachable_size returns %d, should be %d, %s\n", result1,
         answer1, (result1 == answer1 ? "CORRECT" : "WRONG"));
  memcpy(vals, test1, sizeof(int) * 4 * 5);
  int result2 = reachable_size((int *)vals, 4, 5, 3, 3);
  int answer2 = 3;
  printf("Test 2 of reachable_size returns %d, should be %d, %s\n", result2,
         answer2, (result2 == answer2 ? "CORRECT" : "WRONG"));
  memcpy(vals, test1, sizeof(int) * 4 * 5);
  int result3 = reachable_size((int *)vals, 4, 5, 2, 1);
  int answer3 = 1;
  printf("Test 3 of reachable_size returns %d, should be %d, %s\n", result3,
         answer3, (result3 == answer3 ? "CORRECT" : "WRONG"));
  memcpy(vals, test1, sizeof(int) * 4 * 5);
  int result4 = reachable_size((int *)vals, 4, 5, 0, 0);
  int answer4 = 0;
  printf("Test 4 of reachable_size returns %d, should be %d, %s\n", result4,
         answer4, (result4 == answer4 ? "CORRECT" : "WRONG"));
}


x86 assembly (clang, -O0):
<test_reachable_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
lea    0xfbc(%rip),%rsi
mov    $0x50,%edx
call   1050 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x50,%edx
call   1050 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
mov    $0x4,%esi
mov    $0x5,%edx
mov    $0x1,%r8d
mov    %r8d,%ecx
call   1040 <reachable_size@plt>
mov    %eax,-0xa4(%rbp)
movl   $0x3,-0xa8(%rbp)
mov    -0xa4(%rbp),%esi
mov    -0xa8(%rbp),%edx
mov    -0xa4(%rbp),%edi
mov    -0xa8(%rbp),%r8d
lea    0xea1(%rip),%rcx
lea    0xe92(%rip),%rax
cmp    %r8d,%edi
cmove  %rax,%rcx
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xa0(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x50,%edx
call   1050 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
mov    $0x4,%esi
mov    $0x5,%edx
mov    $0x3,%r8d
mov    %r8d,%ecx
call   1040 <reachable_size@plt>
mov    %eax,-0xac(%rbp)
movl   $0x3,-0xb0(%rbp)
mov    -0xac(%rbp),%esi
mov    -0xb0(%rbp),%edx
mov    -0xac(%rbp),%edi
mov    -0xb0(%rbp),%r8d
lea    0xe21(%rip),%rcx
lea    0xe12(%rip),%rax
cmp    %r8d,%edi
cmove  %rax,%rcx
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xa0(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x50,%edx
call   1050 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
mov    $0x4,%esi
mov    $0x5,%edx
mov    $0x2,%ecx
mov    $0x1,%r8d
call   1040 <reachable_size@plt>
mov    %eax,-0xb4(%rbp)
movl   $0x1,-0xb8(%rbp)
mov    -0xb4(%rbp),%esi
mov    -0xb8(%rbp),%edx
mov    -0xb4(%rbp),%edi
mov    -0xb8(%rbp),%r8d
lea    0xd9f(%rip),%rcx
lea    0xd90(%rip),%rax
cmp    %r8d,%edi
cmove  %rax,%rcx
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xa0(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x50,%edx
call   1050 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
mov    $0x4,%esi
mov    $0x5,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1040 <reachable_size@plt>
mov    %eax,-0xbc(%rbp)
movl   $0x0,-0xc0(%rbp)
mov    -0xbc(%rbp),%esi
mov    -0xc0(%rbp),%edx
mov    -0xbc(%rbp),%edi
mov    -0xc0(%rbp),%r8d
lea    0xd22(%rip),%rcx
lea    0xd13(%rip),%rax
cmp    %r8d,%edi
cmove  %rax,%rcx
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_reachable_size>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    0xfe5(%rip),%rdi
call   1030 <puts@plt>
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xec3(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xea7(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe8b(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe6f(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x50(%rsp),%r15
mov    %rsp,%r14
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x50,%edx
call   1060 <memcpy@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x5,%edx
mov    $0x1,%ecx
mov    $0x1,%r8d
call   1050 <reachable_size@plt>
cmp    $0x3,%eax
lea    0xeb3(%rip),%r12
lea    0xeb4(%rip),%rbx
mov    %rbx,%rcx
cmove  %r12,%rcx
lea    0xe67(%rip),%rdi
mov    %eax,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x50,%edx
call   1060 <memcpy@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x5,%edx
mov    $0x3,%ecx
mov    $0x3,%r8d
call   1050 <reachable_size@plt>
cmp    $0x3,%eax
mov    %rbx,%rcx
cmove  %r12,%rcx
lea    0xe60(%rip),%rdi
mov    %eax,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x50,%edx
call   1060 <memcpy@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x5,%edx
mov    $0x2,%ecx
mov    $0x1,%r8d
call   1050 <reachable_size@plt>
cmp    $0x1,%eax
mov    %rbx,%rcx
cmove  %r12,%rcx
lea    0xe4b(%rip),%rdi
mov    %eax,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x50,%edx
call   1060 <memcpy@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x5,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <reachable_size@plt>
test   %eax,%eax
cmove  %r12,%rbx
lea    0xe40(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [36 x i8] c"TESTING PROBLEM 5: reachable_size\0A\0A\00"
@__const.test_reachable_size.test1 = [4 x [5 x i32]] [[5 x i32] [i32 1, i32 1, i32 1, i32 1, i32 1], [5 x i32] [i32 1, i32 0, i32 1, i32 0, i32 1], [5 x i32] [i32 1, i32 0, i32 1, i32 1, i32 1], [5 x i32] [i32 1, i32 1, i32 1, i32 0, i32 1]]
@.str.1 = [55 x i8] c"Test 1 of reachable_size returns %d, should be %d, %s\0A\00"
@.str.2 = [8 x i8] c"CORRECT\00"
@.str.3 = [6 x i8] c"WRONG\00"
@.str.4 = [55 x i8] c"Test 2 of reachable_size returns %d, should be %d, %s\0A\00"
@.str.5 = [55 x i8] c"Test 3 of reachable_size returns %d, should be %d, %s\0A\00"
@.str.6 = [55 x i8] c"Test 4 of reachable_size returns %d, should be %d, %s\0A\00"
define void @test_reachable_size() {
%1 = alloca [4 x [5 x i32]]
%2 = alloca [4 x [5 x i32]]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%12 = bitcast [4 x [5 x i32]]* %1 to i8*
%13 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %2, i64 0, i64 0
%14 = bitcast [5 x i32]* %13 to i32**
%15 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %1, i64 0, i64 0
%16 = bitcast [5 x i32]* %15 to i32**
%17 = call i32 @memcpy(i32** %14, i32** %16, i32 80)
%18 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %2, i64 0, i64 0
%19 = bitcast [5 x i32]* %18 to i32*
%20 = call i32 @reachable_size(i32* %19, i32 4, i32 5, i32 1, i32 1)
store i32 %20, i32* %3
store i32 3, i32* %4
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = icmp eq i32 %23, %24
%26 = zext i1 %25 to i64
%27 = select i1 %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22, i8* %27)
%29 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %2, i64 0, i64 0
%30 = bitcast [5 x i32]* %29 to i32**
%31 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %1, i64 0, i64 0
%32 = bitcast [5 x i32]* %31 to i32**
%33 = call i32 @memcpy(i32** %30, i32** %32, i32 80)
%34 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %2, i64 0, i64 0
%35 = bitcast [5 x i32]* %34 to i32*
%36 = call i32 @reachable_size(i32* %35, i32 4, i32 5, i32 3, i32 3)
store i32 %36, i32* %5
store i32 3, i32* %6
%37 = load i32, i32* %5
%38 = load i32, i32* %6
%39 = load i32, i32* %5
%40 = load i32, i32* %6
%41 = icmp eq i32 %39, %40
%42 = zext i1 %41 to i64
%43 = select i1 %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i32 %37, i32 %38, i8* %43)
%45 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %2, i64 0, i64 0
%46 = bitcast [5 x i32]* %45 to i32**
%47 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %1, i64 0, i64 0
%48 = bitcast [5 x i32]* %47 to i32**
%49 = call i32 @memcpy(i32** %46, i32** %48, i32 80)
%50 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %2, i64 0, i64 0
%51 = bitcast [5 x i32]* %50 to i32*
%52 = call i32 @reachable_size(i32* %51, i32 4, i32 5, i32 2, i32 1)
store i32 %52, i32* %7
store i32 1, i32* %8
%53 = load i32, i32* %7
%54 = load i32, i32* %8
%55 = load i32, i32* %7
%56 = load i32, i32* %8
%57 = icmp eq i32 %55, %56
%58 = zext i1 %57 to i64
%59 = select i1 %57, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i32 %53, i32 %54, i8* %59)
%61 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %2, i64 0, i64 0
%62 = bitcast [5 x i32]* %61 to i32**
%63 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %1, i64 0, i64 0
%64 = bitcast [5 x i32]* %63 to i32**
%65 = call i32 @memcpy(i32** %62, i32** %64, i32 80)
%66 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %2, i64 0, i64 0
%67 = bitcast [5 x i32]* %66 to i32*
%68 = call i32 @reachable_size(i32* %67, i32 4, i32 5, i32 0, i32 0)
store i32 %68, i32* %9
store i32 0, i32* %10
%69 = load i32, i32* %9
%70 = load i32, i32* %10
%71 = load i32, i32* %9
%72 = load i32, i32* %10
%73 = icmp eq i32 %71, %72
%74 = zext i1 %73 to i64
%75 = select i1 %73, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), i32 %69, i32 %70, i8* %75)
ret void
}

LLVM IR (-O2):
@__const.test_reachable_size.test1 = [4 x [5 x i32]] [[5 x i32] [i32 1, i32 1, i32 1, i32 1, i32 1], [5 x i32] [i32 1, i32 0, i32 1, i32 0, i32 1], [5 x i32] [i32 1, i32 0, i32 1, i32 1, i32 1], [5 x i32] [i32 1, i32 1, i32 1, i32 0, i32 1]]
@.str.1 = [55 x i8] c"Test 1 of reachable_size returns %d, should be %d, %s\0A\00"
@.str.2 = [8 x i8] c"CORRECT\00"
@.str.3 = [6 x i8] c"WRONG\00"
@.str.4 = [55 x i8] c"Test 2 of reachable_size returns %d, should be %d, %s\0A\00"
@.str.5 = [55 x i8] c"Test 3 of reachable_size returns %d, should be %d, %s\0A\00"
@.str.6 = [55 x i8] c"Test 4 of reachable_size returns %d, should be %d, %s\0A\00"
@str = [35 x i8] c"TESTING PROBLEM 5: reachable_size\0A\00"
define void @test_reachable_size() {
%1 = alloca [4 x [5 x i32]]
%2 = alloca [4 x [5 x i32]]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%4 = bitcast [4 x [5 x i32]]* %1 to i8*
%5 = bitcast [4 x [5 x i32]]* %2 to i8*
%6 = bitcast [4 x [5 x i32]]* %2 to i32**
%7 = bitcast [4 x [5 x i32]]* %1 to i32**
%8 = call i32 @memcpy(i32** %6, i32** %7, i32 80)
%9 = getelementptr inbounds [4 x [5 x i32]], [4 x [5 x i32]]* %2, i64 0, i64 0, i64 0
%10 = call i32 @reachable_size(i32* %9, i32 4, i32 5, i32 1, i32 1)
%11 = icmp eq i32 %10, 3
%12 = select i1 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 3, i8* %12)
%14 = call i32 @memcpy(i32** %6, i32** %7, i32 80)
%15 = call i32 @reachable_size(i32* %9, i32 4, i32 5, i32 3, i32 3)
%16 = icmp eq i32 %15, 3
%17 = select i1 %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i32 %15, i32 3, i8* %17)
%19 = call i32 @memcpy(i32** %6, i32** %7, i32 80)
%20 = call i32 @reachable_size(i32* %9, i32 4, i32 5, i32 2, i32 1)
%21 = icmp eq i32 %20, 1
%22 = select i1 %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i32 %20, i32 1, i8* %22)
%24 = call i32 @memcpy(i32** %6, i32** %7, i32 80)
%25 = call i32 @reachable_size(i32* %9, i32 4, i32 5, i32 0, i32 0)
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0), i32 %25, i32 0, i8* %27)
ret void
}