; 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
declare hidden void @cubeio_push_event(ptr noundef, i32 noundef) #0

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

13:                                               ; preds = %2
  %14 = load i16, ptr %4, align 2, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.cubeio_t, ptr %15, i32 0, i32 11
  %17 = getelementptr inbounds %struct.cubeio_rate_t, ptr %16, i32 0, i32 2
  store i16 %14, ptr %17, align 2, !tbaa !11
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  call void @cubeio_push_event(ptr noundef %18, i32 noundef 10)
  br label %19

19:                                               ; preds = %13, %2
  ret void
}

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 314}
!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}


; 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: nounwind uwtable
declare hidden void @cubeio_push_event(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @cubeio_set_default_freq(ptr noundef %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 314
  %4 = load i16, ptr %3, align 2, !tbaa !5
  %.not = icmp eq i16 %4, %1
  br i1 %.not, label %6, label %5

5:                                                ; preds = %2
  store i16 %1, ptr %3, align 2, !tbaa !5
  tail call void @cubeio_push_event(ptr noundef nonnull %0, i32 noundef 10)
  br label %6

6:                                                ; preds = %5, %2
  ret void
}

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, !15, i64 314}
!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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass