; LLVM IR from robinrodricks/InspiritImage :: Inspirit.Assurf/clib/rpp (rpp)

; 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.vec3_t = type { [3 x double] }

; 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

declare void @vec3_mult_mat(ptr noundef, ptr noundef, ptr noundef) #1

declare void @vec3_add_vec(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @xformproj(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !9
  %14 = load i32, ptr %10, align 4, !tbaa !9
  %15 = zext i32 %14 to i64
  %16 = call ptr @llvm.stacksave.p0()
  store ptr %16, ptr %11, align 8
  %17 = alloca %struct.vec3_t, i64 %15, align 16
  store i64 %15, ptr %12, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %79, %5
  %19 = load i32, ptr %13, align 4, !tbaa !9
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %82

22:                                               ; preds = %18
  %23 = load i32, ptr %13, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds %struct.vec3_t, ptr %17, i64 %24
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i32, ptr %13, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %struct.vec3_t, ptr %27, i64 %29
  call void @vec3_mult_mat(ptr noundef %25, ptr noundef %26, ptr noundef %30)
  %31 = load i32, ptr %13, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds %struct.vec3_t, ptr %17, i64 %32
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  call void @vec3_add_vec(ptr noundef %33, ptr noundef %34)
  %35 = load i32, ptr %13, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.vec3_t, ptr %17, i64 %36
  %38 = getelementptr inbounds %struct.vec3_t, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds [3 x double], ptr %38, i64 0, i64 0
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = load i32, ptr %13, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.vec3_t, ptr %17, i64 %42
  %44 = getelementptr inbounds %struct.vec3_t, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds [3 x double], ptr %44, i64 0, i64 2
  %46 = load double, ptr %45, align 8, !tbaa !11
  %47 = fdiv double %40, %46
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %struct.vec3_t, ptr %48, i64 %50
  %52 = getelementptr inbounds %struct.vec3_t, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds [3 x double], ptr %52, i64 0, i64 0
  store double %47, ptr %53, align 8, !tbaa !11
  %54 = load i32, ptr %13, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds %struct.vec3_t, ptr %17, i64 %55
  %57 = getelementptr inbounds %struct.vec3_t, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds [3 x double], ptr %57, i64 0, i64 1
  %59 = load double, ptr %58, align 8, !tbaa !11
  %60 = load i32, ptr %13, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.vec3_t, ptr %17, i64 %61
  %63 = getelementptr inbounds %struct.vec3_t, ptr %62, i32 0, i32 0
  %64 = getelementptr inbounds [3 x double], ptr %63, i64 0, i64 2
  %65 = load double, ptr %64, align 8, !tbaa !11
  %66 = fdiv double %59, %65
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load i32, ptr %13, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds %struct.vec3_t, ptr %67, i64 %69
  %71 = getelementptr inbounds %struct.vec3_t, ptr %70, i32 0, i32 0
  %72 = getelementptr inbounds [3 x double], ptr %71, i64 0, i64 1
  store double %66, ptr %72, align 8, !tbaa !11
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load i32, ptr %13, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds %struct.vec3_t, ptr %73, i64 %75
  %77 = getelementptr inbounds %struct.vec3_t, ptr %76, i32 0, i32 0
  %78 = getelementptr inbounds [3 x double], ptr %77, i64 0, i64 2
  store double 1.000000e+00, ptr %78, align 8, !tbaa !11
  br label %79

79:                                               ; preds = %22
  %80 = load i32, ptr %13, align 4, !tbaa !9
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %13, align 4, !tbaa !9
  br label %18, !llvm.loop !13

82:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  %83 = load ptr, ptr %11, align 8
  call void @llvm.stackrestore.p0(ptr %83)
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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.vec3_t = type { [3 x double] }

declare void @vec3_mult_mat(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @vec3_add_vec(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @xformproj(ptr nocapture noundef writeonly %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = zext i32 %4 to i64
  %7 = alloca %struct.vec3_t, i64 %6, align 16
  %8 = icmp sgt i32 %4, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %5 ]
  %9 = getelementptr inbounds %struct.vec3_t, ptr %7, i64 %indvars.iv
  %10 = getelementptr inbounds %struct.vec3_t, ptr %1, i64 %indvars.iv
  call void @vec3_mult_mat(ptr noundef nonnull %9, ptr noundef %2, ptr noundef %10) #2
  call void @vec3_add_vec(ptr noundef nonnull %9, ptr noundef %3) #2
  %11 = getelementptr inbounds i8, ptr %9, i64 16
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.vec3_t, ptr %0, i64 %indvars.iv
  %14 = load <2 x double>, ptr %9, align 8, !tbaa !5
  %15 = insertelement <2 x double> poison, double %12, i64 0
  %16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
  %17 = fdiv <2 x double> %14, %16
  store <2 x double> %17, ptr %13, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %13, i64 16
  store double 1.000000e+00, ptr %18, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %6
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %5
  ret void
}

attributes #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 = { 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 #2 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass