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

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

%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: 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10MagAk0991610UpdateDataEv(ptr noundef nonnull align 8 dereferenceable(160) %0) unnamed_addr #1 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  store i8 16, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  %8 = load ptr, ptr %7, align 8, !tbaa !10
  %9 = getelementptr inbounds ptr, ptr %8, i64 25
  %10 = load ptr, ptr %9, align 8
  %11 = call noundef i32 %10(ptr noundef nonnull align 8 dereferenceable(160) %7, i32 noundef 12, ptr noundef %4, i32 noundef 1, ptr noundef %5, i32 noundef 1)
  %12 = load i8, ptr %5, align 1, !tbaa !9
  %13 = zext i8 %12 to i32
  %14 = and i32 %13, 1
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %50

16:                                               ; preds = %1
  store i8 17, ptr %4, align 1, !tbaa !9
  %17 = getelementptr inbounds %class.MagSensor, ptr %7, i32 0, i32 3
  %18 = getelementptr inbounds %struct.__MagSensor_Raw_Data, ptr %17, i32 0, i32 2
  %19 = getelementptr inbounds [3 x i32], ptr %18, i64 0, i64 0
  %20 = load ptr, ptr %7, align 8, !tbaa !10
  %21 = getelementptr inbounds ptr, ptr %20, i64 25
  %22 = load ptr, ptr %21, align 8
  %23 = call noundef i32 %22(ptr noundef nonnull align 8 dereferenceable(160) %7, i32 noundef 12, ptr noundef %4, i32 noundef 1, ptr noundef %19, i32 noundef 6)
  %24 = load ptr, ptr %7, align 8, !tbaa !10
  %25 = getelementptr i8, ptr %24, i64 -24
  %26 = load i64, ptr %25, align 8
  %27 = getelementptr inbounds i8, ptr %7, i64 %26
  %28 = getelementptr inbounds %class.Device, ptr %27, i32 0, i32 4
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %45

31:                                               ; preds = %16
  %32 = load ptr, ptr %7, align 8, !tbaa !10
  %33 = getelementptr i8, ptr %32, i64 -24
  %34 = load i64, ptr %33, align 8
  %35 = getelementptr inbounds i8, ptr %7, i64 %34
  %36 = getelementptr inbounds %class.Device, ptr %35, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  %38 = load ptr, ptr %37, align 8, !tbaa !10
  %39 = getelementptr inbounds ptr, ptr %38, i64 16
  %40 = load ptr, ptr %39, align 8
  %41 = call noundef i64 %40(ptr noundef nonnull align 8 dereferenceable(140) %37)
  %42 = mul i64 %41, 1000
  %43 = getelementptr inbounds %class.MagSensor, ptr %7, i32 0, i32 3
  %44 = getelementptr inbounds %struct.__MagSensor_Raw_Data, ptr %43, i32 0, i32 0
  store i64 %42, ptr %44, align 4, !tbaa !18
  br label %45

45:                                               ; preds = %31, %16
  store i8 24, ptr %4, align 1, !tbaa !9
  %46 = load ptr, ptr %7, align 8, !tbaa !10
  %47 = getelementptr inbounds ptr, ptr %46, i64 25
  %48 = load ptr, ptr %47, align 8
  %49 = call noundef i32 %48(ptr noundef nonnull align 8 dereferenceable(160) %7, i32 noundef 12, ptr noundef %4, i32 noundef 1, ptr noundef %5, i32 noundef 1)
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %51

50:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %51

51:                                               ; preds = %50, %45
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  %52 = load i1, ptr %2, align 1
  ret i1 %52
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !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, !6, i64 24}
!13 = !{!"_ZTS6Device", !14, i64 8, !15, i64 12, !6, i64 16, !6, i64 24, !16, i64 32, !14, i64 40, !6, i64 48, !7, i64 56, !17, i64 60}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ZTS21__Dev_Data_Byte_Order", !7, i64 0}
!18 = !{!19, !16, i64 84}
!19 = !{!"_ZTS9MagSensor", !20, i64 0, !7, i64 74, !25, i64 80, !26, i64 84, !7, i64 112, !7, i64 148}
!20 = !{!"_ZTS6Sensor", !15, i64 8, !21, i64 12, !22, i64 16, !15, i64 20, !16, i64 24, !14, i64 32, !16, i64 40, !16, i64 48, !15, i64 56, !15, i64 60, !15, i64 64, !15, i64 68, !23, i64 72}
!21 = !{!"_ZTS14__Sensor_State", !7, i64 0}
!22 = !{!"_ZTS15__Sensor_OpMode", !7, i64 0}
!23 = !{!"_ZTSSt11atomic_flag", !24, i64 0}
!24 = !{!"_ZTSSt18__atomic_flag_base", !14, i64 0}
!25 = !{!"_ZTS21__MagSensor_Precision", !7, i64 0}
!26 = !{!"_ZTS20__MagSensor_Raw_Data", !16, i64 0, !7, i64 8, !7, i64 14}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10MagAk0991610UpdateDataEv(ptr noundef nonnull align 8 dereferenceable(160) %0) unnamed_addr #1 align 2 {
  %2 = alloca i8, align 1
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #2
  store i8 16, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #2
  %4 = load ptr, ptr %0, align 8, !tbaa !8
  %5 = getelementptr inbounds i8, ptr %4, i64 200
  %6 = load ptr, ptr %5, align 8
  %7 = call noundef i32 %6(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef 12, ptr noundef nonnull %2, i32 noundef 1, ptr noundef nonnull %3, i32 noundef 1)
  %8 = load i8, ptr %3, align 1, !tbaa !5
  %9 = and i8 %8, 1
  %.not = icmp ne i8 %9, 0
  br i1 %.not, label %10, label %34

