; 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
@CMD_MS5611_CONVERT_D1_OSR1024 = external hidden constant i8, align 1
@.str.1 = external hidden unnamed_addr constant [26 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 void @ms5611_fsm(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %4, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.ms5611_t, ptr %5, i32 0, i32 7
  %7 = load i32, ptr %6, align 8, !tbaa !9
  switch i32 %7, label %49 [
    i32 0, label %8
    i32 1, label %12
    i32 2, label %41
    i32 3, label %48
  ]

8:                                                ; preds = %1
  call void @vTaskDelay(i32 noundef 5)
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ms5611_reset(ptr noundef %9)
  call void @vTaskDelay(i32 noundef 5)
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ms5611_t, ptr %10, i32 0, i32 7
  store i32 1, ptr %11, align 8, !tbaa !9
  br label %49

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call i32 @ms5611_read_calib(ptr noundef %13)
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %21

16:                                               ; preds = %12
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ms5611_t, ptr %17, i32 0, i32 8
  %19 = load i8, ptr %18, align 4, !tbaa !19
  %20 = add i8 %19, 1
  store i8 %20, ptr %18, align 4, !tbaa !19
  br label %28

21:                                               ; preds = %12
  call void @vTaskDelay(i32 noundef 10)
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ms5611_exchange(ptr noundef %22, ptr noundef @CMD_MS5611_CONVERT_D1_OSR1024, ptr noundef null, i16 noundef zeroext 1)
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ms5611_t, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds [32 x i8], ptr %24, i64 0, i64 0
  call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 0, ptr noundef %25, ptr noundef @.str.1)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ms5611_t, ptr %26, i32 0, i32 7
  store i32 2, ptr %27, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %21, %16
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ms5611_t, ptr %29, i32 0, i32 8
  %31 = load i8, ptr %30, align 4, !tbaa !19
  %32 = zext i8 %31 to i32
  %33 = icmp sgt i32 %32, 5
  br i1 %33, label %34, label %40

34:                                               ; preds = %28
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ms5611_t, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds [32 x i8], ptr %36, i64 0, i64 0
  call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef %37, ptr noundef @.str)
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ms5611_t, ptr %38, i32 0, i32 7
  store i32 3, ptr %39, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %34, %28
  br label %49

41:                                               ; preds = %1
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = call i32 @ms5611_read_meas(ptr noundef %42)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %47, label %45

45:                                               ; preds = %41
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ms5611_process_meas(ptr noundef %46)
  br label %47

47:                                               ; preds = %45, %41
  br label %49

48:                                               ; preds = %1
  call void @vTaskDelete(ptr noundef null)
  br label %49

49:                                               ; preds = %48, %47, %40, %8, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

declare void @vTaskDelay(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @ms5611_reset(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @ms5611_read_calib(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @ms5611_exchange(ptr noundef, ptr noundef, ptr noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @ms5611_read_meas(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @ms5611_process_meas(ptr noundef) #1

declare void @vTaskDelete(ptr noundef) #2

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 = { "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 }

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


; 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
@CMD_MS5611_CONVERT_D1_OSR1024 = external hidden constant i8, align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @ms5611_fsm(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 104
  %3 = load i32, ptr %2, align 8, !tbaa !5
  switch i32 %3, label %20 [
    i32 0, label %4
    i32 1, label %5
    i32 2, label %16
    i32 3, label %19
  ]

4:                                                ; preds = %1
  tail call void @vTaskDelay(i32 noundef 5) #2
  tail call void @ms5611_reset(ptr noundef nonnull %0)
  tail call void @vTaskDelay(i32 noundef 5) #2
  store i32 1, ptr %2, align 8, !tbaa !5
  br label %20

5:                                                ; preds = %1
  %6 = tail call i32 @ms5611_read_calib(ptr noundef nonnull %0)
  %.not14 = icmp eq i32 %6, 0
  br i1 %.not14, label %11, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 108
  %9 = load i8, ptr %8, align 4, !tbaa !18
  %10 = add i8 %9, 1
  store i8 %10, ptr %8, align 4, !tbaa !18
  br label %12

11:                                               ; preds = %5
  tail call void @vTaskDelay(i32 noundef 10) #2
  tail call void @ms5611_exchange(ptr noundef nonnull %0, ptr noundef nonnull @CMD_MS5611_CONVERT_D1_OSR1024, ptr noundef null, i16 noundef zeroext 1)
  tail call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 0, ptr noundef nonnull %0, ptr noundef nonnull @.str.1) #2
  store i32 2, ptr %2, align 8, !tbaa !5
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 108
  %.pre = load i8, ptr %.phi.trans.insert, align 4, !tbaa !18
  br label %12

12:                                               ; preds = %11, %7
  %13 = phi i8 [ %.pre, %11 ], [ %10, %7 ]
  %14 = icmp ugt i8 %13, 5
  br i1 %14, label %15, label %20

15:                                               ; preds = %12
  tail call void (i8, ptr, ptr, ...) @log_module(i8 noundef zeroext 2, ptr noundef nonnull %0, ptr noundef nonnull @.str) #2
  store i32 3, ptr %2, align 8, !tbaa !5
  br label %20

16:                                               ; preds = %1
  %17 = tail call i32 @ms5611_read_meas(ptr noundef nonnull %0)
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %18, label %20

18:                                               ; preds = %16
  tail call void @ms5611_process_meas(ptr noundef nonnull %0)
  br label %20

19:                                               ; preds = %1
  tail call void @vTaskDelete(ptr noundef null) #2
  br label %20

20:                                               ; preds = %16, %18, %12, %15, %19, %4, %1
  ret void
}

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

declare void @vTaskDelay(i32 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare hidden void @ms5611_exchange(ptr noundef, ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

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

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

declare void @vTaskDelete(ptr noundef) local_unnamed_addr #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 = { "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, !15, i64 104}
!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, !7, i64 108}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass