; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @cubeio_set_range(ptr noundef %0, i32 noundef %1, i8 noundef zeroext %2, i16 noundef zeroext %3, i16 noundef zeroext %4, i16 noundef zeroext %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i16, align 2
  %11 = alloca i16, align 2
  %12 = alloca i16, align 2
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i8 %2, ptr %9, align 1, !tbaa !11
  store i16 %3, ptr %10, align 2, !tbaa !12
  store i16 %4, ptr %11, align 2, !tbaa !12
  store i16 %5, ptr %12, align 2, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %21

17:                                               ; preds = %6
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.cubeio_t, ptr %18, i32 0, i32 14
  %20 = getelementptr inbounds [16 x %struct.cubeio_range_cfg_t], ptr %19, i64 0, i64 0
  store ptr %20, ptr %13, align 8, !tbaa !5
  br label %30

21:                                               ; preds = %6
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %28

24:                                               ; preds = %21
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.cubeio_t, ptr %25, i32 0, i32 15
  %27 = getelementptr inbounds [16 x %struct.cubeio_range_cfg_t], ptr %26, i64 0, i64 0
  store ptr %27, ptr %13, align 8, !tbaa !5
  br label %29

28:                                               ; preds = %21
  store i32 1, ptr %14, align 4
  br label %54

29:                                               ; preds = %24
  br label %30

30:                                               ; preds = %29, %17
  %31 = load i8, ptr %9, align 1, !tbaa !11
  %32 = zext i8 %31 to i32
  %33 = icmp sgt i32 %32, 16
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  store i32 1, ptr %14, align 4
  br label %54

35:                                               ; preds = %30
  %36 = load i16, ptr %10, align 2, !tbaa !12
  %37 = load ptr, ptr %13, align 8, !tbaa !5
  %38 = load i8, ptr %9, align 1, !tbaa !11
  %39 = zext i8 %38 to i64
  %40 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %37, i64 %39
  %41 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %40, i32 0, i32 0
  store i16 %36, ptr %41, align 2, !tbaa !14
  %42 = load i16, ptr %11, align 2, !tbaa !12
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = load i8, ptr %9, align 1, !tbaa !11
  %45 = zext i8 %44 to i64
  %46 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %43, i64 %45
  %47 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %46, i32 0, i32 1
  store i16 %42, ptr %47, align 2, !tbaa !16
  %48 = load i16, ptr %12, align 2, !tbaa !12
  %49 = load ptr, ptr %13, align 8, !tbaa !5
  %50 = load i8, ptr %9, align 1, !tbaa !11
  %51 = zext i8 %50 to i64
  %52 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %49, i64 %51
  %53 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %52, i32 0, i32 2
  store i16 %48, ptr %53, align 2, !tbaa !17
  store i32 0, ptr %14, align 4
  br label %54

54:                                               ; preds = %35, %34, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  %55 = load i32, ptr %14, align 4
  switch i32 %55, label %57 [
    i32 0, label %56
    i32 1, label %56
  ]

56:                                               ; preds = %54, %54
  ret void

57:                                               ; preds = %54
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4}
!16 = !{!15, !13, i64 2}
!17 = !{!15, !13, i64 4}


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

%struct.cubeio_range_cfg_t = type { i16, i16, i16 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @cubeio_set_range(ptr nocapture noundef writeonly %0, i32 noundef %1, i8 noundef zeroext %2, i16 noundef zeroext %3, i16 noundef zeroext %4, i16 noundef zeroext %5) local_unnamed_addr #0 {
  switch i32 %1, label %17 [
    i32 0, label %8
    i32 1, label %7
  ]

7:                                                ; preds = %6
  br label %8

8:                                                ; preds = %6, %7
  %9 = phi i64 [ 482, %7 ], [ 386, %6 ]
  %10 = icmp ugt i8 %2, 16
  br i1 %10, label %17, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 %9
  %13 = zext nneg i8 %2 to i64
  %14 = getelementptr inbounds %struct.cubeio_range_cfg_t, ptr %12, i64 %13
  store i16 %3, ptr %14, align 2, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 2
  store i16 %4, ptr %15, align 2, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %14, i64 4
  store i16 %5, ptr %16, align 2, !tbaa !11
  br label %17

17:                                               ; preds = %8, %6, %11
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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, !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 2}
!11 = !{!6, !7, i64 4}


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