; 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.mat33_t = type { [9 x double] }
%struct.vec3_t = type { [3 x double] }
%struct.pose_t = type { %struct.mat33_t, %struct.vec3_t, double, %struct.mat33_t, %struct.vec3_t, double }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @GetRotationbyVector(ptr noundef, ptr noundef, ptr noundef) #2

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

; 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

declare void @vec3_clear(ptr noundef) #1

declare void @mat33_transpose(ptr noundef, ptr noundef byval(%struct.mat33_t) align 8) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @getRfor2ndPose_V_Exact(ptr noundef, ptr noundef, ptr noundef, ptr noundef byval(%struct.mat33_t) align 8, ptr noundef byval(%struct.vec3_t) align 8, double noundef, i32 noundef, ptr noundef) #2

declare void @vec3_array_mult_vec2(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @get2ndPose_Exact(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef byval(%struct.mat33_t) align 8 %3, ptr noundef byval(%struct.vec3_t) align 8 %4, double noundef %5, i32 noundef %6, ptr noundef %7) #2 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca %struct.vec3_t, align 8
  %16 = alloca %struct.vec3_t, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca %struct.mat33_t, align 8
  %20 = alloca i64, align 8
  %21 = alloca %struct.mat33_t, align 8
  %22 = alloca %struct.vec3_t, align 8
  %23 = alloca i32, align 4
  %24 = alloca %struct.mat33_t, align 8
  %25 = alloca i32, align 4
  %26 = alloca %struct.vec3_t, align 8
  %27 = alloca %struct.mat33_t, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store double %5, ptr %12, align 8, !tbaa !9
  store i32 %6, ptr %13, align 4, !tbaa !11
  store ptr %7, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %16) #4
  %28 = load i32, ptr %13, align 4, !tbaa !11
  %29 = zext i32 %28 to i64
  %30 = call ptr @llvm.stacksave.p0()
  store ptr %30, ptr %17, align 8
  %31 = alloca %struct.vec3_t, i64 %29, align 16
  store i64 %29, ptr %18, align 8
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = load i32, ptr %13, align 4, !tbaa !11
  call void @normRv2(ptr noundef %31, ptr noundef %32, i32 noundef %33)
  %34 = load i32, ptr %13, align 4, !tbaa !11
  call void @vec3_array_mean(ptr noundef %16, ptr noundef %31, i32 noundef %34)
  call void @normRv(ptr noundef %15, ptr noundef %16)
  call void @llvm.lifetime.start.p0(i64 72, ptr %19) #4
  call void @vec3_clear(ptr noundef %16)
  %35 = getelementptr inbounds %struct.vec3_t, ptr %16, i32 0, i32 0
  %36 = getelementptr inbounds [3 x double], ptr %35, i64 0, i64 2
  store double 1.000000e+00, ptr %36, align 8, !tbaa !9
  call void @GetRotationbyVector(ptr noundef %19, ptr noundef %16, ptr noundef %15)
  %37 = load i32, ptr %13, align 4, !tbaa !11
  %38 = zext i32 %37 to i64
  %39 = alloca %struct.vec3_t, i64 %38, align 16
  store i64 %38, ptr %20, align 8
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = load i32, ptr %13, align 4, !tbaa !11
  call void @vec3_array_mult_vec2(ptr noundef %39, ptr noundef %19, ptr noundef %40, i32 noundef %41)
  %42 = load i32, ptr %13, align 4, !tbaa !11
  call void @normRv2(ptr noundef %31, ptr noundef %39, i32 noundef %42)
  %43 = load i32, ptr %13, align 4, !tbaa !11
  call void @vec3_array_mean(ptr noundef %16, ptr noundef %31, i32 noundef %43)
  call void @normRv(ptr noundef %15, ptr noundef %16)
  call void @llvm.lifetime.start.p0(i64 72, ptr %21) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %22) #4
  call void @mat33_mult_mat2(ptr noundef %21, ptr noundef %19, ptr noundef %3)
  call void @vec3_mult_mat(ptr noundef %22, ptr noundef %19, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #4
  store i32 0, ptr %23, align 4, !tbaa !11
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load double, ptr %12, align 8, !tbaa !9
  %47 = load i32, ptr %13, align 4, !tbaa !11
  call void @getRfor2ndPose_V_Exact(ptr noundef %44, ptr noundef %39, ptr noundef %45, ptr noundef byval(%struct.mat33_t) align 8 %21, ptr noundef byval(%struct.vec3_t) align 8 %22, double noundef %46, i32 noundef %47, ptr noundef %23)
  call void @llvm.lifetime.start.p0(i64 72, ptr %24) #4
  call void @mat33_transpose(ptr noundef %24, ptr noundef byval(%struct.mat33_t) align 8 %19)
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %26) #4
  call void @llvm.lifetime.start.p0(i64 72, ptr %27) #4
  store i32 0, ptr %25, align 4, !tbaa !11
  br label %48

