; 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: mustprogress nounwind uwtable
define dso_local zeroext i1 @isBtGapConnected() #0 {
  %1 = alloca i1, align 1
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %18, %0
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 10
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  store i32 2, ptr %3, align 4
  br label %21

8:                                                ; preds = %4
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [10 x %struct.__Bt_Gap_Connection], ptr @_ZL17s_BtGapConnection, i64 0, i64 %10
  %12 = getelementptr inbounds %struct.__Bt_Gap_Connection, ptr %11, i32 0, i32 0
  %13 = load i16, ptr %12, align 2, !tbaa !9
  %14 = zext i16 %13 to i32
  %15 = icmp ne i32 %14, 65535
  br i1 %15, label %16, label %17

16:                                               ; preds = %8
  store i1 true, ptr %1, align 1
  store i32 1, ptr %3, align 4
  br label %21

17:                                               ; preds = %8
  br label %18

18:                                               ; preds = %17
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %2, align 4, !tbaa !5
  br label %4, !llvm.loop !12

21:                                               ; preds = %16, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  %22 = load i32, ptr %3, align 4
  switch i32 %22, label %26 [
    i32 2, label %23
    i32 1, label %24
  ]

23:                                               ; preds = %21
  store i1 false, ptr %1, align 1
  br label %24

24:                                               ; preds = %23, %21
  %25 = load i1, ptr %1, align 1
  ret i1 %25

26:                                               ; preds = %21
  unreachable
}

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS19__Bt_Gap_Connection", !11, i64 0, !7, i64 2, !7, i64 3, !7, i64 4}
!11 = !{!"short", !7, i64 0}
!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.__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(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local zeroext i1 @isBtGapConnected() local_unnamed_addr #0 {
  %1 = load <8 x i16>, ptr @_ZL17s_BtGapConnection, align 4
  %2 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 10), align 2
  %3 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 20), align 4
  %4 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 30), align 2
  %5 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 40), align 4
  %6 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 50), align 2
  %7 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 60), align 4
  %8 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 70), align 2
  %9 = insertelement <8 x i16> %1, i16 %2, i64 1
  %10 = insertelement <8 x i16> %9, i16 %3, i64 2
  %11 = insertelement <8 x i16> %10, i16 %4, i64 3
  %12 = insertelement <8 x i16> %11, i16 %5, i64 4
  %13 = insertelement <8 x i16> %12, i16 %6, i64 5
  %14 = insertelement <8 x i16> %13, i16 %7, i64 6
  %15 = insertelement <8 x i16> %14, i16 %8, i64 7
  %.fr = freeze <8 x i16> %15
  %16 = icmp ne <8 x i16> %.fr, <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>
  %17 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 80), align 4
  %.fr21 = freeze i16 %17
  %.not.8 = icmp ne i16 %.fr21, -1
  %18 = load i16, ptr getelementptr inbounds (i8, ptr @_ZL17s_BtGapConnection, i64 90), align 2
  %.not.9 = icmp ne i16 %18, -1
  %19 = bitcast <8 x i1> %16 to i8
  %20 = icmp ne i8 %19, 0
  %op.rdx = or i1 %20, %.not.8
  %op.rdx20 = select i1 %op.rdx, i1 true, i1 %.not.9
  ret i1 %op.rdx20
}

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,VectorCombinePass