; LLVM IR from aap/librw :: src/ps2/pds.ll (ZN2rw3ps215registerPDSPipeEPNS_8PipelineE)

; 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.rw::ps2::PdsGlobals" = type { ptr, i32, i32 }

@_ZN2rw3ps2L10pdsGlobalsE = external hidden global %"struct.rw::ps2::PdsGlobals", align 8
@.str = external hidden unnamed_addr constant [74 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [59 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw3ps215registerPDSPipeEPNS_8PipelineE = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw3ps215registerPDSPipeEPNS_8PipelineE(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr @_ZN2rw3ps2L10pdsGlobalsE, align 8, !tbaa !9
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %10

5:                                                ; preds = %1
  %6 = load i32, ptr getelementptr inbounds (%"struct.rw::ps2::PdsGlobals", ptr @_ZN2rw3ps2L10pdsGlobalsE, i32 0, i32 1), align 8, !tbaa !12
  %7 = sext i32 %6 to i64
  %8 = mul i64 %7, 8
  %9 = call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %8, i32 noundef 262449, ptr noundef @.str)
  store ptr %9, ptr @_ZN2rw3ps2L10pdsGlobalsE, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %5, %1
  %11 = load i32, ptr getelementptr inbounds (%"struct.rw::ps2::PdsGlobals", ptr @_ZN2rw3ps2L10pdsGlobalsE, i32 0, i32 2), align 4, !tbaa !13
  %12 = load i32, ptr getelementptr inbounds (%"struct.rw::ps2::PdsGlobals", ptr @_ZN2rw3ps2L10pdsGlobalsE, i32 0, i32 1), align 8, !tbaa !12
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  br label %17

15:                                               ; preds = %10
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 41, ptr noundef @__PRETTY_FUNCTION__._ZN2rw3ps215registerPDSPipeEPNS_8PipelineE) #3
  unreachable

16:                                               ; No predecessors!
  br label %17

17:                                               ; preds = %16, %14
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = load ptr, ptr @_ZN2rw3ps2L10pdsGlobalsE, align 8, !tbaa !9
  %20 = load i32, ptr getelementptr inbounds (%"struct.rw::ps2::PdsGlobals", ptr @_ZN2rw3ps2L10pdsGlobalsE, i32 0, i32 2), align 4, !tbaa !13
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr getelementptr inbounds (%"struct.rw::ps2::PdsGlobals", ptr @_ZN2rw3ps2L10pdsGlobalsE, i32 0, i32 2), align 4, !tbaa !13
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds ptr, ptr %19, i64 %22
  store ptr %18, ptr %23, align 8, !tbaa !5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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 = { inlinehint 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 = { noreturn 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 #3 = { noreturn 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 = !{!"_ZTSN2rw3ps210PdsGlobalsE", !6, i64 0, !11, i64 8, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 12}


; 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.rw::ps2::PdsGlobals" = type { ptr, i32, i32 }

@_ZN2rw3ps2L10pdsGlobalsE = external hidden local_unnamed_addr global %"struct.rw::ps2::PdsGlobals", align 8
@.str = external hidden unnamed_addr constant [74 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [59 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw3ps215registerPDSPipeEPNS_8PipelineE = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw3ps215registerPDSPipeEPNS_8PipelineE(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @_ZN2rw3ps2L10pdsGlobalsE, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %9

4:                                                ; preds = %1
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @_ZN2rw3ps2L10pdsGlobalsE, i64 8), align 8, !tbaa !11
  %6 = sext i32 %5 to i64
  %7 = shl nsw i64 %6, 3
  %8 = tail call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %7, i32 noundef 262449, ptr noundef nonnull @.str)
  store ptr %8, ptr @_ZN2rw3ps2L10pdsGlobalsE, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %4, %1
  %10 = phi ptr [ %8, %4 ], [ %2, %1 ]
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @_ZN2rw3ps2L10pdsGlobalsE, i64 12), align 4, !tbaa !12
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @_ZN2rw3ps2L10pdsGlobalsE, i64 8), align 8, !tbaa !11
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  tail call void @__assert_fail(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 41, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN2rw3ps215registerPDSPipeEPNS_8PipelineE) #3
  unreachable

15:                                               ; preds = %9
  %16 = add nsw i32 %11, 1
  store i32 %16, ptr getelementptr inbounds (i8, ptr @_ZN2rw3ps2L10pdsGlobalsE, i64 12), align 4, !tbaa !12
  %17 = sext i32 %11 to i64
  %18 = getelementptr inbounds ptr, ptr %10, i64 %17
  store ptr %0, ptr %18, align 8, !tbaa !13
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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 = { inlinehint 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 = { noreturn 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 #3 = { noreturn 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 = !{!"_ZTSN2rw3ps210PdsGlobalsE", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 12}
!13 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass