; LLVM IR from facebookresearch/habitat-sim :: src/deps/tinyxml2/tinyxml2.ll (ZN8tinyxml210XMLPrinter12CloseElementEb)

; 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::XMLPrinter" = type { %"class.tinyxml2::XMLVisitor", i8, %"class.tinyxml2::DynArray.7", i8, ptr, i32, i32, i8, i8, [64 x i8], [64 x i8], [6 x i8], %"class.tinyxml2::DynArray.8" }
%"class.tinyxml2::XMLVisitor" = type { ptr }
%"class.tinyxml2::DynArray.7" = type { ptr, [10 x ptr], i32, i32 }
%"class.tinyxml2::DynArray.8" = type <{ ptr, [20 x i8], i32, i32, [4 x i8] }>

@.str.20 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.55 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.56 = external hidden unnamed_addr constant [3 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: mustprogress uwtable
declare dso_local void @_ZN8tinyxml210XMLPrinter4PutcEc(ptr noundef nonnull align 8 dereferenceable(312), i8 noundef signext) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN8tinyxml210XMLPrinter5WriteEPKc(ptr noundef nonnull align 8 dereferenceable(312), ptr noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8tinyxml210XMLPrinter12CloseElementEb(ptr noundef nonnull align 8 dereferenceable(312) %0, i1 noundef zeroext %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = zext i1 %1 to i8
  store i8 %6, ptr %4, align 1, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %"class.tinyxml2::XMLPrinter", ptr %7, i32 0, i32 5
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %11 = getelementptr inbounds %"class.tinyxml2::XMLPrinter", ptr %7, i32 0, i32 2
  %12 = call noundef ptr @_ZN8tinyxml28DynArrayIPKcLi10EE3PopEv(ptr noundef nonnull align 8 dereferenceable(96) %11)
  store ptr %12, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %"class.tinyxml2::XMLPrinter", ptr %7, i32 0, i32 1
  %14 = load i8, ptr %13, align 8, !tbaa !17, !range !18, !noundef !19
  %15 = trunc i8 %14 to i1
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  call void @_ZN8tinyxml210XMLPrinter5WriteEPKc(ptr noundef nonnull align 8 dereferenceable(312) %7, ptr noundef @.str.55)
  br label %32

17:                                               ; preds = %2
  %18 = getelementptr inbounds %"class.tinyxml2::XMLPrinter", ptr %7, i32 0, i32 6
  %19 = load i32, ptr %18, align 4, !tbaa !20
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %30

21:                                               ; preds = %17
  %22 = load i8, ptr %4, align 1, !tbaa !9, !range !18, !noundef !19
  %23 = trunc i8 %22 to i1
  br i1 %23, label %30, label %24

24:                                               ; preds = %21
  call void @_ZN8tinyxml210XMLPrinter4PutcEc(ptr noundef nonnull align 8 dereferenceable(312) %7, i8 noundef signext 10)
  %25 = getelementptr inbounds %"class.tinyxml2::XMLPrinter", ptr %7, i32 0, i32 5
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = load ptr, ptr %7, align 8, !tbaa !21
  %28 = getelementptr inbounds ptr, ptr %27, i64 12
  %29 = load ptr, ptr %28, align 8
  call void %29(ptr noundef nonnull align 8 dereferenceable(312) %7, i32 noundef %26)
  br label %30

30:                                               ; preds = %24, %21, %17
  call void @_ZN8tinyxml210XMLPrinter5WriteEPKc(ptr noundef nonnull align 8 dereferenceable(312) %7, ptr noundef @.str.56)
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN8tinyxml210XMLPrinter5WriteEPKc(ptr noundef nonnull align 8 dereferenceable(312) %7, ptr noundef %31)
  call void @_ZN8tinyxml210XMLPrinter5WriteEPKc(ptr noundef nonnull align 8 dereferenceable(312) %7, ptr noundef @.str.20)
  br label %32

32:                                               ; preds = %30, %16
  %33 = getelementptr inbounds %"class.tinyxml2::XMLPrinter", ptr %7, i32 0, i32 6
  %34 = load i32, ptr %33, align 4, !tbaa !20
  %35 = getelementptr inbounds %"class.tinyxml2::XMLPrinter", ptr %7, i32 0, i32 5
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = icmp eq i32 %34, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %32
  %39 = getelementptr inbounds %"class.tinyxml2::XMLPrinter", ptr %7, i32 0, i32 6
  store i32 -1, ptr %39, align 4, !tbaa !20
  br label %40

40:                                               ; preds = %38, %32
  %41 = getelementptr inbounds %"class.tinyxml2::XMLPrinter", ptr %7, i32 0, i32 5
  %42 = load i32, ptr %41, align 8, !tbaa !11
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %40
  %45 = load i8, ptr %4, align 1, !tbaa !9, !range !18, !noundef !19
  %46 = trunc i8 %45 to i1
  br i1 %46, label %48, label %47

47:                                               ; preds = %44
  call void @_ZN8tinyxml210XMLPrinter4PutcEc(ptr noundef nonnull align 8 dereferenceable(312) %7, i8 noundef signext 10)
  br label %48

48:                                               ; preds = %47, %44, %40
  %49 = getelementptr inbounds %"class.tinyxml2::XMLPrinter", ptr %7, i32 0, i32 1
  store i8 0, ptr %49, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

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

!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 = !{!"bool", !7, i64 0}
!11 = !{!12, !15, i64 128}
!12 = !{!"_ZTSN8tinyxml210XMLPrinterE", !13, i64 0, !10, i64 8, !14, i64 16, !10, i64 112, !6, i64 120, !15, i64 128, !15, i64 132, !10, i64 136, !10, i64 137, !7, i64 138, !7, i64 202, !16, i64 272}
!13 = !{!"_ZTSN8tinyxml210XMLVisitorE"}
!14 = !{!"_ZTSN8tinyxml28DynArrayIPKcLi10EEE", !6, i64 0, !7, i64 8, !15, i64 88, !15, i64 92}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTSN8tinyxml28DynArrayIcLi20EEE", !6, i64 0, !7, i64 8, !15, i64 28, !15, i64 32}
!17 = !{!12, !10, i64 8}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!12, !15, i64 132}
!21 = !{!22, !22, i64 0}
!22 = !{!"vtable pointer", !8, i64 0}


; 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.20 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.55 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.56 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8tinyxml210XMLPrinter4PutcEc(ptr noundef nonnull align 8 dereferenceable(312), i8 noundef signext) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN8tinyxml210XMLPrinter5WriteEPKc(ptr noundef nonnull align 8 dereferenceable(312), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8tinyxml210XMLPrinter12CloseElementEb(ptr noundef nonnull align 8 dereferenceable(312) %0, i1 noundef zeroext %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 128
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = tail call noundef ptr @_ZN8tinyxml28DynArrayIPKcLi10EE3PopEv(ptr noundef nonnull align 8 dereferenceable(96) %6)
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i8, ptr %8, align 8, !tbaa !15, !range !16, !noundef !17
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %21, label %11

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 132
  %13 = load i32, ptr %12, align 4, !tbaa !18
  %14 = icmp sgt i32 %13, -1
  %brmerge = or i1 %14, %1
  br i1 %brmerge, label %20, label %15

15:                                               ; preds = %11
  tail call void @_ZN8tinyxml210XMLPrinter4PutcEc(ptr noundef nonnull align 8 dereferenceable(312) %0, i8 noundef signext 10)
  %16 = load i32, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %0, align 8, !tbaa !19
  %18 = getelementptr inbounds i8, ptr %17, i64 96
  %19 = load ptr, ptr %18, align 8
  tail call void %19(ptr noundef nonnull align 8 dereferenceable(312) %0, i32 noundef %16)
  br label %20

20:                                               ; preds = %11, %15
  tail call void @_ZN8tinyxml210XMLPrinter5WriteEPKc(ptr noundef nonnull align 8 dereferenceable(312) %0, ptr noundef nonnull @.str.56)
  tail call void @_ZN8tinyxml210XMLPrinter5WriteEPKc(ptr noundef nonnull align 8 dereferenceable(312) %0, ptr noundef %7)
  br label %21

21:                                               ; preds = %2, %20
  %.str.20.sink = phi ptr [ @.str.20, %20 ], [ @.str.55, %2 ]
  tail call void @_ZN8tinyxml210XMLPrinter5WriteEPKc(ptr noundef nonnull align 8 dereferenceable(312) %0, ptr noundef nonnull %.str.20.sink)
  %22 = getelementptr inbounds i8, ptr %0, i64 132
  %23 = load i32, ptr %22, align 4, !tbaa !18
  %24 = load i32, ptr %3, align 8, !tbaa !5
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store i32 -1, ptr %22, align 4, !tbaa !18
  br label %27

27:                                               ; preds = %26, %21
  %28 = icmp ne i32 %24, 0
  %brmerge4 = or i1 %28, %1
  br i1 %brmerge4, label %30, label %29

29:                                               ; preds = %27
  tail call void @_ZN8tinyxml210XMLPrinter4PutcEc(ptr noundef nonnull align 8 dereferenceable(312) %0, i8 noundef signext 10)
  br label %30

30:                                               ; preds = %27, %29
  store i8 0, ptr %8, align 8, !tbaa !15
  ret void
}

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

!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, !13, i64 128}
!6 = !{!"_ZTSN8tinyxml210XMLPrinterE", !7, i64 0, !8, i64 8, !11, i64 16, !8, i64 112, !12, i64 120, !13, i64 128, !13, i64 132, !8, i64 136, !8, i64 137, !9, i64 138, !9, i64 202, !14, i64 272}
!7 = !{!"_ZTSN8tinyxml210XMLVisitorE"}
!8 = !{!"bool", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN8tinyxml28DynArrayIPKcLi10EEE", !12, i64 0, !9, i64 8, !13, i64 88, !13, i64 92}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!"_ZTSN8tinyxml28DynArrayIcLi20EEE", !12, i64 0, !9, i64 8, !13, i64 28, !13, i64 32}
!15 = !{!6, !8, i64 8}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!6, !13, i64 132}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass