; LLVM IR from aap/librw :: tools/subrast/subrast.ll (Z14DestroyCamerasPN2rw5WorldE)

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

@Camera = external dso_local global ptr, align 8
@SubCameras = external dso_local global [4 x ptr], align 16

; 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 void @_Z14DestroyCamerasPN2rw5WorldE(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr @Camera, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  br i1 %5, label %6, label %8

6:                                                ; preds = %1
  %7 = load ptr, ptr @Camera, align 8, !tbaa !5
  call void @_ZN2sk13CameraDestroyEPN2rw6CameraE(ptr noundef %7)
  store ptr null, ptr @Camera, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %6, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %33, %8
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 4
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %36

13:                                               ; preds = %9
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [4 x ptr], ptr @SubCameras, i64 0, i64 %15
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %32

19:                                               ; preds = %13
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [4 x ptr], ptr @SubCameras, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  call void @_ZN2rw5World12removeCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64) %20, ptr noundef %24)
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [4 x ptr], ptr @SubCameras, i64 0, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  call void @_ZN2sk13CameraDestroyEPN2rw6CameraE(ptr noundef %28)
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [4 x ptr], ptr @SubCameras, i64 0, i64 %30
  store ptr null, ptr %31, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %19, %13
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %3, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %3, align 4, !tbaa !9
  br label %9, !llvm.loop !11

36:                                               ; preds = %12
  ret void
}

declare void @_ZN2sk13CameraDestroyEPN2rw6CameraE(ptr noundef) #2

declare void @_ZN2rw5World12removeCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64), ptr 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 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@Camera = external dso_local local_unnamed_addr global ptr, align 8
@SubCameras = external dso_local local_unnamed_addr global [4 x ptr], align 16

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

3:                                                ; preds = %1
  tail call void @_ZN2sk13CameraDestroyEPN2rw6CameraE(ptr noundef nonnull %2)
  store ptr null, ptr @Camera, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %3, %1
  %5 = load ptr, ptr @SubCameras, align 16, !tbaa !5
  %.not8 = icmp eq ptr %5, null
  br i1 %.not8, label %8, label %6

6:                                                ; preds = %4
  tail call void @_ZN2rw5World12removeCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull %5)
  %7 = load ptr, ptr @SubCameras, align 16, !tbaa !5
  tail call void @_ZN2sk13CameraDestroyEPN2rw6CameraE(ptr noundef %7)
  store ptr null, ptr @SubCameras, align 16, !tbaa !5
  br label %8

8:                                                ; preds = %4, %6
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 8), align 8, !tbaa !5
  %.not8.1 = icmp eq ptr %9, null
  br i1 %.not8.1, label %12, label %10

10:                                               ; preds = %8
  tail call void @_ZN2rw5World12removeCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull %9)
  %11 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 8), align 8, !tbaa !5
  tail call void @_ZN2sk13CameraDestroyEPN2rw6CameraE(ptr noundef %11)
  store ptr null, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 8), align 8, !tbaa !5
  br label %12

12:                                               ; preds = %10, %8
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 16), align 16, !tbaa !5
  %.not8.2 = icmp eq ptr %13, null
  br i1 %.not8.2, label %16, label %14

14:                                               ; preds = %12
  tail call void @_ZN2rw5World12removeCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull %13)
  %15 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 16), align 16, !tbaa !5
  tail call void @_ZN2sk13CameraDestroyEPN2rw6CameraE(ptr noundef %15)
  store ptr null, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 16), align 16, !tbaa !5
  br label %16

16:                                               ; preds = %14, %12
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 24), align 8, !tbaa !5
  %.not8.3 = icmp eq ptr %17, null
  br i1 %.not8.3, label %20, label %18

18:                                               ; preds = %16
  tail call void @_ZN2rw5World12removeCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull %17)
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 24), align 8, !tbaa !5
  tail call void @_ZN2sk13CameraDestroyEPN2rw6CameraE(ptr noundef %19)
  store ptr null, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 24), align 8, !tbaa !5
  br label %20

20:                                               ; preds = %18, %16
  ret void
}

declare void @_ZN2sk13CameraDestroyEPN2rw6CameraE(ptr noundef) local_unnamed_addr #1

declare void @_ZN2rw5World12removeCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64), ptr 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 = { "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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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