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

@.str = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @cubeio_start(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %9, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %17, label %14

14:                                               ; preds = %4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14, %4
  store ptr null, ptr %5, align 8
  br label %90

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %19 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 856) #6
  store ptr %19, ptr %10, align 8, !tbaa !5
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %18
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %89

23:                                               ; preds = %18
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.cubeio_t, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [32 x i8], ptr %25, i64 0, i64 0
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = call ptr @strncpy(ptr noundef %26, ptr noundef %27, i64 noundef 31) #5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.cubeio_t, ptr %30, i32 0, i32 2
  %32 = getelementptr inbounds %struct.cubeio_interface_t, ptr %31, i32 0, i32 0
  store ptr %29, ptr %32, align 8, !tbaa !11
  %33 = call ptr @xQueueGenericCreate(i64 noundef 1, i64 noundef 0, i8 noundef zeroext 3)
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.cubeio_t, ptr %34, i32 0, i32 4
  %36 = getelementptr inbounds %struct.cubeio_sync_t, ptr %35, i32 0, i32 0
  store ptr %33, ptr %36, align 8, !tbaa !24
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.cubeio_t, ptr %37, i32 0, i32 4
  %39 = getelementptr inbounds %struct.cubeio_sync_t, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !24
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %43

42:                                               ; preds = %23
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %89

43:                                               ; preds = %23
  %44 = call ptr @xQueueCreateMutex(i8 noundef zeroext 1)
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.cubeio_t, ptr %45, i32 0, i32 4
  %47 = getelementptr inbounds %struct.cubeio_sync_t, ptr %46, i32 0, i32 1
  store ptr %44, ptr %47, align 8, !tbaa !25
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.cubeio_t, ptr %48, i32 0, i32 4
  %50 = getelementptr inbounds %struct.cubeio_sync_t, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !25
  %52 = icmp eq ptr %51, null
  br i1 %52, label %53, label %54

53:                                               ; preds = %43
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %89

54:                                               ; preds = %43
  %55 = call ptr @xQueueGenericCreate(i64 noundef 1, i64 noundef 0, i8 noundef zeroext 3)
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.cubeio_t, ptr %56, i32 0, i32 4
  %58 = getelementptr inbounds %struct.cubeio_sync_t, ptr %57, i32 0, i32 2
  store ptr %55, ptr %58, align 8, !tbaa !26
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.cubeio_t, ptr %59, i32 0, i32 4
  %61 = getelementptr inbounds %struct.cubeio_sync_t, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !26
  %63 = icmp eq ptr %62, null
  br i1 %63, label %64, label %65

64:                                               ; preds = %54
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %89

65:                                               ; preds = %54
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.cubeio_t, ptr %66, i32 0, i32 3
  store i32 0, ptr %67, align 8, !tbaa !27
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.cubeio_t, ptr %68, i32 0, i32 0
  %70 = getelementptr inbounds [32 x i8], ptr %69, i64 0, i64 0
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = load i32, ptr %7, align 4, !tbaa !9
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = call ptr @service_start(ptr noundef %70, ptr noundef %71, ptr noundef @cubeio_fsm, i32 noundef %72, i32 noundef %73)
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.cubeio_t, ptr %75, i32 0, i32 1
  store ptr %74, ptr %76, align 8, !tbaa !28
  %77 = icmp eq ptr %74, null
  br i1 %77, label %78, label %82

78:                                               ; preds = %65
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.cubeio_t, ptr %79, i32 0, i32 0
  %81 = getelementptr inbounds [32 x i8], ptr %80, i64 0, i64 0
  call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef %81, ptr noundef @.str)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %89

82:                                               ; preds = %65
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.cubeio_t, ptr %83, i32 0, i32 4
  %85 = getelementptr inbounds %struct.cubeio_sync_t, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !24
  %87 = call i64 @xQueueSemaphoreTake(ptr noundef %86, i32 noundef -1)
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %88, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %89

89:                                               ; preds = %82, %78, %64, %53, %42, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %90

90:                                               ; preds = %89, %17
  %91 = load ptr, ptr %5, align 8
  ret ptr %91
}

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #3

declare ptr @xQueueGenericCreate(i64 noundef, i64 noundef, i8 noundef zeroext) #4

declare ptr @xQueueCreateMutex(i8 noundef zeroext) #4

