; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/utils/sc_string.ll (ZN5sc_dt13sc_string_oldpLEc)

; 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.sc_dt::sc_string_old" = type { ptr }
%"class.sc_dt::sc_string_rep" = type { i32, i32, ptr }

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5sc_dt13sc_string_rep6resizeEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5sc_dt13sc_string_repC2Ei(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5sc_dt13sc_string_old6lengthEv(ptr noundef nonnull align 8 dereferenceable(8)) #5 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN5sc_dt13sc_string_oldpLEc(ptr noundef nonnull align 8 dereferenceable(8) %0, i8 noundef signext %1) #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %10 = call noundef i32 @_ZNK5sc_dt13sc_string_old6lengthEv(ptr noundef nonnull align 8 dereferenceable(8) %9)
  store i32 %10, ptr %5, align 4, !tbaa !10
  %11 = getelementptr inbounds %"class.sc_dt::sc_string_old", ptr %9, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %13 = getelementptr inbounds %"class.sc_dt::sc_string_rep", ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !14
  %15 = icmp sgt i32 %14, 1
  br i1 %15, label %16, label %57

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %17 = getelementptr inbounds %"class.sc_dt::sc_string_old", ptr %9, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  store ptr %18, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.sc_dt::sc_string_old", ptr %9, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = getelementptr inbounds %"class.sc_dt::sc_string_rep", ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !14
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr %21, align 8, !tbaa !14
  %24 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 16) #7
  %25 = load i32, ptr %5, align 4, !tbaa !10
  %26 = add nsw i32 %25, 2
  invoke void @_ZN5sc_dt13sc_string_repC2Ei(ptr noundef nonnull align 8 dereferenceable(16) %24, i32 noundef %26)
          to label %27 unwind label %53

27:                                               ; preds = %16
  %28 = getelementptr inbounds %"class.sc_dt::sc_string_old", ptr %9, i32 0, i32 0
  store ptr %24, ptr %28, align 8, !tbaa !12
  %29 = getelementptr inbounds %"class.sc_dt::sc_string_old", ptr %9, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = getelementptr inbounds %"class.sc_dt::sc_string_rep", ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.sc_dt::sc_string_rep", ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = call ptr @strcpy(ptr noundef %32, ptr noundef %35) #6
  %37 = load i8, ptr %4, align 1, !tbaa !9
  %38 = getelementptr inbounds %"class.sc_dt::sc_string_old", ptr %9, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !12
  %40 = getelementptr inbounds %"class.sc_dt::sc_string_rep", ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = load i32, ptr %5, align 4, !tbaa !10
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  store i8 %37, ptr %44, align 1, !tbaa !9
  %45 = getelementptr inbounds %"class.sc_dt::sc_string_old", ptr %9, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !12
  %47 = getelementptr inbounds %"class.sc_dt::sc_string_rep", ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = load i32, ptr %5, align 4, !tbaa !10
  %50 = add nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %48, i64 %51
  store i8 0, ptr %52, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %78

53:                                               ; preds = %16
  %54 = landingpad { ptr, i32 }
          cleanup
  %55 = extractvalue { ptr, i32 } %54, 0
  store ptr %55, ptr %7, align 8
  %56 = extractvalue { ptr, i32 } %54, 1
  store i32 %56, ptr %8, align 4
  call void @_ZdlPvm(ptr noundef %24, i64 noundef 16) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %79

57:                                               ; preds = %2
  %58 = getelementptr inbounds %"class.sc_dt::sc_string_old", ptr %9, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !12
  %60 = load i32, ptr %5, align 4, !tbaa !10
  %61 = add nsw i32 %60, 2
  call void @_ZN5sc_dt13sc_string_rep6resizeEi(ptr noundef nonnull align 8 dereferenceable(16) %59, i32 noundef %61)
  %62 = load i8, ptr %4, align 1, !tbaa !9
  %63 = getelementptr inbounds %"class.sc_dt::sc_string_old", ptr %9, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !12
  %65 = getelementptr inbounds %"class.sc_dt::sc_string_rep", ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !16
  %67 = load i32, ptr %5, align 4, !tbaa !10
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i8, ptr %66, i64 %68
  store i8 %62, ptr %69, align 1, !tbaa !9
  %70 = getelementptr inbounds %"class.sc_dt::sc_string_old", ptr %9, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !12
  %72 = getelementptr inbounds %"class.sc_dt::sc_string_rep", ptr %71, i32 0, i32 2
  %73 = load ptr, ptr %72, align 8, !tbaa !16
  %74 = load i32, ptr %5, align 4, !tbaa !10
  %75 = add nsw i32 %74, 1
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i8, ptr %73, i64 %76
  store i8 0, ptr %77, align 1, !tbaa !9
  br label %78

