; LLVM IR from AlgoGenesis/C :: Backtracking Algorithms/Dancing Links (DLX) (program)

; 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.Column = type { %struct.Node, i32, [20 x i8] }
%struct.Node = type { ptr, ptr, ptr, ptr, ptr }

; 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: nounwind uwtable
define dso_local void @cover(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.Column, ptr %6, i32 0, i32 0
  %8 = getelementptr inbounds %struct.Node, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Column, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds %struct.Node, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds %struct.Node, ptr %13, i32 0, i32 0
  store ptr %9, ptr %14, align 8, !tbaa !14
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Column, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.Node, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Column, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %struct.Node, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.Node, ptr %22, i32 0, i32 1
  store ptr %18, ptr %23, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Column, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.Node, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  store ptr %27, ptr %3, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %69, %1
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Column, ptr %30, i32 0, i32 0
  %32 = icmp ne ptr %29, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %28
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %73

34:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Node, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  store ptr %37, ptr %5, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %64, %34
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = icmp ne ptr %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %68

43:                                               ; preds = %38
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Node, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Node, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = getelementptr inbounds %struct.Node, ptr %49, i32 0, i32 2
  store ptr %46, ptr %50, align 8, !tbaa !17
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.Node, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Node, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = getelementptr inbounds %struct.Node, ptr %56, i32 0, i32 3
  store ptr %53, ptr %57, align 8, !tbaa !18
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.Node, ptr %58, i32 0, i32 4
  %60 = load ptr, ptr %59, align 8, !tbaa !19
  %61 = getelementptr inbounds %struct.Column, ptr %60, i32 0, i32 1
  %62 = load i32, ptr %61, align 8, !tbaa !20
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr %61, align 8, !tbaa !20
  br label %64

64:                                               ; preds = %43
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.Node, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !15
  store ptr %67, ptr %5, align 8, !tbaa !5
  br label %38, !llvm.loop !21

68:                                               ; preds = %42
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.Node, ptr %70, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !18
  store ptr %72, ptr %3, align 8, !tbaa !5
  br label %28, !llvm.loop !23

73:                                               ; preds = %33
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"Column", !11, i64 0, !12, i64 40, !7, i64 44}
!11 = !{!"Node", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!11, !6, i64 0}
!15 = !{!11, !6, i64 8}
!16 = !{!10, !6, i64 24}
!17 = !{!11, !6, i64 16}
!18 = !{!11, !6, i64 24}
!19 = !{!11, !6, i64 32}
!20 = !{!10, !12, i64 40}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


; 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"

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @cover(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !12
  store ptr %2, ptr %4, align 8, !tbaa !13
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %4, ptr %5, align 8, !tbaa !14
  %.017.in23 = getelementptr inbounds i8, ptr %0, i64 24
  %.01724 = load ptr, ptr %.017.in23, align 8, !tbaa !15
  %.not25 = icmp eq ptr %.01724, %0
  br i1 %.not25, label %._crit_edge, label %.preheader

.loopexit:                                        ; preds = %.lr.ph, %.preheader
  %.017.in = getelementptr inbounds i8, ptr %.01726, i64 24
  %.017 = load ptr, ptr %.017.in, align 8, !tbaa !15
  %.not = icmp eq ptr %.017, %0
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !16

.preheader:                                       ; preds = %1, %.loopexit
  %.01726 = phi ptr [ %.017, %.loopexit ], [ %.01724, %1 ]
  %.0.in19 = getelementptr inbounds i8, ptr %.01726, i64 8
  %.020 = load ptr, ptr %.0.in19, align 8, !tbaa !14
  %.not1821 = icmp eq ptr %.020, %.01726
  br i1 %.not1821, label %.loopexit, label %.lr.ph

._crit_edge:                                      ; preds = %.loopexit, %1
  ret void

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.022 = phi ptr [ %.0, %.lr.ph ], [ %.020, %.preheader ]
  %6 = getelementptr inbounds i8, ptr %.022, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !18
  %8 = getelementptr inbounds i8, ptr %.022, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %7, ptr %10, align 8, !tbaa !18
  %11 = getelementptr inbounds i8, ptr %7, i64 24
  store ptr %9, ptr %11, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %.022, i64 32
  %13 = load ptr, ptr %12, align 8, !tbaa !19
  %14 = getelementptr inbounds i8, ptr %13, i64 40
  %15 = load i32, ptr %14, align 8, !tbaa !20
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %14, align 8, !tbaa !20
  %.0.in = getelementptr inbounds i8, ptr %.022, i64 8
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !14
  %.not18 = icmp eq ptr %.0, %.01726
  br i1 %.not18, label %.loopexit, label %.lr.ph, !llvm.loop !21
}

attributes #0 = { nofree norecurse nosync nounwind memory(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, !8, i64 0}
!6 = !{!"Column", !7, i64 0, !11, i64 40, !9, i64 44}
!7 = !{!"Node", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!6, !8, i64 8}
!13 = !{!7, !8, i64 0}
!14 = !{!7, !8, i64 8}
!15 = !{!7, !8, i64 24}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!7, !8, i64 16}
!19 = !{!7, !8, i64 32}
!20 = !{!6, !11, i64 40}
!21 = distinct !{!21, !17}


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