declare ptr @service_start(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #4

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

declare void @log_module(i8 noundef zeroext, ptr noundef, ptr noundef, ...) #4

declare i64 @xQueueSemaphoreTake(ptr noundef, i32 noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(0,1) "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 = { nounwind "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 #4 = { "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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0,1) }

!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 = !{!12, !6, i64 40}
!12 = !{!"", !7, i64 0, !6, i64 32, !13, i64 40, !10, i64 48, !14, i64 56, !15, i64 104, !15, i64 152, !10, 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, !10, i64 848}
!13 = !{!"", !6, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, 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, !10, i64 4, !17, i64 8, !17, i64 10, !10, i64 12, !10, 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 = !{!12, !6, i64 56}
!25 = !{!12, !6, i64 64}
!26 = !{!12, !6, i64 72}
!27 = !{!12, !10, i64 48}
!28 = !{!12, !6, i64 32}


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

@.str = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @cubeio_start(ptr noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %3, null
  %6 = icmp eq ptr %0, null
  %or.cond = or i1 %6, %5
  br i1 %or.cond, label %33, label %7

7:                                                ; preds = %4
  %8 = tail call noalias dereferenceable_or_null(856) ptr @calloc(i64 noundef 1, i64 noundef 856) #4
  %9 = icmp eq ptr %8, null
  br i1 %9, label %33, label %10

10:                                               ; preds = %7
  %11 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %8, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 31) #5
  %12 = getelementptr inbounds i8, ptr %8, i64 40
  store ptr %3, ptr %12, align 8, !tbaa !5
  %13 = tail call ptr @xQueueGenericCreate(i64 noundef 1, i64 noundef 0, i8 noundef zeroext 3) #5
  %14 = getelementptr inbounds i8, ptr %8, i64 56
  store ptr %13, ptr %14, align 8, !tbaa !22
  %15 = icmp eq ptr %13, null
  br i1 %15, label %33, label %16

16:                                               ; preds = %10
  %17 = tail call ptr @xQueueCreateMutex(i8 noundef zeroext 1) #5
  %18 = getelementptr inbounds i8, ptr %8, i64 64
  store ptr %17, ptr %18, align 8, !tbaa !23
  %19 = icmp eq ptr %17, null
  br i1 %19, label %33, label %20

20:                                               ; preds = %16
  %21 = tail call ptr @xQueueGenericCreate(i64 noundef 1, i64 noundef 0, i8 noundef zeroext 3) #5
  %22 = getelementptr inbounds i8, ptr %8, i64 72
  store ptr %21, ptr %22, align 8, !tbaa !24
  %23 = icmp eq ptr %21, null
  br i1 %23, label %33, label %24

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %8, i64 48
  store i32 0, ptr %25, align 8, !tbaa !25
  %26 = tail call ptr @service_start(ptr noundef nonnull %8, ptr noundef nonnull %8, ptr noundef nonnull @cubeio_fsm, i32 noundef %1, i32 noundef %2) #5
  %27 = getelementptr inbounds i8, ptr %8, i64 32
  store ptr %26, ptr %27, align 8, !tbaa !26
  %28 = icmp eq ptr %26, null
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  tail call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef nonnull %8, ptr noundef nonnull @.str) #5
  br label %33

30:                                               ; preds = %24
  %31 = load ptr, ptr %14, align 8, !tbaa !22
  %32 = tail call i64 @xQueueSemaphoreTake(ptr noundef %31, i32 noundef -1) #5
  br label %33

33:                                               ; preds = %29, %30, %7, %10, %16, %20, %4
  %.1 = phi ptr [ null, %4 ], [ null, %29 ], [ %8, %30 ], [ null, %7 ], [ null, %10 ], [ null, %16 ], [ null, %20 ]
  ret ptr %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #2

declare ptr @xQueueGenericCreate(i64 noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #3

declare ptr @xQueueCreateMutex(i8 noundef zeroext) local_unnamed_addr #3

declare ptr @service_start(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

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

declare void @log_module(i8 noundef zeroext, ptr noundef, ptr noundef, ...) local_unnamed_addr #3

declare i64 @xQueueSemaphoreTake(ptr noundef, i32 noundef) local_unnamed_addr #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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { "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 #4 = { nounwind allocsize(0,1) }
attributes #5 = { 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, !9, i64 40}
!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 56}
!23 = !{!6, !9, i64 64}
!24 = !{!6, !9, i64 72}
!25 = !{!6, !11, i64 48}
!26 = !{!6, !9, i64 32}


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