; LLVM IR from IOsonata/IOsonata :: src/bluetooth (bt_gap)

; 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_Gap_Connection = type { i16, i8, i8, [6 x i8] }

@_ZL17s_BtGapConnection = external hidden global <{ %struct.__Bt_Gap_Connection, [9 x %struct.__Bt_Gap_Connection] }>, align 4

; 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 nounwind uwtable
define dso_local zeroext i1 @BtGapAddConnection(i16 noundef zeroext %0, i8 noundef zeroext %1, i8 noundef zeroext %2, ptr noundef %3) #1 {
  %5 = alloca i1, align 1
  %6 = alloca i16, align 2
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i16 %0, ptr %6, align 2, !tbaa !5
  store i8 %1, ptr %7, align 1, !tbaa !9
  store i8 %2, ptr %8, align 1, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !12
  br label %12

12:                                               ; preds = %47, %4
  %13 = load i32, ptr %10, align 4, !tbaa !12
  %14 = icmp slt i32 %13, 10
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 2, ptr %11, align 4
  br label %50

16:                                               ; preds = %12
  %17 = load i32, ptr %10, align 4, !tbaa !12
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [10 x %struct.__Bt_Gap_Connection], ptr @_ZL17s_BtGapConnection, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.__Bt_Gap_Connection, ptr %19, i32 0, i32 0
  %21 = load i16, ptr %20, align 2, !tbaa !14
  %22 = zext i16 %21 to i32
  %23 = icmp eq i32 %22, 65535
  br i1 %23, label %24, label %46

24:                                               ; preds = %16
  %25 = load i16, ptr %6, align 2, !tbaa !5
  %26 = load i32, ptr %10, align 4, !tbaa !12
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [10 x %struct.__Bt_Gap_Connection], ptr @_ZL17s_BtGapConnection, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.__Bt_Gap_Connection, ptr %28, i32 0, i32 0
  store i16 %25, ptr %29, align 2, !tbaa !14
  %30 = load i8, ptr %7, align 1, !tbaa !9
  %31 = load i32, ptr %10, align 4, !tbaa !12
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [10 x %struct.__Bt_Gap_Connection], ptr @_ZL17s_BtGapConnection, i64 0, i64 %32
  %34 = getelementptr inbounds %struct.__Bt_Gap_Connection, ptr %33, i32 0, i32 1
  store i8 %30, ptr %34, align 2, !tbaa !16
  %35 = load i8, ptr %8, align 1, !tbaa !9
  %36 = load i32, ptr %10, align 4, !tbaa !12
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10 x %struct.__Bt_Gap_Connection], ptr @_ZL17s_BtGapConnection, i64 0, i64 %37
  %39 = getelementptr inbounds %struct.__Bt_Gap_Connection, ptr %38, i32 0, i32 2
  store i8 %35, ptr %39, align 1, !tbaa !17
  %40 = load i32, ptr %10, align 4, !tbaa !12
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [10 x %struct.__Bt_Gap_Connection], ptr @_ZL17s_BtGapConnection, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.__Bt_Gap_Connection, ptr %42, i32 0, i32 3
  %44 = getelementptr inbounds [6 x i8], ptr %43, i64 0, i64 0
  %45 = load ptr, ptr %9, align 8, !tbaa !10
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %44, ptr align 1 %45, i64 6, i1 false)
  store i1 true, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %50

46:                                               ; preds = %16
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %10, align 4, !tbaa !12
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %10, align 4, !tbaa !12
  br label %12, !llvm.loop !18

50:                                               ; preds = %24, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %51 = load i32, ptr %11, align 4
  switch i32 %51, label %55 [
    i32 2, label %52
    i32 1, label %53
  ]

52:                                               ; preds = %50
  store i1 false, ptr %5, align 1
  br label %53

53:                                               ; preds = %52, %50
  %54 = load i1, ptr %5, align 1
  ret i1 %54

