; LLVM IR from marcinlos/iga-ads :: examples/erikkson/inverse.ll (Z12choose_nodesbbd)

; 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.std::array" = type { [4 x double] }

@constinit = external hidden constant [4 x double], align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z12choose_nodesbbd(ptr dead_on_unwind noalias writable sret(%"struct.std::array") align 8 %0, i1 noundef zeroext %1, i1 noundef zeroext %2, double noundef %3) #0 {
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca double, align 8
  %8 = zext i1 %1 to i8
  store i8 %8, ptr %5, align 1, !tbaa !5
  %9 = zext i1 %2 to i8
  store i8 %9, ptr %6, align 1, !tbaa !5
  store double %3, ptr %7, align 8, !tbaa !9
  %10 = load i8, ptr %5, align 1, !tbaa !5, !range !11, !noundef !12
  %11 = trunc i8 %10 to i1
  br i1 %11, label %12, label %23

12:                                               ; preds = %4
  %13 = load i8, ptr %6, align 1, !tbaa !5, !range !11, !noundef !12
  %14 = trunc i8 %13 to i1
  br i1 %14, label %15, label %23

15:                                               ; preds = %12
  %16 = getelementptr inbounds %"struct.std::array", ptr %0, i32 0, i32 0
  store double 0.000000e+00, ptr %16, align 8, !tbaa !9
  %17 = getelementptr inbounds double, ptr %16, i64 1
  %18 = load double, ptr %7, align 8, !tbaa !9
  store double %18, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds double, ptr %16, i64 2
  %20 = load double, ptr %7, align 8, !tbaa !9
  %21 = fsub double 1.000000e+00, %20
  store double %21, ptr %19, align 8, !tbaa !9
  %22 = getelementptr inbounds double, ptr %16, i64 3
  store double 1.000000e+00, ptr %22, align 8, !tbaa !9
  br label %44

23:                                               ; preds = %12, %4
  %24 = load i8, ptr %5, align 1, !tbaa !5, !range !11, !noundef !12
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %32

26:                                               ; preds = %23
  %27 = getelementptr inbounds %"struct.std::array", ptr %0, i32 0, i32 0
  store double 0.000000e+00, ptr %27, align 8, !tbaa !9
  %28 = getelementptr inbounds double, ptr %27, i64 1
  %29 = load double, ptr %7, align 8, !tbaa !9
  store double %29, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds double, ptr %27, i64 2
  store double 7.500000e-01, ptr %30, align 8, !tbaa !9
  %31 = getelementptr inbounds double, ptr %27, i64 3
  store double 1.000000e+00, ptr %31, align 8, !tbaa !9
  br label %44

32:                                               ; preds = %23
  %33 = load i8, ptr %6, align 1, !tbaa !5, !range !11, !noundef !12
  %34 = trunc i8 %33 to i1
  br i1 %34, label %35, label %42

35:                                               ; preds = %32
  %36 = getelementptr inbounds %"struct.std::array", ptr %0, i32 0, i32 0
  store double 0.000000e+00, ptr %36, align 8, !tbaa !9
  %37 = getelementptr inbounds double, ptr %36, i64 1
  store double 2.500000e-01, ptr %37, align 8, !tbaa !9
  %38 = getelementptr inbounds double, ptr %36, i64 2
  %39 = load double, ptr %7, align 8, !tbaa !9
  %40 = fsub double 1.000000e+00, %39
  store double %40, ptr %38, align 8, !tbaa !9
  %41 = getelementptr inbounds double, ptr %36, i64 3
  store double 1.000000e+00, ptr %41, align 8, !tbaa !9
  br label %44

42:                                               ; preds = %32
  %43 = getelementptr inbounds %"struct.std::array", ptr %0, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %43, ptr align 8 @constinit, i64 32, i1 false), !tbaa.struct !13
  br label %44

44:                                               ; preds = %42, %35, %26, %15
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{i64 0, i64 32, !14}
!14 = !{!7, !7, i64 0}


; 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.std::array" = type { [4 x double] }

@constinit = external hidden local_unnamed_addr constant [4 x double], align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_Z12choose_nodesbbd(ptr dead_on_unwind noalias nocapture writable writeonly sret(%"struct.std::array") align 8 %0, i1 noundef zeroext %1, i1 noundef zeroext %2, double noundef %3) local_unnamed_addr #0 {
  %brmerge.demorgan = and i1 %1, %2
  br i1 %brmerge.demorgan, label %5, label %10

5:                                                ; preds = %4
  store double 0.000000e+00, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  store double %3, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = fsub double 1.000000e+00, %3
  store double %8, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  store double 1.000000e+00, ptr %9, align 8, !tbaa !5
  br label %20

10:                                               ; preds = %4
  br i1 %1, label %11, label %14

11:                                               ; preds = %10
  store double 0.000000e+00, ptr %0, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  store double %3, ptr %12, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  store <2 x double> <double 7.500000e-01, double 1.000000e+00>, ptr %13, align 8, !tbaa !5
  br label %20

14:                                               ; preds = %10
  br i1 %2, label %15, label %19

15:                                               ; preds = %14
  store <2 x double> <double 0.000000e+00, double 2.500000e-01>, ptr %0, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = fsub double 1.000000e+00, %3
  store double %17, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  store double 1.000000e+00, ptr %18, align 8, !tbaa !5
  br label %20

19:                                               ; preds = %14
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) @constinit, i64 32, i1 false), !tbaa.struct !9
  br label %20

20:                                               ; preds = %19, %15, %11, %5
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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++ TBAA"}
!9 = !{i64 0, i64 32, !10}
!10 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass