; LLVM IR from ctlst-tech/catpilot :: bsp/ics/cubeio (cubeio)

; 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.cubeio_range_cfg_t = type { i16, i16, i16 }

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @cubeio_scale_output(double noundef %0, ptr noundef %1) #0 {
  %3 = alloca i16, align 2
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  store double %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %6, i32 0, i32 0
  %8 = load i16, ptr %7, align 2, !tbaa !11
  %9 = zext i16 %8 to i32
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %30

11:                                               ; preds = %2
  %12 = load double, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %13, i32 0, i32 2
  %15 = load i16, ptr %14, align 2, !tbaa !14
  %16 = zext i16 %15 to i32
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %17, i32 0, i32 1
  %19 = load i16, ptr %18, align 2, !tbaa !15
  %20 = zext i16 %19 to i32
  %21 = sub nsw i32 %16, %20
  %22 = sitofp i32 %21 to double
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %23, i32 0, i32 1
  %25 = load i16, ptr %24, align 2, !tbaa !15
  %26 = zext i16 %25 to i32
  %27 = sitofp i32 %26 to double
  %28 = call double @llvm.fmuladd.f64(double %12, double %22, double %27)
  %29 = fptoui double %28 to i16
  store i16 %29, ptr %3, align 2
  br label %60

30:                                               ; preds = %2
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %31, i32 0, i32 0
  %33 = load i16, ptr %32, align 2, !tbaa !11
  %34 = zext i16 %33 to i32
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %36, label %58

36:                                               ; preds = %30
  %37 = load double, ptr %4, align 8, !tbaa !5
  %38 = fadd double %37, 1.000000e+00
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %39, i32 0, i32 2
  %41 = load i16, ptr %40, align 2, !tbaa !14
  %42 = zext i16 %41 to i32
  %43 = load ptr, ptr %5, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %43, i32 0, i32 1
  %45 = load i16, ptr %44, align 2, !tbaa !15
  %46 = zext i16 %45 to i32
  %47 = sub nsw i32 %42, %46
  %48 = sitofp i32 %47 to double
  %49 = fmul double %38, %48
  %50 = fdiv double %49, 2.000000e+00
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %51, i32 0, i32 1
  %53 = load i16, ptr %52, align 2, !tbaa !15
  %54 = zext i16 %53 to i32
  %55 = sitofp i32 %54 to double
  %56 = fadd double %50, %55
  %57 = fptoui double %56 to i16
  store i16 %57, ptr %3, align 2
  br label %60

58:                                               ; preds = %30
  br label %59

59:                                               ; preds = %58
  store i16 0, ptr %3, align 2
  br label %60

60:                                               ; preds = %59, %36, %11
  %61 = load i16, ptr %3, align 2
  ret i16 %61
}

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

attributes #0 = { 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 speculatable willreturn memory(none) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 4}
!15 = !{!12, !13, i64 2}


; 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: read) uwtable
define dso_local zeroext i16 @cubeio_scale_output(double noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i16, ptr %1, align 2, !tbaa !5
  switch i16 %3, label %31 [
    i16 0, label %4
    i16 1, label %16
  ]

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %6 = load i16, ptr %5, align 2, !tbaa !10
  %7 = zext i16 %6 to i32
  %8 = getelementptr inbounds i8, ptr %1, i64 2
  %9 = load i16, ptr %8, align 2, !tbaa !11
  %10 = zext i16 %9 to i32
  %11 = sub nsw i32 %7, %10
  %12 = sitofp i32 %11 to double
  %13 = uitofp i16 %9 to double
  %14 = tail call double @llvm.fmuladd.f64(double %0, double %12, double %13)
  %15 = fptoui double %14 to i16
  br label %31

16:                                               ; preds = %2
  %17 = fadd double %0, 1.000000e+00
  %18 = getelementptr inbounds i8, ptr %1, i64 4
  %19 = load i16, ptr %18, align 2, !tbaa !10
  %20 = zext i16 %19 to i32
  %21 = getelementptr inbounds i8, ptr %1, i64 2
  %22 = load i16, ptr %21, align 2, !tbaa !11
  %23 = zext i16 %22 to i32
  %24 = sub nsw i32 %20, %23
  %25 = sitofp i32 %24 to double
  %26 = fmul double %17, %25
  %27 = fmul double %26, 5.000000e-01
  %28 = uitofp i16 %22 to double
  %29 = fadd double %27, %28
  %30 = fptoui double %29 to i16
  br label %31

31:                                               ; preds = %2, %16, %4
  %.0 = phi i16 [ %15, %4 ], [ %30, %16 ], [ 0, %2 ]
  ret i16 %.0
}

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

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

!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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 2, !7, i64 4}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 2}


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