; LLVM IR from Samson-Mano/EM_Propogation_simulation :: EM_Propogation_simulation/src/ImGui/imgui_widgets.ll (Z20ImParseFormatFindEndPKc)

; 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: 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: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z20ImParseFormatFindEndPKc(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 0
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = sext i8 %10 to i32
  %12 = icmp ne i32 %11, 37
  br i1 %12, label %13, label %15

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %14, ptr %2, align 8
  br label %67

15:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 2304, ptr %4, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 38275712, ptr %5, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  br label %16

16:                                               ; preds = %59, %15
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i8, ptr %17, align 1, !tbaa !9
  store i8 %18, ptr %6, align 1, !tbaa !9
  %19 = sext i8 %18 to i32
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 2, ptr %7, align 4
  br label %62

22:                                               ; preds = %16
  %23 = load i8, ptr %6, align 1, !tbaa !9
  %24 = sext i8 %23 to i32
  %25 = icmp sge i32 %24, 65
  br i1 %25, label %26, label %40

26:                                               ; preds = %22
  %27 = load i8, ptr %6, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = icmp sle i32 %28, 90
  br i1 %29, label %30, label %40

30:                                               ; preds = %26
  %31 = load i8, ptr %6, align 1, !tbaa !9
  %32 = sext i8 %31 to i32
  %33 = sub nsw i32 %32, 65
  %34 = shl i32 1, %33
  %35 = and i32 %34, 2304
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %40

37:                                               ; preds = %30
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 1
  store ptr %39, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %62

40:                                               ; preds = %30, %26, %22
  %41 = load i8, ptr %6, align 1, !tbaa !9
  %42 = sext i8 %41 to i32
  %43 = icmp sge i32 %42, 97
  br i1 %43, label %44, label %58

44:                                               ; preds = %40
  %45 = load i8, ptr %6, align 1, !tbaa !9
  %46 = sext i8 %45 to i32
  %47 = icmp sle i32 %46, 122
  br i1 %47, label %48, label %58

48:                                               ; preds = %44
  %49 = load i8, ptr %6, align 1, !tbaa !9
  %50 = sext i8 %49 to i32
  %51 = sub nsw i32 %50, 97
  %52 = shl i32 1, %51
  %53 = and i32 %52, 38275712
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %58

55:                                               ; preds = %48
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 1
  store ptr %57, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %62

58:                                               ; preds = %48, %44, %40
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i32 1
  store ptr %61, ptr %3, align 8, !tbaa !5
  br label %16, !llvm.loop !12

62:                                               ; preds = %55, %37, %21
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  %63 = load i32, ptr %7, align 4
  switch i32 %63, label %66 [
    i32 2, label %64
  ]

64:                                               ; preds = %62
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %65, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %66

66:                                               ; preds = %64, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %67

67:                                               ; preds = %66, %13
  %68 = load ptr, ptr %2, align 8
  ret ptr %68
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef ptr @_Z20ImParseFormatFindEndPKc(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %.not = icmp eq i8 %2, 37
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %1, %.thread
  %3 = phi i32 [ %23, %.thread ], [ 37, %1 ]
  %.02026 = phi ptr [ %22, %.thread ], [ %0, %1 ]
  %4 = phi i8 [ %.pr, %.thread ], [ 37, %1 ]
  %5 = add i8 %4, -65
  %or.cond = icmp ult i8 %5, 26
  br i1 %or.cond, label %6, label %13

6:                                                ; preds = %.preheader
  %7 = add nsw i32 %3, -65
  %8 = shl nuw nsw i32 1, %7
  %9 = and i32 %8, 2304
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %.thread

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %.02026, i64 1
  br label %.loopexit

13:                                               ; preds = %.preheader
  %14 = add i8 %4, -97
  %or.cond5 = icmp ult i8 %14, 26
  br i1 %or.cond5, label %15, label %.thread

15:                                               ; preds = %13
  %16 = add nsw i32 %3, -97
  %17 = shl nuw nsw i32 1, %16
  %18 = and i32 %17, 38275712
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %.thread

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %.02026, i64 1
  br label %.loopexit

.thread:                                          ; preds = %6, %13, %15
  %22 = getelementptr inbounds i8, ptr %.02026, i64 1
  %.pr = load i8, ptr %22, align 1, !tbaa !5
  %23 = sext i8 %.pr to i32
  %.not22 = icmp eq i8 %.pr, 0
  br i1 %.not22, label %.loopexit, label %.preheader, !llvm.loop !8

.loopexit:                                        ; preds = %.thread, %11, %20, %1
  %.2 = phi ptr [ %0, %1 ], [ %12, %11 ], [ %21, %20 ], [ %22, %.thread ]
  ret ptr %.2
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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