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

; 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: mustprogress uwtable
declare dso_local void @_ZNK7XMLNode12getChildNodeEi(ptr dead_on_unwind noalias writable sret(%struct.XMLNode) align 8, ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7XMLNode12getChildNodeEPKcPi(ptr dead_on_unwind noalias writable sret(%struct.XMLNode) align 8, ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK7XMLNode12getChildNodeEPKci(ptr dead_on_unwind noalias writable sret(%struct.XMLNode) align 8 %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2, i32 noundef %3) #1 align 2 {
  %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 %struct.XMLNode, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8
  %14 = getelementptr inbounds %struct.XMLNode, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %4
  call void @_ZN7XMLNodeC1ERKS_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) @_ZN7XMLNode12emptyXMLNodeE)
  br label %63

18:                                               ; preds = %4
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = icmp sge i32 %19, 0
  br i1 %20, label %21, label %30

21:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %26, %21
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr %8, align 4, !tbaa !9
  %25 = icmp sgt i32 %23, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %22
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZNK7XMLNode12getChildNodeEPKcPi(ptr dead_on_unwind writable sret(%struct.XMLNode) align 8 %10, ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef %27, ptr noundef %9)
  call void @_ZN7XMLNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %10) #3
  br label %22, !llvm.loop !13

28:                                               ; preds = %22
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZNK7XMLNode12getChildNodeEPKcPi(ptr dead_on_unwind writable sret(%struct.XMLNode) align 8 %0, ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef %29, ptr noundef %9)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %63

30:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %31 = getelementptr inbounds %struct.XMLNode, ptr %13, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = getelementptr inbounds %"struct.XMLNode::XMLNodeDataTag", ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !15
  store i32 %34, ptr %11, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %55, %30
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr %11, align 4, !tbaa !9
  %38 = icmp ne i32 %36, 0
  br i1 %38, label %39, label %56

39:                                               ; preds = %35
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.XMLNode, ptr %13, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = getelementptr inbounds %"struct.XMLNode::XMLNodeDataTag", ptr %42, i32 0, i32 7
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds %struct.XMLNode, ptr %44, i64 %46
  %48 = getelementptr inbounds %struct.XMLNode, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  %50 = getelementptr inbounds %"struct.XMLNode::XMLNodeDataTag", ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  %52 = call noundef i32 @_ZL8xstricmpPKcS0_(ptr noundef %40, ptr noundef %51)
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %55, label %54

54:                                               ; preds = %39
  br label %56

55:                                               ; preds = %39
  br label %35, !llvm.loop !19

56:                                               ; preds = %54, %35
  %57 = load i32, ptr %11, align 4, !tbaa !9
  %58 = icmp slt i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %56
  call void @_ZN7XMLNodeC1ERKS_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) @_ZN7XMLNode12emptyXMLNodeE)
  store i32 1, ptr %12, align 4
  br label %62

60:                                               ; preds = %56
  %61 = load i32, ptr %11, align 4, !tbaa !9
  call void @_ZNK7XMLNode12getChildNodeEi(ptr dead_on_unwind writable sret(%struct.XMLNode) align 8 %0, ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef %61)
  store i32 1, ptr %12, align 4
  br label %62

62:                                               ; preds = %60, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %63

63:                                               ; preds = %62, %28, %17
  ret void
}

declare void @_ZN7XMLNodeD1Ev(ptr)

declare void @_ZN7XMLNodeC1ERKS_(ptr, ptr)

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


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 @_ZNK7XMLNode12getChildNodeEi(ptr dead_on_unwind noalias writable sret(%struct.XMLNode) align 8, ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7XMLNode12getChildNodeEPKcPi(ptr dead_on_unwind noalias writable sret(%struct.XMLNode) align 8, ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK7XMLNode12getChildNodeEPKci(ptr dead_on_unwind noalias writable sret(%struct.XMLNode) align 8 %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca %struct.XMLNode, align 8
  %7 = load ptr, ptr %1, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %8, label %9

8:                                                ; preds = %4
  tail call void @_ZN7XMLNodeC1ERKS_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) @_ZN7XMLNode12emptyXMLNodeE)
  br label %32

9:                                                ; preds = %4
  %10 = icmp sgt i32 %3, -1
  br i1 %10, label %11, label %14

11:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  store i32 0, ptr %5, align 4, !tbaa !10
  %.not18 = icmp eq i32 %3, 0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.0917 = phi i32 [ %12, %.lr.ph ], [ %3, %11 ]
  %12 = add nsw i32 %.0917, -1
  call void @_ZNK7XMLNode12getChildNodeEPKcPi(ptr dead_on_unwind nonnull writable sret(%struct.XMLNode) align 8 %6, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2, ptr noundef nonnull %5)
  call void @_ZN7XMLNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %6) #3
  %13 = icmp ugt i32 %.0917, 1
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %11
  call void @_ZNK7XMLNode12getChildNodeEPKcPi(ptr dead_on_unwind writable sret(%struct.XMLNode) align 8 %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2, ptr noundef nonnull %5)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %32

14:                                               ; preds = %9
  %15 = getelementptr inbounds i8, ptr %7, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = sext i32 %16 to i64
  br label %18

18:                                               ; preds = %20, %14
  %indvars.iv = phi i64 [ %indvars.iv.next, %20 ], [ %17, %14 ]
  %19 = icmp eq i64 %indvars.iv, 0
  br i1 %19, label %.thread, label %20

20:                                               ; preds = %18
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %21 = load ptr, ptr %1, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 40
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = getelementptr inbounds %struct.XMLNode, ptr %23, i64 %indvars.iv.next
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = tail call noundef i32 @_ZL8xstricmpPKcS0_(ptr noundef %2, ptr noundef %26)
  %.not14 = icmp eq i32 %27, 0
  br i1 %.not14, label %28, label %18, !llvm.loop !18

28:                                               ; preds = %20
  %29 = icmp slt i64 %indvars.iv, 1
  br i1 %29, label %.thread, label %30

.thread:                                          ; preds = %18, %28
  tail call void @_ZN7XMLNodeC1ERKS_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) @_ZN7XMLNode12emptyXMLNodeE)
  br label %32

30:                                               ; preds = %28
  %31 = trunc nsw i64 %indvars.iv.next to i32
  tail call void @_ZNK7XMLNode12getChildNodeEi(ptr dead_on_unwind writable sret(%struct.XMLNode) align 8 %0, ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %31)
  br label %32

32:                                               ; preds = %.thread, %30, %._crit_edge, %8
  ret void
}

declare void @_ZN7XMLNodeD1Ev(ptr) local_unnamed_addr

declare void @_ZN7XMLNodeC1ERKS_(ptr, ptr) local_unnamed_addr

attributes #0 = { mustprogress 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 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, !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, !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !11, i64 8}
!15 = !{!"_ZTSN7XMLNode14XMLNodeDataTagE", !7, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !8, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !11, i64 80}
!16 = !{!15, !7, i64 40}
!17 = !{!15, !7, i64 0}
!18 = distinct !{!18, !13}


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