; LLVM IR from Xiangyu-Hu/SPHinXsys :: src/shared/tools/tinyxml2.ll (ZN8tinyxml27StrPair18CollapseWhitespaceEv)

; 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.tinyxml2::StrPair" = type { i32, ptr, ptr }

; 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 uwtable
define dso_local void @_ZN8tinyxml27StrPair18CollapseWhitespaceEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  br label %6

6:                                                ; preds = %1
  br label %7

7:                                                ; preds = %6
  %8 = getelementptr inbounds %"class.tinyxml2::StrPair", ptr %5, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = call noundef ptr @_ZN8tinyxml27XMLUtil14SkipWhiteSpaceEPcPi(ptr noundef %9, ptr noundef null)
  %11 = getelementptr inbounds %"class.tinyxml2::StrPair", ptr %5, i32 0, i32 1
  store ptr %10, ptr %11, align 8, !tbaa !9
  %12 = getelementptr inbounds %"class.tinyxml2::StrPair", ptr %5, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = load i8, ptr %13, align 1, !tbaa !12
  %15 = icmp ne i8 %14, 0
  br i1 %15, label %16, label %51

16:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %17 = getelementptr inbounds %"class.tinyxml2::StrPair", ptr %5, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  store ptr %18, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %19 = getelementptr inbounds %"class.tinyxml2::StrPair", ptr %5, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  store ptr %20, ptr %4, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %41, %16
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !12
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %25, label %49

25:                                               ; preds = %21
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !12
  %28 = call noundef zeroext i1 @_ZN8tinyxml27XMLUtil12IsWhiteSpaceEc(i8 noundef signext %27)
  br i1 %28, label %29, label %41

29:                                               ; preds = %25
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = call noundef ptr @_ZN8tinyxml27XMLUtil14SkipWhiteSpaceEPKcPi(ptr noundef %30, ptr noundef null)
  store ptr %31, ptr %3, align 8, !tbaa !5
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load i8, ptr %32, align 1, !tbaa !12
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %29
  br label %49

37:                                               ; preds = %29
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  store i8 32, ptr %38, align 1, !tbaa !12
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i32 1
  store ptr %40, ptr %4, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %37, %25
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load i8, ptr %42, align 1, !tbaa !12
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  store i8 %43, ptr %44, align 1, !tbaa !12
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i32 1
  store ptr %46, ptr %4, align 8, !tbaa !5
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i32 1
  store ptr %48, ptr %3, align 8, !tbaa !5
  br label %21, !llvm.loop !13

49:                                               ; preds = %36, %21
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  store i8 0, ptr %50, align 1, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %51

51:                                               ; preds = %49, %7
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN8tinyxml27XMLUtil14SkipWhiteSpaceEPcPi(ptr noundef, ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN8tinyxml27XMLUtil12IsWhiteSpaceEc(i8 noundef signext) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN8tinyxml27XMLUtil14SkipWhiteSpaceEPKcPi(ptr noundef, ptr noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!10, !6, i64 8}
!10 = !{!"_ZTSN8tinyxml27StrPairE", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 uwtable
define dso_local void @_ZN8tinyxml27StrPair18CollapseWhitespaceEv(ptr nocapture noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = tail call noundef ptr @_ZN8tinyxml27XMLUtil14SkipWhiteSpaceEPcPi(ptr noundef %3, ptr noundef null)
  store ptr %4, ptr %2, align 8, !tbaa !5
  %5 = load i8, ptr %4, align 1, !tbaa !11
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %19, label %.preheader

.preheader:                                       ; preds = %1, %14
  %.017 = phi ptr [ %16, %14 ], [ %4, %1 ]
  %.01216 = phi ptr [ %17, %14 ], [ %4, %1 ]
  %6 = phi i8 [ %.pr, %14 ], [ %5, %1 ]
  %7 = tail call noundef zeroext i1 @_ZN8tinyxml27XMLUtil12IsWhiteSpaceEc(i8 noundef signext %6)
  br i1 %7, label %8, label %14

8:                                                ; preds = %.preheader
  %9 = tail call noundef ptr @_ZN8tinyxml27XMLUtil14SkipWhiteSpaceEPKcPi(ptr noundef nonnull %.01216, ptr noundef null)
  %10 = load i8, ptr %9, align 1, !tbaa !11
  %11 = icmp eq i8 %10, 0
  br i1 %11, label %18, label %12

12:                                               ; preds = %8
  store i8 32, ptr %.017, align 1, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %.017, i64 1
  br label %14

14:                                               ; preds = %12, %.preheader
  %.113 = phi ptr [ %9, %12 ], [ %.01216, %.preheader ]
  %.1 = phi ptr [ %13, %12 ], [ %.017, %.preheader ]
  %15 = load i8, ptr %.113, align 1, !tbaa !11
  store i8 %15, ptr %.1, align 1, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %.1, i64 1
  %17 = getelementptr inbounds i8, ptr %.113, i64 1
  %.pr = load i8, ptr %17, align 1, !tbaa !11
  %.not15 = icmp eq i8 %.pr, 0
  br i1 %.not15, label %18, label %.preheader, !llvm.loop !12

18:                                               ; preds = %8, %14
  %.0.lcssa = phi ptr [ %.017, %8 ], [ %16, %14 ]
  store i8 0, ptr %.0.lcssa, align 1, !tbaa !11
  br label %19

19:                                               ; preds = %18, %1
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN8tinyxml27XMLUtil14SkipWhiteSpaceEPcPi(ptr noundef, ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN8tinyxml27XMLUtil12IsWhiteSpaceEc(i8 noundef signext) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN8tinyxml27XMLUtil14SkipWhiteSpaceEPKcPi(ptr noundef, ptr noundef) local_unnamed_addr #0 align 2

attributes #0 = { 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" }

!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 = !{!"_ZTSN8tinyxml27StrPairE", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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