; LLVM IR from IOsonata/IOsonata :: src/sensors (mag_ak09940)

; 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.__MagSensor_Config = type <{ i32, i32, i32, i32, i8, i32 }>
%class.Device = type { ptr, i8, i32, ptr, ptr, i64, i8, ptr, i8, i32 }
%class.MagSensor = type { %class.Sensor.base, [3 x i16], i32, %struct.__MagSensor_Raw_Data, [3 x [3 x float]], [3 x float], %class.Device }
%class.Sensor.base = type <{ ptr, i32, i32, i32, i32, i64, i8, [7 x i8], i64, i64, i32, i32, i32, i32, %"struct.std::atomic_flag" }>
%"struct.std::atomic_flag" = type { %"struct.std::__atomic_flag_base" }
%"struct.std::__atomic_flag_base" = type { i8 }
%struct.__MagSensor_Raw_Data = type <{ i64, [3 x i16], %union.anon }>
%union.anon = type { [3 x i32] }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10MagAk099404InitERK18__MagSensor_ConfigP11DeviceIntrfP5Timer(ptr noundef nonnull align 8 dereferenceable(160) %0, ptr noundef nonnull align 1 dereferenceable(21) %1, ptr noundef %2, ptr noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca i16, align 2
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  store i8 0, ptr %10, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  store i16 0, ptr %11, align 2, !tbaa !10
  %14 = call noundef i32 @_ZN6Sensor4TypeEj(ptr noundef nonnull align 8 dereferenceable(73) %13, i32 noundef 64)
  %15 = load ptr, ptr %13, align 8, !tbaa !12
  %16 = getelementptr i8, ptr %15, i64 -24
  %17 = load i64, ptr %16, align 8
  %18 = getelementptr inbounds i8, ptr %13, i64 %17
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN6Device9InterfaceEP11DeviceIntrf(ptr noundef nonnull align 8 dereferenceable(64) %18, ptr noundef %19)
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = getelementptr inbounds ptr, ptr %21, i64 1
  %23 = load ptr, ptr %22, align 8
  %24 = call noundef i32 %23(ptr noundef nonnull align 8 dereferenceable(8) %20)
  %25 = icmp eq i32 %24, 6
  br i1 %25, label %26, label %37

26:                                               ; preds = %4
  %27 = load ptr, ptr %13, align 8, !tbaa !12
  %28 = getelementptr i8, ptr %27, i64 -24
  %29 = load i64, ptr %28, align 8
  %30 = getelementptr inbounds i8, ptr %13, i64 %29
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.__MagSensor_Config, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 1, !tbaa !14
  %34 = load ptr, ptr %30, align 8, !tbaa !12
  %35 = getelementptr inbounds ptr, ptr %34, i64 6
  %36 = load ptr, ptr %35, align 8
  call void %36(ptr noundef nonnull align 8 dereferenceable(64) %30, i32 noundef %33)
  br label %45

37:                                               ; preds = %4
  %38 = load ptr, ptr %13, align 8, !tbaa !12
  %39 = getelementptr i8, ptr %38, i64 -24
  %40 = load i64, ptr %39, align 8
  %41 = getelementptr inbounds i8, ptr %13, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !12
  %43 = getelementptr inbounds ptr, ptr %42, i64 6
  %44 = load ptr, ptr %43, align 8
  call void %44(ptr noundef nonnull align 8 dereferenceable(64) %41, i32 noundef 12)
  br label %45

45:                                               ; preds = %37, %26
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %55

48:                                               ; preds = %45
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = load ptr, ptr %13, align 8, !tbaa !12
  %51 = getelementptr i8, ptr %50, i64 -24
  %52 = load i64, ptr %51, align 8
  %53 = getelementptr inbounds i8, ptr %13, i64 %52
  %54 = getelementptr inbounds %class.Device, ptr %53, i32 0, i32 4
  store ptr %49, ptr %54, align 8, !tbaa !20
  br label %55

55:                                               ; preds = %48, %45
  %56 = load ptr, ptr %13, align 8, !tbaa !12
  %57 = getelementptr inbounds ptr, ptr %56, i64 25
  %58 = load ptr, ptr %57, align 8
  %59 = call noundef i32 %58(ptr noundef nonnull align 8 dereferenceable(160) %13, i32 noundef 12, ptr noundef %10, i32 noundef 1, ptr noundef %11, i32 noundef 2)
  %60 = load i16, ptr %11, align 2, !tbaa !10
  %61 = zext i16 %60 to i32
  %62 = icmp ne i32 %61, 41800
  br i1 %62, label %63, label %64

63:                                               ; preds = %55
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %112

64:                                               ; preds = %55
  %65 = load ptr, ptr %13, align 8, !tbaa !12
  %66 = getelementptr inbounds ptr, ptr %65, i64 32
  %67 = load ptr, ptr %66, align 8
  call void %67(ptr noundef nonnull align 8 dereferenceable(160) %13)
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.__MagSensor_Config, ptr %68, i32 0, i32 2
  %70 = load i32, ptr %69, align 1, !tbaa !25
  %71 = load ptr, ptr %13, align 8, !tbaa !12
  %72 = getelementptr inbounds ptr, ptr %71, i64 7
  %73 = load ptr, ptr %72, align 8
  %74 = call noundef i32 %73(ptr noundef nonnull align 8 dereferenceable(160) %13, i32 noundef %70)
  %75 = load ptr, ptr %13, align 8, !tbaa !12
  %76 = getelementptr inbounds ptr, ptr %75, i64 14
  %77 = load ptr, ptr %76, align 8
  %78 = call noundef i32 %77(ptr noundef nonnull align 8 dereferenceable(73) %13, i32 noundef 131070)
  %79 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %80 = getelementptr inbounds [3 x i16], ptr %79, i64 0, i64 0
  store i16 10, ptr %80, align 2, !tbaa !10
  %81 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %82 = getelementptr inbounds [3 x i16], ptr %81, i64 0, i64 0
  %83 = load i16, ptr %82, align 2, !tbaa !10
  %84 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %85 = getelementptr inbounds [3 x i16], ptr %84, i64 0, i64 1
  store i16 %83, ptr %85, align 2, !tbaa !10
  %86 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %87 = getelementptr inbounds [3 x i16], ptr %86, i64 0, i64 0
  %88 = load i16, ptr %87, align 2, !tbaa !10
  %89 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %90 = getelementptr inbounds [3 x i16], ptr %89, i64 0, i64 2
  store i16 %88, ptr %90, align 2, !tbaa !10
  %91 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %92 = getelementptr inbounds [3 x i16], ptr %91, i64 0, i64 0
  %93 = load i16, ptr %92, align 2, !tbaa !10
  %94 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 3
  %95 = getelementptr inbounds %struct.__MagSensor_Raw_Data, ptr %94, i32 0, i32 1
  %96 = getelementptr inbounds [3 x i16], ptr %95, i64 0, i64 0
  store i16 %93, ptr %96, align 4, !tbaa !10
  %97 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %98 = getelementptr inbounds [3 x i16], ptr %97, i64 0, i64 1
  %99 = load i16, ptr %98, align 2, !tbaa !10
  %100 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 3
  %101 = getelementptr inbounds %struct.__MagSensor_Raw_Data, ptr %100, i32 0, i32 1
  %102 = getelementptr inbounds [3 x i16], ptr %101, i64 0, i64 1
  store i16 %99, ptr %102, align 2, !tbaa !10
  %103 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %104 = getelementptr inbounds [3 x i16], ptr %103, i64 0, i64 2
  %105 = load i16, ptr %104, align 2, !tbaa !10
  %106 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 3
  %107 = getelementptr inbounds %struct.__MagSensor_Raw_Data, ptr %106, i32 0, i32 1
  %108 = getelementptr inbounds [3 x i16], ptr %107, i64 0, i64 2
  store i16 %105, ptr %108, align 4, !tbaa !10
  %109 = load ptr, ptr %13, align 8, !tbaa !12
  %110 = getelementptr inbounds ptr, ptr %109, i64 23
  %111 = load ptr, ptr %110, align 8
  call void %111(ptr noundef nonnull align 8 dereferenceable(160) %13)
  store i1 true, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %112

112:                                              ; preds = %64, %63
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  %113 = load i1, ptr %5, align 1
  ret i1 %113
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN6Sensor4TypeEj(ptr noundef nonnull align 8 dereferenceable(73), i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Device9InterfaceEP11DeviceIntrf(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef) #2 align 2

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

attributes #0 = { mustprogress 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 = { mustprogress 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 #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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"vtable pointer", !8, i64 0}
!14 = !{!15, !16, i64 0}
!15 = !{!"_ZTS18__MagSensor_Config", !16, i64 0, !17, i64 4, !16, i64 8, !18, i64 12, !7, i64 16, !19, i64 17}
!16 = !{!"int", !7, i64 0}
!17 = !{!"_ZTS15__Sensor_OpMode", !7, i64 0}
!18 = !{!"_ZTS21__MagSensor_Precision", !7, i64 0}
!19 = !{!"_ZTS24__Dev_Interrupt_Polarity", !7, i64 0}
!20 = !{!21, !6, i64 24}
!21 = !{!"_ZTS6Device", !22, i64 8, !16, i64 12, !6, i64 16, !6, i64 24, !23, i64 32, !22, i64 40, !6, i64 48, !7, i64 56, !24, i64 60}
!22 = !{!"bool", !7, i64 0}
!23 = !{!"long", !7, i64 0}
!24 = !{!"_ZTS21__Dev_Data_Byte_Order", !7, i64 0}
!25 = !{!15, !16, i64 8}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10MagAk099404InitERK18__MagSensor_ConfigP11DeviceIntrfP5Timer(ptr noundef nonnull align 8 dereferenceable(160) %0, ptr nocapture noundef nonnull readonly align 1 dereferenceable(21) %1, ptr noundef %2, ptr noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca i8, align 1
  %6 = alloca i16, align 2
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #3
  store i8 0, ptr %5, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %6) #3
  store i16 0, ptr %6, align 2, !tbaa !8
  %7 = tail call noundef i32 @_ZN6Sensor4TypeEj(ptr noundef nonnull align 8 dereferenceable(73) %0, i32 noundef 64)
  %8 = load ptr, ptr %0, align 8, !tbaa !10
  %9 = getelementptr i8, ptr %8, i64 -24
  %10 = load i64, ptr %9, align 8
  %11 = getelementptr inbounds i8, ptr %0, i64 %10
  tail call void @_ZN6Device9InterfaceEP11DeviceIntrf(ptr noundef nonnull align 8 dereferenceable(64) %11, ptr noundef %2)
  %12 = load ptr, ptr %2, align 8, !tbaa !10
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = load ptr, ptr %13, align 8
  %15 = tail call noundef i32 %14(ptr noundef nonnull align 8 dereferenceable(8) %2)
  %16 = icmp eq i32 %15, 6
  %17 = load ptr, ptr %0, align 8, !tbaa !10
  %18 = getelementptr i8, ptr %17, i64 -24
  %19 = load i64, ptr %18, align 8
  %20 = getelementptr inbounds i8, ptr %0, i64 %19
  %21 = load i32, ptr %1, align 1
  %.sink = select i1 %16, i32 %21, i32 12
  %22 = load ptr, ptr %20, align 8, !tbaa !10
  %23 = getelementptr inbounds i8, ptr %22, i64 48
  %24 = load ptr, ptr %23, align 8
  tail call void %24(ptr noundef nonnull align 8 dereferenceable(64) %20, i32 noundef %.sink)
  %.not = icmp eq ptr %3, null
  %.pre = load ptr, ptr %0, align 8, !tbaa !10
  br i1 %.not, label %30, label %25

25:                                               ; preds = %4
  %26 = getelementptr i8, ptr %.pre, i64 -24
  %27 = load i64, ptr %26, align 8
  %28 = getelementptr inbounds i8, ptr %0, i64 %27
  %29 = getelementptr inbounds i8, ptr %28, i64 24
  store ptr %3, ptr %29, align 8, !tbaa !12
  br label %30

30:                                               ; preds = %25, %4
  %31 = getelementptr inbounds i8, ptr %.pre, i64 200
  %32 = load ptr, ptr %31, align 8
  %33 = call noundef i32 %32(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef 12, ptr noundef nonnull %5, i32 noundef 1, ptr noundef nonnull %6, i32 noundef 2)
  %34 = load i16, ptr %6, align 2, !tbaa !8
  %.not9 = icmp eq i16 %34, -23736
  br i1 %.not9, label %35, label %58

35:                                               ; preds = %30
  %36 = load ptr, ptr %0, align 8, !tbaa !10
  %37 = getelementptr inbounds i8, ptr %36, i64 256
  %38 = load ptr, ptr %37, align 8
  call void %38(ptr noundef nonnull align 8 dereferenceable(160) %0)
  %39 = getelementptr inbounds i8, ptr %1, i64 8
  %40 = load i32, ptr %39, align 1, !tbaa !19
  %41 = load ptr, ptr %0, align 8, !tbaa !10
  %42 = getelementptr inbounds i8, ptr %41, i64 56
  %43 = load ptr, ptr %42, align 8
  %44 = call noundef i32 %43(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %40)
  %45 = load ptr, ptr %0, align 8, !tbaa !10
  %46 = getelementptr inbounds i8, ptr %45, i64 112
  %47 = load ptr, ptr %46, align 8
  %48 = call noundef i32 %47(ptr noundef nonnull align 8 dereferenceable(73) %0, i32 noundef 131070)
  %49 = getelementptr inbounds i8, ptr %0, i64 74
  store i16 10, ptr %49, align 2, !tbaa !8
  %50 = getelementptr inbounds i8, ptr %0, i64 76
  store i16 10, ptr %50, align 4, !tbaa !8
  %51 = getelementptr inbounds i8, ptr %0, i64 78
  store i16 10, ptr %51, align 2, !tbaa !8
  %52 = getelementptr inbounds i8, ptr %0, i64 92
  store i16 10, ptr %52, align 4, !tbaa !8
  %53 = getelementptr inbounds i8, ptr %0, i64 94
  store i16 10, ptr %53, align 2, !tbaa !8
  %54 = getelementptr inbounds i8, ptr %0, i64 96
  store i16 10, ptr %54, align 8, !tbaa !8
  %55 = load ptr, ptr %0, align 8, !tbaa !10
  %56 = getelementptr inbounds i8, ptr %55, i64 184
  %57 = load ptr, ptr %56, align 8
  call void %57(ptr noundef nonnull align 8 dereferenceable(160) %0)
  br label %58

58:                                               ; preds = %30, %35
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #3
  ret i1 %.not9
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN6Sensor4TypeEj(ptr noundef nonnull align 8 dereferenceable(73), i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Device9InterfaceEP11DeviceIntrf(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef) local_unnamed_addr #2 align 2

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

attributes #0 = { mustprogress 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"vtable pointer", !7, i64 0}
!12 = !{!13, !16, i64 24}
!13 = !{!"_ZTS6Device", !14, i64 8, !15, i64 12, !16, i64 16, !16, i64 24, !17, i64 32, !14, i64 40, !16, i64 48, !6, i64 56, !18, i64 60}
!14 = !{!"bool", !6, i64 0}
!15 = !{!"int", !6, i64 0}
!16 = !{!"any pointer", !6, i64 0}
!17 = !{!"long", !6, i64 0}
!18 = !{!"_ZTS21__Dev_Data_Byte_Order", !6, i64 0}
!19 = !{!20, !15, i64 8}
!20 = !{!"_ZTS18__MagSensor_Config", !15, i64 0, !21, i64 4, !15, i64 8, !22, i64 12, !6, i64 16, !23, i64 17}
!21 = !{!"_ZTS15__Sensor_OpMode", !6, i64 0}
!22 = !{!"_ZTS21__MagSensor_Precision", !6, i64 0}
!23 = !{!"_ZTS24__Dev_Interrupt_Polarity", !6, i64 0}


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