; LLVM IR from sourceryinstitute/MORFEUS-Source :: src/FV/src/mesh_optimize/OptMS (SMintrinsic)

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

@stderr = external global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [34 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: nounwind
declare double @sqrt(double noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @is_zero_vector(ptr noundef byval(%struct.DERIV_TYPE) align 8) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @g_ad_acos(ptr noundef %0, ptr noundef byval(%struct.DERIV_TYPE) align 8 %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %9 = getelementptr inbounds %struct.DERIV_TYPE, ptr %1, i32 0, i32 0
  %10 = load double, ptr %9, align 8, !tbaa !9
  store double %10, ptr %4, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %11 = load double, ptr %4, align 8, !tbaa !12
  %12 = call double @acos(double noundef %11) #4
  store double %12, ptr %5, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %13 = load double, ptr %4, align 8, !tbaa !12
  %14 = call double @llvm.fabs.f64(double %13)
  %15 = fcmp ole double %14, 1.000000e+00
  br i1 %15, label %16, label %24

16:                                               ; preds = %2
  %17 = load double, ptr %4, align 8, !tbaa !12
  %18 = fadd double 1.000000e+00, %17
  %19 = load double, ptr %4, align 8, !tbaa !12
  %20 = fsub double 1.000000e+00, %19
  %21 = fmul double %18, %20
  %22 = call double @sqrt(double noundef %21) #4
  %23 = fdiv double -1.000000e+00, %22
  store double %23, ptr %6, align 8, !tbaa !12
  br label %32

24:                                               ; preds = %2
  %25 = call i32 @is_zero_vector(ptr noundef byval(%struct.DERIV_TYPE) align 8 %1)
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %31, label %27

27:                                               ; preds = %24
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = load double, ptr %4, align 8, !tbaa !12
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef @.str.5, double noundef %29) #4
  br label %31

31:                                               ; preds = %27, %24
  store double 0.000000e+00, ptr %6, align 8, !tbaa !12
  br label %32

32:                                               ; preds = %31, %16
  %33 = load double, ptr %5, align 8, !tbaa !12
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.DERIV_TYPE, ptr %34, i32 0, i32 0
  store double %33, ptr %35, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %36 = load double, ptr %6, align 8, !tbaa !12
  store double %36, ptr %7, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %37

37:                                               ; preds = %53, %32
  %38 = load i32, ptr %8, align 4, !tbaa !13
  %39 = icmp slt i32 %38, 3
  br i1 %39, label %40, label %56

40:                                               ; preds = %37
  %41 = load double, ptr %7, align 8, !tbaa !12
  %42 = getelementptr inbounds %struct.DERIV_TYPE, ptr %1, i32 0, i32 1
  %43 = load i32, ptr %8, align 4, !tbaa !13
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [3 x double], ptr %42, i64 0, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !12
  %47 = fmul double %41, %46
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.DERIV_TYPE, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %8, align 4, !tbaa !13
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [3 x double], ptr %49, i64 0, i64 %51
  store double %47, ptr %52, align 8, !tbaa !12
  br label %53

53:                                               ; preds = %40
  %54 = load i32, ptr %8, align 4, !tbaa !13
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %8, align 4, !tbaa !13
  br label %37, !llvm.loop !15

56:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  ret void
}

; Function Attrs: nounwind
declare double @acos(double noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 speculatable willreturn memory(none) }
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, !11, i64 0}
!10 = !{!"DERIV_TYPE", !11, i64 0, !7, i64 8}
!11 = !{!"double", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.DERIV_TYPE = type { double, [3 x double] }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @is_zero_vector(ptr noundef byval(%struct.DERIV_TYPE) align 8) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @g_ad_acos(ptr nocapture noundef writeonly %0, ptr noundef byval(%struct.DERIV_TYPE) align 8 %1) local_unnamed_addr #1 {
  %3 = load double, ptr %1, align 8, !tbaa !5
  %4 = tail call double @acos(double noundef %3) #4
  %5 = tail call double @llvm.fabs.f64(double %3)
  %6 = fcmp ugt double %5, 1.000000e+00
  br i1 %6, label %13, label %7

7:                                                ; preds = %2
  %8 = fadd double %3, 1.000000e+00
  %9 = fsub double 1.000000e+00, %3
  %10 = fmul double %8, %9
  %11 = tail call double @sqrt(double noundef %10) #4
  %12 = fdiv double -1.000000e+00, %11
  br label %18

13:                                               ; preds = %2
  %14 = tail call i32 @is_zero_vector(ptr noundef nonnull byval(%struct.DERIV_TYPE) align 8 %1)
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %15, label %18

15:                                               ; preds = %13
  %16 = load ptr, ptr @stderr, align 8, !tbaa !10
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.5, double noundef %3) #5
  br label %18

18:                                               ; preds = %13, %15, %7
  %.013 = phi double [ %12, %7 ], [ 0.000000e+00, %15 ], [ 0.000000e+00, %13 ]
  store double %4, ptr %0, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %1, i64 8
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load <2 x double>, ptr %19, align 8, !tbaa !12
  %22 = insertelement <2 x double> poison, double %.013, i64 0
  %23 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> zeroinitializer
  %24 = fmul <2 x double> %23, %21
  store <2 x double> %24, ptr %20, align 8, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %1, i64 24
  %26 = load double, ptr %25, align 8, !tbaa !12
  %27 = fmul double %.013, %26
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  store double %27, ptr %28, align 8, !tbaa !12
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @acos(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #3

attributes #0 = { mustprogress nofree nounwind willreturn memory(write) "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 = { nofree 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { cold 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 = !{!"DERIV_TYPE", !7, i64 0, !8, i64 8}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!7, !7, i64 0}


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