; LLVM IR from gzc/CLRS :: C32-String-Matching (FA)

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @suffix(ptr noundef, i32 noundef, i32 noundef, i8 noundef signext) #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
define dso_local void @compute_transition_function(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i64 @strlen(ptr noundef %13) #4
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %64, %3
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp sle i32 %17, %18
  br i1 %19, label %20, label %67

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

21:                                               ; preds = %60, %20
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %63

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  %29 = call i32 @min(i32 noundef %26, i32 noundef %28)
  store i32 %29, ptr %10, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %49, %25
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %50

33:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = add nsw i32 97, %34
  %36 = trunc i32 %35 to i8
  store i8 %36, ptr %11, align 1, !tbaa !11
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = load i8, ptr %11, align 1, !tbaa !11
  %41 = call i32 @suffix(ptr noundef %37, i32 noundef %38, i32 noundef %39, i8 noundef signext %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %33
  store i32 9, ptr %12, align 4
  br label %47

44:                                               ; preds = %33
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %12, align 4
  br label %47

47:                                               ; preds = %44, %43
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  %48 = load i32, ptr %12, align 4
  switch i32 %48, label %68 [
    i32 0, label %49
    i32 9, label %50
  ]

49:                                               ; preds = %47
  br label %30, !llvm.loop !12

50:                                               ; preds = %47, %30
  %51 = load i32, ptr %10, align 4, !tbaa !9
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = mul nsw i32 %53, %54
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = add nsw i32 %55, %56
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %52, i64 %58
  store i32 %51, ptr %59, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %60

60:                                               ; preds = %50
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %9, align 4, !tbaa !9
  br label %21, !llvm.loop !14

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

64:                                               ; preds = %63
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %8, align 4, !tbaa !9
  br label %16, !llvm.loop !15

67:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void

68:                                               ; preds = %47
  unreachable
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(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 = { 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 }
attributes #4 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !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"

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

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

; Function Attrs: nounwind uwtable
define dso_local void @compute_transition_function(ptr noundef %0, ptr nocapture noundef writeonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #2
  %5 = trunc i64 %4 to i32
  %.not29 = icmp sgt i32 %5, -1
  %6 = icmp sgt i32 %2, 0
  %or.cond = and i1 %.not29, %6
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge31

.preheader.us.preheader:                          ; preds = %3
  %7 = zext nneg i32 %2 to i64
  %8 = add nuw nsw i64 %4, 1
  %wide.trip.count37 = and i64 %8, 4294967295
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv34 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next35, %._crit_edge.us ]
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %9 = mul nuw nsw i64 %indvars.iv34, %7
  %10 = trunc nuw nsw i64 %indvars.iv.next35 to i32
  %11 = trunc nuw nsw i64 %indvars.iv34 to i32
  %invariant.gep = getelementptr inbounds i32, ptr %1, i64 %9
  br label %12

12:                                               ; preds = %.preheader.us, %20
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %20 ]
  %13 = tail call i32 @min(i32 noundef %5, i32 noundef %10)
  %14 = trunc i64 %indvars.iv to i8
  %15 = add i8 %14, 97
  br label %16

16:                                               ; preds = %17, %12
  %.022.us = phi i32 [ %13, %12 ], [ %19, %17 ]
  %.not26.us = icmp eq i32 %.022.us, 0
  br i1 %.not26.us, label %20, label %17

17:                                               ; preds = %16
  %18 = tail call i32 @suffix(ptr noundef %0, i32 noundef %.022.us, i32 noundef %11, i8 noundef signext %15)
  %.not27.us = icmp eq i32 %18, 0
  %19 = add nsw i32 %.022.us, -1
  br i1 %.not27.us, label %16, label %20

20:                                               ; preds = %17, %16
  %gep = getelementptr inbounds i32, ptr %invariant.gep, i64 %indvars.iv
  store i32 %.022.us, ptr %gep, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %7
  br i1 %exitcond.not, label %._crit_edge.us, label %12, !llvm.loop !9

._crit_edge.us:                                   ; preds = %20
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count37
  br i1 %exitcond38.not, label %._crit_edge31, label %.preheader.us, !llvm.loop !11

._crit_edge31:                                    ; preds = %._crit_edge.us, %3
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) 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 = { 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 #2 = { 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 = !{!"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}


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