; 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_accel_config = type { i8, i8, i8, i8, i8 }
%struct.bmi3_sens_config = type { i8, %union.bmi3_sens_config_types }
%union.bmi3_sens_config_types = type { %struct.bmi3_step_counter_config }
%struct.bmi3_step_counter_config = type { i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16 }
%struct.bmi3_accel_foc_g_value = type { i8, i8, i8, i8 }

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

; 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
declare dso_local signext i8 @bmi3_set_sensor_config(ptr noundef, i8 noundef zeroext, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @bmi3_get_sensor_config(ptr noundef, i8 noundef zeroext, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local signext i8 @bmi3_perform_accel_foc(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca %struct.bmi3_accel_config, align 1
  %7 = alloca %struct.bmi3_sens_config, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 5, ptr %6) #3
  call void @llvm.memset.p0.i64(ptr align 1 %6, i8 0, i64 5, i1 false)
  call void @llvm.lifetime.start.p0(i64 46, ptr %7) #3
  call void @llvm.memset.p0.i64(ptr align 2 %7, i8 0, i64 46, i1 false)
  %8 = getelementptr inbounds %struct.bmi3_sens_config, ptr %7, i32 0, i32 0
  store i8 0, ptr %8, align 2, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call signext i8 @null_ptr_check(ptr noundef %9)
  store i8 %10, ptr %5, align 1, !tbaa !11
  %11 = load i8, ptr %5, align 1, !tbaa !11
  %12 = sext i8 %11 to i32
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %122

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

17:                                               ; preds = %14
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.bmi3_accel_foc_g_value, ptr %18, i32 0, i32 0
  %20 = load i8, ptr %19, align 1, !tbaa !12
  %21 = zext i8 %20 to i32
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %17
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.bmi3_accel_foc_g_value, ptr %24, i32 0, i32 0
  %26 = load i8, ptr %25, align 1, !tbaa !12
  %27 = zext i8 %26 to i32
  br label %34

28:                                               ; preds = %17
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.bmi3_accel_foc_g_value, ptr %29, i32 0, i32 0
  %31 = load i8, ptr %30, align 1, !tbaa !12
  %32 = zext i8 %31 to i32
  %33 = sub nsw i32 0, %32
  br label %34

34:                                               ; preds = %28, %23
  %35 = phi i32 [ %27, %23 ], [ %33, %28 ]
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.bmi3_accel_foc_g_value, ptr %36, i32 0, i32 1
  %38 = load i8, ptr %37, align 1, !tbaa !14
  %39 = zext i8 %38 to i32
  %40 = icmp sgt i32 %39, 0
  br i1 %40, label %41, label %46

41:                                               ; preds = %34
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.bmi3_accel_foc_g_value, ptr %42, i32 0, i32 1
  %44 = load i8, ptr %43, align 1, !tbaa !14
  %45 = zext i8 %44 to i32
  br label %52

46:                                               ; preds = %34
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.bmi3_accel_foc_g_value, ptr %47, i32 0, i32 1
  %49 = load i8, ptr %48, align 1, !tbaa !14
  %50 = zext i8 %49 to i32
  %51 = sub nsw i32 0, %50
  br label %52

52:                                               ; preds = %46, %41
  %53 = phi i32 [ %45, %41 ], [ %51, %46 ]
  %54 = add nsw i32 %35, %53
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.bmi3_accel_foc_g_value, ptr %55, i32 0, i32 2
  %57 = load i8, ptr %56, align 1, !tbaa !15
  %58 = zext i8 %57 to i32
  %59 = icmp sgt i32 %58, 0
  br i1 %59, label %60, label %65

60:                                               ; preds = %52
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.bmi3_accel_foc_g_value, ptr %61, i32 0, i32 2
  %63 = load i8, ptr %62, align 1, !tbaa !15
  %64 = zext i8 %63 to i32
  br label %71

65:                                               ; preds = %52
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.bmi3_accel_foc_g_value, ptr %66, i32 0, i32 2
  %68 = load i8, ptr %67, align 1, !tbaa !15
  %69 = zext i8 %68 to i32
  %70 = sub nsw i32 0, %69
  br label %71

71:                                               ; preds = %65, %60
  %72 = phi i32 [ %64, %60 ], [ %70, %65 ]
  %73 = add nsw i32 %54, %72
  %74 = icmp eq i32 %73, 1
  br i1 %74, label %75, label %120

75:                                               ; preds = %71
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.bmi3_accel_foc_g_value, ptr %76, i32 0, i32 3
  %78 = load i8, ptr %77, align 1, !tbaa !16
  %79 = zext i8 %78 to i32
  %80 = icmp eq i32 %79, 1
  br i1 %80, label %87, label %81

81:                                               ; preds = %75
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.bmi3_accel_foc_g_value, ptr %82, i32 0, i32 3
  %84 = load i8, ptr %83, align 1, !tbaa !16
  %85 = zext i8 %84 to i32
  %86 = icmp eq i32 %85, 0
  br i1 %86, label %87, label %120

87:                                               ; preds = %81, %75
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = call signext i8 @verify_foc_position(i8 noundef zeroext 0, ptr noundef %88, ptr noundef %89)
  store i8 %90, ptr %5, align 1, !tbaa !11
  %91 = load i8, ptr %5, align 1, !tbaa !11
  %92 = sext i8 %91 to i32
  %93 = icmp eq i32 %92, 0
  br i1 %93, label %94, label %97

94:                                               ; preds = %87
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = call signext i8 @bmi3_get_sensor_config(ptr noundef %7, i8 noundef zeroext 1, ptr noundef %95)
  store i8 %96, ptr %5, align 1, !tbaa !11
  br label %97

97:                                               ; preds = %94, %87
  %98 = load i8, ptr %5, align 1, !tbaa !11
  %99 = sext i8 %98 to i32
  %100 = icmp eq i32 %99, 0
  br i1 %100, label %101, label %104

101:                                              ; preds = %97
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = call signext i8 @set_accel_foc_config(ptr noundef %102)
  store i8 %103, ptr %5, align 1, !tbaa !11
  br label %104

104:                                              ; preds = %101, %97
  %105 = load i8, ptr %5, align 1, !tbaa !11
  %106 = sext i8 %105 to i32
  %107 = icmp eq i32 %106, 0
  br i1 %107, label %108, label %112

108:                                              ; preds = %104
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  %110 = load ptr, ptr %4, align 8, !tbaa !5
  %111 = call signext i8 @perform_accel_foc(ptr noundef %109, ptr noundef %6, ptr noundef %110)
  store i8 %111, ptr %5, align 1, !tbaa !11
  br label %112

112:                                              ; preds = %108, %104
  %113 = load i8, ptr %5, align 1, !tbaa !11
  %114 = sext i8 %113 to i32
  %115 = icmp eq i32 %114, 0
  br i1 %115, label %116, label %119

116:                                              ; preds = %112
  %117 = load ptr, ptr %4, align 8, !tbaa !5
  %118 = call signext i8 @bmi3_set_sensor_config(ptr noundef %7, i8 noundef zeroext 1, ptr noundef %117)
  store i8 %118, ptr %5, align 1, !tbaa !11
  br label %119

119:                                              ; preds = %116, %112
  br label %121

120:                                              ; preds = %81, %71
  store i8 -8, ptr %5, align 1, !tbaa !11
  br label %121

121:                                              ; preds = %120, %119
  br label %123

122:                                              ; preds = %14, %2
  store i8 -1, ptr %5, align 1, !tbaa !11
  br label %123

123:                                              ; preds = %122, %121
  %124 = load i8, ptr %5, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 46, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 5, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  ret i8 %124
}

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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/C++ TBAA"}
!9 = !{!10, !7, i64 0}
!10 = !{!"bmi3_sens_config", !7, i64 0, !7, i64 2}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"bmi3_accel_foc_g_value", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!14 = !{!13, !7, i64 1}
!15 = !{!13, !7, i64 2}
!16 = !{!13, !7, i64 3}


; 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_accel_config = type { i8, i8, i8, i8, i8 }
%struct.bmi3_sens_config = type { i8, %union.bmi3_sens_config_types }
%union.bmi3_sens_config_types = type { %struct.bmi3_step_counter_config }
%struct.bmi3_step_counter_config = type { i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16 }

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @bmi3_set_sensor_config(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @bmi3_get_sensor_config(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local signext i8 @bmi3_perform_accel_foc(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.bmi3_accel_config, align 1
  %4 = alloca %struct.bmi3_sens_config, align 2
  call void @llvm.lifetime.start.p0(i64 5, ptr nonnull %3) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) %3, i8 0, i64 5, i1 false)
  call void @llvm.lifetime.start.p0(i64 46, ptr nonnull %4) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(46) %4, i8 0, i64 46, i1 false)
  %5 = tail call signext i8 @null_ptr_check(ptr noundef %1)
  %6 = icmp eq i8 %5, 0
  %7 = icmp ne ptr %0, null
  %or.cond = and i1 %7, %6
  br i1 %or.cond, label %8, label %.thread40

8:                                                ; preds = %2
  %9 = load i8, ptr %0, align 1, !tbaa !5
  %10 = zext i8 %9 to i32
  %11 = getelementptr inbounds i8, ptr %0, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = zext i8 %12 to i32
  %14 = add nuw nsw i32 %13, %10
  %15 = getelementptr inbounds i8, ptr %0, i64 2
  %16 = load i8, ptr %15, align 1, !tbaa !10
  %17 = zext i8 %16 to i32
  %18 = add nuw nsw i32 %14, %17
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %.thread40

20:                                               ; preds = %8
  %21 = getelementptr inbounds i8, ptr %0, i64 3
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %switch = icmp ult i8 %22, 2
  br i1 %switch, label %23, label %.thread40

23:                                               ; preds = %20
  %24 = tail call signext i8 @verify_foc_position(i8 noundef zeroext 0, ptr noundef nonnull %0, ptr noundef %1)
  %25 = icmp eq i8 %24, 0
  br i1 %25, label %26, label %.thread40

26:                                               ; preds = %23
  %27 = call signext i8 @bmi3_get_sensor_config(ptr noundef nonnull %4, i8 noundef zeroext 1, ptr noundef %1)
  %28 = icmp eq i8 %27, 0
  br i1 %28, label %29, label %.thread40

29:                                               ; preds = %26
  %30 = call signext i8 @set_accel_foc_config(ptr noundef %1)
  %31 = icmp eq i8 %30, 0
  br i1 %31, label %32, label %.thread40

32:                                               ; preds = %29
  %33 = call signext i8 @perform_accel_foc(ptr noundef nonnull %0, ptr noundef nonnull %3, ptr noundef %1)
  %34 = icmp eq i8 %33, 0
  br i1 %34, label %35, label %.thread40

35:                                               ; preds = %32
  %36 = call signext i8 @bmi3_set_sensor_config(ptr noundef nonnull %4, i8 noundef zeroext 1, ptr noundef %1)
  br label %.thread40

.thread40:                                        ; preds = %23, %26, %29, %20, %2, %8, %35, %32
  %.3 = phi i8 [ %36, %35 ], [ %33, %32 ], [ -8, %20 ], [ -8, %8 ], [ -1, %2 ], [ %30, %29 ], [ %27, %26 ], [ %24, %23 ]
  call void @llvm.lifetime.end.p0(i64 46, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 5, ptr nonnull %3) #3
  ret i8 %.3
}

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

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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, !7, i64 0}
!6 = !{!"bmi3_accel_foc_g_value", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!6, !7, i64 1}
!10 = !{!6, !7, i64 2}
!11 = !{!6, !7, i64 3}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MemCpyOptPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass