; LLVM IR from thuhcsi/Crystal.TTVS :: TinyXML/tinyxml.ll (ZN9TiXmlNode11GetDocumentEv)

; 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.TiXmlNode = type { %class.TiXmlBase, ptr, i32, ptr, ptr, %class.TiXmlString, ptr, ptr }
%class.TiXmlBase = type { ptr, %struct.TiXmlCursor, ptr }
%struct.TiXmlCursor = type { i32, i32 }
%class.TiXmlString = type { ptr, i64, i64 }

; 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 noundef ptr @_ZN9TiXmlNode11GetDocumentEv(ptr noundef nonnull align 8 dereferenceable(96) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr %6, ptr %4, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %18, %1
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %22

10:                                               ; preds = %7
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call noundef ptr @_ZN9TiXmlNode10ToDocumentEv(ptr noundef nonnull align 8 dereferenceable(96) %11)
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %17

14:                                               ; preds = %10
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call noundef ptr @_ZN9TiXmlNode10ToDocumentEv(ptr noundef nonnull align 8 dereferenceable(96) %15)
  store ptr %16, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %23

17:                                               ; preds = %10
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %class.TiXmlNode, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  store ptr %21, ptr %4, align 8, !tbaa !5
  br label %7, !llvm.loop !17

22:                                               ; preds = %7
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %23

23:                                               ; preds = %22, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %24 = load ptr, ptr %2, align 8
  ret ptr %24
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN9TiXmlNode10ToDocumentEv(ptr noundef nonnull align 8 dereferenceable(96)) #2 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 = { 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 }

!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 24}
!10 = !{!"_ZTS9TiXmlNode", !11, i64 0, !6, i64 24, !14, i64 32, !6, i64 40, !6, i64 48, !15, i64 56, !6, i64 80, !6, i64 88}
!11 = !{!"_ZTS9TiXmlBase", !12, i64 8, !6, i64 16}
!12 = !{!"_ZTS11TiXmlCursor", !13, i64 0, !13, i64 4}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSN9TiXmlNode8NodeTypeE", !7, i64 0}
!15 = !{!"_ZTS11TiXmlString", !6, i64 0, !16, i64 8, !16, i64 16}
!16 = !{!"long", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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 nounwind uwtable
define dso_local noundef ptr @_ZN9TiXmlNode11GetDocumentEv(ptr noundef nonnull align 8 dereferenceable(96) %0) local_unnamed_addr #0 align 2 {
  br label %2

2:                                                ; preds = %1, %6
  %.09 = phi ptr [ %0, %1 ], [ %8, %6 ]
  %3 = tail call noundef ptr @_ZN9TiXmlNode10ToDocumentEv(ptr noundef nonnull align 8 dereferenceable(96) %.09)
  %.not7 = icmp eq ptr %3, null
  br i1 %.not7, label %6, label %4

4:                                                ; preds = %2
  %5 = tail call noundef ptr @_ZN9TiXmlNode10ToDocumentEv(ptr noundef nonnull align 8 dereferenceable(96) %.09)
  br label %.loopexit

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %.09, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %.loopexit, label %2, !llvm.loop !16

.loopexit:                                        ; preds = %6, %4
  %.06 = phi ptr [ %5, %4 ], [ null, %6 ]
  ret ptr %.06
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN9TiXmlNode10ToDocumentEv(ptr noundef nonnull align 8 dereferenceable(96)) local_unnamed_addr #0 align 2

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

!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, !12, i64 24}
!6 = !{!"_ZTS9TiXmlNode", !7, i64 0, !12, i64 24, !13, i64 32, !12, i64 40, !12, i64 48, !14, i64 56, !12, i64 80, !12, i64 88}
!7 = !{!"_ZTS9TiXmlBase", !8, i64 8, !12, i64 16}
!8 = !{!"_ZTS11TiXmlCursor", !9, i64 0, !9, i64 4}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"any pointer", !10, i64 0}
!13 = !{!"_ZTSN9TiXmlNode8NodeTypeE", !10, i64 0}
!14 = !{!"_ZTS11TiXmlString", !12, i64 0, !15, i64 8, !15, i64 16}
!15 = !{!"long", !10, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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