55:                                               ; preds = %50
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTS19__Bt_Gap_Connection", !6, i64 0, !7, i64 2, !7, i64 3, !7, i64 4}
!16 = !{!15, !7, i64 2}
!17 = !{!15, !7, i64 3}
!18 = distinct !{!18, !19}
!19 = !{!"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.__Bt_Gap_Connection = type { i16, i8, i8, [6 x i8] }

@_ZL17s_BtGapConnection = external hidden local_unnamed_addr global <{ %struct.__Bt_Gap_Connection, [9 x %struct.__Bt_Gap_Connection] }>, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @BtGapAddConnection(i16 noundef zeroext %0, i8 noundef zeroext %1, i8 noundef zeroext %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = load i16, ptr @_ZL17s_BtGapConnection, align 4, !tbaa !5
  %6 = icmp eq i16 %5, -1
  br i1 %6, label %34, label %7

7:                                                ; preds = %4
  %8 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 10), align 2, !tbaa !5
  %9 = icmp eq i16 %8, -1
  br i1 %9, label %34, label %10

10:                                               ; preds = %7
  %11 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 20), align 4, !tbaa !5
  %12 = icmp eq i16 %11, -1
  br i1 %12, label %34, label %13

13:                                               ; preds = %10
  %14 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 30), align 2, !tbaa !5
  %15 = icmp eq i16 %14, -1
  br i1 %15, label %34, label %16

16:                                               ; preds = %13
  %17 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 40), align 4, !tbaa !5
  %18 = icmp eq i16 %17, -1
  br i1 %18, label %34, label %19

19:                                               ; preds = %16
  %20 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 50), align 2, !tbaa !5
  %21 = icmp eq i16 %20, -1
  br i1 %21, label %34, label %22

22:                                               ; preds = %19
  %23 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 60), align 4, !tbaa !5
  %24 = icmp eq i16 %23, -1
  br i1 %24, label %34, label %25

25:                                               ; preds = %22
  %26 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 70), align 2, !tbaa !5
  %27 = icmp eq i16 %26, -1
  br i1 %27, label %34, label %28

28:                                               ; preds = %25
  %29 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 80), align 4, !tbaa !5
  %30 = icmp eq i16 %29, -1
  br i1 %30, label %34, label %31

31:                                               ; preds = %28
  %32 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 90), align 2, !tbaa !5
  %33 = icmp eq i16 %32, -1
  br i1 %33, label %34, label %.loopexit

34:                                               ; preds = %31, %28, %25, %22, %19, %16, %13, %10, %7, %4
  %.lcssa = phi ptr [ @_ZL17s_BtGapConnection, %4 ], [ getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 10), %7 ], [ getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 20), %10 ], [ getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 30), %13 ], [ getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 40), %16 ], [ getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 50), %19 ], [ getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 60), %22 ], [ getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 70), %25 ], [ getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 80), %28 ], [ getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 90), %31 ]
  store i16 %0, ptr %.lcssa, align 2, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %.lcssa, i64 2
  store i8 %1, ptr %35, align 2, !tbaa !10
  %36 = getelementptr inbounds i8, ptr %.lcssa, i64 3
  store i8 %2, ptr %36, align 1, !tbaa !11
  %37 = getelementptr inbounds i8, ptr %.lcssa, i64 4
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(6) %37, ptr noundef nonnull align 1 dereferenceable(6) %3, i64 6, i1 false)
  br label %.loopexit

.loopexit:                                        ; preds = %31, %34
  %38 = phi i1 [ true, %34 ], [ false, %31 ]
  ret i1 %38
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) 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 nounwind willreturn memory(argmem: readwrite) }

!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 = !{!"_ZTS19__Bt_Gap_Connection", !7, i64 0, !8, i64 2, !8, i64 3, !8, i64 4}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !8, i64 2}
!11 = !{!6, !8, i64 3}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass