; LLVM IR from IOsonata/IOsonata :: src/sensors/am_fxos8700cq.ll (ZN12AmFxos8700cq4InitEjP11DeviceIntrfP5Timer)

; 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.AmFxos8700cq = type <{ %class.AccelSensor.base, [4 x i8], %class.MagSensor.base, i8, [7 x i8], %class.Device }>
%class.AccelSensor.base = type <{ %class.Sensor.base, %struct.__AccelSensor_Raw_Data, [5 x i8], ptr, i16, [2 x i8], [3 x [3 x float]], [3 x float] }>
%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.__AccelSensor_Raw_Data = type <{ i64, i16, i16, %union.anon }>
%union.anon = type { [3 x i16] }
%class.MagSensor.base = type { %class.Sensor.base, [3 x i16], i32, %struct.__MagSensor_Raw_Data, [3 x [3 x float]], [3 x float] }
%struct.__MagSensor_Raw_Data = type <{ i64, [3 x i16], %union.anon.0 }>
%union.anon.0 = type { [3 x i32] }
%class.Device = type { ptr, i8, i32, ptr, ptr, i64, i8, ptr, i8, i32 }

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN12AmFxos8700cq4InitEjP11DeviceIntrfP5Timer(ptr noundef nonnull align 8 dereferenceable(321) %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #0 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8
  %16 = getelementptr inbounds %class.AmFxos8700cq, ptr %15, i32 0, i32 3
  %17 = load i8, ptr %16, align 8, !tbaa !11, !range !26, !noundef !27
  %18 = trunc i8 %17 to i1
  br i1 %18, label %19, label %20

19:                                               ; preds = %4
  store i1 true, ptr %5, align 1
  br label %78

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

23:                                               ; preds = %20
  store i1 false, ptr %5, align 1
  br label %78

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #4
  store i8 0, ptr %12, align 1, !tbaa !28
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #4
  store i8 0, ptr %13, align 1, !tbaa !28
  %25 = load ptr, ptr %15, align 8, !tbaa !29
  %26 = getelementptr i8, ptr %25, i64 -24
  %27 = load i64, ptr %26, align 8
  %28 = getelementptr inbounds i8, ptr %15, i64 %27
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN6Device9InterfaceEP11DeviceIntrf(ptr noundef nonnull align 8 dereferenceable(64) %28, ptr noundef %29)
  %30 = load ptr, ptr %15, align 8, !tbaa !29
  %31 = getelementptr i8, ptr %30, i64 -24
  %32 = load i64, ptr %31, align 8
  %33 = getelementptr inbounds i8, ptr %15, i64 %32
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = load ptr, ptr %33, align 8, !tbaa !29
  %36 = getelementptr inbounds ptr, ptr %35, i64 6
  %37 = load ptr, ptr %36, align 8
  call void %37(ptr noundef nonnull align 8 dereferenceable(64) %33, i32 noundef %34)
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %47

40:                                               ; preds = %24
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %15, align 8, !tbaa !29
  %43 = getelementptr i8, ptr %42, i64 -24
  %44 = load i64, ptr %43, align 8
  %45 = getelementptr inbounds i8, ptr %15, i64 %44
  %46 = getelementptr inbounds %class.Device, ptr %45, i32 0, i32 4
  store ptr %41, ptr %46, align 8, !tbaa !31
  br label %47

47:                                               ; preds = %40, %24
  store i8 13, ptr %10, align 1, !tbaa !28
  %48 = load ptr, ptr %15, align 8, !tbaa !29
  %49 = getelementptr i8, ptr %48, i64 -24
  %50 = load i64, ptr %49, align 8
  %51 = getelementptr inbounds i8, ptr %15, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !29
  %53 = getelementptr inbounds ptr, ptr %52, i64 11
  %54 = load ptr, ptr %53, align 8
  %55 = call noundef zeroext i8 %54(ptr noundef nonnull align 8 dereferenceable(64) %51, ptr noundef %10, i32 noundef 1)
  store i8 %55, ptr %11, align 1, !tbaa !28
  %56 = load i8, ptr %11, align 1, !tbaa !28
  %57 = zext i8 %56 to i32
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %57)
  %59 = load i8, ptr %11, align 1, !tbaa !28
  %60 = zext i8 %59 to i32
  %61 = icmp ne i32 %60, 199
  br i1 %61, label %62, label %63

62:                                               ; preds = %47
  store i1 false, ptr %5, align 1
  store i32 1, ptr %14, align 4
  br label %77

