; 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
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [46 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

5:                                                ; preds = %52, %1
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %11 = call noalias ptr @malloc(i64 noundef 64) #6
  store ptr %11, ptr %4, align 8, !tbaa !14
  %12 = load ptr, ptr %4, align 8, !tbaa !14
  %13 = icmp ne ptr %12, null
  br i1 %13, label %17, label %14

14:                                               ; preds = %10
  %15 = load ptr, ptr @stderr, align 8, !tbaa !14
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str) #5
  call void @exit(i32 noundef 1) #7
  unreachable

17:                                               ; preds = %10
  %18 = load ptr, ptr %4, align 8, !tbaa !14
  %19 = getelementptr inbounds %struct.Column, ptr %18, i32 0, i32 1
  store i32 0, ptr %19, align 8, !tbaa !15
  %20 = load ptr, ptr %4, align 8, !tbaa !14
  %21 = getelementptr inbounds %struct.Column, ptr %20, i32 0, i32 2
  %22 = getelementptr inbounds [20 x i8], ptr %21, i64 0, i64 0
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %22, i64 noundef 20, ptr noundef @.str.1, i32 noundef %23) #5
  %25 = load ptr, ptr %4, align 8, !tbaa !14
  %26 = getelementptr inbounds %struct.Column, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %4, align 8, !tbaa !14
  %28 = getelementptr inbounds %struct.Column, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds %struct.Node, ptr %28, i32 0, i32 2
  store ptr %26, ptr %29, align 8, !tbaa !16
  %30 = load ptr, ptr %4, align 8, !tbaa !14
  %31 = getelementptr inbounds %struct.Column, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %4, align 8, !tbaa !14
  %33 = getelementptr inbounds %struct.Column, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %struct.Node, ptr %33, i32 0, i32 3
  store ptr %31, ptr %34, align 8, !tbaa !17
  %35 = load ptr, ptr %4, align 8, !tbaa !14
  %36 = load ptr, ptr %4, align 8, !tbaa !14
  %37 = getelementptr inbounds %struct.Column, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds %struct.Node, ptr %37, i32 0, i32 4
  store ptr %35, ptr %38, align 8, !tbaa !18
  %39 = load ptr, ptr getelementptr inbounds (%struct.Node, ptr @root, i32 0, i32 1), align 8, !tbaa !9
  %40 = load ptr, ptr %4, align 8, !tbaa !14
  %41 = getelementptr inbounds %struct.Column, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds %struct.Node, ptr %41, i32 0, i32 1
  store ptr %39, ptr %42, align 8, !tbaa !9
  %43 = load ptr, ptr %4, align 8, !tbaa !14
  %44 = getelementptr inbounds %struct.Column, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds %struct.Node, ptr %44, i32 0, i32 0
  store ptr @root, ptr %45, align 8, !tbaa !13
  %46 = load ptr, ptr %4, align 8, !tbaa !14
  %47 = getelementptr inbounds %struct.Column, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr getelementptr inbounds (%struct.Node, ptr @root, i32 0, i32 1), align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.Node, ptr %48, i32 0, i32 0
  store ptr %47, ptr %49, align 8, !tbaa !19
  %50 = load ptr, ptr %4, align 8, !tbaa !14
  %51 = getelementptr inbounds %struct.Column, ptr %50, i32 0, i32 0
  store ptr %51, ptr getelementptr inbounds (%struct.Node, ptr @root, i32 0, i32 1), align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %52

52:                                               ; preds = %17
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %3, align 4, !tbaa !5
  br label %5, !llvm.loop !20

55:                                               ; preds = %9
  ret void
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 #3 = { 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" }
attributes #4 = { noreturn 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" }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { noreturn 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 = !{!10, !12, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !6, i64 40}
!16 = !{!10, !12, i64 16}
!17 = !{!10, !12, i64 24}
!18 = !{!10, !12, i64 32}
!19 = !{!11, !12, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; 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
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [46 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @initialize_dlx(i32 noundef %0) local_unnamed_addr #0 {
  store ptr @root, ptr getelementptr inbounds (i8, ptr @root, i64 8), align 8, !tbaa !5
  store ptr @root, ptr @root, align 8, !tbaa !12
  %2 = icmp sgt i32 %0, 0
  br i1 %2, label %.lr.ph, label %._crit_edge

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

.lr.ph:                                           ; preds = %1, %7
  %.017 = phi i32 [ %16, %7 ], [ 0, %1 ]
  %3 = tail call noalias dereferenceable_or_null(64) ptr @malloc(i64 noundef 64) #4
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %4, label %7

4:                                                ; preds = %.lr.ph
  %5 = load ptr, ptr @stderr, align 8, !tbaa !13
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str) #5
  tail call void @exit(i32 noundef 1) #6
  unreachable

7:                                                ; preds = %.lr.ph
  %8 = getelementptr inbounds i8, ptr %3, i64 40
  store i32 0, ptr %8, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %3, i64 44
  %10 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %9, i64 noundef 20, ptr noundef nonnull @.str.1, i32 noundef %.017) #7
  %11 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %3, ptr %11, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr %3, ptr %12, align 8, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %3, i64 32
  store ptr %3, ptr %13, align 8, !tbaa !17
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @root, i64 8), align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %14, ptr %15, align 8, !tbaa !5
  store ptr @root, ptr %3, align 8, !tbaa !12
  store ptr %3, ptr %14, align 8, !tbaa !18
  store ptr %3, ptr getelementptr inbounds (i8, ptr @root, i64 8), align 8, !tbaa !5
  %16 = add nuw nsw i32 %.017, 1
  %exitcond.not = icmp eq i32 %16, %0
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !19
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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" }
attributes #3 = { noreturn 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" }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { cold nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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, !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 = !{!6, !8, i64 0}
!13 = !{!8, !8, i64 0}
!14 = !{!6, !11, i64 40}
!15 = !{!6, !8, i64 16}
!16 = !{!6, !8, i64 24}
!17 = !{!6, !8, i64 32}
!18 = !{!7, !8, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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