; 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 void @cubeio_set_pwm(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load i8, ptr %5, align 1, !tbaa !9
  %8 = zext i8 %7 to i32
  %9 = icmp slt i32 %8, 1
  br i1 %9, label %10, label %11

10:                                               ; preds = %3
  br label %35

11:                                               ; preds = %3
  %12 = load i8, ptr %5, align 1, !tbaa !9
  %13 = zext i8 %12 to i32
  %14 = icmp slt i32 %13, 16
  br i1 %14, label %15, label %18

15:                                               ; preds = %11
  %16 = load i8, ptr %5, align 1, !tbaa !9
  %17 = zext i8 %16 to i32
  br label %19

18:                                               ; preds = %11
  br label %19

19:                                               ; preds = %18, %15
  %20 = phi i32 [ %17, %15 ], [ 16, %18 ]
  %21 = trunc i32 %20 to i8
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.cubeio_t, ptr %22, i32 0, i32 9
  %24 = getelementptr inbounds %struct.cubeio_pwm_out_t, ptr %23, i32 0, i32 0
  store i8 %21, ptr %24, align 8, !tbaa !10
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.cubeio_t, ptr %25, i32 0, i32 16
  %27 = getelementptr inbounds [16 x double], ptr %26, i64 0, i64 0
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %27, ptr align 8 %28, i64 128, i1 false)
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  call void @cubeio_push_event(ptr noundef %29, i32 noundef 1)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.cubeio_t, ptr %30, i32 0, i32 4
  %32 = getelementptr inbounds %struct.cubeio_sync_t, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !24
  %34 = call i64 @xQueueGenericSend(ptr noundef %33, ptr noundef null, i32 noundef 0, i64 noundef 0)
  br label %35

35:                                               ; preds = %19, %10
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden void @cubeio_push_event(ptr noundef, i32 noundef) #0

declare i64 @xQueueGenericSend(ptr noundef, ptr noundef, i32 noundef, i64 noundef) #2

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 nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 208}
!11 = !{!"", !7, i64 0, !6, i64 32, !12, i64 40, !13, i64 48, !14, i64 56, !15, i64 104, !15, i64 152, !13, i64 200, !16, 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, !13, i64 848}
!12 = !{!"", !6, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40}
!15 = !{!"", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!16 = !{!"", !17, i64 0, !17, i64 2}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !7, i64 0, !7, i64 2, !7, i64 34, !7, i64 66, !17, i64 68}
!19 = !{!"", !7, i64 0}
!20 = !{!"", !17, i64 0, !17, i64 2, !17, i64 4, !17, i64 6, !7, i64 8, !7, i64 9}
!21 = !{!"", !17, i64 0, !13, i64 4, !17, i64 8, !17, i64 10, !13, i64 12, !13, 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, !17, i64 36}
!23 = !{!"double", !7, i64 0}
!24 = !{!11, !6, i64 72}


; 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
define dso_local void @cubeio_set_pwm(ptr noundef %0, i8 noundef zeroext %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = icmp eq i8 %1, 0
  br i1 %4, label %12, label %5

5:                                                ; preds = %3
  %6 = tail call i8 @llvm.umin.i8(i8 %1, i8 16)
  %7 = getelementptr inbounds i8, ptr %0, i64 208
  store i8 %6, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 584
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(128) %8, ptr noundef nonnull align 8 dereferenceable(128) %2, i64 128, i1 false)
  tail call void @cubeio_push_event(ptr noundef %0, i32 noundef 1)
  %9 = getelementptr inbounds i8, ptr %0, i64 72
  %10 = load ptr, ptr %9, align 8, !tbaa !22
  %11 = tail call i64 @xQueueGenericSend(ptr noundef %10, ptr noundef null, i32 noundef 0, i64 noundef 0) #4
  br label %12

12:                                               ; preds = %3, %5
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden void @cubeio_push_event(ptr noundef, i32 noundef) local_unnamed_addr #0

declare i64 @xQueueGenericSend(ptr noundef, ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.umin.i8(i8, i8) #3

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 208}
!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 = !{!6, !9, i64 72}


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