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

; 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 void @_ZNK7XMLNode12getChildNodeEPKcPi(ptr dead_on_unwind noalias writable sret(%struct.XMLNode) align 8 %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2, ptr noundef %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %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
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %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 !9
  %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 %66

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #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 %10, align 4, !tbaa !11
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %28

25:                                               ; preds = %18
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load i32, ptr %26, align 4, !tbaa !11
  store i32 %27, ptr %9, align 4, !tbaa !11
  br label %28

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

36:                                               ; preds = %61, %28
  %37 = load i32, ptr %9, align 4, !tbaa !11
  %38 = load i32, ptr %10, align 4, !tbaa !11
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %64

40:                                               ; preds = %36
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.XMLNode, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = getelementptr inbounds %"struct.XMLNode::XMLNodeDataTag", ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = call noundef i32 @_ZL8xstricmpPKcS0_(ptr noundef %45, ptr noundef %46)
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %58, label %49

49:                                               ; preds = %40
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %56

52:                                               ; preds = %49
  %53 = load i32, ptr %9, align 4, !tbaa !11
  %54 = add nsw i32 %53, 1
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %54, ptr %55, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %52, %49
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  call void @_ZN7XMLNodeC1ERKS_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) %57)
  store i32 1, ptr %12, align 4
  br label %65

58:                                               ; preds = %40
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.XMLNode, ptr %59, i32 1
  store ptr %60, ptr %11, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %58
  %62 = load i32, ptr %9, align 4, !tbaa !11
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %9, align 4, !tbaa !11
  br label %36, !llvm.loop !17

64:                                               ; preds = %36
  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 %65

65:                                               ; preds = %64, %56
  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
  br label %66

66:                                               ; preds = %65, %17
  ret void
}

declare void @_ZN7XMLNodeC1ERKS_(ptr, ptr)

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 uwtable
define dso_local void @_ZNK7XMLNode12getChildNodeEPKcPi(ptr dead_on_unwind noalias writable sret(%struct.XMLNode) align 8 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 align 2 {
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %._crit_edge, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %5, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !10
  %.not17 = icmp eq ptr %3, null
  br i1 %.not17, label %11, label %9

9:                                                ; preds = %6
  %10 = load i32, ptr %3, align 4, !tbaa !13
  br label %11

11:                                               ; preds = %9, %6
  %.013 = phi i32 [ %10, %9 ], [ 0, %6 ]
  %12 = icmp slt i32 %.013, %8
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %11
  %13 = getelementptr inbounds i8, ptr %5, i64 40
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = sext i32 %.013 to i64
  %16 = getelementptr inbounds %struct.XMLNode, ptr %14, i64 %15
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %23
  %.022 = phi ptr [ %24, %23 ], [ %16, %.lr.ph.preheader ]
  %.121 = phi i32 [ %25, %23 ], [ %.013, %.lr.ph.preheader ]
  %17 = load ptr, ptr %.022, align 8, !tbaa !5
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = tail call noundef i32 @_ZL8xstricmpPKcS0_(ptr noundef %18, ptr noundef %2)
  %.not18 = icmp eq i32 %19, 0
  br i1 %.not18, label %20, label %23

20:                                               ; preds = %.lr.ph
  br i1 %.not17, label %._crit_edge, label %21

21:                                               ; preds = %20
  %22 = add nsw i32 %.121, 1
  store i32 %22, ptr %3, align 4, !tbaa !13
  br label %._crit_edge

23:                                               ; preds = %.lr.ph
  %24 = getelementptr inbounds i8, ptr %.022, i64 8
  %25 = add i32 %.121, 1
  %exitcond.not = icmp eq i32 %25, %8
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %23, %11, %20, %21, %4
  %.022.lcssa.sink = phi ptr [ @_ZN7XMLNode12emptyXMLNodeE, %4 ], [ %.022, %21 ], [ %.022, %20 ], [ @_ZN7XMLNode12emptyXMLNodeE, %11 ], [ @_ZN7XMLNode12emptyXMLNodeE, %23 ]
  tail call void @_ZN7XMLNodeC1ERKS_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) %.022.lcssa.sink)
  ret void
}

declare void @_ZN7XMLNodeC1ERKS_(ptr, ptr) local_unnamed_addr

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, !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 = !{!12, !12, i64 0}
!14 = !{!11, !7, i64 40}
!15 = !{!11, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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