; LLVM IR from kajott/GIPS :: src/string_util.ll (ZN10StringUtil9Tokenizer11extendUntilEPKcb)

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

%"class.StringUtil::Tokenizer" = type <{ ptr, i32, i32, [32 x i8], i32, [4 x i8] }>

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10StringUtil9Tokenizer11extendUntilEPKcb(ptr noundef nonnull align 8 dereferenceable(52) %0, ptr noundef %1, i1 noundef zeroext %2) #2 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  %13 = zext i1 %2 to i8
  store i8 %13, ptr %7, align 1, !tbaa !9
  %14 = load ptr, ptr %5, align 8
  %15 = getelementptr inbounds %"class.StringUtil::Tokenizer", ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  br label %83

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call i64 @strlen(ptr noundef %20) #5
  %22 = trunc i64 %21 to i32
  store i32 %22, ptr %8, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %23 = getelementptr inbounds %"class.StringUtil::Tokenizer", ptr %14, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !15
  %25 = load i32, ptr %8, align 4, !tbaa !14
  %26 = sub nsw i32 %24, %25
  store i32 %26, ptr %9, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %27 = getelementptr inbounds %"class.StringUtil::Tokenizer", ptr %14, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !16
  store i32 %28, ptr %10, align 4, !tbaa !14
  br label %29

29:                                               ; preds = %72, %19
  %30 = load i32, ptr %10, align 4, !tbaa !14
  %31 = load i32, ptr %9, align 4, !tbaa !14
  %32 = icmp sle i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 2, ptr %11, align 4
  br label %75

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %35 = getelementptr inbounds %"class.StringUtil::Tokenizer", ptr %14, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = load i32, ptr %10, align 4, !tbaa !14
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  store ptr %39, ptr %12, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %54, %34
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 1, !tbaa !17
  %43 = icmp ne i8 %42, 0
  br i1 %43, label %44, label %52

44:                                               ; preds = %40
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = load i8, ptr %45, align 1, !tbaa !17
  %47 = sext i8 %46 to i32
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i8, ptr %48, align 1, !tbaa !17
  %50 = sext i8 %49 to i32
  %51 = icmp eq i32 %47, %50
  br label %52

52:                                               ; preds = %44, %40
  %53 = phi i1 [ false, %40 ], [ %51, %44 ]
  br i1 %53, label %54, label %59

54:                                               ; preds = %52
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i32 1
  store ptr %56, ptr %12, align 8, !tbaa !5
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i32 1
  store ptr %58, ptr %6, align 8, !tbaa !5
  br label %40, !llvm.loop !18

59:                                               ; preds = %52
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load i8, ptr %60, align 1, !tbaa !17
  %62 = icmp ne i8 %61, 0
  br i1 %62, label %68, label %63

63:                                               ; preds = %59
  %64 = load i32, ptr %10, align 4, !tbaa !14
  %65 = load i32, ptr %8, align 4, !tbaa !14
  %66 = add nsw i32 %64, %65
  %67 = getelementptr inbounds %"class.StringUtil::Tokenizer", ptr %14, i32 0, i32 1
  store i32 %66, ptr %67, align 8, !tbaa !16
  store i1 true, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %69

68:                                               ; preds = %59
  store i32 0, ptr %11, align 4
  br label %69

69:                                               ; preds = %68, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %70 = load i32, ptr %11, align 4
  switch i32 %70, label %75 [
    i32 0, label %71
  ]

71:                                               ; preds = %69
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %10, align 4, !tbaa !14
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %10, align 4, !tbaa !14
  br label %29, !llvm.loop !20

75:                                               ; preds = %69, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %76 = load i32, ptr %11, align 4
  switch i32 %76, label %82 [
    i32 2, label %77
  ]

77:                                               ; preds = %75
  %78 = load i8, ptr %7, align 1, !tbaa !9, !range !21, !noundef !22
  %79 = trunc i8 %78 to i1
  br i1 %79, label %80, label %81

80:                                               ; preds = %77
  call void @_ZN10StringUtil9Tokenizer14extendUntilEndEv(ptr noundef nonnull align 8 dereferenceable(52) %14)
  br label %81

81:                                               ; preds = %80, %77
  store i1 true, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %82

