; LLVM IR from PrantikGhosh/SudokuSolver-using-DIP-OpenCV :: sudoku_solver_16.ll (Z20MapSolutionToGrid_16PA16_i)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.Node = type { ptr, ptr, ptr, ptr, ptr, i32, [3 x i32] }

@solution_16 = external dso_local global [1000 x ptr], align 16
@orig_values_16 = external dso_local global [1000 x ptr], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z20MapSolutionToGrid_16PA16_i(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %41, %1
  %6 = load i32, ptr %3, align 4, !tbaa !9
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [1000 x ptr], ptr @solution_16, i64 0, i64 %7
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %44

12:                                               ; preds = %5
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1000 x ptr], ptr @solution_16, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Node, ptr %16, i32 0, i32 6
  %18 = getelementptr inbounds [3 x i32], ptr %17, i64 0, i64 0
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1000 x ptr], ptr @solution_16, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Node, ptr %24, i32 0, i32 6
  %26 = getelementptr inbounds [3 x i32], ptr %25, i64 0, i64 1
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = sub nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [16 x i32], ptr %20, i64 %29
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1000 x ptr], ptr @solution_16, i64 0, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Node, ptr %34, i32 0, i32 6
  %36 = getelementptr inbounds [3 x i32], ptr %35, i64 0, i64 2
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [16 x i32], ptr %30, i64 0, i64 %39
  store i32 %19, ptr %40, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %12
  %42 = load i32, ptr %3, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %3, align 4, !tbaa !9
  br label %5, !llvm.loop !11

44:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %81, %44
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1000 x ptr], ptr @orig_values_16, i64 0, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %52, label %51

51:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %84

52:                                               ; preds = %45
  %53 = load i32, ptr %4, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [1000 x ptr], ptr @orig_values_16, i64 0, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.Node, ptr %56, i32 0, i32 6
  %58 = getelementptr inbounds [3 x i32], ptr %57, i64 0, i64 0
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = load i32, ptr %4, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [1000 x ptr], ptr @orig_values_16, i64 0, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.Node, ptr %64, i32 0, i32 6
  %66 = getelementptr inbounds [3 x i32], ptr %65, i64 0, i64 1
  %67 = load i32, ptr %66, align 4, !tbaa !9
  %68 = sub nsw i32 %67, 1
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [16 x i32], ptr %60, i64 %69
  %71 = load i32, ptr %4, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [1000 x ptr], ptr @orig_values_16, i64 0, i64 %72
  %74 = load ptr, ptr %73, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.Node, ptr %74, i32 0, i32 6
  %76 = getelementptr inbounds [3 x i32], ptr %75, i64 0, i64 2
  %77 = load i32, ptr %76, align 4, !tbaa !9
  %78 = sub nsw i32 %77, 1
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [16 x i32], ptr %70, i64 0, i64 %79
  store i32 %59, ptr %80, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %52
  %82 = load i32, ptr %4, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %4, align 4, !tbaa !9
  br label %45, !llvm.loop !13

84:                                               ; preds = %51
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@solution_16 = external dso_local local_unnamed_addr global [1000 x ptr], align 16
@orig_values_16 = external dso_local local_unnamed_addr global [1000 x ptr], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z20MapSolutionToGrid_16PA16_i(ptr nocapture noundef writeonly %0) local_unnamed_addr #0 {
  %invariant.gep = getelementptr i8, ptr %0, i64 -64
  %2 = load ptr, ptr @solution_16, align 16, !tbaa !5
  %.not15 = icmp eq ptr %2, null
  br i1 %.not15, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %1
  %3 = load ptr, ptr @orig_values_16, align 16, !tbaa !5
  %.not1419 = icmp eq ptr %3, null
  br i1 %.not1419, label %._crit_edge, label %.lr.ph21

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %4 = phi ptr [ %16, %.lr.ph ], [ %2, %1 ]
  %5 = getelementptr inbounds i8, ptr %4, i64 44
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %4, i64 48
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds i8, ptr %4, i64 52
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = add nsw i32 %11, -1
  %13 = sext i32 %12 to i64
  %14 = getelementptr nusw [16 x i32], ptr %invariant.gep, i64 %9, i64 %13
  store i32 %6, ptr %14, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = getelementptr inbounds [1000 x ptr], ptr @solution_16, i64 0, i64 %indvars.iv.next
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph21, %.preheader
  ret void

.lr.ph21:                                         ; preds = %.preheader, %.lr.ph21
  %indvars.iv23 = phi i64 [ %indvars.iv.next24, %.lr.ph21 ], [ 0, %.preheader ]
  %17 = phi ptr [ %29, %.lr.ph21 ], [ %3, %.preheader ]
  %18 = getelementptr inbounds i8, ptr %17, i64 44
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %17, i64 48
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %17, i64 52
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = add nsw i32 %24, -1
  %26 = sext i32 %25 to i64
  %27 = getelementptr nusw [16 x i32], ptr %invariant.gep, i64 %22, i64 %26
  store i32 %19, ptr %27, align 4, !tbaa !9
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %28 = getelementptr inbounds [1000 x ptr], ptr @orig_values_16, i64 0, i64 %indvars.iv.next24
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %.not14 = icmp eq ptr %29, null
  br i1 %.not14, label %._crit_edge, label %.lr.ph21, !llvm.loop !13
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass