; LLVM IR from ctlst-tech/catpilot :: bsp/ics/ist8310 (ist8310)

; 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.ist8310_t = type { [32 x i8], %struct.ist8310_interface_t, ptr, %struct.ist8310_sync_t, %struct.ist8310_raw_t, %struct.ist8310_meas_t, %struct.ist8310_param_t, i32, i8 }
%struct.ist8310_interface_t = type { ptr }
%struct.ist8310_sync_t = type { ptr, ptr, ptr }
%struct.ist8310_raw_t = type { i8, i8, i8, i8, i8, i8, i8 }
%struct.ist8310_meas_t = type { float, float, float }
%struct.ist8310_param_t = type { float }

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

; Function Attrs: nounwind uwtable
define dso_local ptr @ist8310_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 %23, label %14

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

17:                                               ; preds = %14
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp ule i32 %18, 0
  br i1 %19, label %23, label %20

20:                                               ; preds = %17
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = icmp ule i32 %21, 0
  br i1 %22, label %23, label %24

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

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %25 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 104) #6
  store ptr %25, ptr %10, align 8, !tbaa !5
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %84

29:                                               ; preds = %24
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ist8310_t, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [32 x i8], ptr %31, i64 0, i64 0
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = call ptr @strncpy(ptr noundef %32, ptr noundef %33, i64 noundef 31) #5
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ist8310_t, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds %struct.ist8310_interface_t, ptr %37, i32 0, i32 0
  store ptr %35, ptr %38, align 8, !tbaa !11
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ist8310_t, ptr %39, i32 0, i32 7
  store i32 0, ptr %40, align 8, !tbaa !19
  %41 = call ptr @xQueueGenericCreate(i64 noundef 1, i64 noundef 0, i8 noundef zeroext 3)
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ist8310_t, ptr %42, i32 0, i32 3
  %44 = getelementptr inbounds %struct.ist8310_sync_t, ptr %43, i32 0, i32 1
  store ptr %41, ptr %44, align 8, !tbaa !20
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ist8310_t, ptr %45, i32 0, i32 3
  %47 = getelementptr inbounds %struct.ist8310_sync_t, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !20
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %51

50:                                               ; preds = %29
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %84

51:                                               ; preds = %29
  %52 = call ptr @xQueueCreateMutex(i8 noundef zeroext 1)
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ist8310_t, ptr %53, i32 0, i32 3
  %55 = getelementptr inbounds %struct.ist8310_sync_t, ptr %54, i32 0, i32 2
  store ptr %52, ptr %55, align 8, !tbaa !21
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ist8310_t, ptr %56, i32 0, i32 3
  %58 = getelementptr inbounds %struct.ist8310_sync_t, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !21
  %60 = icmp eq ptr %59, null
  br i1 %60, label %61, label %62

61:                                               ; preds = %51
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %84

62:                                               ; preds = %51
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ist8310_t, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds [32 x i8], ptr %64, i64 0, i64 0
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = call ptr @service_start(ptr noundef %65, ptr noundef %66, ptr noundef @ist8310_fsm, i32 noundef %67, i32 noundef %68)
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.ist8310_t, ptr %70, i32 0, i32 2
  store ptr %69, ptr %71, align 8, !tbaa !22
  %72 = icmp eq ptr %69, null
  br i1 %72, label %73, label %77

73:                                               ; preds = %62
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.ist8310_t, ptr %74, i32 0, i32 0
  %76 = getelementptr inbounds [32 x i8], ptr %75, i64 0, i64 0
  call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef %76, ptr noundef @.str)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %84

77:                                               ; preds = %62
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.ist8310_t, ptr %78, i32 0, i32 3
  %80 = getelementptr inbounds %struct.ist8310_sync_t, ptr %79, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8, !tbaa !20
  %82 = call i64 @xQueueSemaphoreTake(ptr noundef %81, i32 noundef -1)
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %83, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %84

84:                                               ; preds = %77, %73, %61, %50, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %85

85:                                               ; preds = %84, %23
  %86 = load ptr, ptr %5, align 8
  ret ptr %86
}

; 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 @ist8310_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 32}
!12 = !{!"", !7, i64 0, !13, i64 32, !6, i64 40, !14, i64 48, !15, i64 72, !16, i64 80, !18, i64 92, !10, i64 96, !7, i64 100}
!13 = !{!"", !6, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6}
!16 = !{!"", !17, i64 0, !17, i64 4, !17, i64 8}
!17 = !{!"float", !7, i64 0}
!18 = !{!"", !17, i64 0}
!19 = !{!12, !10, i64 96}
!20 = !{!12, !6, i64 56}
!21 = !{!12, !6, i64 64}
!22 = !{!12, !6, i64 40}


; 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 @ist8310_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
  %7 = icmp eq i32 %1, 0
  %or.cond3 = or i1 %7, %or.cond
  %8 = icmp eq i32 %2, 0
  %or.cond5 = or i1 %8, %or.cond3
  br i1 %or.cond5, label %30, label %9

9:                                                ; preds = %4
  %10 = tail call noalias dereferenceable_or_null(104) ptr @calloc(i64 noundef 1, i64 noundef 104) #4
  %11 = icmp eq ptr %10, null
  br i1 %11, label %30, label %12

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

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

22:                                               ; preds = %18
  %23 = tail call ptr @service_start(ptr noundef nonnull %10, ptr noundef nonnull %10, ptr noundef nonnull @ist8310_fsm, i32 noundef %1, i32 noundef %2) #5
  %24 = getelementptr inbounds i8, ptr %10, i64 40
  store ptr %23, ptr %24, align 8, !tbaa !19
  %25 = icmp eq ptr %23, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  tail call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef nonnull %10, ptr noundef nonnull @.str) #5
  br label %30

27:                                               ; preds = %22
  %28 = load ptr, ptr %16, align 8, !tbaa !17
  %29 = tail call i64 @xQueueSemaphoreTake(ptr noundef %28, i32 noundef -1) #5
  br label %30

30:                                               ; preds = %26, %27, %9, %12, %18, %4
  %.1 = phi ptr [ null, %4 ], [ null, %26 ], [ %10, %27 ], [ null, %9 ], [ null, %12 ], [ null, %18 ]
  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 @ist8310_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, !10, i64 32}
!6 = !{!"", !7, i64 0, !9, i64 32, !10, i64 40, !11, i64 48, !12, i64 72, !13, i64 80, !15, i64 92, !16, i64 96, !7, i64 100}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"", !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16}
!12 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6}
!13 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8}
!14 = !{!"float", !7, i64 0}
!15 = !{!"", !14, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!6, !10, i64 56}
!18 = !{!6, !10, i64 64}
!19 = !{!6, !10, i64 40}


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