82:                                               ; preds = %81, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %83

83:                                               ; preds = %82, %18
  %84 = load i1, ptr %4, align 1
  ret i1 %84
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN10StringUtil9Tokenizer14extendUntilEndEv(ptr noundef nonnull align 8 dereferenceable(52)) #3 align 2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 = { inlinehint mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN10StringUtil9TokenizerE", !6, i64 0, !13, i64 8, !13, i64 12, !7, i64 16, !13, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 12}
!16 = !{!12, !13, i64 8}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = !{i8 0, i8 2}
!22 = !{}


; 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 nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN10StringUtil9Tokenizer11extendUntilEPKcb(ptr noundef nonnull align 8 dereferenceable(52) %0, ptr nocapture noundef readonly %1, i1 noundef zeroext %2) local_unnamed_addr #1 align 2 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp ne ptr %4, null
  br i1 %.not, label %5, label %27

5:                                                ; preds = %3
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %7 = trunc i64 %6 to i32
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = sub nsw i32 %9, %7
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !12
  %.not2641 = icmp sgt i32 %12, %10
  br i1 %.not2641, label %.critedge32, label %.lr.ph45.preheader

.lr.ph45.preheader:                               ; preds = %5
  %13 = sext i32 %12 to i64
  %14 = add i32 %9, 1
  %15 = sub i32 %14, %7
  %.pre = load i8, ptr %1, align 1, !tbaa !13
  br label %.lr.ph45

.lr.ph45:                                         ; preds = %.lr.ph45.preheader, %.critedge30
  %16 = phi i8 [ %.pre, %.lr.ph45.preheader ], [ %18, %.critedge30 ]
  %indvars.iv = phi i64 [ %13, %.lr.ph45.preheader ], [ %indvars.iv.next, %.critedge30 ]
  %.02342 = phi ptr [ %1, %.lr.ph45.preheader ], [ %.12437, %.critedge30 ]
  %.not2736 = icmp eq i8 %16, 0
  br i1 %.not2736, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph45
  %17 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %21
  %18 = phi i8 [ %24, %21 ], [ %16, %.lr.ph.preheader ]
  %.038 = phi ptr [ %22, %21 ], [ %17, %.lr.ph.preheader ]
  %.12437 = phi ptr [ %23, %21 ], [ %.02342, %.lr.ph.preheader ]
  %19 = load i8, ptr %.038, align 1, !tbaa !13
  %20 = icmp eq i8 %19, %18
  br i1 %20, label %21, label %.critedge30

21:                                               ; preds = %.lr.ph
  %22 = getelementptr inbounds i8, ptr %.038, i64 1
  %23 = getelementptr inbounds i8, ptr %.12437, i64 1
  %24 = load i8, ptr %23, align 1, !tbaa !13
  %.not27 = icmp eq i8 %24, 0
  br i1 %.not27, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph45, %21
  %.0204350 = trunc i64 %indvars.iv to i32
  %25 = add nsw i32 %.0204350, %7
  store i32 %25, ptr %11, align 8, !tbaa !12
  br label %27

.critedge30:                                      ; preds = %.lr.ph
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  %exitcond.not = icmp eq i32 %15, %lftr.wideiv
  br i1 %exitcond.not, label %.critedge32, label %.lr.ph45, !llvm.loop !16

.critedge32:                                      ; preds = %.critedge30, %5
  br i1 %2, label %26, label %27

26:                                               ; preds = %.critedge32
  tail call void @_ZN10StringUtil9Tokenizer14extendUntilEndEv(ptr noundef nonnull align 8 dereferenceable(52) %0)
  br label %27

27:                                               ; preds = %._crit_edge, %26, %.critedge32, %3
  ret i1 %.not
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN10StringUtil9Tokenizer14extendUntilEndEv(ptr noundef nonnull align 8 dereferenceable(52)) local_unnamed_addr #2 align 2

attributes #0 = { 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 #1 = { mustprogress 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 = { inlinehint mustprogress 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 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, !7, i64 0}
!6 = !{!"_ZTSN10StringUtil9TokenizerE", !7, i64 0, !10, i64 8, !10, i64 12, !8, i64 16, !10, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !10, i64 8}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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