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

; 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: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

; 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 noundef ptr @_ZN8tinyxml27StrPair9ParseTextEPcPKciPi(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #2 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8
  br label %17

17:                                               ; preds = %5
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %23, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #4
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = load i8, ptr %24, align 1, !tbaa !11
  store i8 %25, ptr %13, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = call i64 @strlen(ptr noundef %26) #5
  store i64 %27, ptr %14, align 8, !tbaa !12
  br label %28

28:                                               ; preds = %67, %22
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = icmp ne i8 %30, 0
  br i1 %31, label %32, label %68

32:                                               ; preds = %28
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = sext i8 %34 to i32
  %36 = load i8, ptr %13, align 1, !tbaa !11
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %35, %37
  br i1 %38, label %39, label %52

39:                                               ; preds = %32
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load i64, ptr %14, align 8, !tbaa !12
  %43 = call i32 @strncmp(ptr noundef %40, ptr noundef %41, i64 noundef %42) #5
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %52

45:                                               ; preds = %39
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !9
  call void @_ZN8tinyxml27StrPair3SetEPcS1_i(ptr noundef nonnull align 8 dereferenceable(24) %16, ptr noundef %46, ptr noundef %47, i32 noundef %48)
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i64, ptr %14, align 8, !tbaa !12
  %51 = getelementptr inbounds i8, ptr %49, i64 %50
  store ptr %51, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %69

52:                                               ; preds = %39, %32
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = sext i8 %54 to i32
  %56 = icmp eq i32 %55, 10
  br i1 %56, label %57, label %61

57:                                               ; preds = %52
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %58, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %57, %52
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i32 1
  store ptr %64, ptr %8, align 8, !tbaa !5
  br label %65

65:                                               ; preds = %62
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  br label %28, !llvm.loop !14

68:                                               ; preds = %28
  store ptr null, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %69

69:                                               ; preds = %68, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %70 = load ptr, ptr %6, align 8
  ret ptr %70
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8tinyxml27StrPair3SetEPcS1_i(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, ptr noundef, i32 noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, 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: 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 ptr @_ZN8tinyxml27StrPair9ParseTextEPcPKciPi(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, ptr nocapture noundef %4) local_unnamed_addr #1 align 2 {
  %6 = load i8, ptr %2, align 1, !tbaa !5
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #2
  %8 = load i8, ptr %1, align 1, !tbaa !5
  %.not21 = icmp eq i8 %8, 0
  br i1 %.not21, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %5, %21
  %9 = phi i8 [ %23, %21 ], [ %8, %5 ]
  %.01822 = phi ptr [ %22, %21 ], [ %1, %5 ]
  %10 = icmp eq i8 %9, %6
  br i1 %10, label %11, label %16

11:                                               ; preds = %.lr.ph
  %12 = tail call i32 @strncmp(ptr noundef nonnull %.01822, ptr noundef nonnull %2, i64 noundef %7) #2
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  tail call void @_ZN8tinyxml27StrPair3SetEPcS1_i(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull %1, ptr noundef nonnull %.01822, i32 noundef %3)
  %15 = getelementptr inbounds i8, ptr %.01822, i64 %7
  br label %.loopexit

16:                                               ; preds = %11, %.lr.ph
  %17 = icmp eq i8 %9, 10
  br i1 %17, label %18, label %21

18:                                               ; preds = %16
  %19 = load i32, ptr %4, align 4, !tbaa !8
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %4, align 4, !tbaa !8
  br label %21

21:                                               ; preds = %16, %18
  %22 = getelementptr inbounds i8, ptr %.01822, i64 1
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %.not = icmp eq i8 %23, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !10

.loopexit:                                        ; preds = %21, %5, %14
  %.0 = phi ptr [ %15, %14 ], [ null, %5 ], [ null, %21 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8tinyxml27StrPair3SetEPcS1_i(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1 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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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