; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/datatypes/fx/scfx_rep.ll (ZN5sc_dt8scfx_repnwEm)

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

%"union.sc_dt::scfx_rep_node" = type { ptr, [32 x i8] }

@_ZN5sc_dtL4listE = external hidden global ptr, 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
define dso_local noundef ptr @_ZN5sc_dt8scfx_repnwEm(i64 noundef %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1024, ptr %4, align 4, !tbaa !9
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = icmp ne i64 %8, 40
  br i1 %9, label %10, label %13

10:                                               ; preds = %1
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = call noalias noundef nonnull ptr @_Znwm(i64 noundef %11) #4
  store ptr %12, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %44

13:                                               ; preds = %1
  %14 = load ptr, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !11
  %15 = icmp ne ptr %14, null
  br i1 %15, label %38, label %16

16:                                               ; preds = %13
  %17 = call noalias noundef nonnull ptr @_Znam(i64 noundef 40960) #5
  store ptr %17, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %32, %16
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 1023
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %35

22:                                               ; preds = %18
  %23 = load ptr, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !11
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds %"union.sc_dt::scfx_rep_node", ptr %23, i64 %25
  %27 = getelementptr inbounds %"union.sc_dt::scfx_rep_node", ptr %26, i64 1
  %28 = load ptr, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !11
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %"union.sc_dt::scfx_rep_node", ptr %28, i64 %30
  store ptr %27, ptr %31, align 8, !tbaa !13
  br label %32

32:                                               ; preds = %22
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %6, align 4, !tbaa !9
  br label %18, !llvm.loop !14

35:                                               ; preds = %21
  %36 = load ptr, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !11
  %37 = getelementptr inbounds %"union.sc_dt::scfx_rep_node", ptr %36, i64 1023
  store ptr null, ptr %37, align 8, !tbaa !13
  br label %38

38:                                               ; preds = %35, %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %39 = load ptr, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !11
  %40 = getelementptr inbounds [40 x i8], ptr %39, i64 0, i64 0
  store ptr %40, ptr %7, align 8, !tbaa !11
  %41 = load ptr, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !11
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  store ptr %42, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !11
  %43 = load ptr, ptr %7, align 8, !tbaa !11
  store ptr %43, ptr %2, align 8
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %44

44:                                               ; preds = %38, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %45 = load ptr, ptr %2, align 8
  ret ptr %45
}

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

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

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 = { 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 = { nounwind }
attributes #4 = { allocsize(0) }
attributes #5 = { builtin 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 = !{!"long", !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, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

%"union.sc_dt::scfx_rep_node" = type { ptr, [32 x i8] }

@_ZN5sc_dtL4listE = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN5sc_dt8scfx_repnwEm(i64 noundef %0) local_unnamed_addr #0 align 2 {
  %.not = icmp eq i64 %0, 40
  br i1 %.not, label %4, label %2

2:                                                ; preds = %1
  %3 = tail call noalias noundef nonnull ptr @_Znwm(i64 noundef %0) #2
  br label %26

4:                                                ; preds = %1
  %5 = load ptr, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !5
  %.not9 = icmp eq ptr %5, null
  br i1 %.not9, label %6, label %23

6:                                                ; preds = %4
  %7 = tail call noalias noundef nonnull dereferenceable(40960) ptr @_Znam(i64 noundef 40960) #3
  store ptr %7, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !5
  br label %11

8:                                                ; preds = %11
  %9 = load ptr, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 40920
  store ptr null, ptr %10, align 8, !tbaa !9
  br label %23

11:                                               ; preds = %11, %6
  %indvars.iv = phi i64 [ 0, %6 ], [ %indvars.iv.next.2, %11 ]
  %12 = load ptr, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !5
  %13 = getelementptr inbounds %"union.sc_dt::scfx_rep_node", ptr %12, i64 %indvars.iv
  %14 = getelementptr inbounds i8, ptr %13, i64 40
  store ptr %14, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !5
  %16 = getelementptr inbounds %"union.sc_dt::scfx_rep_node", ptr %15, i64 %indvars.iv
  %17 = getelementptr inbounds i8, ptr %16, i64 40
  %18 = getelementptr inbounds i8, ptr %16, i64 80
  store ptr %18, ptr %17, align 8, !tbaa !9
  %19 = load ptr, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !5
  %20 = getelementptr inbounds %"union.sc_dt::scfx_rep_node", ptr %19, i64 %indvars.iv
  %21 = getelementptr inbounds i8, ptr %20, i64 80
  %22 = getelementptr inbounds i8, ptr %20, i64 120
  store ptr %22, ptr %21, align 8, !tbaa !9
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %exitcond.not.2 = icmp eq i64 %indvars.iv.next.2, 1023
  br i1 %exitcond.not.2, label %8, label %11, !llvm.loop !10

23:                                               ; preds = %8, %4
  %24 = phi ptr [ %9, %8 ], [ %5, %4 ]
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  store ptr %25, ptr @_ZN5sc_dtL4listE, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %23, %2
  %.0 = phi ptr [ %3, %2 ], [ %24, %23 ]
  ret ptr %.0
}

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

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

attributes #0 = { 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 #1 = { 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 #2 = { allocsize(0) }
attributes #3 = { builtin 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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