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

; 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.ms5611_t = type { [32 x i8], %struct.ms5611_interface_t, ptr, %struct.ms5611_sync_t, %struct.ms5611_prom_t, %struct.ms5611_raw_t, %struct.ms5611_meas_t, i32, i8 }
%struct.ms5611_interface_t = type { ptr, ptr }
%struct.ms5611_sync_t = type { ptr }
%struct.ms5611_prom_t = type { i16, i16, i16, i16, i16, i16, i16, i16 }
%struct.ms5611_raw_t = type { i32, i32 }
%struct.ms5611_meas_t = type { double, double }

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

; 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 ptr @ms5611_start(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %14 = load ptr, ptr %10, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %22, label %16

16:                                               ; preds = %5
  %17 = load ptr, ptr %11, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %22, label %19

19:                                               ; preds = %16
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %19, %16, %5
  store ptr null, ptr %6, align 8
  br label %77

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

27:                                               ; preds = %23
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %76

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

51:                                               ; preds = %28
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %76

52:                                               ; preds = %28
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ms5611_t, ptr %53, i32 0, i32 7
  store i32 0, ptr %54, align 8, !tbaa !22
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ms5611_t, ptr %55, i32 0, i32 0
  %57 = getelementptr inbounds [32 x i8], ptr %56, i64 0, i64 0
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = call ptr @service_start(ptr noundef %57, ptr noundef %58, ptr noundef @ms5611_fsm, i32 noundef %59, i32 noundef %60)
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ms5611_t, ptr %62, i32 0, i32 2
  store ptr %61, ptr %63, align 8, !tbaa !23
  %64 = icmp eq ptr %61, null
  br i1 %64, label %65, label %69

65:                                               ; preds = %52
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ms5611_t, ptr %66, i32 0, i32 0
  %68 = getelementptr inbounds [32 x i8], ptr %67, i64 0, i64 0
  call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef %68, ptr noundef @.str)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %76

69:                                               ; preds = %52
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.ms5611_t, ptr %70, i32 0, i32 3
  %72 = getelementptr inbounds %struct.ms5611_sync_t, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !21
  %74 = call i64 @xQueueSemaphoreTake(ptr noundef %73, i32 noundef 100)
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %75, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %76

76:                                               ; preds = %69, %65, %51, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %77

77:                                               ; preds = %76, %22
  %78 = load ptr, ptr %6, align 8
  ret ptr %78
}

; 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 @service_start(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local void @ms5611_fsm(ptr noundef) #1

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

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

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 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 48, !14, i64 56, !15, i64 64, !17, i64 80, !18, i64 88, !10, i64 104, !7, i64 108}
!13 = !{!"", !6, i64 0, !6, i64 8}
!14 = !{!"", !6, i64 0}
!15 = !{!"", !16, i64 0, !16, i64 2, !16, i64 4, !16, i64 6, !16, i64 8, !16, i64 10, !16, i64 12, !16, i64 14, !16, i64 15}
!16 = !{!"short", !7, i64 0}
!17 = !{!"", !10, i64 0, !10, i64 4}
!18 = !{!"", !19, i64 0, !19, i64 8}
!19 = !{!"double", !7, i64 0}
!20 = !{!12, !6, i64 40}
!21 = !{!12, !6, i64 56}
!22 = !{!12, !10, i64 104}
!23 = !{!12, !6, i64 48}


; 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 @ms5611_start(ptr noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq ptr %3, null
  %7 = icmp eq ptr %4, null
  %or.cond = or i1 %6, %7
  %8 = icmp eq ptr %0, null
  %or.cond3 = or i1 %8, %or.cond
  br i1 %or.cond3, label %28, label %9

9:                                                ; preds = %5
  %10 = tail call noalias dereferenceable_or_null(112) ptr @calloc(i64 noundef 1, i64 noundef 112) #4
  %11 = icmp eq ptr %10, null
  br i1 %11, label %28, 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 = getelementptr inbounds i8, ptr %10, i64 40
  store ptr %4, ptr %15, align 8, !tbaa !18
  %16 = tail call ptr @xQueueGenericCreate(i64 noundef 1, i64 noundef 0, i8 noundef zeroext 3) #5
  %17 = getelementptr inbounds i8, ptr %10, i64 56
  store ptr %16, ptr %17, align 8, !tbaa !19
  %18 = icmp eq ptr %16, null
  br i1 %18, label %28, label %19

19:                                               ; preds = %12
  %20 = getelementptr inbounds i8, ptr %10, i64 104
  store i32 0, ptr %20, align 8, !tbaa !20
  %21 = tail call ptr @service_start(ptr noundef nonnull %10, ptr noundef nonnull %10, ptr noundef nonnull @ms5611_fsm, i32 noundef %1, i32 noundef %2) #5
  %22 = getelementptr inbounds i8, ptr %10, i64 48
  store ptr %21, ptr %22, align 8, !tbaa !21
  %23 = icmp eq ptr %21, null
  br i1 %23, label %24, label %25

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

25:                                               ; preds = %19
  %26 = load ptr, ptr %17, align 8, !tbaa !19
  %27 = tail call i64 @xQueueSemaphoreTake(ptr noundef %26, i32 noundef 100) #5
  br label %28

28:                                               ; preds = %24, %25, %9, %12, %5
  %.1 = phi ptr [ null, %5 ], [ null, %24 ], [ %10, %25 ], [ null, %9 ], [ null, %12 ]
  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 @service_start(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @ms5611_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 48, !11, i64 56, !12, i64 64, !14, i64 80, !16, i64 88, !15, i64 104, !7, i64 108}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"", !10, i64 0, !10, i64 8}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"", !10, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !13, i64 8, !13, i64 10, !13, i64 12, !13, i64 14, !13, i64 15}
!13 = !{!"short", !7, i64 0}
!14 = !{!"", !15, i64 0, !15, i64 4}
!15 = !{!"int", !7, i64 0}
!16 = !{!"", !17, i64 0, !17, i64 8}
!17 = !{!"double", !7, i64 0}
!18 = !{!6, !10, i64 40}
!19 = !{!6, !10, i64 56}
!20 = !{!6, !15, i64 104}
!21 = !{!6, !10, i64 48}


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