63:                                               ; preds = %47
  %64 = load ptr, ptr %15, align 8, !tbaa !29
  %65 = getelementptr inbounds ptr, ptr %64, i64 30
  %66 = load ptr, ptr %65, align 8
  call void %66(ptr noundef nonnull align 8 dereferenceable(321) %15)
  %67 = load ptr, ptr %15, align 8, !tbaa !29
  %68 = getelementptr i8, ptr %67, i64 -24
  %69 = load i64, ptr %68, align 8
  %70 = getelementptr inbounds i8, ptr %15, i64 %69
  %71 = load i8, ptr %11, align 1, !tbaa !28
  %72 = zext i8 %71 to i64
  call void @_ZN6Device8DeviceIDEm(ptr noundef nonnull align 8 dereferenceable(64) %70, i64 noundef %72)
  %73 = load ptr, ptr %15, align 8, !tbaa !29
  %74 = getelementptr i8, ptr %73, i64 -24
  %75 = load i64, ptr %74, align 8
  %76 = getelementptr inbounds i8, ptr %15, i64 %75
  call void @_ZN6Device5ValidEb(ptr noundef nonnull align 8 dereferenceable(64) %76, i1 noundef zeroext true)
  store i1 true, ptr %5, align 1
  store i32 1, ptr %14, align 4
  br label %77

77:                                               ; preds = %63, %62
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  br label %78

78:                                               ; preds = %77, %23, %19
  %79 = load i1, ptr %5, align 1
  ret i1 %79
}

; 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 void @_ZN6Device9InterfaceEP11DeviceIntrf(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef) #2 align 2

declare i32 @printf(ptr noundef, ...) #3

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Device5ValidEb(ptr noundef nonnull align 8 dereferenceable(64), i1 noundef zeroext) #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 = { "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 }

!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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !18, i64 320}
!12 = !{!"_ZTS12AmFxos8700cq", !13, i64 0, !23, i64 160, !18, i64 320}
!13 = !{!"_ZTS11AccelSensor", !14, i64 0, !21, i64 73, !6, i64 96, !22, i64 104, !7, i64 108, !7, i64 144}
!14 = !{!"_ZTS6Sensor", !10, i64 8, !15, i64 12, !16, i64 16, !10, i64 20, !17, i64 24, !18, i64 32, !17, i64 40, !17, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !19, i64 72}
!15 = !{!"_ZTS14__Sensor_State", !7, i64 0}
!16 = !{!"_ZTS15__Sensor_OpMode", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"_ZTSSt11atomic_flag", !20, i64 0}
!20 = !{!"_ZTSSt18__atomic_flag_base", !18, i64 0}
!21 = !{!"_ZTS22__AccelSensor_Raw_Data", !17, i64 0, !22, i64 8, !22, i64 10, !7, i64 12}
!22 = !{!"short", !7, i64 0}
!23 = !{!"_ZTS9MagSensor", !14, i64 0, !7, i64 74, !24, i64 80, !25, i64 84, !7, i64 112, !7, i64 148}
!24 = !{!"_ZTS21__MagSensor_Precision", !7, i64 0}
!25 = !{!"_ZTS20__MagSensor_Raw_Data", !17, i64 0, !7, i64 8, !7, i64 14}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!7, !7, i64 0}
!29 = !{!30, !30, i64 0}
!30 = !{!"vtable pointer", !8, i64 0}
!31 = !{!32, !6, i64 24}
!32 = !{!"_ZTS6Device", !18, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !17, i64 32, !18, i64 40, !6, i64 48, !7, i64 56, !33, i64 60}
!33 = !{!"_ZTS21__Dev_Data_Byte_Order", !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"

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN12AmFxos8700cq4InitEjP11DeviceIntrfP5Timer(ptr noundef nonnull align 8 dereferenceable(321) %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 align 2 {
  %5 = alloca i8, align 1
  %6 = getelementptr inbounds i8, ptr %0, i64 320
  %7 = load i8, ptr %6, align 8, !tbaa !5, !range !24, !noundef !25
  %8 = trunc nuw i8 %7 to i1
  br i1 %8, label %51, label %9

9:                                                ; preds = %4
  %10 = icmp eq ptr %2, null
  br i1 %10, label %51, label %11

11:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #4
  %12 = load ptr, ptr %0, align 8, !tbaa !26
  %13 = getelementptr i8, ptr %12, i64 -24
  %14 = load i64, ptr %13, align 8
  %15 = getelementptr inbounds i8, ptr %0, i64 %14
  tail call void @_ZN6Device9InterfaceEP11DeviceIntrf(ptr noundef nonnull align 8 dereferenceable(64) %15, ptr noundef nonnull %2)
  %16 = load ptr, ptr %0, align 8, !tbaa !26
  %17 = getelementptr i8, ptr %16, i64 -24
  %18 = load i64, ptr %17, align 8
  %19 = getelementptr inbounds i8, ptr %0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !26
  %21 = getelementptr inbounds i8, ptr %20, i64 48
  %22 = load ptr, ptr %21, align 8
  tail call void %22(ptr noundef nonnull align 8 dereferenceable(64) %19, i32 noundef %1)
  %.not = icmp eq ptr %3, null
  %.pre = load ptr, ptr %0, align 8, !tbaa !26
  br i1 %.not, label %28, label %23

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

28:                                               ; preds = %23, %11
  store i8 13, ptr %5, align 1, !tbaa !31
  %29 = getelementptr i8, ptr %.pre, i64 -24
  %30 = load i64, ptr %29, align 8
  %31 = getelementptr inbounds i8, ptr %0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !26
  %33 = getelementptr inbounds i8, ptr %32, i64 88
  %34 = load ptr, ptr %33, align 8
  %35 = call noundef zeroext i8 %34(ptr noundef nonnull align 8 dereferenceable(64) %31, ptr noundef nonnull %5, i32 noundef 1)
  %36 = zext i8 %35 to i32
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %36)
  %.not11 = icmp eq i8 %35, -57
  br i1 %.not11, label %38, label %50

38:                                               ; preds = %28
  %39 = load ptr, ptr %0, align 8, !tbaa !26
  %40 = getelementptr inbounds i8, ptr %39, i64 240
  %41 = load ptr, ptr %40, align 8
  call void %41(ptr noundef nonnull align 8 dereferenceable(321) %0)
  %42 = load ptr, ptr %0, align 8, !tbaa !26
  %43 = getelementptr i8, ptr %42, i64 -24
  %44 = load i64, ptr %43, align 8
  %45 = getelementptr inbounds i8, ptr %0, i64 %44
  call void @_ZN6Device8DeviceIDEm(ptr noundef nonnull align 8 dereferenceable(64) %45, i64 noundef 199)
  %46 = load ptr, ptr %0, align 8, !tbaa !26
  %47 = getelementptr i8, ptr %46, i64 -24
  %48 = load i64, ptr %47, align 8
  %49 = getelementptr inbounds i8, ptr %0, i64 %48
  call void @_ZN6Device5ValidEb(ptr noundef nonnull align 8 dereferenceable(64) %49, i1 noundef zeroext true)
  br label %50

50:                                               ; preds = %28, %38
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #4
  br label %51

51:                                               ; preds = %9, %4, %50
  %.1 = phi i1 [ %.not11, %50 ], [ true, %4 ], [ false, %9 ]
  ret i1 %.1
}

; 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 void @_ZN6Device9InterfaceEP11DeviceIntrf(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Device5ValidEb(ptr noundef nonnull align 8 dereferenceable(64), i1 noundef zeroext) 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 = { nofree 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 = { 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 320}
!6 = !{!"_ZTS12AmFxos8700cq", !7, i64 0, !21, i64 160, !15, i64 320}
!7 = !{!"_ZTS11AccelSensor", !8, i64 0, !18, i64 73, !20, i64 96, !19, i64 104, !10, i64 108, !10, i64 144}
!8 = !{!"_ZTS6Sensor", !9, i64 8, !12, i64 12, !13, i64 16, !9, i64 20, !14, i64 24, !15, i64 32, !14, i64 40, !14, i64 48, !9, i64 56, !9, i64 60, !9, i64 64, !9, i64 68, !16, i64 72}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTS14__Sensor_State", !10, i64 0}
!13 = !{!"_ZTS15__Sensor_OpMode", !10, i64 0}
!14 = !{!"long", !10, i64 0}
!15 = !{!"bool", !10, i64 0}
!16 = !{!"_ZTSSt11atomic_flag", !17, i64 0}
!17 = !{!"_ZTSSt18__atomic_flag_base", !15, i64 0}
!18 = !{!"_ZTS22__AccelSensor_Raw_Data", !14, i64 0, !19, i64 8, !19, i64 10, !10, i64 12}
!19 = !{!"short", !10, i64 0}
!20 = !{!"any pointer", !10, i64 0}
!21 = !{!"_ZTS9MagSensor", !8, i64 0, !10, i64 74, !22, i64 80, !23, i64 84, !10, i64 112, !10, i64 148}
!22 = !{!"_ZTS21__MagSensor_Precision", !10, i64 0}
!23 = !{!"_ZTS20__MagSensor_Raw_Data", !14, i64 0, !10, i64 8, !10, i64 14}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = !{!27, !27, i64 0}
!27 = !{!"vtable pointer", !11, i64 0}
!28 = !{!29, !20, i64 24}
!29 = !{!"_ZTS6Device", !15, i64 8, !9, i64 12, !20, i64 16, !20, i64 24, !14, i64 32, !15, i64 40, !20, i64 48, !10, i64 56, !30, i64 60}
!30 = !{!"_ZTS21__Dev_Data_Byte_Order", !10, i64 0}
!31 = !{!10, !10, i64 0}


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