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

@root = external hidden global %struct.Column, align 8
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@solution_count = external hidden global i32, align 4
@.str.5 = external hidden unnamed_addr constant [6 x i8], align 1
@solution = external hidden global [1000 x ptr], align 16
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1

; 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
declare dso_local ptr @choose_column() #1

; Function Attrs: nounwind uwtable
declare dso_local void @cover(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @uncover(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @search(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  %10 = load ptr, ptr getelementptr inbounds (%struct.Node, ptr @root, i32 0, i32 1), align 8, !tbaa !9
  %11 = icmp eq ptr %10, @root
  br i1 %11, label %12, label %50

12:                                               ; preds = %1
  %13 = load i32, ptr @solution_count, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr @solution_count, align 4, !tbaa !5
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %14)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %46, %12
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %49

21:                                               ; preds = %16
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1000 x ptr], ptr @solution, i64 0, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  store ptr %26, ptr %4, align 8, !tbaa !13
  br label %27

27:                                               ; preds = %37, %21
  %28 = load ptr, ptr %4, align 8, !tbaa !13
  %29 = getelementptr inbounds %struct.Node, ptr %28, i32 0, i32 4
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = getelementptr inbounds %struct.Column, ptr %30, i32 0, i32 2
  %32 = getelementptr inbounds [20 x i8], ptr %31, i64 0, i64 0
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %32)
  %34 = load ptr, ptr %4, align 8, !tbaa !13
  %35 = getelementptr inbounds %struct.Node, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  store ptr %36, ptr %4, align 8, !tbaa !13
  br label %37

37:                                               ; preds = %27
  %38 = load ptr, ptr %4, align 8, !tbaa !13
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [1000 x ptr], ptr @solution, i64 0, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = icmp ne ptr %38, %42
  br i1 %43, label %27, label %44, !llvm.loop !16

44:                                               ; preds = %37
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %46

46:                                               ; preds = %44
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %3, align 4, !tbaa !5
  br label %16, !llvm.loop !18

49:                                               ; preds = %20
  br label %121

50:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %51 = call ptr @choose_column()
  store ptr %51, ptr %5, align 8, !tbaa !13
  %52 = load ptr, ptr %5, align 8, !tbaa !13
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %59

54:                                               ; preds = %50
  %55 = load ptr, ptr %5, align 8, !tbaa !13
  %56 = getelementptr inbounds %struct.Column, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 8, !tbaa !19
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %54, %50
  store i32 1, ptr %6, align 4
  br label %119

60:                                               ; preds = %54
  %61 = load ptr, ptr %5, align 8, !tbaa !13
  call void @cover(ptr noundef %61)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %62 = load ptr, ptr %5, align 8, !tbaa !13
  %63 = getelementptr inbounds %struct.Column, ptr %62, i32 0, i32 0
  %64 = getelementptr inbounds %struct.Node, ptr %63, i32 0, i32 3
  %65 = load ptr, ptr %64, align 8, !tbaa !20
  store ptr %65, ptr %7, align 8, !tbaa !13
  br label %66

66:                                               ; preds = %113, %60
  %67 = load ptr, ptr %7, align 8, !tbaa !13
  %68 = load ptr, ptr %5, align 8, !tbaa !13
  %69 = getelementptr inbounds %struct.Column, ptr %68, i32 0, i32 0
  %70 = icmp ne ptr %67, %69
  br i1 %70, label %72, label %71

71:                                               ; preds = %66
  store i32 7, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %117

72:                                               ; preds = %66
  %73 = load ptr, ptr %7, align 8, !tbaa !13
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [1000 x ptr], ptr @solution, i64 0, i64 %75
  store ptr %73, ptr %76, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %77 = load ptr, ptr %7, align 8, !tbaa !13
  %78 = getelementptr inbounds %struct.Node, ptr %77, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8, !tbaa !15
  store ptr %79, ptr %8, align 8, !tbaa !13
  br label %80

80:                                               ; preds = %89, %72
  %81 = load ptr, ptr %8, align 8, !tbaa !13
  %82 = load ptr, ptr %7, align 8, !tbaa !13
  %83 = icmp ne ptr %81, %82
  br i1 %83, label %85, label %84

84:                                               ; preds = %80
  store i32 10, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %93

85:                                               ; preds = %80
  %86 = load ptr, ptr %8, align 8, !tbaa !13
  %87 = getelementptr inbounds %struct.Node, ptr %86, i32 0, i32 4
  %88 = load ptr, ptr %87, align 8, !tbaa !14
  call void @cover(ptr noundef %88)
  br label %89

89:                                               ; preds = %85
  %90 = load ptr, ptr %8, align 8, !tbaa !13
  %91 = getelementptr inbounds %struct.Node, ptr %90, i32 0, i32 1
  %92 = load ptr, ptr %91, align 8, !tbaa !15
  store ptr %92, ptr %8, align 8, !tbaa !13
  br label %80, !llvm.loop !21

93:                                               ; preds = %84
  %94 = load i32, ptr %2, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  call void @search(i32 noundef %95)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %96 = load ptr, ptr %7, align 8, !tbaa !13
  %97 = getelementptr inbounds %struct.Node, ptr %96, i32 0, i32 0
  %98 = load ptr, ptr %97, align 8, !tbaa !22
  store ptr %98, ptr %9, align 8, !tbaa !13
  br label %99

99:                                               ; preds = %108, %93
  %100 = load ptr, ptr %9, align 8, !tbaa !13
  %101 = load ptr, ptr %7, align 8, !tbaa !13
  %102 = icmp ne ptr %100, %101
  br i1 %102, label %104, label %103

103:                                              ; preds = %99
  store i32 13, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %112

104:                                              ; preds = %99
  %105 = load ptr, ptr %9, align 8, !tbaa !13
  %106 = getelementptr inbounds %struct.Node, ptr %105, i32 0, i32 4
  %107 = load ptr, ptr %106, align 8, !tbaa !14
  call void @uncover(ptr noundef %107)
  br label %108

108:                                              ; preds = %104
  %109 = load ptr, ptr %9, align 8, !tbaa !13
  %110 = getelementptr inbounds %struct.Node, ptr %109, i32 0, i32 0
  %111 = load ptr, ptr %110, align 8, !tbaa !22
  store ptr %111, ptr %9, align 8, !tbaa !13
  br label %99, !llvm.loop !23

112:                                              ; preds = %103
  br label %113

113:                                              ; preds = %112
  %114 = load ptr, ptr %7, align 8, !tbaa !13
  %115 = getelementptr inbounds %struct.Node, ptr %114, i32 0, i32 3
  %116 = load ptr, ptr %115, align 8, !tbaa !24
  store ptr %116, ptr %7, align 8, !tbaa !13
  br label %66, !llvm.loop !25

117:                                              ; preds = %71
  %118 = load ptr, ptr %5, align 8, !tbaa !13
  call void @uncover(ptr noundef %118)
  store i32 0, ptr %6, align 4
  br label %119

119:                                              ; preds = %117, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %120 = load i32, ptr %6, align 4
  switch i32 %120, label %122 [
    i32 0, label %121
    i32 1, label %121
  ]

121:                                              ; preds = %119, %119, %49
  ret void

122:                                              ; preds = %119
  unreachable
}

declare i32 @printf(ptr noundef, ...) #2

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


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

%struct.Column = type { %struct.Node, i32, [20 x i8] }
%struct.Node = type { ptr, ptr, ptr, ptr, ptr }

