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

; 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"

@.str.1 = external hidden unnamed_addr constant [108 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [27 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

declare i32 @SMerror(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 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 i32 @vGradCosineDihedrals(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @vNegateGradCosineDihedrals(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = load ptr, ptr %12, align 8, !tbaa !5
  %23 = load ptr, ptr %13, align 8, !tbaa !5
  %24 = call i32 @vGradCosineDihedrals(ptr noundef %18, ptr noundef %19, ptr noundef %20, ptr noundef %21, ptr noundef %22, ptr noundef %23)
  store i32 %24, ptr %14, align 4, !tbaa !9
  %25 = load i32, ptr %14, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %6
  %28 = load i32, ptr %14, align 4, !tbaa !9
  %29 = call i32 @SMerror(i32 noundef 503, ptr noundef @.str.20, ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef %28, i32 noundef 0, ptr noundef null)
  store i32 %29, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %67

30:                                               ; preds = %6
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %63, %30
  %32 = load i32, ptr %15, align 4, !tbaa !9
  %33 = load ptr, ptr %13, align 8, !tbaa !5
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = icmp slt i32 %32, %34
  br i1 %35, label %36, label %66

36:                                               ; preds = %31
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %59, %36
  %38 = load i32, ptr %16, align 4, !tbaa !9
  %39 = icmp slt i32 %38, 3
  br i1 %39, label %40, label %62

40:                                               ; preds = %37
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = load i32, ptr %15, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds ptr, ptr %41, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = load i32, ptr %16, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %45, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fneg double %49
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = load i32, ptr %15, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds ptr, ptr %51, i64 %53
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = load i32, ptr %16, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds double, ptr %55, i64 %57
  store double %50, ptr %58, align 8, !tbaa !11
  br label %59

59:                                               ; preds = %40
  %60 = load i32, ptr %16, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %16, align 4, !tbaa !9
  br label %37, !llvm.loop !13

62:                                               ; preds = %37
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %15, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %15, align 4, !tbaa !9
  br label %31, !llvm.loop !15

66:                                               ; preds = %31
  store i32 0, ptr %14, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %67

67:                                               ; preds = %66, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %68 = load i32, ptr %7, align 4
  ret i32 %68
}

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 = { 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"}
!15 = distinct !{!15, !14}


; 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"

@.str.1 = external hidden unnamed_addr constant [108 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [27 x i8], align 1

declare i32 @SMerror(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @vGradCosineDihedrals(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @vNegateGradCosineDihedrals(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #1 {
  %7 = tail call i32 @vGradCosineDihedrals(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %.preheader22, label %11

.preheader22:                                     ; preds = %6
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %.preheader22
  %wide.trip.count = zext nneg i32 %8 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %10 = icmp eq i32 %8, 1
  br i1 %10, label %.loopexit.loopexit.unr-lcssa, label %.preheader.preheader.new

.preheader.preheader.new:                         ; preds = %.preheader.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.preheader

11:                                               ; preds = %6
  %12 = tail call i32 @SMerror(i32 noundef 503, ptr noundef nonnull @.str.20, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef %7, i32 noundef 0, ptr noundef null) #2
  br label %.loopexit

.preheader:                                       ; preds = %.preheader, %.preheader.preheader.new
  %indvars.iv = phi i64 [ 0, %.preheader.preheader.new ], [ %indvars.iv.next.1, %.preheader ]
  %niter = phi i64 [ 0, %.preheader.preheader.new ], [ %niter.next.1, %.preheader ]
  %13 = getelementptr inbounds ptr, ptr %4, i64 %indvars.iv
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = load <2 x double>, ptr %14, align 8, !tbaa !11
  %16 = fneg <2 x double> %15
  store <2 x double> %16, ptr %14, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %14, i64 16
  %18 = load double, ptr %17, align 8, !tbaa !11
  %19 = fneg double %18
  store double %19, ptr %17, align 8, !tbaa !11
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %20 = getelementptr inbounds ptr, ptr %4, i64 %indvars.iv.next
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = load <2 x double>, ptr %21, align 8, !tbaa !11
  %23 = fneg <2 x double> %22
  store <2 x double> %23, ptr %21, align 8, !tbaa !11
  %24 = getelementptr inbounds i8, ptr %21, i64 16
  %25 = load double, ptr %24, align 8, !tbaa !11
  %26 = fneg double %25
  store double %26, ptr %24, align 8, !tbaa !11
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %.preheader, !llvm.loop !13

.loopexit.loopexit.unr-lcssa:                     ; preds = %.preheader, %.preheader.preheader
  %indvars.iv.unr = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next.1, %.preheader ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.preheader.epil

.preheader.epil:                                  ; preds = %.loopexit.loopexit.unr-lcssa
  %27 = getelementptr inbounds ptr, ptr %4, i64 %indvars.iv.unr
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = load <2 x double>, ptr %28, align 8, !tbaa !11
  %30 = fneg <2 x double> %29
  store <2 x double> %30, ptr %28, align 8, !tbaa !11
  %31 = getelementptr inbounds i8, ptr %28, i64 16
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = fneg double %32
  store double %33, ptr %31, align 8, !tbaa !11
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.epil, %.loopexit.loopexit.unr-lcssa, %.preheader22, %11
  %.020 = phi i32 [ %12, %11 ], [ 0, %.preheader22 ], [ 0, %.loopexit.loopexit.unr-lcssa ], [ 0, %.preheader.epil ]
  ret i32 %.020
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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