; LLVM IR from sp-nitech/SPTK :: src/compression/a_law_compression.ll (ZNK4sptk15ALawCompression3RunEdPd)

; 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.sptk::ALawCompression" = type <{ ptr, double, double, double, i8, [7 x i8] }>

; Function Attrs: nounwind
declare double @log(double noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK4sptk15ALawCompression3RunEdPd(ptr noundef nonnull align 8 dereferenceable(33) %0, double noundef %1, ptr noundef %2) #1 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8
  %11 = getelementptr inbounds %"class.sptk::ALawCompression", ptr %10, i32 0, i32 4
  %12 = load i8, ptr %11, align 8, !tbaa !11, !range !14, !noundef !15
  %13 = trunc i8 %12 to i1
  br i1 %13, label %14, label %17

14:                                               ; preds = %3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp eq ptr null, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %14, %3
  store i1 false, ptr %4, align 1
  br label %47

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %19 = load double, ptr %6, align 8, !tbaa !9
  %20 = call double @llvm.fabs.f64(double %19)
  %21 = getelementptr inbounds %"class.sptk::ALawCompression", ptr %10, i32 0, i32 1
  %22 = load double, ptr %21, align 8, !tbaa !16
  %23 = fdiv double %20, %22
  store double %23, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %24 = getelementptr inbounds %"class.sptk::ALawCompression", ptr %10, i32 0, i32 2
  %25 = load double, ptr %24, align 8, !tbaa !17
  %26 = load double, ptr %8, align 8, !tbaa !9
  %27 = fmul double %25, %26
  store double %27, ptr %9, align 8, !tbaa !9
  %28 = getelementptr inbounds %"class.sptk::ALawCompression", ptr %10, i32 0, i32 2
  %29 = load double, ptr %28, align 8, !tbaa !17
  %30 = fdiv double 1.000000e+00, %29
  %31 = load double, ptr %8, align 8, !tbaa !9
  %32 = fcmp ole double %30, %31
  br i1 %32, label %33, label %37

33:                                               ; preds = %18
  %34 = load double, ptr %9, align 8, !tbaa !9
  %35 = call double @log(double noundef %34) #5
  %36 = fadd double 1.000000e+00, %35
  store double %36, ptr %9, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %33, %18
  %38 = getelementptr inbounds %"class.sptk::ALawCompression", ptr %10, i32 0, i32 3
  %39 = load double, ptr %38, align 8, !tbaa !18
  %40 = load double, ptr %6, align 8, !tbaa !9
  %41 = call noundef i32 @_ZN4sptk11ExtractSignEd(double noundef %40)
  %42 = sitofp i32 %41 to double
  %43 = fmul double %39, %42
  %44 = load double, ptr %9, align 8, !tbaa !9
  %45 = fmul double %43, %44
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  store double %45, ptr %46, align 8, !tbaa !9
  store i1 true, ptr %4, align 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %47

47:                                               ; preds = %37, %17
  %48 = load i1, ptr %4, align 1
  ret i1 %48
}

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

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

declare noundef i32 @_ZN4sptk11ExtractSignEd(double noundef) #4

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

attributes #0 = { 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 #1 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { "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 #5 = { 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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !13, i64 32}
!12 = !{!"_ZTSN4sptk15ALawCompressionE", !10, i64 8, !10, i64 16, !10, i64 24, !13, i64 32}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!12, !10, i64 8}
!17 = !{!12, !10, i64 16}
!18 = !{!12, !10, i64 24}


; 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 nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK4sptk15ALawCompression3RunEdPd(ptr nocapture noundef nonnull readonly align 8 dereferenceable(33) %0, double noundef %1, ptr noundef writeonly %2) local_unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i8, ptr %4, align 8, !tbaa !5, !range !11, !noundef !12
  %6 = trunc nuw i8 %5 to i1
  %7 = icmp ne ptr %2, null
  %or.cond.not = and i1 %7, %6
  br i1 %or.cond.not, label %8, label %29

8:                                                ; preds = %3
  %9 = tail call double @llvm.fabs.f64(double %1)
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load <2 x double>, ptr %10, align 8, !tbaa !13
  %12 = insertelement <2 x double> <double poison, double 1.000000e+00>, double %9, i64 0
  %13 = fdiv <2 x double> %12, %11
  %14 = extractelement <2 x double> %13, i64 0
  %shift = shufflevector <2 x double> %11, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %15 = fmul <2 x double> %shift, %13
  %16 = extractelement <2 x double> %15, i64 0
  %17 = extractelement <2 x double> %13, i64 1
  %18 = fcmp ugt double %17, %14
  br i1 %18, label %22, label %19

19:                                               ; preds = %8
  %20 = tail call double @log(double noundef %16) #4
  %21 = fadd double %20, 1.000000e+00
  br label %22

22:                                               ; preds = %19, %8
  %.0 = phi double [ %21, %19 ], [ %16, %8 ]
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  %24 = load double, ptr %23, align 8, !tbaa !14
  %25 = tail call noundef i32 @_ZN4sptk11ExtractSignEd(double noundef %1)
  %26 = sitofp i32 %25 to double
  %27 = fmul double %24, %26
  %28 = fmul double %.0, %27
  store double %28, ptr %2, align 8, !tbaa !13
  br label %29

29:                                               ; preds = %3, %22
  ret i1 %or.cond.not
}

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

declare noundef i32 @_ZN4sptk11ExtractSignEd(double noundef) local_unnamed_addr #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 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { "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 #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, !10, i64 32}
!6 = !{!"_ZTSN4sptk15ALawCompressionE", !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !7, i64 24}


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