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

; 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_Hci_Evt_Packet = type { %struct.__Bt_Hci_Evt_Packet_Header, [1 x i8] }
%struct.__Bt_Hci_Evt_Packet_Header = type { i8, i8 }
%struct.__Bt_Hci_Device = type { ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.__Bt_Hci_Evt_Discon_Complete = type <{ i8, i16, i8 }>
%struct.__Bt_Hci_Evt_Nb_Completed_Pkt = type <{ i8, [1 x %struct.anon] }>
%struct.anon = type { i16, i16 }

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

; 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

; Function Attrs: mustprogress uwtable
define dso_local void @BtHciProcessEvent(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.__Bt_Hci_Evt_Packet, ptr %9, i32 0, i32 0
  %11 = getelementptr inbounds %struct.__Bt_Hci_Evt_Packet_Header, ptr %10, i32 0, i32 0
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = zext i8 %12 to i32
  switch i32 %13, label %76 [
    i32 1, label %76
    i32 2, label %76
    i32 3, label %14
    i32 4, label %76
    i32 5, label %18
    i32 6, label %76
    i32 7, label %76
    i32 8, label %76
    i32 89, label %76
    i32 9, label %76
    i32 10, label %76
    i32 11, label %76
    i32 12, label %76
    i32 13, label %76
    i32 14, label %76
    i32 15, label %76
    i32 16, label %76
    i32 17, label %76
    i32 18, label %76
    i32 19, label %31
    i32 20, label %76
    i32 21, label %76
    i32 22, label %76
    i32 23, label %76
    i32 24, label %76
    i32 25, label %76
    i32 26, label %76
    i32 27, label %76
    i32 28, label %76
    i32 29, label %76
    i32 30, label %76
    i32 32, label %76
    i32 33, label %76
    i32 34, label %76
    i32 35, label %76
    i32 44, label %76
    i32 45, label %76
    i32 46, label %76
    i32 47, label %76
    i32 48, label %76
    i32 49, label %76
    i32 50, label %76
    i32 51, label %76
    i32 52, label %76
    i32 53, label %76
    i32 54, label %76
    i32 56, label %76
    i32 57, label %76
    i32 59, label %76
    i32 60, label %76
    i32 61, label %76
    i32 72, label %76
    i32 78, label %76
    i32 79, label %76
    i32 80, label %76
    i32 81, label %76
    i32 82, label %76
    i32 83, label %76
    i32 84, label %76
    i32 85, label %76
    i32 86, label %76
    i32 87, label %76
    i32 88, label %76
    i32 62, label %71
  ]

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.__Bt_Hci_Evt_Packet, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds [1 x i8], ptr %16, i64 0, i64 0
  store ptr %17, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %76

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.__Bt_Hci_Evt_Packet, ptr %19, i32 0, i32 1
  %21 = getelementptr inbounds [1 x i8], ptr %20, i64 0, i64 0
  store ptr %21, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.__Bt_Hci_Device, ptr %22, i32 0, i32 6
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.__Bt_Hci_Evt_Discon_Complete, ptr %25, i32 0, i32 1
  %27 = load i16, ptr %26, align 1, !tbaa !15
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.__Bt_Hci_Evt_Discon_Complete, ptr %28, i32 0, i32 2
  %30 = load i8, ptr %29, align 1, !tbaa !18
  call void %24(i16 noundef zeroext %27, i8 noundef zeroext %30)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %76

31:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.__Bt_Hci_Evt_Packet, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds [1 x i8], ptr %33, i64 0, i64 0
  store ptr %34, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.__Bt_Hci_Device, ptr %35, i32 0, i32 7
  %37 = load ptr, ptr %36, align 8, !tbaa !19
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %70

39:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !20
  br label %40

40:                                               ; preds = %66, %39
  %41 = load i32, ptr %8, align 4, !tbaa !20
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.__Bt_Hci_Evt_Nb_Completed_Pkt, ptr %42, i32 0, i32 0
  %44 = load i8, ptr %43, align 1, !tbaa !21
  %45 = zext i8 %44 to i32
  %46 = icmp slt i32 %41, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %69

48:                                               ; preds = %40
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.__Bt_Hci_Device, ptr %49, i32 0, i32 7
  %51 = load ptr, ptr %50, align 8, !tbaa !19
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.__Bt_Hci_Evt_Nb_Completed_Pkt, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %8, align 4, !tbaa !20
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1 x %struct.anon], ptr %53, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.anon, ptr %56, i32 0, i32 0
  %58 = load i16, ptr %57, align 1, !tbaa !23
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.__Bt_Hci_Evt_Nb_Completed_Pkt, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %8, align 4, !tbaa !20
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [1 x %struct.anon], ptr %60, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.anon, ptr %63, i32 0, i32 1
  %65 = load i16, ptr %64, align 1, !tbaa !25
  call void %51(i16 noundef zeroext %58, i16 noundef zeroext %65)
  br label %66

66:                                               ; preds = %48
  %67 = load i32, ptr %8, align 4, !tbaa !20
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %8, align 4, !tbaa !20
  br label %40, !llvm.loop !26

69:                                               ; preds = %47
  br label %70

70:                                               ; preds = %69, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %76

71:                                               ; preds = %2
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.__Bt_Hci_Evt_Packet, ptr %73, i32 0, i32 1
  %75 = getelementptr inbounds [1 x i8], ptr %74, i64 0, i64 0
  call void @_Z19BtHciProcessLeEventP15__Bt_Hci_DeviceP21__Bt_HciLe_Evt_Packet(ptr noundef %72, ptr noundef %75)
  br label %76

76:                                               ; preds = %71, %70, %18, %14, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2, %2
  ret void
}

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 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !7, i64 0}
!10 = !{!"_ZTS19__Bt_Hci_Evt_Packet", !11, i64 0, !7, i64 2}
!11 = !{!"_ZTS26__Bt_Hci_Evt_Packet_Header", !7, i64 0, !7, i64 1}
!12 = !{!13, !6, i64 40}
!13 = !{!"_ZTS15__Bt_Hci_Device", !6, i64 0, !14, i64 8, !14, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !17, i64 1}
!16 = !{!"_ZTS28__Bt_Hci_Evt_Discon_Complete", !7, i64 0, !17, i64 1, !7, i64 3}
!17 = !{!"short", !7, i64 0}
!18 = !{!16, !7, i64 3}
!19 = !{!13, !6, i64 48}
!20 = !{!14, !14, i64 0}
!21 = !{!22, !7, i64 0}
!22 = !{!"_ZTS29__Bt_Hci_Evt_Nb_Completed_Pkt", !7, i64 0, !7, i64 1}
!23 = !{!24, !17, i64 0}
!24 = !{!"_ZTSN29__Bt_Hci_Evt_Nb_Completed_PktUt_E", !17, i64 0, !17, i64 2}
!25 = !{!24, !17, i64 2}
!26 = distinct !{!26, !27}
!27 = !{!"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.anon = type { i16, i16 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @BtHciProcessEvent(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i8, ptr %1, align 1, !tbaa !5
  switch i8 %3, label %.loopexit [
    i8 62, label %26
    i8 19, label %11
    i8 5, label %4
  ]

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = load ptr, ptr %5, align 8, !tbaa !10
  %7 = getelementptr inbounds i8, ptr %1, i64 3
  %8 = load i16, ptr %7, align 1, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %1, i64 5
  %10 = load i8, ptr %9, align 1, !tbaa !17
  tail call void %6(i16 noundef zeroext %8, i8 noundef zeroext %10)
  br label %.loopexit

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %1, i64 2
  %13 = getelementptr inbounds i8, ptr %0, i64 48
  %14 = load ptr, ptr %13, align 8, !tbaa !18
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %11
  %15 = load i8, ptr %12, align 1, !tbaa !19
  %.not18 = icmp eq i8 %15, 0
  br i1 %.not18, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %16 = getelementptr inbounds i8, ptr %1, i64 3
  br label %17

17:                                               ; preds = %.lr.ph, %17
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %17 ]
  %18 = load ptr, ptr %13, align 8, !tbaa !18
  %19 = getelementptr inbounds [1 x %struct.anon], ptr %16, i64 0, i64 %indvars.iv
  %20 = load i16, ptr %19, align 1, !tbaa !21
  %21 = getelementptr inbounds i8, ptr %19, i64 2
  %22 = load i16, ptr %21, align 1, !tbaa !23
  tail call void %18(i16 noundef zeroext %20, i16 noundef zeroext %22)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load i8, ptr %12, align 1, !tbaa !19
  %24 = zext i8 %23 to i64
  %25 = icmp ult i64 %indvars.iv.next, %24
  br i1 %25, label %17, label %.loopexit, !llvm.loop !24

26:                                               ; preds = %2
  %27 = getelementptr inbounds i8, ptr %1, i64 2
  tail call void @_Z19BtHciProcessLeEventP15__Bt_Hci_DeviceP21__Bt_HciLe_Evt_Packet(ptr noundef %0, ptr noundef nonnull %27)
  br label %.loopexit

.loopexit:                                        ; preds = %17, %.preheader, %11, %26, %4, %2
  ret void
}

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

!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, !8, i64 0}
!6 = !{!"_ZTS19__Bt_Hci_Evt_Packet", !7, i64 0, !8, i64 2}
!7 = !{!"_ZTS26__Bt_Hci_Evt_Packet_Header", !8, i64 0, !8, i64 1}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !12, i64 40}
!11 = !{!"_ZTS15__Bt_Hci_Device", !12, i64 0, !13, i64 8, !13, i64 12, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!15, !16, i64 1}
!15 = !{!"_ZTS28__Bt_Hci_Evt_Discon_Complete", !8, i64 0, !16, i64 1, !8, i64 3}
!16 = !{!"short", !8, i64 0}
!17 = !{!15, !8, i64 3}
!18 = !{!11, !12, i64 48}
!19 = !{!20, !8, i64 0}
!20 = !{!"_ZTS29__Bt_Hci_Evt_Nb_Completed_Pkt", !8, i64 0, !8, i64 1}
!21 = !{!22, !16, i64 0}
!22 = !{!"_ZTSN29__Bt_Hci_Evt_Nb_Completed_PktUt_E", !16, i64 0, !16, i64 2}
!23 = !{!22, !16, i64 2}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass