; 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.4 = external hidden unnamed_addr constant [33 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 uwtable
declare hidden i32 @is_zero_vector(ptr noundef byval(%struct.DERIV_TYPE) align 8) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @g_ad_fabs(ptr noundef %0, ptr noundef byval(%struct.DERIV_TYPE) align 8 %1) #1 {
  %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) #3
  %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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = load double, ptr %4, align 8, !tbaa !12
  %12 = fcmp olt double %11, 0.000000e+00
  br i1 %12, label %13, label %16

13:                                               ; preds = %2
  store double -1.000000e+00, ptr %6, align 8, !tbaa !12
  %14 = load double, ptr %4, align 8, !tbaa !12
  %15 = fneg double %14
  store double %15, ptr %5, align 8, !tbaa !12
  br label %31

16:                                               ; preds = %2
  %17 = load double, ptr %4, align 8, !tbaa !12
  %18 = fcmp ogt double %17, 0.000000e+00
  br i1 %18, label %19, label %21

19:                                               ; preds = %16
  store double 1.000000e+00, ptr %6, align 8, !tbaa !12
  %20 = load double, ptr %4, align 8, !tbaa !12
  store double %20, ptr %5, align 8, !tbaa !12
  br label %30

21:                                               ; preds = %16
  %22 = call i32 @is_zero_vector(ptr noundef byval(%struct.DERIV_TYPE) align 8 %1)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %28, label %24

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

28:                                               ; preds = %24, %21
  store double 0.000000e+00, ptr %6, align 8, !tbaa !12
  %29 = load double, ptr %4, align 8, !tbaa !12
  store double %29, ptr %5, align 8, !tbaa !12
  br label %30

30:                                               ; preds = %28, %19
  br label %31

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

36:                                               ; preds = %52, %31
  %37 = load i32, ptr %8, align 4, !tbaa !13
  %38 = icmp slt i32 %37, 3
  br i1 %38, label %39, label %55

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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/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.4 = external hidden unnamed_addr constant [33 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @g_ad_fabs(ptr nocapture noundef writeonly %0, ptr noundef byval(%struct.DERIV_TYPE) align 8 %1) local_unnamed_addr #0 {
  %3 = load double, ptr %1, align 8, !tbaa !5
  %4 = fcmp olt double %3, 0.000000e+00
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = fneg double %3
  br label %14

7:                                                ; preds = %2
  %8 = fcmp ogt double %3, 0.000000e+00
  br i1 %8, label %14, label %9

9:                                                ; preds = %7
  %10 = tail call i32 @is_zero_vector(ptr noundef nonnull byval(%struct.DERIV_TYPE) align 8 %1)
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %11, label %14

11:                                               ; preds = %9
  %12 = load ptr, ptr @stderr, align 8, !tbaa !10
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.4, double noundef %3) #2
  br label %14

14:                                               ; preds = %9, %11, %7, %5
  %.015 = phi double [ -1.000000e+00, %5 ], [ 1.000000e+00, %7 ], [ 0.000000e+00, %11 ], [ 0.000000e+00, %9 ]
  %.014 = phi double [ %6, %5 ], [ %3, %7 ], [ %3, %11 ], [ %3, %9 ]
  store double %.014, ptr %0, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load <2 x double>, ptr %15, align 8, !tbaa !12
  %18 = insertelement <2 x double> poison, double %.015, i64 0
  %19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
  %20 = fmul <2 x double> %19, %17
  store <2 x double> %20, ptr %16, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %1, i64 24
  %22 = load double, ptr %21, align 8, !tbaa !12
  %23 = fmul double %.015, %22
  %24 = getelementptr inbounds i8, ptr %0, i64 24
  store double %23, ptr %24, align 8, !tbaa !12
  ret void
}

attributes #0 = { 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 #1 = { 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 #2 = { 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