; LLVM IR from AlgoGenesis/C :: Dynamic Programming/Word Ladder II (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.QueueNode = type { ptr, i32, 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
declare dso_local void @enqueue(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @dequeue(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @oneLetterDifference(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @ladderLength(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %35, %4
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %12, align 4
  br label %38

24:                                               ; preds = %19
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds ptr, ptr %25, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = call i32 @strcmp(ptr noundef %29, ptr noundef %30) #5
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %24
  store i32 1, ptr %10, align 4, !tbaa !9
  store i32 2, ptr %12, align 4
  br label %38

34:                                               ; preds = %24
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %11, align 4, !tbaa !9
  br label %19, !llvm.loop !11

38:                                               ; preds = %33, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %43, label %42

42:                                               ; preds = %39
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %119

43:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store ptr null, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store ptr null, ptr %14, align 8, !tbaa !5
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  call void @enqueue(ptr noundef %13, ptr noundef %14, ptr noundef %44, i32 noundef 1)
  br label %45

45:                                               ; preds = %116, %43
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %117

48:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %49 = call ptr @dequeue(ptr noundef %13, ptr noundef %14)
  store ptr %49, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %50 = load ptr, ptr %15, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.QueueNode, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !13
  store ptr %52, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %53 = load ptr, ptr %15, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.QueueNode, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 8, !tbaa !15
  store i32 %55, ptr %17, align 4, !tbaa !9
  %56 = load ptr, ptr %16, align 8, !tbaa !5
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = call i32 @strcmp(ptr noundef %56, ptr noundef %57) #5
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %60, label %66

60:                                               ; preds = %48
  %61 = load ptr, ptr %15, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.QueueNode, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !13
  call void @free(ptr noundef %63) #4
  %64 = load ptr, ptr %15, align 8, !tbaa !5
  call void @free(ptr noundef %64) #4
  %65 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %65, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %114

66:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %106, %66
  %68 = load i32, ptr %18, align 4, !tbaa !9
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = icmp slt i32 %68, %69
  br i1 %70, label %72, label %71

71:                                               ; preds = %67
  store i32 7, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  br label %109

72:                                               ; preds = %67
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = load i32, ptr %18, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds ptr, ptr %73, i64 %75
  %77 = load ptr, ptr %76, align 8, !tbaa !5
  %78 = icmp ne ptr %77, null
  br i1 %78, label %79, label %105

79:                                               ; preds = %72
  %80 = load ptr, ptr %16, align 8, !tbaa !5
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = load i32, ptr %18, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds ptr, ptr %81, i64 %83
  %85 = load ptr, ptr %84, align 8, !tbaa !5
  %86 = call i32 @oneLetterDifference(ptr noundef %80, ptr noundef %85)
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %105

88:                                               ; preds = %79
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = load i32, ptr %18, align 4, !tbaa !9
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds ptr, ptr %89, i64 %91
  %93 = load ptr, ptr %92, align 8, !tbaa !5
  %94 = load i32, ptr %17, align 4, !tbaa !9
  %95 = add nsw i32 %94, 1
  call void @enqueue(ptr noundef %13, ptr noundef %14, ptr noundef %93, i32 noundef %95)
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = load i32, ptr %18, align 4, !tbaa !9
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds ptr, ptr %96, i64 %98
  %100 = load ptr, ptr %99, align 8, !tbaa !5
  call void @free(ptr noundef %100) #4
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = load i32, ptr %18, align 4, !tbaa !9
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds ptr, ptr %101, i64 %103
  store ptr null, ptr %104, align 8, !tbaa !5
  br label %105

105:                                              ; preds = %88, %79, %72
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %18, align 4, !tbaa !9
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %18, align 4, !tbaa !9
  br label %67, !llvm.loop !16

109:                                              ; preds = %71
  %110 = load ptr, ptr %15, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.QueueNode, ptr %110, i32 0, i32 0
  %112 = load ptr, ptr %111, align 8, !tbaa !13
  call void @free(ptr noundef %112) #4
  %113 = load ptr, ptr %15, align 8, !tbaa !5
  call void @free(ptr noundef %113) #4
  store i32 0, ptr %12, align 4
  br label %114

114:                                              ; preds = %109, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  %115 = load i32, ptr %12, align 4
  switch i32 %115, label %118 [
    i32 0, label %116
  ]

116:                                              ; preds = %114
  br label %45, !llvm.loop !17

117:                                              ; preds = %45
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %118

118:                                              ; preds = %117, %114
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %119

119:                                              ; preds = %118, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %120 = load i32, ptr %5, align 4
  ret i32 %120
}

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 willreturn memory(read) "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 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 0}
!14 = !{!"QueueNode", !6, i64 0, !10, i64 8, !6, i64 16}
!15 = !{!14, !10, i64 8}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !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"

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

; Function Attrs: mustprogress 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 void @enqueue(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @dequeue(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @oneLetterDifference(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i32 @ladderLength(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %.not45 = icmp sgt i32 %3, 0
  br i1 %.not45, label %.lr.ph.preheader, label %.critedge

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

7:                                                ; preds = %.lr.ph
  %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 %.critedge, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %.lr.ph.preheader, %7
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %7 ]
  %8 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv
  %9 = load ptr, ptr %8, align 8, !tbaa !7
  %10 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %9, ptr noundef nonnull dereferenceable(1) %1) #4
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %7

12:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  store ptr null, ptr %5, align 8, !tbaa !7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  store ptr null, ptr %6, align 8, !tbaa !7
  call void @enqueue(ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef %0, i32 noundef 1)
  %13 = load ptr, ptr %5, align 8, !tbaa !7
  %.not3849 = icmp eq ptr %13, null
  br i1 %.not3849, label %.loopexit, label %.lr.ph51.split.us

.lr.ph51.split.us:                                ; preds = %12, %._crit_edge.us
  %14 = call ptr @dequeue(ptr noundef nonnull %5, ptr noundef nonnull %6)
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %14, i64 8
  %17 = load i32, ptr %16, align 8, !tbaa !14
  %18 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %15, ptr noundef nonnull dereferenceable(1) %1) #4
  %.not41.us = icmp eq i32 %18, 0
  br i1 %.not41.us, label %.thread, label %.preheader.us

19:                                               ; preds = %.preheader.us, %27
  %indvars.iv63 = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next64, %27 ]
  %20 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv63
  %21 = load ptr, ptr %20, align 8, !tbaa !7
  %.not39.us = icmp eq ptr %21, null
  br i1 %.not39.us, label %27, label %22

22:                                               ; preds = %19
  %23 = call i32 @oneLetterDifference(ptr noundef %15, ptr noundef nonnull %21)
  %.not40.us = icmp eq i32 %23, 0
  br i1 %.not40.us, label %27, label %24

24:                                               ; preds = %22
  %25 = load ptr, ptr %20, align 8, !tbaa !7
  call void @enqueue(ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef %25, i32 noundef %28)
  %26 = load ptr, ptr %20, align 8, !tbaa !7
  call void @free(ptr noundef %26) #5
  store ptr null, ptr %20, align 8, !tbaa !7
  br label %27

27:                                               ; preds = %24, %22, %19
  %indvars.iv.next64 = add nuw nsw i64 %indvars.iv63, 1
  %exitcond67.not = icmp eq i64 %indvars.iv.next64, %wide.trip.count
  br i1 %exitcond67.not, label %._crit_edge.us, label %19, !llvm.loop !15

.preheader.us:                                    ; preds = %.lr.ph51.split.us
  %28 = add nsw i32 %17, 1
  br label %19

._crit_edge.us:                                   ; preds = %27
  %29 = load ptr, ptr %14, align 8, !tbaa !11
  call void @free(ptr noundef %29) #5
  call void @free(ptr noundef %14) #5
  %30 = load ptr, ptr %5, align 8, !tbaa !7
  %.not38.us = icmp eq ptr %30, null
  br i1 %.not38.us, label %.loopexit, label %.lr.ph51.split.us

.thread:                                          ; preds = %.lr.ph51.split.us
  call void @free(ptr noundef %15) #5
  call void @free(ptr noundef nonnull %14) #5
  br label %.loopexit

.loopexit:                                        ; preds = %._crit_edge.us, %12, %.thread
  %.2 = phi i32 [ %17, %.thread ], [ 0, %12 ], [ 0, %._crit_edge.us ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  br label %.critedge

.critedge:                                        ; preds = %7, %4, %.loopexit
  %.3 = phi i32 [ %.2, %.loopexit ], [ 0, %4 ], [ 0, %7 ]
  ret i32 %.3
}

attributes #0 = { mustprogress 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #4 = { nounwind willreturn memory(read) }
attributes #5 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!12, !8, i64 0}
!12 = !{!"QueueNode", !8, i64 0, !13, i64 8, !8, i64 16}
!13 = !{!"int", !9, i64 0}
!14 = !{!12, !13, i64 8}
!15 = distinct !{!15, !6}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass