#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*/ execute_parallel(int, int **, int);
int /*<<< orphan*/ execute_serial(int, int **);
int /*<<< orphan*/ fail(int, char *, char *);
int **initialize_matrix(int, int **);
void *compare_serial_parallel_exec(void *args) {
  int mat[4][4] = {{0, 1, 4, 6}, {1, 0, 4, 8}, {4, 4, 0, 1}, {6, 8, 1, 0}};
  int **arr_ser = initialize_matrix(4, mat);
  int **arr_par = initialize_matrix(4, mat);
  execute_serial(4, arr_ser);
  execute_parallel(4, arr_par, 4);
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (arr_ser[i][j] != arr_par[i][j]) {
        fail(-1, "compare_serial_parallel_exec",
             "Parallel results did not match serial execution result.");
      }
    }
  }
  return (NULL);
}


x86 assembly (clang, -O0):
<compare_serial_parallel_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe99(%rip),%rsi
mov    $0x40,%edx
call   1060 <memcpy@plt>
lea    -0x50(%rbp),%rsi
mov    $0x4,%edi
call   1070 <initialize_matrix@plt>
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rsi
mov    $0x4,%edi
call   1070 <initialize_matrix@plt>
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rsi
mov    $0x4,%edi
call   1050 <execute_serial@plt>
mov    -0x60(%rbp),%rsi
mov    $0x4,%edx
mov    %edx,%edi
call   1040 <execute_parallel@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x4,-0x64(%rbp)
jge    123f <compare_serial_parallel_exec+0xef>
movl   $0x0,-0x68(%rbp)
cmpl   $0x4,-0x68(%rbp)
jge    122c <compare_serial_parallel_exec+0xdc>
mov    -0x58(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x68(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x60(%rbp),%rcx
movslq -0x64(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
movslq -0x68(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
je     1219 <compare_serial_parallel_exec+0xc9>
mov    $0xffffffff,%edi
lea    0xe33(%rip),%rsi
lea    0xe49(%rip),%rdx
call   1030 <fail@plt>
jmp    121e <compare_serial_parallel_exec+0xce>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11cb <compare_serial_parallel_exec+0x7b>
jmp    1231 <compare_serial_parallel_exec+0xe1>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11ba <compare_serial_parallel_exec+0x6a>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_serial_parallel_exec>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
movaps 0xedc(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xec0(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xea4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe88(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    $0x4,%edi
mov    %rbx,%rsi
call   1060 <initialize_matrix@plt>
mov    %rax,%r14
mov    $0x4,%edi
mov    %rbx,%rsi
call   1060 <initialize_matrix@plt>
mov    %rax,%r13
mov    $0x4,%edi
mov    %r14,%rsi
call   1050 <execute_serial@plt>
mov    $0x4,%edi
mov    %r13,%rsi
mov    $0x4,%edx
call   1040 <execute_parallel@plt>
xor    %ebx,%ebx
lea    0xe79(%rip),%r15
lea    0xe8f(%rip),%r12
jmp    11de <compare_serial_parallel_exec+0x9e>
add    $0x1,%rbx
cmp    $0x4,%rbx
je     1265 <compare_serial_parallel_exec+0x125>
mov    (%r14,%rbx,8),%rax
mov    (%rax),%edx
mov    0x0(%r13,%rbx,8),%rcx
cmp    (%rcx),%edx
je     1206 <compare_serial_parallel_exec+0xc6>
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <fail@plt>
mov    (%r14,%rbx,8),%rax
mov    0x0(%r13,%rbx,8),%rcx
mov    0x4(%rax),%edx
cmp    0x4(%rcx),%edx
je     1227 <compare_serial_parallel_exec+0xe7>
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <fail@plt>
mov    (%r14,%rbx,8),%rax
mov    0x0(%r13,%rbx,8),%rcx
mov    0x8(%rax),%edx
cmp    0x8(%rcx),%edx
je     1248 <compare_serial_parallel_exec+0x108>
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <fail@plt>
mov    (%r14,%rbx,8),%rax
mov    0x0(%r13,%rbx,8),%rcx
mov    0xc(%rax),%eax
cmp    0xc(%rcx),%eax
je     11d0 <compare_serial_parallel_exec+0x90>
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <fail@plt>
jmp    11d0 <compare_serial_parallel_exec+0x90>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.compare_serial_parallel_exec.mat = [4 x [4 x i32]] [[4 x i32] [i32 0, i32 1, i32 4, i32 6], [4 x i32] [i32 1, i32 0, i32 4, i32 8], [4 x i32] [i32 4, i32 4, i32 0, i32 1], [4 x i32] [i32 6, i32 8, i32 1, i32 0]]
@.str = [29 x i8] c"compare_serial_parallel_exec\00"
@.str.1 = [56 x i8] c"Parallel results did not match serial execution result.\00"
define i8* @compare_serial_parallel_exec(i8* %0) {
%2 = alloca i8*
%3 = alloca [4 x [4 x i32]]
%4 = alloca i32**
%5 = alloca i32**
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = bitcast [4 x [4 x i32]]* %3 to i8*
%9 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 0
%10 = bitcast [4 x i32]* %9 to i32**
%11 = call i32** @initialize_matrix(i32 4, i32** %10)
store i32** %11, i32*** %4
%12 = getelementptr inbounds [4 x [4 x i32]], [4 x [4 x i32]]* %3, i64 0, i64 0
%13 = bitcast [4 x i32]* %12 to i32**
%14 = call i32** @initialize_matrix(i32 4, i32** %13)
store i32** %14, i32*** %5
%15 = load i32**, i32*** %4
%16 = call i32 @execute_serial(i32 4, i32** %15)
%17 = load i32**, i32*** %5
%18 = call i32 @execute_parallel(i32 4, i32** %17, i32 4)
store i32 0, i32* %6
br label %19
19: ; preds = %53, %1
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 4
br i1 %21, label %22, label %56
22: ; preds = %19
store i32 0, i32* %7
br label %23
23: ; preds = %49, %22
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 4
br i1 %25, label %26, label %52
26: ; preds = %23
%27 = load i32**, i32*** %4
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32*, i32** %27, i64 %29
%31 = load i32*, i32** %30
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = load i32**, i32*** %5
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32*, i32** %36, i64 %38
%40 = load i32*, i32** %39
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = icmp ne i32 %35, %44
br i1 %45, label %46, label %48
46: ; preds = %26
%47 = call i32 @fail(i32 -1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %46, %26
br label %49
49: ; preds = %48
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %23
52: ; preds = %23
br label %53
53: ; preds = %52
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
store i32 %55, i32* %6
br label %19
56: ; preds = %19
ret i8* null
}

LLVM IR (-O2):
@__const.compare_serial_parallel_exec.mat = [4 x [4 x i32]] [[4 x i32] [i32 0, i32 1, i32 4, i32 6], [4 x i32] [i32 1, i32 0, i32 4, i32 8], [4 x i32] [i32 4, i32 4, i32 0, i32 1], [4 x i32] [i32 6, i32 8, i32 1, i32 0]]
@.str = [29 x i8] c"compare_serial_parallel_exec\00"
@.str.1 = [56 x i8] c"Parallel results did not match serial execution result.\00"
define noalias i8* @compare_serial_parallel_exec(i8* nocapture readnone %0) {
%2 = alloca [4 x [4 x i32]]
%3 = bitcast [4 x [4 x i32]]* %2 to i8*
%4 = bitcast [4 x [4 x i32]]* %2 to i32**
%5 = call i32** @initialize_matrix(i32 4, i32** %4)
%6 = call i32** @initialize_matrix(i32 4, i32** %4)
%7 = call i32 @execute_serial(i32 4, i32** %5)
%8 = call i32 @execute_parallel(i32 4, i32** %6, i32 4)
br label %9
9: ; preds = %1, %57
%10 = phi i64 [ 0, %1 ], [ %58, %57 ]
%11 = getelementptr inbounds i32*, i32** %5, i64 %10
%12 = getelementptr inbounds i32*, i32** %6, i64 %10
%13 = load i32*, i32** %11
%14 = load i32, i32* %13
%15 = load i32*, i32** %12
%16 = load i32, i32* %15
%17 = icmp eq i32 %14, %16
br i1 %17, label %23, label %19
18: ; preds = %57
ret i8* null
19: ; preds = %9
%20 = call i32 @fail(i32 -1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32*, i32** %11
%22 = load i32*, i32** %12
br label %23
23: ; preds = %9, %19
%24 = phi i32* [ %15, %9 ], [ %22, %19 ]
%25 = phi i32* [ %13, %9 ], [ %21, %19 ]
%26 = getelementptr inbounds i32, i32* %25, i64 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds i32, i32* %24, i64 1
%29 = load i32, i32* %28
%30 = icmp eq i32 %27, %29
br i1 %30, label %35, label %31
31: ; preds = %23
%32 = call i32 @fail(i32 -1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32*, i32** %11
%34 = load i32*, i32** %12
br label %35
35: ; preds = %31, %23
%36 = phi i32* [ %34, %31 ], [ %24, %23 ]
%37 = phi i32* [ %33, %31 ], [ %25, %23 ]
%38 = getelementptr inbounds i32, i32* %37, i64 2
%39 = load i32, i32* %38
%40 = getelementptr inbounds i32, i32* %36, i64 2
%41 = load i32, i32* %40
%42 = icmp eq i32 %39, %41
br i1 %42, label %47, label %43
43: ; preds = %35
%44 = call i32 @fail(i32 -1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%45 = load i32*, i32** %11
%46 = load i32*, i32** %12
br label %47
47: ; preds = %43, %35
%48 = phi i32* [ %46, %43 ], [ %36, %35 ]
%49 = phi i32* [ %45, %43 ], [ %37, %35 ]
%50 = getelementptr inbounds i32, i32* %49, i64 3
%51 = load i32, i32* %50
%52 = getelementptr inbounds i32, i32* %48, i64 3
%53 = load i32, i32* %52
%54 = icmp eq i32 %51, %53
br i1 %54, label %57, label %55
55: ; preds = %47
%56 = call i32 @fail(i32 -1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
br label %57
57: ; preds = %55, %47
%58 = add nuw nsw i64 %10, 1
%59 = icmp eq i64 %58, 4
br i1 %59, label %18, label %9
}