48:                                               ; preds = %73, %8
  %49 = load i32, ptr %25, align 4, !tbaa !11
  %50 = load i32, ptr %23, align 4, !tbaa !11
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %52, label %76

52:                                               ; preds = %48
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load i32, ptr %25, align 4, !tbaa !11
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds %struct.pose_t, ptr %53, i64 %55
  %57 = getelementptr inbounds %struct.pose_t, ptr %56, i32 0, i32 1
  call void @vec3_mult_mat(ptr noundef %26, ptr noundef %24, ptr noundef %57)
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = load i32, ptr %25, align 4, !tbaa !11
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds %struct.pose_t, ptr %58, i64 %60
  %62 = getelementptr inbounds %struct.pose_t, ptr %61, i32 0, i32 0
  call void @mat33_mult_mat2(ptr noundef %27, ptr noundef %24, ptr noundef %62)
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = load i32, ptr %25, align 4, !tbaa !11
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %struct.pose_t, ptr %63, i64 %65
  %67 = getelementptr inbounds %struct.pose_t, ptr %66, i32 0, i32 1
  call void @vec3_copy(ptr noundef %67, ptr noundef %26)
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load i32, ptr %25, align 4, !tbaa !11
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds %struct.pose_t, ptr %68, i64 %70
  %72 = getelementptr inbounds %struct.pose_t, ptr %71, i32 0, i32 0
  call void @mat33_copy(ptr noundef %72, ptr noundef %27)
  br label %73

73:                                               ; preds = %52
  %74 = load i32, ptr %25, align 4, !tbaa !11
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %25, align 4, !tbaa !11
  br label %48, !llvm.loop !13

76:                                               ; preds = %48
  %77 = load i32, ptr %23, align 4, !tbaa !11
  %78 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 %77, ptr %78, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 72, ptr %27) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %26) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr %24) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %22) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr %19) #4
  %79 = load ptr, ptr %17, align 8
  call void @llvm.stackrestore.p0(ptr %79)
  call void @llvm.lifetime.end.p0(i64 24, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %15) #4
  ret void
}

declare void @normRv2(ptr noundef, ptr noundef, i32 noundef) #1

