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

; 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.sk::Globals" = type { ptr, i32, i32, i32 }

@Camera = external dso_local global ptr, align 8
@SubCameras = external dso_local global [4 x ptr], align 16
@_ZN2sk7globalsE = external global %"struct.sk::Globals", align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__._Z13CreateCamerasPN2rw5WorldE = external hidden unnamed_addr constant [32 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x 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: mustprogress uwtable
declare dso_local void @_Z18PositionSubCamerasv() #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z13CreateCamerasPN2rw5WorldE(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 i32, ptr getelementptr inbounds (%"struct.sk::Globals", ptr @_ZN2sk7globalsE, i32 0, i32 1), align 8, !tbaa !9
  %5 = load i32, ptr getelementptr inbounds (%"struct.sk::Globals", ptr @_ZN2sk7globalsE, i32 0, i32 2), align 4, !tbaa !12
  %6 = call noundef ptr @_ZN2sk12CameraCreateEiii(i32 noundef %4, i32 noundef %5, i32 noundef 1)
  store ptr %6, ptr @Camera, align 8, !tbaa !5
  %7 = load ptr, ptr @Camera, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  br label %12

10:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 109, ptr noundef @__PRETTY_FUNCTION__._Z13CreateCamerasPN2rw5WorldE) #4
  unreachable

11:                                               ; No predecessors!
  br label %12

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

13:                                               ; preds = %52, %12
  %14 = load i32, ptr %3, align 4, !tbaa !13
  %15 = icmp slt i32 %14, 4
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %55

17:                                               ; preds = %13
  %18 = call noundef ptr @_ZN2sk12CameraCreateEiii(i32 noundef 0, i32 noundef 0, i32 noundef 1)
  %19 = load i32, ptr %3, align 4, !tbaa !13
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [4 x ptr], ptr @SubCameras, i64 0, i64 %20
  store ptr %18, ptr %21, align 8, !tbaa !5
  %22 = load i32, ptr %3, align 4, !tbaa !13
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [4 x ptr], ptr @SubCameras, i64 0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %17
  br label %30

28:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 113, ptr noundef @__PRETTY_FUNCTION__._Z13CreateCamerasPN2rw5WorldE) #4
  unreachable

29:                                               ; No predecessors!
  br label %30

30:                                               ; preds = %29, %27
  %31 = load i32, ptr %3, align 4, !tbaa !13
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [4 x ptr], ptr @SubCameras, i64 0, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  call void @_ZN2rw6Camera12setNearPlaneEf(ptr noundef nonnull align 8 dereferenceable(600) %34, float noundef 0x3FB99999A0000000)
  %35 = load i32, ptr %3, align 4, !tbaa !13
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [4 x ptr], ptr @SubCameras, i64 0, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  call void @_ZN2rw6Camera11setFarPlaneEf(ptr noundef nonnull align 8 dereferenceable(600) %38, float noundef 3.000000e+01)
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = load i32, ptr %3, align 4, !tbaa !13
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [4 x ptr], ptr @SubCameras, i64 0, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  call void @_ZN2rw5World9addCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64) %39, ptr noundef %43)
  %44 = load i32, ptr %3, align 4, !tbaa !13
  %45 = icmp sgt i32 %44, 0
  br i1 %45, label %46, label %51

46:                                               ; preds = %30
  %47 = load i32, ptr %3, align 4, !tbaa !13
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [4 x ptr], ptr @SubCameras, i64 0, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  call void @_ZN2rw6Camera13setProjectionEi(ptr noundef nonnull align 8 dereferenceable(600) %50, i32 noundef 2)
  br label %51

51:                                               ; preds = %46, %30
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %3, align 4, !tbaa !13
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %3, align 4, !tbaa !13
  br label %13, !llvm.loop !14

55:                                               ; preds = %16
  call void @_Z18PositionSubCamerasv()
  ret void
}

declare noundef ptr @_ZN2sk12CameraCreateEiii(i32 noundef, i32 noundef, i32 noundef) #2

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

declare void @_ZN2rw6Camera12setNearPlaneEf(ptr noundef nonnull align 8 dereferenceable(600), float noundef) #2

declare void @_ZN2rw6Camera11setFarPlaneEf(ptr noundef nonnull align 8 dereferenceable(600), float noundef) #2

declare void @_ZN2rw5World9addCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef) #2

declare void @_ZN2rw6Camera13setProjectionEi(ptr noundef nonnull align 8 dereferenceable(600), i32 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 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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, !11, i64 8}
!10 = !{!"_ZTSN2sk7GlobalsE", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 12}
!13 = !{!11, !11, 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"

%"struct.sk::Globals" = type { ptr, i32, i32, i32 }

@Camera = external dso_local local_unnamed_addr global ptr, align 8
@SubCameras = external dso_local local_unnamed_addr global [4 x ptr], align 16
@_ZN2sk7globalsE = external local_unnamed_addr global %"struct.sk::Globals", align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__._Z13CreateCamerasPN2rw5WorldE = external hidden unnamed_addr constant [32 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z18PositionSubCamerasv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z13CreateCamerasPN2rw5WorldE(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @_ZN2sk7globalsE, i64 8), align 8, !tbaa !5
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @_ZN2sk7globalsE, i64 12), align 4, !tbaa !11
  %4 = tail call noundef ptr @_ZN2sk12CameraCreateEiii(i32 noundef %2, i32 noundef %3, i32 noundef 1)
  store ptr %4, ptr @Camera, align 8, !tbaa !12
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %6, label %.preheader.preheader

.preheader.preheader:                             ; preds = %1
  %5 = tail call noundef ptr @_ZN2sk12CameraCreateEiii(i32 noundef 0, i32 noundef 0, i32 noundef 1)
  store ptr %5, ptr @SubCameras, align 16, !tbaa !12
  %.not10 = icmp eq ptr %5, null
  br i1 %.not10, label %7, label %.preheader.1

6:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 109, ptr noundef nonnull @__PRETTY_FUNCTION__._Z13CreateCamerasPN2rw5WorldE) #3
  unreachable

