; LLVM IR from gem5/gem5 :: ext/mcpat/xmlParser.ll (ZNK7XMLNode15getChildNodePtrEPKcPi)

; 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"

%struct.XMLNode = type { ptr }
%"struct.XMLNode::XMLNodeDataTag" = type { ptr, i32, i32, i32, i32, i8, ptr, ptr, ptr, ptr, ptr, ptr, i32 }

@_ZN7XMLNode12emptyXMLNodeE = external dso_local global %struct.XMLNode, align 8

; 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 hidden noundef i32 @_ZL8xstricmpPKcS0_(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK7XMLNode15getChildNodePtrEPKcPi(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8
  %14 = getelementptr inbounds %struct.XMLNode, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %3
  store ptr @_ZN7XMLNode12emptyXMLNodeE, ptr %4, align 8
  br label %61

18:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %19 = getelementptr inbounds %struct.XMLNode, ptr %13, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %"struct.XMLNode::XMLNodeDataTag", ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !13
  store i32 %22, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %23 = getelementptr inbounds %struct.XMLNode, ptr %13, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds %"struct.XMLNode::XMLNodeDataTag", ptr %24, i32 0, i32 7
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = load i32, ptr %8, align 4, !tbaa !11
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds %struct.XMLNode, ptr %26, i64 %28
  store ptr %29, ptr %11, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %56, %18
  %31 = load i32, ptr %8, align 4, !tbaa !11
  %32 = load i32, ptr %9, align 4, !tbaa !11
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %59

34:                                               ; preds = %30
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XMLNode, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = getelementptr inbounds %"struct.XMLNode::XMLNodeDataTag", ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = call noundef i32 @_ZL8xstricmpPKcS0_(ptr noundef %39, ptr noundef %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %53, label %43

43:                                               ; preds = %34
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i32, ptr %44, align 4, !tbaa !11
  %46 = load i32, ptr %10, align 4, !tbaa !11
  %47 = icmp eq i32 %45, %46
  br i1 %47, label %48, label %50

48:                                               ; preds = %43
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %49, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %60

50:                                               ; preds = %43
  %51 = load i32, ptr %10, align 4, !tbaa !11
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %10, align 4, !tbaa !11
  br label %53

53:                                               ; preds = %50, %34
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.XMLNode, ptr %54, i32 1
  store ptr %55, ptr %11, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %53
  %57 = load i32, ptr %8, align 4, !tbaa !11
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %8, align 4, !tbaa !11
  br label %30, !llvm.loop !17

59:                                               ; preds = %30
  store ptr @_ZN7XMLNode12emptyXMLNodeE, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %60

60:                                               ; preds = %59, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %61

61:                                               ; preds = %60, %17
  %62 = load ptr, ptr %4, align 8
  ret ptr %62
}

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 0}
!10 = !{!"_ZTS7XMLNode", !6, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"_ZTSN7XMLNode14XMLNodeDataTagE", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !7, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !12, i64 80}
!15 = !{!14, !6, i64 40}
!16 = !{!14, !6, 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"

%struct.XMLNode = type { ptr }

@_ZN7XMLNode12emptyXMLNodeE = external dso_local global %struct.XMLNode, align 8

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL8xstricmpPKcS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZNK7XMLNode15getChildNodePtrEPKcPi(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0, ptr noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 align 2 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %.loopexit, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !10
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %5
  %9 = getelementptr inbounds i8, ptr %4, i64 40
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %19
  %.020 = phi ptr [ %20, %19 ], [ %10, %.lr.ph.preheader ]
  %.01219 = phi i32 [ %.1, %19 ], [ 0, %.lr.ph.preheader ]
  %.01518 = phi i32 [ %21, %19 ], [ 0, %.lr.ph.preheader ]
  %11 = load ptr, ptr %.020, align 8, !tbaa !5
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = tail call noundef i32 @_ZL8xstricmpPKcS0_(ptr noundef %12, ptr noundef %1)
  %.not17 = icmp eq i32 %13, 0
  br i1 %.not17, label %14, label %19

14:                                               ; preds = %.lr.ph
  %15 = load i32, ptr %2, align 4, !tbaa !15
  %16 = icmp eq i32 %15, %.01219
  br i1 %16, label %.loopexit, label %17

17:                                               ; preds = %14
  %18 = add nsw i32 %.01219, 1
  br label %19

19:                                               ; preds = %17, %.lr.ph
  %.1 = phi i32 [ %.01219, %.lr.ph ], [ %18, %17 ]
  %20 = getelementptr inbounds i8, ptr %.020, i64 8
  %21 = add nuw nsw i32 %.01518, 1
  %exitcond.not = icmp eq i32 %21, %7
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !16

.loopexit:                                        ; preds = %19, %14, %5, %3
  %.114 = phi ptr [ @_ZN7XMLNode12emptyXMLNodeE, %3 ], [ @_ZN7XMLNode12emptyXMLNodeE, %5 ], [ @_ZN7XMLNode12emptyXMLNodeE, %19 ], [ %.020, %14 ]
  ret ptr %.114
}

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 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, !7, i64 0}
!6 = !{!"_ZTS7XMLNode", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !12, i64 8}
!11 = !{!"_ZTSN7XMLNode14XMLNodeDataTagE", !7, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !8, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !12, i64 80}
!12 = !{!"int", !8, i64 0}
!13 = !{!11, !7, i64 40}
!14 = !{!11, !7, i64 0}
!15 = !{!12, !12, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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