; LLVM IR from AlgoGenesis/C :: Searching Algorithms/Bidirectional Search (Bidirectional Search)

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

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = 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
define dso_local void @printPath(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca [100 x i32], align 16
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 400, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %15 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %15, ptr %13, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %19, %5
  %17 = load i32, ptr %13, align 4, !tbaa !9
  %18 = icmp ne i32 %17, -1
  br i1 %18, label %19, label %30

19:                                               ; preds = %16
  %20 = load i32, ptr %13, align 4, !tbaa !9
  %21 = load i32, ptr %12, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %12, align 4, !tbaa !9
  %23 = sext i32 %21 to i64
  %24 = getelementptr inbounds [100 x i32], ptr %11, i64 0, i64 %23
  store i32 %20, ptr %24, align 4, !tbaa !9
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %13, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr %25, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !9
  store i32 %29, ptr %13, align 4, !tbaa !9
  br label %16, !llvm.loop !11

30:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %31 = load i32, ptr %12, align 4, !tbaa !9
  %32 = sub nsw i32 %31, 1
  store i32 %32, ptr %14, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %43, %30
  %34 = load i32, ptr %14, align 4, !tbaa !9
  %35 = icmp sge i32 %34, 0
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %46

37:                                               ; preds = %33
  %38 = load i32, ptr %14, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100 x i32], ptr %11, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %41)
  br label %43

43:                                               ; preds = %37
  %44 = load i32, ptr %14, align 4, !tbaa !9
  %45 = add nsw i32 %44, -1
  store i32 %45, ptr %14, align 4, !tbaa !9
  br label %33, !llvm.loop !13

46:                                               ; preds = %36
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %47, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !9
  store i32 %51, ptr %13, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %55, %46
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = icmp ne i32 %53, -1
  br i1 %54, label %55, label %63

55:                                               ; preds = %52
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %56)
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load i32, ptr %13, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !9
  store i32 %62, ptr %13, align 4, !tbaa !9
  br label %52, !llvm.loop !14

63:                                               ; preds = %52
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 400, ptr %11) #3
  ret void
}

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 = !{!"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 = distinct !{!13, !12}
!14 = distinct !{!14, !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"

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; 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: nofree nounwind uwtable
define dso_local void @printPath(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = alloca [100 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 400, ptr nonnull %6) #3
  %.not19 = icmp eq i32 %2, -1
  br i1 %.not19, label %.preheader, label %.lr.ph

.preheader18:                                     ; preds = %.lr.ph
  %7 = trunc nuw i64 %indvars.iv.next to i32
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph23.preheader, label %.preheader

.lr.ph23.preheader:                               ; preds = %.preheader18
  %9 = and i64 %indvars.iv.next, 2147483647
  br label %.lr.ph23

.lr.ph:                                           ; preds = %5, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %5 ]
  %.01521 = phi i32 [ %13, %.lr.ph ], [ %2, %5 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = getelementptr inbounds [100 x i32], ptr %6, i64 0, i64 %indvars.iv
  store i32 %.01521, ptr %10, align 4, !tbaa !5
  %11 = sext i32 %.01521 to i64
  %12 = getelementptr inbounds i32, ptr %0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not = icmp eq i32 %13, -1
  br i1 %.not, label %.preheader18, label %.lr.ph, !llvm.loop !9

.preheader:                                       ; preds = %.lr.ph23, %5, %.preheader18
  %.pn24 = sext i32 %2 to i64
  %.1.in25 = getelementptr inbounds i32, ptr %1, i64 %.pn24
  %.126 = load i32, ptr %.1.in25, align 4, !tbaa !5
  %.not1727 = icmp eq i32 %.126, -1
  br i1 %.not1727, label %._crit_edge, label %.lr.ph29

.lr.ph23:                                         ; preds = %.lr.ph23.preheader, %.lr.ph23
  %indvars.iv31 = phi i64 [ %9, %.lr.ph23.preheader ], [ %indvars.iv.next32, %.lr.ph23 ]
  %indvars.iv.next32 = add nsw i64 %indvars.iv31, -1
  %14 = getelementptr inbounds [100 x i32], ptr %6, i64 0, i64 %indvars.iv.next32
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %15)
  %17 = icmp ugt i64 %indvars.iv31, 1
  br i1 %17, label %.lr.ph23, label %.preheader, !llvm.loop !11

.lr.ph29:                                         ; preds = %.preheader, %.lr.ph29
  %.128 = phi i32 [ %.1, %.lr.ph29 ], [ %.126, %.preheader ]
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %.128)
  %.pn = sext i32 %.128 to i64
  %.1.in = getelementptr inbounds i32, ptr %1, i64 %.pn
  %.1 = load i32, ptr %.1.in, align 4, !tbaa !5
  %.not17 = icmp eq i32 %.1, -1
  br i1 %.not17, label %._crit_edge, label %.lr.ph29, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph29, %.preheader
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @llvm.lifetime.end.p0(i64 400, ptr nonnull %6) #3
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 = { 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass