; LLVM IR from aagdev/mlimgsynth :: src (tensor_name_conv)

; 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.StrSlice = type { ptr, i64 }

; Function Attrs: nounwind uwtable
define dso_local i32 @tnconv_prefix_match(ptr %0, i64 %1, ptr %2, i64 %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca %struct.StrSlice, align 8
  %7 = alloca %struct.StrSlice, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 0
  store ptr %0, ptr %12, align 8
  %13 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 1
  store i64 %1, ptr %13, align 8
  %14 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 0
  store ptr %2, ptr %14, align 8
  %15 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 1
  store i64 %3, ptr %15, align 8
  %16 = getelementptr inbounds %struct.StrSlice, ptr %6, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.StrSlice, ptr %7, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = icmp uge i64 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  br label %64

22:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %58, %22
  %24 = load i64, ptr %8, align 8, !tbaa !11
  %25 = getelementptr inbounds %struct.StrSlice, ptr %7, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = icmp ult i64 %24, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  store i32 2, ptr %9, align 4
  br label %61

29:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %30 = getelementptr inbounds %struct.StrSlice, ptr %7, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = load i64, ptr %8, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %31, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !13
  store i8 %34, ptr %10, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  %35 = getelementptr inbounds %struct.StrSlice, ptr %6, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !12
  %37 = load i64, ptr %8, align 8, !tbaa !11
  %38 = getelementptr inbounds i8, ptr %36, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !13
  store i8 %39, ptr %11, align 1, !tbaa !13
  %40 = load i8, ptr %10, align 1, !tbaa !13
  %41 = sext i8 %40 to i32
  %42 = load i8, ptr %11, align 1, !tbaa !13
  %43 = sext i8 %42 to i32
  %44 = icmp eq i32 %41, %43
  br i1 %44, label %54, label %45

45:                                               ; preds = %29
  %46 = load i8, ptr %10, align 1, !tbaa !13
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %47, 46
  br i1 %48, label %49, label %53

49:                                               ; preds = %45
  %50 = load i8, ptr %11, align 1, !tbaa !13
  %51 = call i32 @char_sep_is(i8 noundef signext %50)
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %54, label %53

53:                                               ; preds = %49, %45
  store i32 0, ptr %5, align 4
  store i32 1, ptr %9, align 4
  br label %55

54:                                               ; preds = %49, %29
  store i32 0, ptr %9, align 4
  br label %55

55:                                               ; preds = %54, %53
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  %56 = load i32, ptr %9, align 4
  switch i32 %56, label %61 [
    i32 0, label %57
  ]

57:                                               ; preds = %55
  br label %58

58:                                               ; preds = %57
  %59 = load i64, ptr %8, align 8, !tbaa !11
  %60 = add i64 %59, 1
  store i64 %60, ptr %8, align 8, !tbaa !11
  br label %23, !llvm.loop !14

61:                                               ; preds = %55, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %62 = load i32, ptr %9, align 4
  switch i32 %62, label %66 [
    i32 2, label %63
    i32 1, label %64
  ]

63:                                               ; preds = %61
  store i32 1, ptr %5, align 4
  br label %64

64:                                               ; preds = %63, %61, %21
  %65 = load i32, ptr %5, align 4
  ret i32 %65

66:                                               ; preds = %61
  unreachable
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @char_sep_is(i8 noundef signext) #2

; 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 = { inlinehint 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 #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, !10, i64 8}
!6 = !{!"StrSlice", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local i32 @tnconv_prefix_match(ptr nocapture readonly %0, i64 %1, ptr nocapture readonly %2, i64 %3) local_unnamed_addr #0 {
  %.not = icmp ult i64 %1, %3
  br i1 %.not, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %4
  %.not2021 = icmp eq i64 %3, 0
  br i1 %.not2021, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.critedge
  %.not2023 = phi i1 [ %.not20, %.critedge ], [ false, %.preheader ]
  %.01422 = phi i64 [ %14, %.critedge ], [ 0, %.preheader ]
  %5 = getelementptr inbounds i8, ptr %2, i64 %.01422
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 %.01422
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = icmp eq i8 %6, %8
  br i1 %9, label %.critedge, label %10

10:                                               ; preds = %.lr.ph
  %11 = icmp eq i8 %6, 46
  br i1 %11, label %12, label %._crit_edge.loopexit

12:                                               ; preds = %10
  %13 = tail call i32 @char_sep_is(i8 noundef signext %8)
  %.not19 = icmp eq i32 %13, 0
  br i1 %.not19, label %._crit_edge.loopexit, label %.critedge

.critedge:                                        ; preds = %12, %.lr.ph
  %14 = add nuw i64 %.01422, 1
  %.not20 = icmp uge i64 %14, %3
  %exitcond = icmp eq i64 %14, %3
  br i1 %exitcond, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !8

._crit_edge.loopexit:                             ; preds = %12, %10, %.critedge
  %.not20.lcssa.ph = phi i1 [ %.not20, %.critedge ], [ %.not2023, %10 ], [ %.not2023, %12 ]
  %15 = zext i1 %.not20.lcssa.ph to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %.preheader, %._crit_edge.loopexit, %4
  %.3 = phi i32 [ 0, %4 ], [ 1, %.preheader ], [ %15, %._crit_edge.loopexit ]
  ret i32 %.3
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @char_sep_is(i8 noundef signext) 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 = { inlinehint 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" }

!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"}


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