7:                                                ; preds = %.preheader.3, %.preheader.2, %.preheader.1, %.preheader.preheader
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 113, ptr noundef nonnull @__PRETTY_FUNCTION__._Z13CreateCamerasPN2rw5WorldE) #3
  unreachable

.preheader.1:                                     ; preds = %.preheader.preheader
  tail call void @_ZN2rw6Camera12setNearPlaneEf(ptr noundef nonnull align 8 dereferenceable(600) %5, float noundef 0x3FB99999A0000000)
  %8 = load ptr, ptr @SubCameras, align 16, !tbaa !12
  tail call void @_ZN2rw6Camera11setFarPlaneEf(ptr noundef nonnull align 8 dereferenceable(600) %8, float noundef 3.000000e+01)
  %9 = load ptr, ptr @SubCameras, align 16, !tbaa !12
  tail call void @_ZN2rw5World9addCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %9)
  %10 = tail call noundef ptr @_ZN2sk12CameraCreateEiii(i32 noundef 0, i32 noundef 0, i32 noundef 1)
  store ptr %10, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 8), align 8, !tbaa !12
  %.not10.1 = icmp eq ptr %10, null
  br i1 %.not10.1, label %7, label %.preheader.2

.preheader.2:                                     ; preds = %.preheader.1
  tail call void @_ZN2rw6Camera12setNearPlaneEf(ptr noundef nonnull align 8 dereferenceable(600) %10, float noundef 0x3FB99999A0000000)
  %11 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 8), align 8, !tbaa !12
  tail call void @_ZN2rw6Camera11setFarPlaneEf(ptr noundef nonnull align 8 dereferenceable(600) %11, float noundef 3.000000e+01)
  %12 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 8), align 8, !tbaa !12
  tail call void @_ZN2rw5World9addCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %12)
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 8), align 8, !tbaa !12
  tail call void @_ZN2rw6Camera13setProjectionEi(ptr noundef nonnull align 8 dereferenceable(600) %13, i32 noundef 2)
  %14 = tail call noundef ptr @_ZN2sk12CameraCreateEiii(i32 noundef 0, i32 noundef 0, i32 noundef 1)
  store ptr %14, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 16), align 16, !tbaa !12
  %.not10.2 = icmp eq ptr %14, null
  br i1 %.not10.2, label %7, label %.preheader.3

.preheader.3:                                     ; preds = %.preheader.2
  tail call void @_ZN2rw6Camera12setNearPlaneEf(ptr noundef nonnull align 8 dereferenceable(600) %14, float noundef 0x3FB99999A0000000)
  %15 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 16), align 16, !tbaa !12
  tail call void @_ZN2rw6Camera11setFarPlaneEf(ptr noundef nonnull align 8 dereferenceable(600) %15, float noundef 3.000000e+01)
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 16), align 16, !tbaa !12
  tail call void @_ZN2rw5World9addCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %16)
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 16), align 16, !tbaa !12
  tail call void @_ZN2rw6Camera13setProjectionEi(ptr noundef nonnull align 8 dereferenceable(600) %17, i32 noundef 2)
  %18 = tail call noundef ptr @_ZN2sk12CameraCreateEiii(i32 noundef 0, i32 noundef 0, i32 noundef 1)
  store ptr %18, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 24), align 8, !tbaa !12
  %.not10.3 = icmp eq ptr %18, null
  br i1 %.not10.3, label %7, label %19

19:                                               ; preds = %.preheader.3
  tail call void @_ZN2rw6Camera12setNearPlaneEf(ptr noundef nonnull align 8 dereferenceable(600) %18, float noundef 0x3FB99999A0000000)
  %20 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 24), align 8, !tbaa !12
  tail call void @_ZN2rw6Camera11setFarPlaneEf(ptr noundef nonnull align 8 dereferenceable(600) %20, float noundef 3.000000e+01)
  %21 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 24), align 8, !tbaa !12
  tail call void @_ZN2rw5World9addCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %21)
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @SubCameras, i64 24), align 8, !tbaa !12
  tail call void @_ZN2rw6Camera13setProjectionEi(ptr noundef nonnull align 8 dereferenceable(600) %22, i32 noundef 2)
  tail call void @_Z18PositionSubCamerasv()
  ret void
}

declare noundef ptr @_ZN2sk12CameraCreateEiii(i32 noundef, i32 noundef, i32 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

declare void @_ZN2rw6Camera12setNearPlaneEf(ptr noundef nonnull align 8 dereferenceable(600), float noundef) local_unnamed_addr #1

declare void @_ZN2rw6Camera11setFarPlaneEf(ptr noundef nonnull align 8 dereferenceable(600), float noundef) local_unnamed_addr #1

declare void @_ZN2rw5World9addCameraEPNS_6CameraE(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef) local_unnamed_addr #1

declare void @_ZN2rw6Camera13setProjectionEi(ptr noundef nonnull align 8 dereferenceable(600), i32 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" }
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, !10, i64 8}
!6 = !{!"_ZTSN2sk7GlobalsE", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!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 12}
!12 = !{!7, !7, i64 0}


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