@root = external hidden global %struct.Column, align 8
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@solution_count = external hidden local_unnamed_addr global i32, align 4
@.str.5 = external hidden unnamed_addr constant [6 x i8], align 1
@solution = external hidden local_unnamed_addr global [1000 x ptr], align 16
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @choose_column() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @cover(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @uncover(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @search(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr getelementptr inbounds (i8, ptr @root, i64 8), align 8, !tbaa !5
  %3 = icmp eq ptr %2, @root
  br i1 %3, label %4, label %22

4:                                                ; preds = %1
  %5 = load i32, ptr @solution_count, align 4, !tbaa !12
  %6 = add nsw i32 %5, 1
  store i32 %6, ptr @solution_count, align 4, !tbaa !12
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %6)
  %8 = icmp sgt i32 %0, 0
  br i1 %8, label %.lr.ph56.preheader, label %.loopexit

.lr.ph56.preheader:                               ; preds = %4
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.lr.ph56

.lr.ph56:                                         ; preds = %.lr.ph56.preheader, %20
  %indvars.iv = phi i64 [ 0, %.lr.ph56.preheader ], [ %indvars.iv.next, %20 ]
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %10 = getelementptr inbounds [1000 x ptr], ptr @solution, i64 0, i64 %indvars.iv
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  br label %12

12:                                               ; preds = %12, %.lr.ph56
  %.031 = phi ptr [ %11, %.lr.ph56 ], [ %18, %12 ]
  %13 = getelementptr inbounds i8, ptr %.031, i64 32
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %14, i64 44
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef nonnull %15)
  %17 = getelementptr inbounds i8, ptr %.031, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = load ptr, ptr %10, align 8, !tbaa !13
  %.not36 = icmp eq ptr %18, %19
  br i1 %.not36, label %20, label %12, !llvm.loop !16

20:                                               ; preds = %12
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph56, !llvm.loop !18

22:                                               ; preds = %1
  %23 = tail call ptr @choose_column()
  %.not = icmp eq ptr %23, null
  br i1 %.not, label %.loopexit, label %24

24:                                               ; preds = %22
  %25 = getelementptr inbounds i8, ptr %23, i64 40
  %26 = load i32, ptr %25, align 8, !tbaa !19
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %.loopexit, label %28

28:                                               ; preds = %24
  tail call void @cover(ptr noundef nonnull %23)
  %.029.in47 = getelementptr inbounds i8, ptr %23, i64 24
  %.02948 = load ptr, ptr %.029.in47, align 8, !tbaa !20
  %.not3349 = icmp eq ptr %.02948, %23
  br i1 %.not3349, label %._crit_edge53, label %.lr.ph52

.lr.ph52:                                         ; preds = %28
  %29 = sext i32 %0 to i64
  %30 = getelementptr inbounds [1000 x ptr], ptr @solution, i64 0, i64 %29
  %31 = add nsw i32 %0, 1
  br label %32

.loopexit37:                                      ; preds = %.lr.ph46, %._crit_edge
  %.029.in = getelementptr inbounds i8, ptr %.02950, i64 24
  %.029 = load ptr, ptr %.029.in, align 8, !tbaa !20
  %.not33 = icmp eq ptr %.029, %23
  br i1 %.not33, label %._crit_edge53, label %32, !llvm.loop !21

._crit_edge53:                                    ; preds = %.loopexit37, %28
  tail call void @uncover(ptr noundef nonnull %23)
  br label %.loopexit

32:                                               ; preds = %.lr.ph52, %.loopexit37
  %.02950 = phi ptr [ %.02948, %.lr.ph52 ], [ %.029, %.loopexit37 ]
  store ptr %.02950, ptr %30, align 8, !tbaa !13
  %.028.in38 = getelementptr inbounds i8, ptr %.02950, i64 8
  %.02839 = load ptr, ptr %.028.in38, align 8, !tbaa !15
  %.not3440 = icmp eq ptr %.02839, %.02950
  br i1 %.not3440, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %32
  tail call void @search(i32 noundef %31)
  %.042 = load ptr, ptr %.02950, align 8, !tbaa !22
  %.not3543 = icmp eq ptr %.042, %.02950
  br i1 %.not3543, label %.loopexit37, label %.lr.ph46

.lr.ph:                                           ; preds = %32, %.lr.ph
  %.02841 = phi ptr [ %.028, %.lr.ph ], [ %.02839, %32 ]
  %33 = getelementptr inbounds i8, ptr %.02841, i64 32
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  tail call void @cover(ptr noundef %34)
  %.028.in = getelementptr inbounds i8, ptr %.02841, i64 8
  %.028 = load ptr, ptr %.028.in, align 8, !tbaa !15
  %.not34 = icmp eq ptr %.028, %.02950
  br i1 %.not34, label %._crit_edge, label %.lr.ph, !llvm.loop !23

.lr.ph46:                                         ; preds = %._crit_edge, %.lr.ph46
  %.044 = phi ptr [ %.0, %.lr.ph46 ], [ %.042, %._crit_edge ]
  %35 = getelementptr inbounds i8, ptr %.044, i64 32
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  tail call void @uncover(ptr noundef %36)
  %.0 = load ptr, ptr %.044, align 8, !tbaa !22
  %.not35 = icmp eq ptr %.0, %.02950
  br i1 %.not35, label %.loopexit37, label %.lr.ph46, !llvm.loop !24

.loopexit:                                        ; preds = %20, %4, %._crit_edge53, %24, %22
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { 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 #1 = { nofree nounwind "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 8}
!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 = !{!11, !11, i64 0}
!13 = !{!8, !8, i64 0}
!14 = !{!7, !8, i64 32}
!15 = !{!7, !8, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = !{!6, !11, i64 40}
!20 = !{!7, !8, i64 24}
!21 = distinct !{!21, !17}
!22 = !{!7, !8, i64 0}
!23 = distinct !{!23, !17}
!24 = distinct !{!24, !17}


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