78:                                               ; preds = %57, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  ret ptr %9

79:                                               ; preds = %53
  %80 = load ptr, ptr %7, align 8
  %81 = load i32, ptr %8, align 4
  %82 = insertvalue { ptr, i32 } poison, ptr %80, 0
  %83 = insertvalue { ptr, i32 } %82, i32 %81, 1
  resume { ptr, i32 } %83
}

attributes #0 = { nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nobuiltin 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 #4 = { nobuiltin nounwind "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 #5 = { 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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"_ZTSN5sc_dt13sc_string_oldE", !6, i64 0}
!14 = !{!15, !11, i64 0}
!15 = !{!"_ZTSN5sc_dt13sc_string_repE", !11, i64 0, !11, i64 4, !6, i64 8}
!16 = !{!15, !6, i64 8}


; 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: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #0

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5sc_dt13sc_string_repC2Ei(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5sc_dt13sc_string_old6lengthEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN5sc_dt13sc_string_oldpLEc(ptr noundef nonnull returned align 8 dereferenceable(8) %0, i8 noundef signext %1) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = tail call noundef i32 @_ZNK5sc_dt13sc_string_old6lengthEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 8, !tbaa !10
  %6 = icmp sgt i32 %5, 1
  br i1 %6, label %7, label %19

7:                                                ; preds = %2
  %8 = add nsw i32 %5, -1
  store i32 %8, ptr %4, align 8, !tbaa !10
  %9 = tail call noalias noundef nonnull dereferenceable(16) ptr @_Znwm(i64 noundef 16) #5
  %10 = add nsw i32 %3, 2
  invoke void @_ZN5sc_dt13sc_string_repC2Ei(ptr noundef nonnull align 8 dereferenceable(16) %9, i32 noundef %10)
          to label %11 unwind label %17

11:                                               ; preds = %7
  store ptr %9, ptr %0, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %9, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %4, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %13, ptr noundef nonnull dereferenceable(1) %15) #6
  br label %21

17:                                               ; preds = %7
  %18 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %9, i64 noundef 16) #7
  resume { ptr, i32 } %18

19:                                               ; preds = %2
  %20 = add nsw i32 %3, 2
  tail call void @_ZN5sc_dt13sc_string_rep6resizeEi(ptr noundef nonnull align 8 dereferenceable(16) %4, i32 noundef %20)
  br label %21

21:                                               ; preds = %19, %11
  %22 = load ptr, ptr %0, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = sext i32 %3 to i64
  %26 = getelementptr inbounds i8, ptr %24, i64 %25
  store i8 %1, ptr %26, align 1, !tbaa !14
  %27 = load ptr, ptr %0, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = getelementptr i8, ptr %29, i64 %25
  %31 = getelementptr i8, ptr %30, i64 1
  store i8 0, ptr %31, align 1, !tbaa !14
  ret ptr %0
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { nobuiltin 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 #3 = { nobuiltin nounwind "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 #4 = { 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 #5 = { builtin allocsize(0) }
attributes #6 = { nounwind }
attributes #7 = { builtin 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 = !{!"_ZTSN5sc_dt13sc_string_oldE", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTSN5sc_dt13sc_string_repE", !12, i64 0, !12, i64 4, !7, i64 8}
!12 = !{!"int", !8, i64 0}
!13 = !{!11, !7, i64 8}
!14 = !{!8, !8, i64 0}


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