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

; 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.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] }
%class.Device = type { ptr, i8, i32, ptr, ptr, i64, i8, ptr, i8, i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10MagAk099164InitERK18__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
  %14 = call noundef i32 @_ZN6Sensor4TypeEj(ptr noundef nonnull align 8 dereferenceable(73) %13, i32 noundef 64)
  %15 = load ptr, ptr %13, align 8, !tbaa !10
  %16 = getelementptr inbounds ptr, ptr %15, i64 25
  %17 = load ptr, ptr %16, align 8
  %18 = call noundef i32 %17(ptr noundef nonnull align 8 dereferenceable(160) %13, i32 noundef 12, ptr noundef %10, i32 noundef 1, ptr noundef %11, i32 noundef 2)
  %19 = load i16, ptr %11, align 2, !tbaa !12
  %20 = zext i16 %19 to i32
  %21 = icmp ne i32 %20, 2376
  br i1 %21, label %22, label %23

22:                                               ; preds = %4
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %72

23:                                               ; preds = %4
  store i8 50, ptr %10, align 1, !tbaa !9
  store i16 1, ptr %11, align 2, !tbaa !12
  %24 = load ptr, ptr %13, align 8, !tbaa !10
  %25 = getelementptr inbounds ptr, ptr %24, i64 26
  %26 = load ptr, ptr %25, align 8
  %27 = call noundef i32 %26(ptr noundef nonnull align 8 dereferenceable(160) %13, i32 noundef 12, ptr noundef %10, i32 noundef 1, ptr noundef %11, i32 noundef 1)
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.__MagSensor_Config, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 1, !tbaa !14
  %31 = load ptr, ptr %13, align 8, !tbaa !10
  %32 = getelementptr inbounds ptr, ptr %31, i64 7
  %33 = load ptr, ptr %32, align 8
  %34 = call noundef i32 %33(ptr noundef nonnull align 8 dereferenceable(160) %13, i32 noundef %30)
  %35 = load ptr, ptr %13, align 8, !tbaa !10
  %36 = getelementptr inbounds ptr, ptr %35, i64 14
  %37 = load ptr, ptr %36, align 8
  %38 = call noundef i32 %37(ptr noundef nonnull align 8 dereferenceable(73) %13, i32 noundef 32752)
  %39 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %40 = getelementptr inbounds [3 x i16], ptr %39, i64 0, i64 0
  store i16 149, ptr %40, align 2, !tbaa !12
  %41 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %42 = getelementptr inbounds [3 x i16], ptr %41, i64 0, i64 0
  %43 = load i16, ptr %42, align 2, !tbaa !12
  %44 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %45 = getelementptr inbounds [3 x i16], ptr %44, i64 0, i64 1
  store i16 %43, ptr %45, align 2, !tbaa !12
  %46 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %47 = getelementptr inbounds [3 x i16], ptr %46, i64 0, i64 0
  %48 = load i16, ptr %47, align 2, !tbaa !12
  %49 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %50 = getelementptr inbounds [3 x i16], ptr %49, i64 0, i64 2
  store i16 %48, ptr %50, align 2, !tbaa !12
  %51 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %52 = getelementptr inbounds [3 x i16], ptr %51, i64 0, i64 0
  %53 = load i16, ptr %52, align 2, !tbaa !12
  %54 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 3
  %55 = getelementptr inbounds %struct.__MagSensor_Raw_Data, ptr %54, i32 0, i32 1
  %56 = getelementptr inbounds [3 x i16], ptr %55, i64 0, i64 0
  store i16 %53, ptr %56, align 4, !tbaa !12
  %57 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %58 = getelementptr inbounds [3 x i16], ptr %57, i64 0, i64 1
  %59 = load i16, ptr %58, align 2, !tbaa !12
  %60 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 3
  %61 = getelementptr inbounds %struct.__MagSensor_Raw_Data, ptr %60, i32 0, i32 1
  %62 = getelementptr inbounds [3 x i16], ptr %61, i64 0, i64 1
  store i16 %59, ptr %62, align 2, !tbaa !12
  %63 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 1
  %64 = getelementptr inbounds [3 x i16], ptr %63, i64 0, i64 2
  %65 = load i16, ptr %64, align 2, !tbaa !12
  %66 = getelementptr inbounds %class.MagSensor, ptr %13, i32 0, i32 3
  %67 = getelementptr inbounds %struct.__MagSensor_Raw_Data, ptr %66, i32 0, i32 1
  %68 = getelementptr inbounds [3 x i16], ptr %67, i64 0, i64 2
  store i16 %65, ptr %68, align 4, !tbaa !12
  %69 = load ptr, ptr %13, align 8, !tbaa !10
  %70 = getelementptr inbounds ptr, ptr %69, i64 23
  %71 = load ptr, ptr %70, align 8
  call void %71(ptr noundef nonnull align 8 dereferenceable(160) %13)
  store i1 true, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %72

72:                                               ; preds = %23, %22
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  %73 = load i1, ptr %5, align 1
  ret i1 %73
}

; 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: 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 = !{!"vtable pointer", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !16, i64 8}
!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}


; 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 @_ZN10MagAk099164InitERK18__MagSensor_ConfigP11DeviceIntrfP5Timer(ptr noundef nonnull align 8 dereferenceable(160) %0, ptr nocapture noundef nonnull readonly align 1 dereferenceable(21) %1, ptr nocapture noundef readnone %2, ptr nocapture noundef readnone %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
  %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 !8
  %9 = getelementptr inbounds i8, ptr %8, i64 200
  %10 = load ptr, ptr %9, align 8
  %11 = call noundef i32 %10(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)
  %12 = load i16, ptr %6, align 2, !tbaa !10
  %.not = icmp eq i16 %12, 2376
  br i1 %.not, label %13, label %37

13:                                               ; preds = %4
  store i8 50, ptr %5, align 1, !tbaa !5
  store i16 1, ptr %6, align 2, !tbaa !10
  %14 = load ptr, ptr %0, align 8, !tbaa !8
  %15 = getelementptr inbounds i8, ptr %14, i64 208
  %16 = load ptr, ptr %15, align 8
  %17 = call noundef i32 %16(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef 12, ptr noundef nonnull %5, i32 noundef 1, ptr noundef nonnull %6, i32 noundef 1)
  %18 = getelementptr inbounds i8, ptr %1, i64 8
  %19 = load i32, ptr %18, align 1, !tbaa !12
  %20 = load ptr, ptr %0, align 8, !tbaa !8
  %21 = getelementptr inbounds i8, ptr %20, i64 56
  %22 = load ptr, ptr %21, align 8
  %23 = call noundef i32 %22(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %19)
  %24 = load ptr, ptr %0, align 8, !tbaa !8
  %25 = getelementptr inbounds i8, ptr %24, i64 112
  %26 = load ptr, ptr %25, align 8
  %27 = call noundef i32 %26(ptr noundef nonnull align 8 dereferenceable(73) %0, i32 noundef 32752)
  %28 = getelementptr inbounds i8, ptr %0, i64 74
  store i16 149, ptr %28, align 2, !tbaa !10
  %29 = getelementptr inbounds i8, ptr %0, i64 76
  store i16 149, ptr %29, align 4, !tbaa !10
  %30 = getelementptr inbounds i8, ptr %0, i64 78
  store i16 149, ptr %30, align 2, !tbaa !10
  %31 = getelementptr inbounds i8, ptr %0, i64 92
  store i16 149, ptr %31, align 4, !tbaa !10
  %32 = getelementptr inbounds i8, ptr %0, i64 94
  store i16 149, ptr %32, align 2, !tbaa !10
  %33 = getelementptr inbounds i8, ptr %0, i64 96
  store i16 149, ptr %33, align 8, !tbaa !10
  %34 = load ptr, ptr %0, align 8, !tbaa !8
  %35 = getelementptr inbounds i8, ptr %34, i64 184
  %36 = load ptr, ptr %35, align 8
  call void %36(ptr noundef nonnull align 8 dereferenceable(160) %0)
  br label %37

37:                                               ; preds = %4, %13
  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 %.not
}

; 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 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 = !{!"vtable pointer", !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !6, i64 0}
!12 = !{!13, !14, i64 8}
!13 = !{!"_ZTS18__MagSensor_Config", !14, i64 0, !15, i64 4, !14, i64 8, !16, i64 12, !6, i64 16, !17, i64 17}
!14 = !{!"int", !6, i64 0}
!15 = !{!"_ZTS15__Sensor_OpMode", !6, i64 0}
!16 = !{!"_ZTS21__MagSensor_Precision", !6, i64 0}
!17 = !{!"_ZTS24__Dev_Interrupt_Polarity", !6, i64 0}


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