; LLVM IR from IOsonata/IOsonata :: ARM/Nordic/nRF52/nRF52840/exemples/BoschAppBoard/src (bmi3)

; 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.bmi3_sensor_data = type { i8, %union.bmi3_sens_data }
%union.bmi3_sens_data = type { %struct.bmi3_sens_axes_data }
%struct.bmi3_sens_axes_data = type { i16, i16, i16, i32, i8 }

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

; Function Attrs: nounwind uwtable
declare hidden signext i8 @null_ptr_check(ptr noundef) #1

; 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 signext i8 @bmi3_get_sensor_data(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = call signext i8 @null_ptr_check(ptr noundef %9)
  store i8 %10, ptr %7, align 1, !tbaa !9
  %11 = load i8, ptr %7, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %99

14:                                               ; preds = %3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %99

17:                                               ; preds = %14
  store i8 0, ptr %8, align 1, !tbaa !9
  br label %18

18:                                               ; preds = %95, %17
  %19 = load i8, ptr %8, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = load i8, ptr %5, align 1, !tbaa !9
  %22 = zext i8 %21 to i32
  %23 = icmp slt i32 %20, %22
  br i1 %23, label %24, label %98

24:                                               ; preds = %18
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i8, ptr %8, align 1, !tbaa !9
  %27 = zext i8 %26 to i64
  %28 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %25, i64 %27
  %29 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %28, i32 0, i32 0
  %30 = load i8, ptr %29, align 4, !tbaa !10
  %31 = zext i8 %30 to i32
  switch i32 %31, label %88 [
    i32 0, label %32
    i32 1, label %40
    i32 5, label %48
    i32 7, label %56
    i32 14, label %64
    i32 15, label %72
    i32 16, label %80
  ]

32:                                               ; preds = %24
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load i8, ptr %8, align 1, !tbaa !9
  %35 = zext i8 %34 to i64
  %36 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %33, i64 %35
  %37 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = call signext i8 @get_accel_sensor_data(ptr noundef %37, i8 noundef zeroext 3, ptr noundef %38)
  store i8 %39, ptr %7, align 1, !tbaa !9
  br label %89

40:                                               ; preds = %24
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i8, ptr %8, align 1, !tbaa !9
  %43 = zext i8 %42 to i64
  %44 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %41, i64 %43
  %45 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = call signext i8 @get_gyro_sensor_data(ptr noundef %45, i8 noundef zeroext 6, ptr noundef %46)
  store i8 %47, ptr %7, align 1, !tbaa !9
  br label %89

48:                                               ; preds = %24
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load i8, ptr %8, align 1, !tbaa !9
  %51 = zext i8 %50 to i64
  %52 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %49, i64 %51
  %53 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = call signext i8 @get_step_counter_sensor_data(ptr noundef %53, i8 noundef zeroext 18, ptr noundef %54)
  store i8 %55, ptr %7, align 1, !tbaa !9
  br label %89

56:                                               ; preds = %24
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load i8, ptr %8, align 1, !tbaa !9
  %59 = zext i8 %58 to i64
  %60 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %57, i64 %59
  %61 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = call signext i8 @get_orient_output_data(ptr noundef %61, i8 noundef zeroext 71, ptr noundef %62)
  store i8 %63, ptr %7, align 1, !tbaa !9
  br label %89

64:                                               ; preds = %24
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = load i8, ptr %8, align 1, !tbaa !9
  %67 = zext i8 %66 to i64
  %68 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %65, i64 %67
  %69 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = call signext i8 @get_i3c_sync_accel_sensor_data(ptr noundef %69, ptr noundef %70)
  store i8 %71, ptr %7, align 1, !tbaa !9
  br label %89

72:                                               ; preds = %24
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = load i8, ptr %8, align 1, !tbaa !9
  %75 = zext i8 %74 to i64
  %76 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %73, i64 %75
  %77 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = call signext i8 @get_i3c_sync_gyro_sensor_data(ptr noundef %77, ptr noundef %78)
  store i8 %79, ptr %7, align 1, !tbaa !9
  br label %89

80:                                               ; preds = %24
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load i8, ptr %8, align 1, !tbaa !9
  %83 = zext i8 %82 to i64
  %84 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %81, i64 %83
  %85 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %84, i32 0, i32 1
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = call signext i8 @get_i3c_sync_temp_data(ptr noundef %85, ptr noundef %86)
  store i8 %87, ptr %7, align 1, !tbaa !9
  br label %89

88:                                               ; preds = %24
  store i8 -6, ptr %7, align 1, !tbaa !9
  br label %89

89:                                               ; preds = %88, %80, %72, %64, %56, %48, %40, %32
  %90 = load i8, ptr %7, align 1, !tbaa !9
  %91 = sext i8 %90 to i32
  %92 = icmp ne i32 %91, 0
  br i1 %92, label %93, label %94

93:                                               ; preds = %89
  br label %98

94:                                               ; preds = %89
  br label %95

95:                                               ; preds = %94
  %96 = load i8, ptr %8, align 1, !tbaa !9
  %97 = add i8 %96, 1
  store i8 %97, ptr %8, align 1, !tbaa !9
  br label %18, !llvm.loop !12

98:                                               ; preds = %93, %18
  br label %100

99:                                               ; preds = %14, %3
  store i8 -1, ptr %7, align 1, !tbaa !9
  br label %100

100:                                              ; preds = %99, %98
  %101 = load i8, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  ret i8 %101
}

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_accel_sensor_data(ptr noundef, i8 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_gyro_sensor_data(ptr noundef, i8 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_step_counter_sensor_data(ptr noundef, i8 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_orient_output_data(ptr noundef, i8 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_i3c_sync_accel_sensor_data(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_i3c_sync_gyro_sensor_data(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_i3c_sync_temp_data(ptr noundef, ptr noundef) #1

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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 0}
!11 = !{!"bmi3_sensor_data", !7, i64 0, !7, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

%struct.bmi3_sensor_data = type { i8, %union.bmi3_sens_data }
%union.bmi3_sens_data = type { %struct.bmi3_sens_axes_data }
%struct.bmi3_sens_axes_data = type { i16, i16, i16, i32, i8 }

; Function Attrs: nounwind uwtable
declare hidden signext i8 @null_ptr_check(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local signext i8 @bmi3_get_sensor_data(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call signext i8 @null_ptr_check(ptr noundef %2)
  %5 = icmp eq i8 %4, 0
  %6 = icmp ne ptr %0, null
  %or.cond = and i1 %6, %5
  br i1 %or.cond, label %.preheader, label %.thread

.preheader:                                       ; preds = %3
  %.not40 = icmp eq i8 %1, 0
  br i1 %.not40, label %.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext i8 %1 to i64
  br label %.lr.ph

7:                                                ; preds = %31
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.thread, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %.lr.ph.preheader, %7
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %7 ]
  %8 = getelementptr inbounds %struct.bmi3_sensor_data, ptr %0, i64 %indvars.iv
  %9 = load i8, ptr %8, align 4, !tbaa !7
  switch i8 %9, label %.thread [
    i8 0, label %10
    i8 1, label %13
    i8 5, label %16
    i8 7, label %19
    i8 14, label %22
    i8 15, label %25
    i8 16, label %28
  ]

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds i8, ptr %8, i64 4
  %12 = tail call signext i8 @get_accel_sensor_data(ptr noundef nonnull %11, i8 noundef zeroext 3, ptr noundef %2)
  br label %31

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %8, i64 4
  %15 = tail call signext i8 @get_gyro_sensor_data(ptr noundef nonnull %14, i8 noundef zeroext 6, ptr noundef %2)
  br label %31

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds i8, ptr %8, i64 4
  %18 = tail call signext i8 @get_step_counter_sensor_data(ptr noundef nonnull %17, i8 noundef zeroext 18, ptr noundef %2)
  br label %31

19:                                               ; preds = %.lr.ph
  %20 = getelementptr inbounds i8, ptr %8, i64 4
  %21 = tail call signext i8 @get_orient_output_data(ptr noundef nonnull %20, i8 noundef zeroext 71, ptr noundef %2)
  br label %31

22:                                               ; preds = %.lr.ph
  %23 = getelementptr inbounds i8, ptr %8, i64 4
  %24 = tail call signext i8 @get_i3c_sync_accel_sensor_data(ptr noundef nonnull %23, ptr noundef %2)
  br label %31

25:                                               ; preds = %.lr.ph
  %26 = getelementptr inbounds i8, ptr %8, i64 4
  %27 = tail call signext i8 @get_i3c_sync_gyro_sensor_data(ptr noundef nonnull %26, ptr noundef %2)
  br label %31

28:                                               ; preds = %.lr.ph
  %29 = getelementptr inbounds i8, ptr %8, i64 4
  %30 = tail call signext i8 @get_i3c_sync_temp_data(ptr noundef nonnull %29, ptr noundef %2)
  br label %31

31:                                               ; preds = %28, %25, %22, %19, %16, %13, %10
  %.1 = phi i8 [ %30, %28 ], [ %27, %25 ], [ %24, %22 ], [ %21, %19 ], [ %18, %16 ], [ %15, %13 ], [ %12, %10 ]
  %.not = icmp eq i8 %.1, 0
  br i1 %.not, label %7, label %.thread

.thread:                                          ; preds = %31, %7, %.lr.ph, %.preheader, %3
  %.2 = phi i8 [ -1, %3 ], [ 0, %.preheader ], [ %.1, %31 ], [ 0, %7 ], [ -6, %.lr.ph ]
  ret i8 %.2
}

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_accel_sensor_data(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_gyro_sensor_data(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_step_counter_sensor_data(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_orient_output_data(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_i3c_sync_accel_sensor_data(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_i3c_sync_gyro_sensor_data(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden signext i8 @get_i3c_sync_temp_data(ptr noundef, ptr noundef) local_unnamed_addr #0

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 0}
!8 = !{!"bmi3_sensor_data", !9, i64 0, !9, i64 4}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass