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

; 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_Adv_Packet = type { i32, i32, ptr }
%struct.__Bt_Adv_Data = type { %struct.__Bt_Adv_Data_Header, [1 x i8] }
%struct.__Bt_Adv_Data_Header = type { i8, i8 }

; Function Attrs: mustprogress uwtable
define dso_local ptr @BtAdvDataAllocate(ptr noundef %0, i8 noundef zeroext %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %13 = load i8, ptr %6, align 1, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 1, !tbaa !12
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 1, !tbaa !14
  %20 = call noundef i32 @_ZL19BtAdvDataFindAdvTaghPhi(i8 noundef zeroext %13, ptr noundef %16, i32 noundef %19)
  store i32 %20, ptr %8, align 4, !tbaa !10
  %21 = load i32, ptr %8, align 4, !tbaa !10
  %22 = icmp sge i32 %21, 0
  br i1 %22, label %23, label %78

23:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 1, !tbaa !12
  %27 = load i32, ptr %8, align 4, !tbaa !10
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %26, i64 %28
  store ptr %29, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 1, !tbaa !14
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.__Bt_Adv_Data, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds %struct.__Bt_Adv_Data_Header, ptr %34, i32 0, i32 0
  %36 = load i8, ptr %35, align 1, !tbaa !15
  %37 = zext i8 %36 to i32
  %38 = sub nsw i32 %32, %37
  %39 = sub nsw i32 %38, 1
  store i32 %39, ptr %10, align 4, !tbaa !10
  %40 = load i32, ptr %7, align 4, !tbaa !10
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 1, !tbaa !18
  %44 = load i32, ptr %10, align 4, !tbaa !10
  %45 = sub nsw i32 %43, %44
  %46 = icmp sgt i32 %40, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %23
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %75

48:                                               ; preds = %23
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %49, i32 0, i32 2
  %51 = load ptr, ptr %50, align 1, !tbaa !12
  %52 = load i32, ptr %8, align 4, !tbaa !10
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %51, i64 %53
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 1, !tbaa !12
  %58 = load i32, ptr %8, align 4, !tbaa !10
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.__Bt_Adv_Data, ptr %59, i32 0, i32 0
  %61 = getelementptr inbounds %struct.__Bt_Adv_Data_Header, ptr %60, i32 0, i32 0
  %62 = load i8, ptr %61, align 1, !tbaa !15
  %63 = zext i8 %62 to i32
  %64 = add nsw i32 %58, %63
  %65 = add nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i8, ptr %57, i64 %66
  %68 = load i32, ptr %10, align 4, !tbaa !10
  %69 = load i32, ptr %8, align 4, !tbaa !10
  %70 = sub nsw i32 %68, %69
  %71 = sext i32 %70 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %54, ptr align 1 %67, i64 %71, i1 false)
  %72 = load i32, ptr %10, align 4, !tbaa !10
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %73, i32 0, i32 1
  store i32 %72, ptr %74, align 1, !tbaa !14
  store i32 0, ptr %11, align 4
  br label %75

75:                                               ; preds = %48, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %76 = load i32, ptr %11, align 4
  switch i32 %76, label %116 [
    i32 0, label %77
  ]

77:                                               ; preds = %75
  br label %90

78:                                               ; preds = %3
  %79 = load i32, ptr %7, align 4, !tbaa !10
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %80, i32 0, i32 0
  %82 = load i32, ptr %81, align 1, !tbaa !18
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %83, i32 0, i32 1
  %85 = load i32, ptr %84, align 1, !tbaa !14
  %86 = sub nsw i32 %82, %85
  %87 = icmp sgt i32 %79, %86
  br i1 %87, label %88, label %89

88:                                               ; preds = %78
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %116

89:                                               ; preds = %78
  br label %90

90:                                               ; preds = %89, %77
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %91, i32 0, i32 2
  %93 = load ptr, ptr %92, align 1, !tbaa !12
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %94, i32 0, i32 1
  %96 = load i32, ptr %95, align 1, !tbaa !14
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds i8, ptr %93, i64 %97
  store ptr %98, ptr %12, align 8, !tbaa !5
  %99 = load i32, ptr %7, align 4, !tbaa !10
  %100 = add nsw i32 %99, 1
  %101 = trunc i32 %100 to i8
  %102 = load ptr, ptr %12, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.__Bt_Adv_Data, ptr %102, i32 0, i32 0
  %104 = getelementptr inbounds %struct.__Bt_Adv_Data_Header, ptr %103, i32 0, i32 0
  store i8 %101, ptr %104, align 1, !tbaa !15
  %105 = load i8, ptr %6, align 1, !tbaa !9
  %106 = load ptr, ptr %12, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.__Bt_Adv_Data, ptr %106, i32 0, i32 0
  %108 = getelementptr inbounds %struct.__Bt_Adv_Data_Header, ptr %107, i32 0, i32 1
  store i8 %105, ptr %108, align 1, !tbaa !19
  %109 = load i32, ptr %7, align 4, !tbaa !10
  %110 = add nsw i32 %109, 2
  %111 = load ptr, ptr %5, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.__Bt_Adv_Packet, ptr %111, i32 0, i32 1
  %113 = load i32, ptr %112, align 1, !tbaa !14
  %114 = add nsw i32 %113, %110
  store i32 %114, ptr %112, align 1, !tbaa !14
  %115 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %115, ptr %4, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %116

