; LLVM IR from l1mey112/yr11-physics-applied :: cimgui/imgui/imgui_widgets.ll (Z32ImParseFormatSanitizeForScanningPKcPcm)

; 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.4 = external hidden unnamed_addr constant [94 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [46 x i8], align 1
@__PRETTY_FUNCTION__._Z32ImParseFormatSanitizeForScanningPKcPcm = external hidden unnamed_addr constant [75 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z32ImParseFormatSanitizeForScanningPKcPcm(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call noundef ptr @_Z20ImParseFormatFindEndPKc(ptr noundef %12)
  store ptr %13, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %14, ptr %8, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = ptrtoint ptr %15 to i64
  %18 = ptrtoint ptr %16 to i64
  %19 = sub i64 %17, %18
  %20 = add nsw i64 %19, 1
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %3
  br label %26

24:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.46, ptr noundef @.str.4, i32 noundef 3246, ptr noundef @__PRETTY_FUNCTION__._Z32ImParseFormatSanitizeForScanningPKcPcm) #4
  unreachable

25:                                               ; No predecessors!
  br label %26

26:                                               ; preds = %25, %23
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  store i8 0, ptr %9, align 1, !tbaa !11
  br label %27

27:                                               ; preds = %95, %93, %26
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = icmp ult ptr %28, %29
  br i1 %30, label %31, label %96

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i32 1
  store ptr %33, ptr %4, align 8, !tbaa !5
  %34 = load i8, ptr %32, align 1, !tbaa !13
  store i8 %34, ptr %10, align 1, !tbaa !13
  %35 = load i8, ptr %9, align 1, !tbaa !11, !range !14, !noundef !15
  %36 = trunc i8 %35 to i1
  br i1 %36, label %50, label %37

37:                                               ; preds = %31
  %38 = load i8, ptr %10, align 1, !tbaa !13
  %39 = sext i8 %38 to i32
  %40 = icmp sge i32 %39, 48
  br i1 %40, label %41, label %45

41:                                               ; preds = %37
  %42 = load i8, ptr %10, align 1, !tbaa !13
  %43 = sext i8 %42 to i32
  %44 = icmp sle i32 %43, 57
  br i1 %44, label %49, label %45

45:                                               ; preds = %41, %37
  %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 %50

49:                                               ; preds = %45, %41
  store i32 2, ptr %11, align 4
  br label %93, !llvm.loop !16

50:                                               ; preds = %45, %31
  %51 = load i8, ptr %10, align 1, !tbaa !13
  %52 = sext i8 %51 to i32
  %53 = icmp sge i32 %52, 97
  br i1 %53, label %54, label %58

54:                                               ; preds = %50
  %55 = load i8, ptr %10, align 1, !tbaa !13
  %56 = sext i8 %55 to i32
  %57 = icmp sle i32 %56, 122
  br i1 %57, label %68, label %58

58:                                               ; preds = %54, %50
  %59 = load i8, ptr %10, align 1, !tbaa !13
  %60 = sext i8 %59 to i32
  %61 = icmp sge i32 %60, 65
  br i1 %61, label %62, label %66

62:                                               ; preds = %58
  %63 = load i8, ptr %10, align 1, !tbaa !13
  %64 = sext i8 %63 to i32
  %65 = icmp sle i32 %64, 90
  br label %66

66:                                               ; preds = %62, %58
  %67 = phi i1 [ false, %58 ], [ %65, %62 ]
  br label %68

68:                                               ; preds = %66, %54
  %69 = phi i1 [ true, %54 ], [ %67, %66 ]
  %70 = zext i1 %69 to i32
  %71 = load i8, ptr %9, align 1, !tbaa !11, !range !14, !noundef !15
  %72 = trunc i8 %71 to i1
  %73 = zext i1 %72 to i32
  %74 = or i32 %73, %70
  %75 = icmp ne i32 %74, 0
  %76 = zext i1 %75 to i8
  store i8 %76, ptr %9, align 1, !tbaa !11
  %77 = load i8, ptr %10, align 1, !tbaa !13
  %78 = sext i8 %77 to i32
  %79 = icmp ne i32 %78, 39
  br i1 %79, label %80, label %92

80:                                               ; preds = %68
  %81 = load i8, ptr %10, align 1, !tbaa !13
  %82 = sext i8 %81 to i32
  %83 = icmp ne i32 %82, 36
  br i1 %83, label %84, label %92

84:                                               ; preds = %80
  %85 = load i8, ptr %10, align 1, !tbaa !13
  %86 = sext i8 %85 to i32
  %87 = icmp ne i32 %86, 95
  br i1 %87, label %88, label %92

88:                                               ; preds = %84
  %89 = load i8, ptr %10, align 1, !tbaa !13
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds i8, ptr %90, i32 1
  store ptr %91, ptr %5, align 8, !tbaa !5
  store i8 %89, ptr %90, align 1, !tbaa !13
  br label %92

92:                                               ; preds = %88, %84, %80, %68
  store i32 0, ptr %11, align 4
  br label %93

93:                                               ; preds = %92, %49
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  %94 = load i32, ptr %11, align 4
  switch i32 %94, label %99 [
    i32 0, label %95
    i32 2, label %27
  ]

95:                                               ; preds = %93
  br label %27, !llvm.loop !16

96:                                               ; preds = %27
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 0, ptr %97, align 1, !tbaa !13
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret ptr %98

99:                                               ; preds = %93
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z20ImParseFormatFindEndPKc(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #2 = { 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 }
attributes #4 = { noreturn 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@.str.4 = external hidden unnamed_addr constant [94 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [46 x i8], align 1
@__PRETTY_FUNCTION__._Z32ImParseFormatSanitizeForScanningPKcPcm = external hidden unnamed_addr constant [75 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z32ImParseFormatSanitizeForScanningPKcPcm(ptr noundef %0, ptr noundef returned writeonly %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = tail call noundef ptr @_Z20ImParseFormatFindEndPKc(ptr noundef %0)
  %5 = ptrtoint ptr %4 to i64
  %6 = ptrtoint ptr %0 to i64
  %reass.sub = sub i64 %5, %6
  %7 = add i64 %reass.sub, 1
  %8 = icmp ult i64 %7, %2
  br i1 %8, label %.preheader, label %10

.preheader:                                       ; preds = %3
  %9 = icmp ugt ptr %4, %0
  br i1 %9, label %.lr.ph, label %._crit_edge

10:                                               ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.46, ptr noundef nonnull @.str.4, i32 noundef 3246, ptr noundef nonnull @__PRETTY_FUNCTION__._Z32ImParseFormatSanitizeForScanningPKcPcm) #2
  unreachable

.lr.ph:                                           ; preds = %.preheader, %23
  %.042 = phi ptr [ %11, %23 ], [ %0, %.preheader ]
  %.03741 = phi i1 [ %.1, %23 ], [ false, %.preheader ]
  %.03840 = phi ptr [ %.2, %23 ], [ %1, %.preheader ]
  %11 = getelementptr inbounds i8, ptr %.042, i64 1
  %12 = load i8, ptr %.042, align 1, !tbaa !5
  br i1 %.03741, label %16, label %13

13:                                               ; preds = %.lr.ph
  %14 = add i8 %12, -48
  %or.cond = icmp ult i8 %14, 10
  %15 = icmp eq i8 %12, 46
  %or.cond5 = or i1 %15, %or.cond
  br i1 %or.cond5, label %23, label %16, !llvm.loop !8

16:                                               ; preds = %13, %.lr.ph
  %17 = and i8 %12, -33
  %18 = add i8 %17, -65
  %19 = icmp ult i8 %18, 26
  %20 = or i1 %.03741, %19
  switch i8 %12, label %21 [
    i8 95, label %23
    i8 39, label %23
    i8 36, label %23
  ]

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %.03840, i64 1
  store i8 %12, ptr %.03840, align 1, !tbaa !5
  br label %23

23:                                               ; preds = %16, %16, %16, %21, %13
  %.2 = phi ptr [ %.03840, %13 ], [ %22, %21 ], [ %.03840, %16 ], [ %.03840, %16 ], [ %.03840, %16 ]
  %.1 = phi i1 [ false, %13 ], [ %20, %21 ], [ %20, %16 ], [ %20, %16 ], [ %20, %16 ]
  %exitcond.not = icmp eq ptr %11, %4
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %23, %.preheader
  %.038.lcssa = phi ptr [ %1, %.preheader ], [ %.2, %23 ]
  store i8 0, ptr %.038.lcssa, align 1, !tbaa !5
  ret ptr %1
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z20ImParseFormatFindEndPKc(ptr noundef) local_unnamed_addr #1

attributes #0 = { noreturn 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 #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 = { noreturn 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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