10:                                               ; preds = %1
  store i8 17, ptr %2, align 1, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 98
  %12 = load ptr, ptr %0, align 8, !tbaa !8
  %13 = getelementptr inbounds i8, ptr %12, i64 200
  %14 = load ptr, ptr %13, align 8
  %15 = call noundef i32 %14(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef 12, ptr noundef nonnull %2, i32 noundef 1, ptr noundef nonnull %11, i32 noundef 6)
  %16 = load ptr, ptr %0, align 8, !tbaa !8
  %17 = getelementptr i8, ptr %16, i64 -24
  %18 = load i64, ptr %17, align 8
  %19 = getelementptr inbounds i8, ptr %0, i64 %18
  %20 = getelementptr inbounds i8, ptr %19, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !10
  %.not3 = icmp eq ptr %21, null
  br i1 %.not3, label %29, label %22

22:                                               ; preds = %10
  %23 = getelementptr inbounds i8, ptr %0, i64 84
  %24 = load ptr, ptr %21, align 8, !tbaa !8
  %25 = getelementptr inbounds i8, ptr %24, i64 128
  %26 = load ptr, ptr %25, align 8
  %27 = call noundef i64 %26(ptr noundef nonnull align 8 dereferenceable(140) %21)
  %28 = mul i64 %27, 1000
  store i64 %28, ptr %23, align 4, !tbaa !17
  %.pre = load ptr, ptr %0, align 8, !tbaa !8
  br label %29

29:                                               ; preds = %22, %10
  %30 = phi ptr [ %.pre, %22 ], [ %16, %10 ]
  store i8 24, ptr %2, align 1, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, 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 %2, i32 noundef 1, ptr noundef nonnull %3, i32 noundef 1)
  br label %34

34:                                               ; preds = %1, %29
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #2
  ret i1 %.not
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !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, !14, i64 24}
!11 = !{!"_ZTS6Device", !12, i64 8, !13, i64 12, !14, i64 16, !14, i64 24, !15, i64 32, !12, i64 40, !14, i64 48, !6, i64 56, !16, i64 60}
!12 = !{!"bool", !6, i64 0}
!13 = !{!"int", !6, i64 0}
!14 = !{!"any pointer", !6, i64 0}
!15 = !{!"long", !6, i64 0}
!16 = !{!"_ZTS21__Dev_Data_Byte_Order", !6, i64 0}
!17 = !{!18, !15, i64 84}
!18 = !{!"_ZTS9MagSensor", !19, i64 0, !6, i64 74, !24, i64 80, !25, i64 84, !6, i64 112, !6, i64 148}
!19 = !{!"_ZTS6Sensor", !13, i64 8, !20, i64 12, !21, i64 16, !13, i64 20, !15, i64 24, !12, i64 32, !15, i64 40, !15, i64 48, !13, i64 56, !13, i64 60, !13, i64 64, !13, i64 68, !22, i64 72}
!20 = !{!"_ZTS14__Sensor_State", !6, i64 0}
!21 = !{!"_ZTS15__Sensor_OpMode", !6, i64 0}
!22 = !{!"_ZTSSt11atomic_flag", !23, i64 0}
!23 = !{!"_ZTSSt18__atomic_flag_base", !12, i64 0}
!24 = !{!"_ZTS21__MagSensor_Precision", !6, i64 0}
!25 = !{!"_ZTS20__MagSensor_Raw_Data", !15, i64 0, !6, i64 8, !6, i64 14}


; Effective O3 passes: EarlyCSEPass,GVNPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass