; LLVM IR from googlecreativelab/open-nsynth-super :: app/open-nsynth/third_party/ADSR.ll (ZN4ADSR5limitEv)

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

%class.ADSR = type { %"struct.ADSR::adr", %"struct.ADSR::adr", float }
%"struct.ADSR::adr" = type { float, float, float }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4ADSR5limitEv(ptr noundef nonnull align 4 dereferenceable(28) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %5 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 0
  %6 = getelementptr inbounds %"struct.ADSR::adr", ptr %5, i32 0, i32 0
  %7 = load float, ptr %6, align 4, !tbaa !9
  %8 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 0
  %9 = getelementptr inbounds %"struct.ADSR::adr", ptr %8, i32 0, i32 1
  %10 = load float, ptr %9, align 4, !tbaa !13
  %11 = fadd float %7, %10
  %12 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 0
  %13 = getelementptr inbounds %"struct.ADSR::adr", ptr %12, i32 0, i32 2
  %14 = load float, ptr %13, align 4, !tbaa !14
  %15 = fadd float %11, %14
  store float %15, ptr %3, align 4, !tbaa !15
  %16 = load float, ptr %3, align 4, !tbaa !15
  %17 = fcmp ogt float %16, 1.000000e+00
  br i1 %17, label %18, label %40

18:                                               ; preds = %1
  %19 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 0
  %20 = getelementptr inbounds %"struct.ADSR::adr", ptr %19, i32 0, i32 0
  %21 = load float, ptr %20, align 4, !tbaa !9
  %22 = load float, ptr %3, align 4, !tbaa !15
  %23 = fdiv float %21, %22
  %24 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 1
  %25 = getelementptr inbounds %"struct.ADSR::adr", ptr %24, i32 0, i32 0
  store float %23, ptr %25, align 4, !tbaa !16
  %26 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 0
  %27 = getelementptr inbounds %"struct.ADSR::adr", ptr %26, i32 0, i32 1
  %28 = load float, ptr %27, align 4, !tbaa !13
  %29 = load float, ptr %3, align 4, !tbaa !15
  %30 = fdiv float %28, %29
  %31 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 1
  %32 = getelementptr inbounds %"struct.ADSR::adr", ptr %31, i32 0, i32 1
  store float %30, ptr %32, align 4, !tbaa !17
  %33 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 0
  %34 = getelementptr inbounds %"struct.ADSR::adr", ptr %33, i32 0, i32 2
  %35 = load float, ptr %34, align 4, !tbaa !14
  %36 = load float, ptr %3, align 4, !tbaa !15
  %37 = fdiv float %35, %36
  %38 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 1
  %39 = getelementptr inbounds %"struct.ADSR::adr", ptr %38, i32 0, i32 2
  store float %37, ptr %39, align 4, !tbaa !18
  br label %56

40:                                               ; preds = %1
  %41 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 0
  %42 = getelementptr inbounds %"struct.ADSR::adr", ptr %41, i32 0, i32 0
  %43 = load float, ptr %42, align 4, !tbaa !9
  %44 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 1
  %45 = getelementptr inbounds %"struct.ADSR::adr", ptr %44, i32 0, i32 0
  store float %43, ptr %45, align 4, !tbaa !16
  %46 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 0
  %47 = getelementptr inbounds %"struct.ADSR::adr", ptr %46, i32 0, i32 1
  %48 = load float, ptr %47, align 4, !tbaa !13
  %49 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 1
  %50 = getelementptr inbounds %"struct.ADSR::adr", ptr %49, i32 0, i32 1
  store float %48, ptr %50, align 4, !tbaa !17
  %51 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 0
  %52 = getelementptr inbounds %"struct.ADSR::adr", ptr %51, i32 0, i32 2
  %53 = load float, ptr %52, align 4, !tbaa !14
  %54 = getelementptr inbounds %class.ADSR, ptr %4, i32 0, i32 1
  %55 = getelementptr inbounds %"struct.ADSR::adr", ptr %54, i32 0, i32 2
  store float %53, ptr %55, align 4, !tbaa !18
  br label %56

56:                                               ; preds = %40, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 0}
!10 = !{!"_ZTS4ADSR", !11, i64 0, !11, i64 12, !12, i64 24}
!11 = !{!"_ZTSN4ADSR3adrE", !12, i64 0, !12, i64 4, !12, i64 8}
!12 = !{!"float", !7, i64 0}
!13 = !{!10, !12, i64 4}
!14 = !{!10, !12, i64 8}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !12, i64 12}
!17 = !{!10, !12, i64 16}
!18 = !{!10, !12, i64 20}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN4ADSR5limitEv(ptr nocapture noundef nonnull align 4 dereferenceable(28) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load float, ptr %2, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = load <2 x float>, ptr %0, align 4, !tbaa !11
  %shift = shufflevector <2 x float> %5, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %6 = fadd <2 x float> %5, %shift
  %7 = extractelement <2 x float> %6, i64 0
  %8 = fadd float %7, %3
  %9 = fcmp ogt float %8, 1.000000e+00
  %10 = insertelement <2 x float> poison, float %8, i64 0
  %11 = shufflevector <2 x float> %10, <2 x float> poison, <2 x i32> zeroinitializer
  %12 = fdiv <2 x float> %5, %11
  %13 = fdiv float %3, %8
  %14 = insertelement <2 x i1> poison, i1 %9, i64 0
  %15 = shufflevector <2 x i1> %14, <2 x i1> poison, <2 x i32> zeroinitializer
  %16 = select <2 x i1> %15, <2 x float> %12, <2 x float> %5
  %.sink = select i1 %9, float %13, float %3
  store <2 x float> %16, ptr %4, align 4
  %17 = getelementptr inbounds i8, ptr %0, i64 20
  store float %.sink, ptr %17, align 4
  ret void
}

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

!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, !8, i64 8}
!6 = !{!"_ZTS4ADSR", !7, i64 0, !7, i64 12, !8, i64 24}
!7 = !{!"_ZTSN4ADSR3adrE", !8, i64 0, !8, i64 4, !8, i64 8}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,VectorCombinePass