; 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_t = type { [32 x i8], ptr, %struct.cubeio_interface_t, i32, %struct.cubeio_sync_t, %struct.cubeio_packet_t, %struct.cubeio_packet_t, i32, %struct.cubeio_page_config_t, %struct.cubeio_pwm_out_t, %struct.cubeio_pwm_in_t, %struct.cubeio_rate_t, %struct.cubeio_page_reg_status_t, %struct.cubeio_page_rc_input_t, [16 x %struct.cubeio_range_cfg_t], [16 x %struct.cubeio_range_cfg_t], [16 x double], double, [16 x double], i32 }
%struct.cubeio_interface_t = type { ptr }
%struct.cubeio_sync_t = type { ptr, ptr, ptr, i32, i32, i32, i32, i32 }
%struct.cubeio_packet_t = type { i8, i8, i8, i8, [22 x i16] }
%struct.cubeio_page_config_t = type { i16, i16 }
%struct.cubeio_pwm_out_t = type { i8, [16 x i16], [16 x i16], i8, i16 }
%struct.cubeio_pwm_in_t = type { [16 x i16] }
%struct.cubeio_rate_t = type { i16, i16, i16, i16, i8, i8 }
%struct.cubeio_page_reg_status_t = type { i16, i32, i16, i16, i32, i32, i8, i8, i8, i8, i8, i8, i8 }
%struct.cubeio_page_rc_input_t = type { i8, i8, i8, [16 x i16], i16 }
%struct.cubeio_range_cfg_t = type { i16, i16, i16 }

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @cubeio_get_freq(ptr noundef %0, i16 noundef zeroext %1) #0 {
  %3 = alloca i16, align 2
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  %6 = load i16, ptr %5, align 2, !tbaa !9
  %7 = zext i16 %6 to i32
  %8 = shl i32 1, %7
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.cubeio_t, ptr %9, i32 0, i32 11
  %11 = getelementptr inbounds %struct.cubeio_rate_t, ptr %10, i32 0, i32 1
  %12 = load i16, ptr %11, align 2, !tbaa !11
  %13 = zext i16 %12 to i32
  %14 = and i32 %8, %13
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %21

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.cubeio_t, ptr %17, i32 0, i32 11
  %19 = getelementptr inbounds %struct.cubeio_rate_t, ptr %18, i32 0, i32 0
  %20 = load i16, ptr %19, align 2, !tbaa !24
  store i16 %20, ptr %3, align 2
  br label %26

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.cubeio_t, ptr %22, i32 0, i32 11
  %24 = getelementptr inbounds %struct.cubeio_rate_t, ptr %23, i32 0, i32 2
  %25 = load i16, ptr %24, align 2, !tbaa !25
  store i16 %25, ptr %3, align 2
  br label %26

26:                                               ; preds = %21, %16
  %27 = load i16, ptr %3, align 2
  ret i16 %27
}

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

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !10, i64 312}
!12 = !{!"", !7, i64 0, !6, i64 32, !13, i64 40, !14, i64 48, !15, i64 56, !16, i64 104, !16, i64 152, !14, i64 200, !17, i64 204, !18, i64 208, !19, i64 278, !20, i64 310, !21, i64 320, !22, i64 348, !7, i64 386, !7, i64 482, !7, i64 584, !23, i64 712, !7, i64 720, !14, i64 848}
!13 = !{!"", !6, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !14, i64 40}
!16 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!17 = !{!"", !10, i64 0, !10, i64 2}
!18 = !{!"", !7, i64 0, !7, i64 2, !7, i64 34, !7, i64 66, !10, i64 68}
!19 = !{!"", !7, i64 0}
!20 = !{!"", !10, i64 0, !10, i64 2, !10, i64 4, !10, i64 6, !7, i64 8, !7, i64 9}
!21 = !{!"", !10, i64 0, !14, i64 4, !10, i64 8, !10, i64 10, !14, i64 12, !14, i64 16, !7, i64 20, !7, i64 21, !7, i64 22, !7, i64 23, !7, i64 24, !7, i64 25, !7, i64 26}
!22 = !{!"", !7, i64 0, !7, i64 1, !7, i64 1, !7, i64 2, !7, i64 4, !10, i64 36}
!23 = !{!"double", !7, i64 0}
!24 = !{!12, !10, i64 310}
!25 = !{!12, !10, i64 314}


; 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_get_freq(ptr nocapture noundef readonly %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = zext nneg i16 %1 to i32
  %4 = shl nuw i32 1, %3
  %5 = getelementptr inbounds i8, ptr %0, i64 312
  %6 = load i16, ptr %5, align 2, !tbaa !5
  %7 = zext i16 %6 to i32
  %8 = and i32 %4, %7
  %.not = icmp eq i32 %8, 0
  %.0.in.v = select i1 %.not, i64 314, i64 310
  %.0.in = getelementptr inbounds i8, ptr %0, i64 %.0.in.v
  %.0 = load i16, ptr %.0.in, align 2, !tbaa !22
  ret i16 %.0
}

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

!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, !15, i64 312}
!6 = !{!"", !7, i64 0, !9, i64 32, !10, i64 40, !11, i64 48, !12, i64 56, !13, i64 104, !13, i64 152, !11, i64 200, !14, i64 204, !16, i64 208, !17, i64 278, !18, i64 310, !19, i64 320, !20, i64 348, !7, i64 386, !7, i64 482, !7, i64 584, !21, i64 712, !7, i64 720, !11, i64 848}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"", !9, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !9, i64 0, !9, i64 8, !9, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40}
!13 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!14 = !{!"", !15, i64 0, !15, i64 2}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !7, i64 0, !7, i64 2, !7, i64 34, !7, i64 66, !15, i64 68}
!17 = !{!"", !7, i64 0}
!18 = !{!"", !15, i64 0, !15, i64 2, !15, i64 4, !15, i64 6, !7, i64 8, !7, i64 9}
!19 = !{!"", !15, i64 0, !11, i64 4, !15, i64 8, !15, i64 10, !11, i64 12, !11, i64 16, !7, i64 20, !7, i64 21, !7, i64 22, !7, i64 23, !7, i64 24, !7, i64 25, !7, i64 26}
!20 = !{!"", !7, i64 0, !7, i64 1, !7, i64 1, !7, i64 2, !7, i64 4, !15, i64 36}
!21 = !{!"double", !7, i64 0}
!22 = !{!15, !15, i64 0}


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