declare void @vec3_array_mean(ptr noundef, ptr noundef, i32 noundef) #1

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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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.mat33_t = type { [9 x double] }
%struct.vec3_t = type { [3 x double] }
%struct.pose_t = type { %struct.mat33_t, %struct.vec3_t, double, %struct.mat33_t, %struct.vec3_t, double }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @normRv(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @vec3_copy(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @GetRotationbyVector(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

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

declare void @vec3_clear(ptr noundef) local_unnamed_addr #1

declare void @mat33_transpose(ptr noundef, ptr noundef byval(%struct.mat33_t) align 8) local_unnamed_addr #1

declare void @mat33_mult_mat2(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @mat33_copy(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @getRfor2ndPose_V_Exact(ptr noundef, ptr noundef, ptr noundef, ptr noundef byval(%struct.mat33_t) align 8, ptr noundef byval(%struct.vec3_t) align 8, double noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare void @vec3_array_mult_vec2(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @get2ndPose_Exact(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef byval(%struct.mat33_t) align 8 %3, ptr noundef byval(%struct.vec3_t) align 8 %4, double noundef %5, i32 noundef %6, ptr nocapture noundef writeonly %7) local_unnamed_addr #2 {
  %9 = alloca %struct.vec3_t, align 8
  %10 = alloca %struct.vec3_t, align 8
  %11 = alloca %struct.mat33_t, align 8
  %12 = alloca %struct.mat33_t, align 8
  %13 = alloca %struct.vec3_t, align 8
  %14 = alloca i32, align 4
  %15 = alloca %struct.mat33_t, align 8
  %16 = alloca %struct.vec3_t, align 8
  %17 = alloca %struct.mat33_t, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %9) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %10) #4
  %18 = zext i32 %6 to i64
  %19 = tail call ptr @llvm.stacksave.p0()
  %20 = alloca %struct.vec3_t, i64 %18, align 16
  call void @normRv2(ptr noundef nonnull %20, ptr noundef %1, i32 noundef %6) #4
  call void @vec3_array_mean(ptr noundef nonnull %10, ptr noundef nonnull %20, i32 noundef %6) #4
  call void @normRv(ptr noundef nonnull %9, ptr noundef nonnull %10) #4
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %11) #4
  call void @vec3_clear(ptr noundef nonnull %10) #4
  %21 = getelementptr inbounds i8, ptr %10, i64 16
  store double 1.000000e+00, ptr %21, align 8, !tbaa !5
  call void @GetRotationbyVector(ptr noundef nonnull %11, ptr noundef nonnull %10, ptr noundef nonnull %9)
  %22 = alloca %struct.vec3_t, i64 %18, align 16
  call void @vec3_array_mult_vec2(ptr noundef nonnull %22, ptr noundef nonnull %11, ptr noundef %1, i32 noundef %6) #4
  call void @normRv2(ptr noundef nonnull %20, ptr noundef nonnull %22, i32 noundef %6) #4
  call void @vec3_array_mean(ptr noundef nonnull %10, ptr noundef nonnull %20, i32 noundef %6) #4
  call void @normRv(ptr noundef nonnull %9, ptr noundef nonnull %10) #4
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %12) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %13) #4
  call void @mat33_mult_mat2(ptr noundef nonnull %12, ptr noundef nonnull %11, ptr noundef nonnull %3) #4
  call void @vec3_mult_mat(ptr noundef nonnull %13, ptr noundef nonnull %11, ptr noundef nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  call void @getRfor2ndPose_V_Exact(ptr noundef %0, ptr noundef nonnull %22, ptr noundef %2, ptr noundef nonnull byval(%struct.mat33_t) align 8 %12, ptr noundef nonnull byval(%struct.vec3_t) align 8 %13, double noundef %5, i32 noundef %6, ptr noundef nonnull %14)
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %15) #4
  call void @mat33_transpose(ptr noundef nonnull %15, ptr noundef nonnull byval(%struct.mat33_t) align 8 %11) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %16) #4
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %17) #4
  %23 = load i32, ptr %14, align 4, !tbaa !9
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %8, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %8 ]
  %25 = getelementptr inbounds %struct.pose_t, ptr %0, i64 %indvars.iv
  %26 = getelementptr inbounds i8, ptr %25, i64 72
  call void @vec3_mult_mat(ptr noundef nonnull %16, ptr noundef nonnull %15, ptr noundef nonnull %26) #4
  call void @mat33_mult_mat2(ptr noundef nonnull %17, ptr noundef nonnull %15, ptr noundef %25) #4
  call void @vec3_copy(ptr noundef nonnull %26, ptr noundef nonnull %16) #4
  call void @mat33_copy(ptr noundef %25, ptr noundef nonnull %17) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = load i32, ptr %14, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = icmp slt i64 %indvars.iv.next, %28
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %8
  %.lcssa = phi i32 [ %23, %8 ], [ %27, %.lr.ph ]
  store i32 %.lcssa, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %17) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %16) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %14) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %13) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %12) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %11) #4
  call void @llvm.stackrestore.p0(ptr %19)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %10) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %9) #4
  ret void
}

declare void @normRv2(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @vec3_array_mean(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { mustprogress 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 = !{!"double", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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