#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*/ fail(int, char *, char *);
int **read_array(char *, int *);
void *successful_open(void *args) {
  int dim;
  int **arr = read_array("test_data/successful_open.txt", &dim);
  int comp_arr[4][4] = {{0, 1, 2, 3}, {1, 0, 4, 5}, {2, 4, 0, 6}, {3, 5, 6, 0}};
  for (int i = 0; i < dim; i++) {
    for (int j = 0; j < dim; j++) {
      if (arr[i][j] != comp_arr[i][j]) {
        fail(-1, "successful_open", "Array did not increment correctly.");
      }
    }
  }
  return (NULL);
}


x86 assembly (clang, -O0):
<successful_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <read_array@plt>
mov    %rax,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xf05(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f8 <successful_open+0xc8>
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e5 <successful_open+0xb5>
mov    -0x18(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x68(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
movslq -0x64(%rbp),%rdx
lea    -0x60(%rbp),%rcx
shl    $0x4,%rdx
add    %rdx,%rcx
movslq -0x68(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
je     11d2 <successful_open+0xa2>
mov    $0xffffffff,%edi
lea    0xe58(%rip),%rsi
lea    0xe61(%rip),%rdx
call   1030 <fail@plt>
jmp    11d7 <successful_open+0xa7>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    117f <successful_open+0x4f>
jmp    11ea <successful_open+0xba>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    116c <successful_open+0x3c>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<successful_open>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xece(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <read_array@plt>
mov    %rax,%r12
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    11b0 <successful_open+0x90>
lea    0xf12(%rip),%r13
xor    %ebx,%ebx
lea    0xec7(%rip),%r14
lea    0xed0(%rip),%r15
jmp    1170 <successful_open+0x50>
add    $0x1,%rbx
movslq %eax,%rcx
add    $0x10,%r13
cmp    %rcx,%rbx
jge    11b0 <successful_open+0x90>
test   %eax,%eax
jle    1160 <successful_open+0x40>
xor    %ebp,%ebp
jmp    118c <successful_open+0x6c>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
movslq %eax,%rcx
cmp    %rcx,%rbp
jge    1160 <successful_open+0x40>
mov    (%r12,%rbx,8),%rcx
mov    (%rcx,%rbp,4),%ecx
cmp    0x0(%r13,%rbp,4),%ecx
je     1180 <successful_open+0x60>
mov    $0xffffffff,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <fail@plt>
mov    0x4(%rsp),%eax
jmp    1180 <successful_open+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"test_data/successful_open.txt\00"
@__const.successful_open.comp_arr = [4 x [4 x i32]] [[4 x i32] [i32 0, i32 1, i32 2, i32 3], [4 x i32] [i32 1, i32 0, i32 4, i32 5], [4 x i32] [i32 2, i32 4, i32 0, i32 6], [4 x i32] [i32 3, i32 5, i32 6, i32 0]]
@.str.1 = [16 x i8] c"successful_open\00"
@.str.2 = [35 x i8] c"Array did not increment correctly.\00"
define i8* @successful_open(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32**
%5 = alloca [4 x [4 x i32]]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = call i32** @read_array(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32** %8, i32*** %4
%9 = bitcast [4 x [4 x i32]]* %5 to i8*
store i32 0, i32* %6
br label %10
10: ; preds = %44, %1
%11 = load i32, i32* %6
%12 = load i32, i32* %3
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %47
14: ; preds = %10
store i32 0, i32* %7
br label %15
15: ; preds = %40, %14
%16 = load i32, i32* %7
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %43
19: ; preds = %15
%20 = load i32**, i32*** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32*, i32** %20, i64 %22
%24 = load i32*, i32** %23
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %5, i64 0, i64 %30
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [4 x i32], [4 x i32]* %31, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = icmp ne i32 %28, %35
br i1 %36, label %37, label %39
37: ; preds = %19
%38 = call i32 @fail(i32 -1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %19
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %15
43: ; preds = %15
br label %44
44: ; preds = %43
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %10
47: ; preds = %10
ret i8* null
}

LLVM IR (-O2):
@.str = [30 x i8] c"test_data/successful_open.txt\00"
@__const.successful_open.comp_arr = [4 x [4 x i32]] [[4 x i32] [i32 0, i32 1, i32 2, i32 3], [4 x i32] [i32 1, i32 0, i32 4, i32 5], [4 x i32] [i32 2, i32 4, i32 0, i32 6], [4 x i32] [i32 3, i32 5, i32 6, i32 0]]
@.str.1 = [16 x i8] c"successful_open\00"
@.str.2 = [35 x i8] c"Array did not increment correctly.\00"
define noalias i8* @successful_open(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32** @read_array(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32* %2)
%5 = load i32, i32* %2
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1, %14
%8 = phi i32 [ %15, %14 ], [ %5, %1 ]
%9 = phi i64 [ %16, %14 ], [ 0, %1 ]
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = getelementptr inbounds i32*, i32** %4, i64 %9
br label %19
13: ; preds = %14, %1
ret i8* null
14: ; preds = %32, %7
%15 = phi i32 [ %8, %7 ], [ %33, %32 ]
%16 = add nuw nsw i64 %9, 1
%17 = sext i32 %15 to i64
%18 = icmp slt i64 %16, %17
br i1 %18, label %7, label %13
19: ; preds = %11, %32
%20 = phi i32 [ %8, %11 ], [ %33, %32 ]
%21 = phi i32 [ %8, %11 ], [ %34, %32 ]
%22 = phi i64 [ 0, %11 ], [ %35, %32 ]
%23 = load i32*, i32** %12
%24 = getelementptr inbounds i32, i32* %23, i64 %22
%25 = load i32, i32* %24
%26 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* @__const.successful_open.comp_arr, i64 0, i64 %9, i64 %22
%27 = load i32, i32* %26
%28 = icmp eq i32 %25, %27
br i1 %28, label %32, label %29
29: ; preds = %19
%30 = call i32 @fail(i32 -1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* %2
br label %32
32: ; preds = %19, %29
%33 = phi i32 [ %20, %19 ], [ %31, %29 ]
%34 = phi i32 [ %21, %19 ], [ %31, %29 ]
%35 = add nuw nsw i64 %22, 1
%36 = sext i32 %34 to i64
%37 = icmp slt i64 %35, %36
br i1 %37, label %19, label %14
}