; LLVM IR from IOsonata/IOsonata :: ARM/Nordic/exemples/BlueIOThingy/BlueIOTms.ll (Z15ImuQuatDataSendPl)

; 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.__Bt_Characteristic = type { i16, i16, i32, ptr, ptr, ptr, ptr, ptr, ptr, i16, i8, i8, i8, i16, i16, i16, i16, i16, ptr }
%struct.__Bt_Service = type <{ i32, ptr, i16, %struct.__Bt_Uuid, i8, ptr, i32, ptr, ptr, ptr, ptr }>
%struct.__Bt_Uuid = type <{ i8, %union.anon }>
%union.anon = type { i32 }

@g_ImuChars = external dso_local global [10 x %struct.__Bt_Characteristic], align 16
@g_ImuSrvc = external dso_local global %struct.__Bt_Service, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15ImuQuatDataSendPl(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [4 x i64], align 16
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load i8, ptr getelementptr inbounds (%struct.__Bt_Characteristic, ptr getelementptr inbounds ([10 x %struct.__Bt_Characteristic], ptr @g_ImuChars, i64 0, i64 3), i32 0, i32 10), align 2, !tbaa !9, !range !14, !noundef !15
  %6 = trunc i8 %5 to i1
  %7 = zext i1 %6 to i32
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  br label %41

10:                                               ; preds = %1
  %11 = call zeroext i1 @isConnected()
  %12 = zext i1 %11 to i32
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  br label %41

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #3
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds i64, ptr %16, i64 0
  %18 = load i64, ptr %17, align 8, !tbaa !16
  %19 = getelementptr inbounds [4 x i64], ptr %3, i64 0, i64 0
  store i64 %18, ptr %19, align 16, !tbaa !16
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds i64, ptr %20, i64 1
  %22 = load i64, ptr %21, align 8, !tbaa !16
  %23 = getelementptr inbounds [4 x i64], ptr %3, i64 0, i64 1
  store i64 %22, ptr %23, align 8, !tbaa !16
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds i64, ptr %24, i64 2
  %26 = load i64, ptr %25, align 8, !tbaa !16
  %27 = getelementptr inbounds [4 x i64], ptr %3, i64 0, i64 2
  store i64 %26, ptr %27, align 16, !tbaa !16
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds i64, ptr %28, i64 3
  %30 = load i64, ptr %29, align 8, !tbaa !16
  %31 = getelementptr inbounds [4 x i64], ptr %3, i64 0, i64 3
  store i64 %30, ptr %31, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %32 = load ptr, ptr getelementptr inbounds (%struct.__Bt_Service, ptr @g_ImuSrvc, i32 0, i32 1), align 4, !tbaa !18
  %33 = getelementptr inbounds %struct.__Bt_Characteristic, ptr %32, i64 3
  %34 = getelementptr inbounds [4 x i64], ptr %3, i64 0, i64 0
  %35 = call zeroext i1 @BtAppNotify(ptr noundef %33, ptr noundef %34, i16 noundef zeroext 32)
  %36 = zext i1 %35 to i32
  store i32 %36, ptr %4, align 4, !tbaa !22
  %37 = load i32, ptr %4, align 4, !tbaa !22
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %15
  br label %40

40:                                               ; preds = %39, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #3
  br label %41

41:                                               ; preds = %40, %14, %9
  ret void
}

declare zeroext i1 @isConnected() #1

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

declare zeroext i1 @BtAppNotify(ptr noundef, ptr noundef, i16 noundef zeroext) #1

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

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !13, i64 58}
!10 = !{!"_ZTS19__Bt_Characteristic", !11, i64 0, !11, i64 2, !12, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !13, i64 58, !13, i64 59, !7, i64 60, !11, i64 62, !11, i64 64, !11, i64 66, !11, i64 68, !11, i64 70, !6, i64 72}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !6, i64 4}
!19 = !{!"_ZTS12__Bt_Service", !12, i64 0, !6, i64 4, !11, i64 12, !20, i64 14, !6, i64 20, !12, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!20 = !{!"_ZTS9__Bt_Uuid", !7, i64 0, !21, i64 0, !7, i64 1}
!21 = !{!"_ZTS14__Bt_Uuid_Type", !7, i64 0}
!22 = !{!12, !12, 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"

%struct.__Bt_Characteristic = type { i16, i16, i32, ptr, ptr, ptr, ptr, ptr, ptr, i16, i8, i8, i8, i16, i16, i16, i16, i16, ptr }
%struct.__Bt_Service = type <{ i32, ptr, i16, %struct.__Bt_Uuid, i8, ptr, i32, ptr, ptr, ptr, ptr }>
%struct.__Bt_Uuid = type <{ i8, %union.anon }>
%union.anon = type { i32 }

@g_ImuChars = external dso_local local_unnamed_addr global [10 x %struct.__Bt_Characteristic], align 16
@g_ImuSrvc = external dso_local local_unnamed_addr global %struct.__Bt_Service, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15ImuQuatDataSendPl(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca [4 x i64], align 16
  %3 = load i8, ptr getelementptr inbounds (i8, ptr @g_ImuChars, i64 298), align 2, !tbaa !5, !range !13, !noundef !14
  %4 = icmp eq i8 %3, 0
  br i1 %4, label %15, label %5

5:                                                ; preds = %1
  %6 = tail call zeroext i1 @isConnected()
  br i1 %6, label %7, label %15

7:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #3
  %8 = load <2 x i64>, ptr %0, align 8, !tbaa !15
  store <2 x i64> %8, ptr %2, align 16, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = getelementptr inbounds i8, ptr %2, i64 16
  %11 = load <2 x i64>, ptr %9, align 8, !tbaa !15
  store <2 x i64> %11, ptr %10, align 16, !tbaa !15
  %12 = load ptr, ptr getelementptr inbounds (i8, ptr @g_ImuSrvc, i64 4), align 4, !tbaa !17
  %13 = getelementptr inbounds i8, ptr %12, i64 240
  %14 = call zeroext i1 @BtAppNotify(ptr noundef nonnull %13, ptr noundef nonnull %2, i16 noundef zeroext 32)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #3
  br label %15

15:                                               ; preds = %5, %1, %7
  ret void
}

declare zeroext i1 @isConnected() local_unnamed_addr #1

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

declare zeroext i1 @BtAppNotify(ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

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

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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 58}
!6 = !{!"_ZTS19__Bt_Characteristic", !7, i64 0, !7, i64 2, !10, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !7, i64 56, !12, i64 58, !12, i64 59, !8, i64 60, !7, i64 62, !7, i64 64, !7, i64 66, !7, i64 68, !7, i64 70, !11, i64 72}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = !{!18, !11, i64 4}
!18 = !{!"_ZTS12__Bt_Service", !10, i64 0, !11, i64 4, !7, i64 12, !19, i64 14, !11, i64 20, !10, i64 28, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!19 = !{!"_ZTS9__Bt_Uuid", !8, i64 0, !20, i64 0, !8, i64 1}
!20 = !{!"_ZTS14__Bt_Uuid_Type", !8, i64 0}


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