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

; 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::XMLElement" = type { %"class.tinyxml2::XMLNode", i32, ptr }
%"class.tinyxml2::XMLNode" = type { ptr, ptr, ptr, %"class.tinyxml2::StrPair", i32, ptr, ptr, ptr, ptr, ptr, ptr }
%"class.tinyxml2::StrPair" = type { i32, ptr, ptr }
%"class.tinyxml2::XMLAttribute" = type { ptr, %"class.tinyxml2::StrPair", %"class.tinyxml2::StrPair", 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN8tinyxml27XMLUtil11StringEqualEPKcS2_i(ptr noundef, ptr noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK8tinyxml212XMLAttribute4NameEv(ptr noundef nonnull align 8 dereferenceable(80)) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN8tinyxml210XMLElement21FindOrCreateAttributeEPKc(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds %"class.tinyxml2::XMLElement", ptr %7, i32 0, i32 2
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %6, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %20, %2
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %25

13:                                               ; preds = %10
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call noundef ptr @_ZNK8tinyxml212XMLAttribute4NameEv(ptr noundef nonnull align 8 dereferenceable(80) %14)
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call noundef zeroext i1 @_ZN8tinyxml27XMLUtil11StringEqualEPKcS2_i(ptr noundef %15, ptr noundef %16, i32 noundef 2147483647)
  br i1 %17, label %18, label %19

18:                                               ; preds = %13
  br label %25

19:                                               ; preds = %13
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %21, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %"class.tinyxml2::XMLAttribute", ptr %22, i32 0, i32 4
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  store ptr %24, ptr %6, align 8, !tbaa !5
  br label %10, !llvm.loop !17

25:                                               ; preds = %18, %10
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %42, label %28

28:                                               ; preds = %25
  %29 = call noundef ptr @_ZN8tinyxml210XMLElement15CreateAttributeEv(ptr noundef nonnull align 8 dereferenceable(120) %7)
  store ptr %29, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %36

32:                                               ; preds = %28
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %"class.tinyxml2::XMLAttribute", ptr %34, i32 0, i32 4
  store ptr %33, ptr %35, align 8, !tbaa !15
  br label %39

36:                                               ; preds = %28
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.tinyxml2::XMLElement", ptr %7, i32 0, i32 2
  store ptr %37, ptr %38, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %36, %32
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN8tinyxml212XMLAttribute7SetNameEPKc(ptr noundef nonnull align 8 dereferenceable(80) %40, ptr noundef %41)
  br label %42

42:                                               ; preds = %39, %25
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %43
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN8tinyxml210XMLElement15CreateAttributeEv(ptr noundef nonnull align 8 dereferenceable(120)) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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 = { 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 112}
!10 = !{!"_ZTSN8tinyxml210XMLElementE", !11, i64 0, !14, i64 104, !6, i64 112}
!11 = !{!"_ZTSN8tinyxml27XMLNodeE", !6, i64 8, !6, i64 16, !12, i64 24, !13, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!12 = !{!"_ZTSN8tinyxml27StrPairE", !13, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSN8tinyxml210XMLElement18ElementClosingTypeE", !7, i64 0}
!15 = !{!16, !6, i64 64}
!16 = !{!"_ZTSN8tinyxml212XMLAttributeE", !12, i64 8, !12, i64 32, !13, i64 56, !6, i64 64, !6, i64 72}
!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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN8tinyxml27XMLUtil11StringEqualEPKcS2_i(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK8tinyxml212XMLAttribute4NameEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN8tinyxml210XMLElement21FindOrCreateAttributeEPKc(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 112
  %.018 = load ptr, ptr %3, align 8, !tbaa !5
  %.not19 = icmp eq ptr %.018, null
  br i1 %.not19, label %11, label %.lr.ph

.lr.ph:                                           ; preds = %2, %6
  %.020 = phi ptr [ %.0, %6 ], [ %.018, %2 ]
  %4 = tail call noundef ptr @_ZNK8tinyxml212XMLAttribute4NameEv(ptr noundef nonnull align 8 dereferenceable(80) %.020)
  %5 = tail call noundef zeroext i1 @_ZN8tinyxml27XMLUtil11StringEqualEPKcS2_i(ptr noundef %4, ptr noundef %1, i32 noundef 2147483647)
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %.lr.ph
  %7 = getelementptr inbounds i8, ptr %.020, i64 64
  %.0 = load ptr, ptr %7, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %8, label %.lr.ph, !llvm.loop !9

8:                                                ; preds = %6
  %9 = tail call noundef ptr @_ZN8tinyxml210XMLElement15CreateAttributeEv(ptr noundef nonnull align 8 dereferenceable(120) %0)
  %10 = getelementptr inbounds i8, ptr %.020, i64 64
  store ptr %9, ptr %10, align 8, !tbaa !11
  br label %13

11:                                               ; preds = %2
  %12 = tail call noundef ptr @_ZN8tinyxml210XMLElement15CreateAttributeEv(ptr noundef nonnull align 8 dereferenceable(120) %0)
  store ptr %12, ptr %3, align 8, !tbaa !15
  br label %13

13:                                               ; preds = %11, %8
  %14 = phi ptr [ %12, %11 ], [ %9, %8 ]
  tail call void @_ZN8tinyxml212XMLAttribute7SetNameEPKc(ptr noundef nonnull align 8 dereferenceable(80) %14, ptr noundef %1)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %13
  %.1 = phi ptr [ %14, %13 ], [ %.020, %.lr.ph ]
  ret ptr %.1
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN8tinyxml210XMLElement15CreateAttributeEv(ptr noundef nonnull align 8 dereferenceable(120)) local_unnamed_addr #1 align 2

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 64}
!12 = !{!"_ZTSN8tinyxml212XMLAttributeE", !13, i64 8, !13, i64 32, !14, i64 56, !6, i64 64, !6, i64 72}
!13 = !{!"_ZTSN8tinyxml27StrPairE", !14, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 112}
!16 = !{!"_ZTSN8tinyxml210XMLElementE", !17, i64 0, !18, i64 104, !6, i64 112}
!17 = !{!"_ZTSN8tinyxml27XMLNodeE", !6, i64 8, !6, i64 16, !13, i64 24, !14, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!18 = !{!"_ZTSN8tinyxml210XMLElement18ElementClosingTypeE", !7, i64 0}


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