116:                                              ; preds = %90, %88, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %117 = load ptr, ptr %4, align 8
  ret ptr %117
}

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL19BtAdvDataFindAdvTaghPhi(i8 noundef zeroext, ptr noundef, i32 noundef) #2

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

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

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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"_ZTS15__Bt_Adv_Packet", !11, i64 0, !11, i64 4, !6, i64 8}
!14 = !{!13, !11, i64 4}
!15 = !{!16, !7, i64 0}
!16 = !{!"_ZTS13__Bt_Adv_Data", !17, i64 0, !7, i64 2}
!17 = !{!"_ZTS20__Bt_Adv_Data_Header", !7, i64 0, !7, i64 1}
!18 = !{!13, !11, i64 0}
!19 = !{!16, !7, i64 1}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @BtAdvDataAllocate(ptr nocapture noundef %0, i8 noundef zeroext %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 1, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 1, !tbaa !11
  %8 = tail call noundef i32 @_ZL19BtAdvDataFindAdvTaghPhi(i8 noundef zeroext %1, ptr noundef %5, i32 noundef %7)
  %9 = icmp sgt i32 %8, -1
  br i1 %9, label %10, label %28

10:                                               ; preds = %3
  %11 = load ptr, ptr %4, align 1, !tbaa !5
  %12 = zext nneg i32 %8 to i64
  %13 = getelementptr inbounds i8, ptr %11, i64 %12
  %14 = load i32, ptr %6, align 1, !tbaa !11
  %15 = load i8, ptr %13, align 1, !tbaa !12
  %16 = zext i8 %15 to i32
  %17 = xor i32 %16, -1
  %18 = add i32 %14, %17
  %19 = load i32, ptr %0, align 1, !tbaa !15
  %20 = sub nsw i32 %19, %18
  %.not = icmp slt i32 %20, %2
  br i1 %.not, label %.critedge, label %21

21:                                               ; preds = %10
  %22 = add nuw nsw i32 %8, %16
  %23 = zext nneg i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %11, i64 %23
  %25 = getelementptr inbounds i8, ptr %24, i64 1
  %26 = sub nsw i32 %18, %8
  %27 = sext i32 %26 to i64
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %13, ptr nonnull align 1 %25, i64 %27, i1 false)
  br label %33

28:                                               ; preds = %3
  %29 = load i32, ptr %0, align 1, !tbaa !15
  %30 = load i32, ptr %6, align 1, !tbaa !11
  %31 = sub nsw i32 %29, %30
  %32 = icmp slt i32 %31, %2
  br i1 %32, label %.critedge, label %33

33:                                               ; preds = %21, %28
  %34 = phi i32 [ %18, %21 ], [ %30, %28 ]
  %35 = load ptr, ptr %4, align 1, !tbaa !5
  %36 = sext i32 %34 to i64
  %37 = getelementptr inbounds i8, ptr %35, i64 %36
  %38 = trunc i32 %2 to i8
  %39 = add i8 %38, 1
  store i8 %39, ptr %37, align 1, !tbaa !12
  %40 = getelementptr inbounds i8, ptr %37, i64 1
  store i8 %1, ptr %40, align 1, !tbaa !16
  %41 = add nsw i32 %2, 2
  %42 = add nsw i32 %41, %34
  store i32 %42, ptr %6, align 1, !tbaa !11
  br label %.critedge

.critedge:                                        ; preds = %10, %28, %33
  %.1 = phi ptr [ %37, %33 ], [ null, %28 ], [ null, %10 ]
  ret ptr %.1
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL19BtAdvDataFindAdvTaghPhi(i8 noundef zeroext, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #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 = { 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, !10, i64 8}
!6 = !{!"_ZTS15__Bt_Adv_Packet", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!13, !8, i64 0}
!13 = !{!"_ZTS13__Bt_Adv_Data", !14, i64 0, !8, i64 2}
!14 = !{!"_ZTS20__Bt_Adv_Data_Header", !8, i64 0, !8, i64 1}
!15 = !{!6, !7, i64 0}
!16 = !{!13, !8, i64 1}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass