; LLVM IR from AlgoGenesis/C :: String Algorithms/Two-Way String-Matching Algorithm (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"

@.str = external hidden unnamed_addr constant [18 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [27 x i8], align 1

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @twoWayMatching(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %4
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %88

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = call i32 @computeCriticalPoint(ptr noundef %19, i32 noundef %20)
  store i32 %21, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = call i32 @computePeriod(ptr noundef %22, i32 noundef %23)
  store i32 %24, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %86, %18
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = sub nsw i32 %27, %28
  %30 = icmp sle i32 %26, %29
  br i1 %30, label %31, label %87

31:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %54, %31
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %52

36:                                               ; preds = %32
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load i32, ptr %12, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = sext i8 %41 to i32
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = load i32, ptr %12, align 4, !tbaa !9
  %46 = add nsw i32 %44, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %43, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = sext i8 %49 to i32
  %51 = icmp eq i32 %42, %50
  br label %52

52:                                               ; preds = %36, %32
  %53 = phi i1 [ false, %32 ], [ %51, %36 ]
  br i1 %53, label %54, label %57

54:                                               ; preds = %52
  %55 = load i32, ptr %12, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %12, align 4, !tbaa !9
  br label %32, !llvm.loop !12

57:                                               ; preds = %52
  %58 = load i32, ptr %12, align 4, !tbaa !9
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = icmp eq i32 %58, %59
  br i1 %60, label %61, label %81

61:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i32, ptr %11, align 4, !tbaa !9
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = call i32 @backwardMatch(ptr noundef %62, ptr noundef %63, i32 noundef %64, i32 noundef %65)
  store i32 %66, ptr %13, align 4, !tbaa !9
  %67 = load i32, ptr %13, align 4, !tbaa !9
  %68 = icmp slt i32 %67, 0
  br i1 %68, label %69, label %75

69:                                               ; preds = %61
  %70 = load i32, ptr %11, align 4, !tbaa !9
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %70)
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = load i32, ptr %11, align 4, !tbaa !9
  %74 = add nsw i32 %73, %72
  store i32 %74, ptr %11, align 4, !tbaa !9
  br label %80

75:                                               ; preds = %61
  %76 = load i32, ptr %13, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  %78 = load i32, ptr %11, align 4, !tbaa !9
  %79 = add nsw i32 %78, %77
  store i32 %79, ptr %11, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %75, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %86

81:                                               ; preds = %57
  %82 = load i32, ptr %12, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  %84 = load i32, ptr %11, align 4, !tbaa !9
  %85 = add nsw i32 %84, %83
  store i32 %85, ptr %11, align 4, !tbaa !9
  br label %86

86:                                               ; preds = %81, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %25, !llvm.loop !14

87:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %88

88:                                               ; preds = %87, %16
  ret void
}

declare i32 @printf(ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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 [18 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [27 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @twoWayMatching(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i32 %3, 0
  br i1 %5, label %6, label %8

6:                                                ; preds = %4
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %.loopexit

8:                                                ; preds = %4
  %9 = tail call i32 @computeCriticalPoint(ptr noundef %2, i32 noundef %3)
  %10 = tail call i32 @computePeriod(ptr noundef %2, i32 noundef %3)
  %11 = sub nsw i32 %1, %3
  %.not35 = icmp slt i32 %11, 0
  br i1 %.not35, label %.loopexit, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %8
  %12 = icmp sgt i32 %9, 0
  br i1 %12, label %.preheader.us.preheader, label %.preheader.lr.ph.split

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

.preheader.us:                                    ; preds = %.preheader.us.preheader, %29
  %.036.us = phi i32 [ %.2.us, %29 ], [ 0, %.preheader.us.preheader ]
  %13 = sext i32 %.036.us to i64
  %invariant.gep = getelementptr i8, ptr %0, i64 %13
  br label %14

14:                                               ; preds = %.preheader.us, %30
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %30 ]
  %15 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %gep = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv
  %17 = load i8, ptr %gep, align 1, !tbaa !5
  %18 = icmp eq i8 %16, %17
  br i1 %18, label %30, label %.critedge.us

.critedge.us:                                     ; preds = %14
  %19 = trunc nuw nsw i64 %indvars.iv to i32
  %20 = icmp eq i32 %9, %19
  br i1 %20, label %.critedge.us.thread, label %21

21:                                               ; preds = %.critedge.us
  %22 = add nuw nsw i32 %19, 1
  br label %29

.critedge.us.thread:                              ; preds = %30, %.critedge.us
  %23 = tail call i32 @backwardMatch(ptr noundef nonnull %0, ptr noundef nonnull %2, i32 noundef %.036.us, i32 noundef %3)
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %27, label %25

25:                                               ; preds = %.critedge.us.thread
  %26 = add nuw nsw i32 %23, 1
  br label %29

27:                                               ; preds = %.critedge.us.thread
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.036.us)
  br label %29

29:                                               ; preds = %27, %25, %21
  %.pn.pn.us = phi i32 [ %22, %21 ], [ %10, %27 ], [ %26, %25 ]
  %.2.us = add nsw i32 %.pn.pn.us, %.036.us
  %.not.us = icmp sgt i32 %.2.us, %11
  br i1 %.not.us, label %.loopexit, label %.preheader.us, !llvm.loop !8

30:                                               ; preds = %14
  %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.us.thread, label %14, !llvm.loop !10

.preheader.lr.ph.split:                           ; preds = %.preheader.lr.ph
  %31 = icmp eq i32 %9, 0
  br i1 %31, label %.preheader.us37, label %.loopexit

.preheader.us37:                                  ; preds = %.preheader.lr.ph.split, %38
  %.036.us38 = phi i32 [ %.2.us40, %38 ], [ 0, %.preheader.lr.ph.split ]
  %32 = tail call i32 @backwardMatch(ptr noundef %0, ptr noundef %2, i32 noundef %.036.us38, i32 noundef %3)
  %33 = icmp slt i32 %32, 0
  br i1 %33, label %36, label %34

34:                                               ; preds = %.preheader.us37
  %35 = add nuw nsw i32 %32, 1
  br label %38

36:                                               ; preds = %.preheader.us37
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.036.us38)
  br label %38

38:                                               ; preds = %36, %34
  %.pn.pn.us39 = phi i32 [ %10, %36 ], [ %35, %34 ]
  %.2.us40 = add nsw i32 %.pn.pn.us39, %.036.us38
  %.not.us41 = icmp sgt i32 %.2.us40, %11
  br i1 %.not.us41, label %.loopexit, label %.preheader.us37, !llvm.loop !8

.loopexit:                                        ; preds = %38, %29, %.preheader.lr.ph.split, %8, %6
  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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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