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

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

@_ZL14dropWhiteSpace = external hidden global 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

14:                                               ; preds = %3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %19

17:                                               ; preds = %14
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %17, %14
  store ptr null, ptr %4, align 8
  br label %54

20:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %21 = load i8, ptr @_ZL14dropWhiteSpace, align 1, !tbaa !13
  %22 = icmp ne i8 %21, 0
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %23, %20
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  %27 = zext i1 %26 to i64
  %28 = select i1 %26, i32 0, i32 -1
  store i32 %28, ptr %6, align 4, !tbaa !9
  %29 = getelementptr inbounds %struct.XMLNode, ptr %10, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = call noundef i32 @_ZN7XMLNode16CreateXMLStringREPNS_14XMLNodeDataTagEPci(ptr noundef %30, ptr noundef null, i32 noundef %31)
  store i32 %32, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = mul i64 %35, 1
  %37 = call noalias ptr @malloc(i64 noundef %36) #4
  store ptr %37, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.XMLNode, ptr %10, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = call noundef i32 @_ZN7XMLNode16CreateXMLStringREPNS_14XMLNodeDataTagEPci(ptr noundef %39, ptr noundef %40, i32 noundef %41)
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  store i8 0, ptr %46, align 1, !tbaa !13
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %52

49:                                               ; preds = %24
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %50, ptr %51, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %49, %24
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %53, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %54

54:                                               ; preds = %52, %19
  %55 = load ptr, ptr %4, align 8
  ret ptr %55
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7XMLNode16CreateXMLStringREPNS_14XMLNodeDataTagEPci(ptr noundef, ptr noundef, i32 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 }
attributes #4 = { nounwind allocsize(0) }

!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 = !{!7, !7, 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"

@_ZL14dropWhiteSpace = external hidden local_unnamed_addr global i8, align 1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK7XMLNode15createXMLStringEiPi(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0, i32 noundef %1, ptr noundef writeonly %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 %5, label %6

5:                                                ; preds = %3
  %.not16 = icmp eq ptr %2, null
  br i1 %.not16, label %17, label %.sink.split

6:                                                ; preds = %3
  %7 = load i8, ptr @_ZL14dropWhiteSpace, align 1, !tbaa !10
  %.not17 = icmp eq i8 %7, 0
  %.not1820 = icmp eq i32 %1, 0
  %.not18 = or i1 %.not1820, %.not17
  %8 = sext i1 %.not18 to i32
  %9 = tail call noundef i32 @_ZN7XMLNode16CreateXMLStringREPNS_14XMLNodeDataTagEPci(ptr noundef nonnull %4, ptr noundef null, i32 noundef %8)
  %10 = add nsw i32 %9, 1
  %11 = sext i32 %10 to i64
  %12 = tail call noalias ptr @malloc(i64 noundef %11) #2
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %14 = tail call noundef i32 @_ZN7XMLNode16CreateXMLStringREPNS_14XMLNodeDataTagEPci(ptr noundef %13, ptr noundef %12, i32 noundef %8)
  %15 = sext i32 %9 to i64
  %16 = getelementptr inbounds i8, ptr %12, i64 %15
  store i8 0, ptr %16, align 1, !tbaa !10
  %.not19 = icmp eq ptr %2, null
  br i1 %.not19, label %17, label %.sink.split

.sink.split:                                      ; preds = %6, %5
  %.sink = phi i32 [ 0, %5 ], [ %9, %6 ]
  %.0.ph = phi ptr [ null, %5 ], [ %12, %6 ]
  store i32 %.sink, ptr %2, align 4, !tbaa !11
  br label %17

17:                                               ; preds = %.sink.split, %6, %5
  %.0 = phi ptr [ null, %5 ], [ %12, %6 ], [ %.0.ph, %.sink.split ]
  ret ptr %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7XMLNode16CreateXMLStringREPNS_14XMLNodeDataTagEPci(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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" }
attributes #2 = { nounwind allocsize(0) }

!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 = !{!8, !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !8, i64 0}


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