; 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_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 }
%struct.__Bt_Gatt_Service_Config = type <{ i8, i8, [16 x i8], i16, i32, ptr, ptr, i32, ptr }>
%struct.__Bt_Gap_Connection = type { i16, i8, i8, [6 x i8] }
%struct.__Bt_Gap_Config = type { i8, i32, i32, i32, float, float, i16, i16 }

@_ZL12s_BtGattSrvc = external hidden global %struct.__Bt_Service, align 4
@_ZL15s_BtGattSrvcCfg = external hidden global %struct.__Bt_Gatt_Service_Config, align 4
@_ZL11s_BtGapSrvc = external hidden global %struct.__Bt_Service, align 4
@_ZL14s_BtGapSrvcCfg = external hidden constant %struct.__Bt_Gatt_Service_Config, align 4
@_ZL17s_BtGapConnection = external hidden global <{ %struct.__Bt_Gap_Connection, [9 x %struct.__Bt_Gap_Connection] }>, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @BtGapParamInit(ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @BtGapInit(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 4 @_ZL17s_BtGapConnection, i8 -1, i64 100, i1 false)
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.__Bt_Gap_Config, ptr %3, i32 0, i32 0
  %5 = load i8, ptr %4, align 4, !tbaa !9
  %6 = zext i8 %5 to i32
  %7 = and i32 %6, 4
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %12

9:                                                ; preds = %1
  %10 = call zeroext i1 @BtGattSrvcAdd(ptr noundef @_ZL12s_BtGattSrvc, ptr noundef @_ZL15s_BtGattSrvcCfg)
  %11 = call zeroext i1 @BtGattSrvcAdd(ptr noundef @_ZL11s_BtGapSrvc, ptr noundef @_ZL14s_BtGapSrvcCfg)
  br label %12

12:                                               ; preds = %9, %1
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.__Bt_Gap_Config, ptr %13, i32 0, i32 0
  %15 = load i8, ptr %14, align 4, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = and i32 %16, 12
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %12
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  call void @BtGapParamInit(ptr noundef %20)
  br label %21

21:                                               ; preds = %19, %12
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

declare zeroext i1 @BtGattSrvcAdd(ptr noundef, ptr noundef) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { "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 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !7, i64 0}
!10 = !{!"_ZTS15__Bt_Gap_Config", !7, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !12, i64 16, !12, i64 20, !13, i64 24, !13, i64 26}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!"short", !7, 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_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 }
%struct.__Bt_Gatt_Service_Config = type <{ i8, i8, [16 x i8], i16, i32, ptr, ptr, i32, ptr }>
%struct.__Bt_Gap_Connection = type { i16, i8, i8, [6 x i8] }

@_ZL12s_BtGattSrvc = external hidden global %struct.__Bt_Service, align 4
@_ZL15s_BtGattSrvcCfg = external hidden global %struct.__Bt_Gatt_Service_Config, align 4
@_ZL11s_BtGapSrvc = external hidden global %struct.__Bt_Service, align 4
@_ZL14s_BtGapSrvcCfg = external hidden constant %struct.__Bt_Gatt_Service_Config, align 4
@_ZL17s_BtGapConnection = external hidden local_unnamed_addr global <{ %struct.__Bt_Gap_Connection, [9 x %struct.__Bt_Gap_Connection] }>, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @BtGapParamInit(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @BtGapInit(ptr noundef %0) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(100) @_ZL17s_BtGapConnection, i8 -1, i64 100, i1 false)
  %2 = load i8, ptr %0, align 4, !tbaa !5
  %3 = and i8 %2, 4
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %7, label %4

4:                                                ; preds = %1
  %5 = tail call zeroext i1 @BtGattSrvcAdd(ptr noundef nonnull @_ZL12s_BtGattSrvc, ptr noundef nonnull @_ZL15s_BtGattSrvcCfg)
  %6 = tail call zeroext i1 @BtGattSrvcAdd(ptr noundef nonnull @_ZL11s_BtGapSrvc, ptr noundef nonnull @_ZL14s_BtGapSrvcCfg)
  %.pre = load i8, ptr %0, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %4, %1
  %8 = phi i8 [ %.pre, %4 ], [ %2, %1 ]
  %9 = and i8 %8, 12
  %.not3 = icmp eq i8 %9, 0
  br i1 %.not3, label %11, label %10

10:                                               ; preds = %7
  tail call void @BtGapParamInit(ptr noundef nonnull %0)
  br label %11

11:                                               ; preds = %10, %7
  ret void
}

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

declare zeroext i1 @BtGattSrvcAdd(ptr noundef, ptr noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { "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 = !{!6, !7, i64 0}
!6 = !{!"_ZTS15__Bt_Gap_Config", !7, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !10, i64 16, !10, i64 20, !11, i64 24, !11, i64 26}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!"short", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass