; LLVM IR from sp-nitech/SPTK :: src/compression (inverse_uniform_quantization)

; 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::InverseUniformQuantization" = type { ptr, double, i32, i32, i8, i32, double }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZNK4sptk26InverseUniformQuantization3RunEiPd(ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %1, ptr noundef %2) #0 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8
  %11 = getelementptr inbounds %"class.sptk::InverseUniformQuantization", ptr %10, i32 0, i32 4
  %12 = load i8, ptr %11, align 8, !tbaa !11, !range !16, !noundef !17
  %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 %67

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %19 = getelementptr inbounds %"class.sptk::InverseUniformQuantization", ptr %10, i32 0, i32 3
  %20 = load i32, ptr %19, align 4, !tbaa !18
  switch i32 %20, label %43 [
    i32 0, label %21
    i32 1, label %32
  ]

21:                                               ; preds = %18
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = getelementptr inbounds %"class.sptk::InverseUniformQuantization", ptr %10, i32 0, i32 5
  %24 = load i32, ptr %23, align 4, !tbaa !19
  %25 = sdiv i32 %24, 2
  %26 = sub nsw i32 %22, %25
  %27 = sitofp i32 %26 to double
  %28 = fadd double %27, 5.000000e-01
  %29 = getelementptr inbounds %"class.sptk::InverseUniformQuantization", ptr %10, i32 0, i32 6
  %30 = load double, ptr %29, align 8, !tbaa !20
  %31 = fmul double %28, %30
  store double %31, ptr %8, align 8, !tbaa !21
  br label %44

32:                                               ; preds = %18
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = getelementptr inbounds %"class.sptk::InverseUniformQuantization", ptr %10, i32 0, i32 5
  %35 = load i32, ptr %34, align 4, !tbaa !19
  %36 = sub nsw i32 %35, 1
  %37 = sdiv i32 %36, 2
  %38 = sub nsw i32 %33, %37
  %39 = sitofp i32 %38 to double
  %40 = getelementptr inbounds %"class.sptk::InverseUniformQuantization", ptr %10, i32 0, i32 6
  %41 = load double, ptr %40, align 8, !tbaa !20
  %42 = fmul double %39, %41
  store double %42, ptr %8, align 8, !tbaa !21
  br label %44

43:                                               ; preds = %18
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %66

44:                                               ; preds = %32, %21
  %45 = load double, ptr %8, align 8, !tbaa !21
  %46 = getelementptr inbounds %"class.sptk::InverseUniformQuantization", ptr %10, i32 0, i32 1
  %47 = load double, ptr %46, align 8, !tbaa !22
  %48 = fneg double %47
  %49 = fcmp olt double %45, %48
  br i1 %49, label %50, label %54

50:                                               ; preds = %44
  %51 = getelementptr inbounds %"class.sptk::InverseUniformQuantization", ptr %10, i32 0, i32 1
  %52 = load double, ptr %51, align 8, !tbaa !22
  %53 = fneg double %52
  store double %53, ptr %8, align 8, !tbaa !21
  br label %63

54:                                               ; preds = %44
  %55 = getelementptr inbounds %"class.sptk::InverseUniformQuantization", ptr %10, i32 0, i32 1
  %56 = load double, ptr %55, align 8, !tbaa !22
  %57 = load double, ptr %8, align 8, !tbaa !21
  %58 = fcmp olt double %56, %57
  br i1 %58, label %59, label %62

59:                                               ; preds = %54
  %60 = getelementptr inbounds %"class.sptk::InverseUniformQuantization", ptr %10, i32 0, i32 1
  %61 = load double, ptr %60, align 8, !tbaa !22
  store double %61, ptr %8, align 8, !tbaa !21
  br label %62

62:                                               ; preds = %59, %54
  br label %63

63:                                               ; preds = %62, %50
  %64 = load double, ptr %8, align 8, !tbaa !21
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  store double %64, ptr %65, align 8, !tbaa !21
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %66

66:                                               ; preds = %63, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %67

67:                                               ; preds = %66, %17
  %68 = load i1, ptr %4, align 1
  ret i1 %68
}

; 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !15, i64 24}
!12 = !{!"_ZTSN4sptk26InverseUniformQuantizationE", !13, i64 8, !10, i64 16, !14, i64 20, !15, i64 24, !10, i64 28, !13, i64 32}
!13 = !{!"double", !7, i64 0}
!14 = !{!"_ZTSN4sptk19UniformQuantization16QuantizationTypeE", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!12, !14, i64 20}
!19 = !{!12, !10, i64 28}
!20 = !{!12, !13, i64 32}
!21 = !{!13, !13, i64 0}
!22 = !{!12, !13, i64 8}


; 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 noundef zeroext i1 @_ZNK4sptk26InverseUniformQuantization3RunEiPd(ptr nocapture noundef nonnull readonly align 8 dereferenceable(40) %0, i32 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i8, ptr %4, align 8, !tbaa !5, !range !13, !noundef !14
  %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 %35

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 20
  %10 = load i32, ptr %9, align 4, !tbaa !15
  switch i32 %10, label %35 [
    i32 0, label %11
    i32 1, label %17
  ]

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 28
  %13 = load i32, ptr %12, align 4, !tbaa !16
  %.neg15 = sdiv i32 %13, -2
  %14 = add i32 %.neg15, %1
  %15 = sitofp i32 %14 to double
  %16 = fadd double %15, 5.000000e-01
  br label %23

17:                                               ; preds = %8
  %18 = getelementptr inbounds i8, ptr %0, i64 28
  %19 = load i32, ptr %18, align 4, !tbaa !16
  %20 = add nsw i32 %19, -1
  %.neg = sdiv i32 %20, -2
  %21 = add i32 %.neg, %1
  %22 = sitofp i32 %21 to double
  br label %23

23:                                               ; preds = %17, %11
  %.sink16 = phi double [ %22, %17 ], [ %16, %11 ]
  %24 = getelementptr inbounds i8, ptr %0, i64 32
  %25 = load double, ptr %24, align 8, !tbaa !17
  %26 = fmul double %25, %.sink16
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  %28 = load double, ptr %27, align 8, !tbaa !18
  %29 = fneg double %28
  %30 = fcmp olt double %26, %29
  br i1 %30, label %34, label %31

31:                                               ; preds = %23
  %32 = fcmp olt double %28, %26
  br i1 %32, label %33, label %34

33:                                               ; preds = %31
  br label %34

34:                                               ; preds = %23, %31, %33
  %.1 = phi double [ %28, %33 ], [ %26, %31 ], [ %29, %23 ]
  store double %.1, ptr %2, align 8, !tbaa !19
  br label %35

35:                                               ; preds = %34, %8, %3
  %.110 = phi i1 [ false, %3 ], [ true, %34 ], [ false, %8 ]
  ret i1 %.110
}

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, !12, i64 24}
!6 = !{!"_ZTSN4sptk26InverseUniformQuantizationE", !7, i64 8, !10, i64 16, !11, i64 20, !12, i64 24, !10, i64 28, !7, i64 32}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTSN4sptk19UniformQuantization16QuantizationTypeE", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!6, !11, i64 20}
!16 = !{!6, !10, i64 28}
!17 = !{!6, !7, i64 32}
!18 = !{!6, !7, i64 8}
!19 = !{!7, !7, i64 0}


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