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

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

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

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

; 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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL3minii(i32 noundef, i32 noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local i64 @BtAdvDataGetDevName(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #4 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = trunc i64 %13 to i32
  %15 = call noundef i32 @_ZL19BtAdvDataFindAdvTaghPhi(i8 noundef zeroext 9, ptr noundef %12, i32 noundef %14)
  store i32 %15, ptr %10, align 4, !tbaa !11
  %16 = load i32, ptr %10, align 4, !tbaa !11
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %23

18:                                               ; preds = %4
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = trunc i64 %20 to i32
  %22 = call noundef i32 @_ZL19BtAdvDataFindAdvTaghPhi(i8 noundef zeroext 8, ptr noundef %19, i32 noundef %21)
  store i32 %22, ptr %10, align 4, !tbaa !11
  br label %23

23:                                               ; preds = %18, %4
  %24 = load i32, ptr %10, align 4, !tbaa !11
  %25 = icmp sge i32 %24, 0
  br i1 %25, label %26, label %46

26:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i32, ptr %10, align 4, !tbaa !11
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %27, i64 %29
  store ptr %30, ptr %11, align 8, !tbaa !5
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = trunc i64 %31 to i32
  %33 = load ptr, ptr %11, 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 !13
  %37 = zext i8 %36 to i64
  %38 = trunc i64 %37 to i32
  %39 = call noundef i32 @_ZL3minii(i32 noundef %32, i32 noundef %38)
  %40 = sext i32 %39 to i64
  store i64 %40, ptr %9, align 8, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.__Bt_Adv_Data, ptr %42, i32 0, i32 1
  %44 = getelementptr inbounds [1 x i8], ptr %43, i64 0, i64 0
  %45 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %41, ptr align 1 %44, i64 %45, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %46

46:                                               ; preds = %26, %23
  %47 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret i64 %47
}

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 = { inlinehint 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 #4 = { 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 #5 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"_ZTS13__Bt_Adv_Data", !15, i64 0, !7, i64 2}
!15 = !{!"_ZTS20__Bt_Adv_Data_Header", !7, i64 0, !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
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.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL3minii(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local range(i64 -2147483648, 2147483648) i64 @BtAdvDataGetDevName(ptr noundef %0, i64 noundef %1, ptr nocapture noundef writeonly %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = trunc i64 %1 to i32
  %6 = tail call noundef i32 @_ZL19BtAdvDataFindAdvTaghPhi(i8 noundef zeroext 9, ptr noundef %0, i32 noundef %5)
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %8, label %.thread

8:                                                ; preds = %4
  %9 = tail call noundef i32 @_ZL19BtAdvDataFindAdvTaghPhi(i8 noundef zeroext 8, ptr noundef %0, i32 noundef %5)
  %10 = icmp sgt i32 %9, -1
  br i1 %10, label %.thread, label %19

.thread:                                          ; preds = %4, %8
  %.01316 = phi i32 [ %9, %8 ], [ %6, %4 ]
  %11 = zext nneg i32 %.01316 to i64
  %12 = getelementptr inbounds i8, ptr %0, i64 %11
  %13 = trunc i64 %3 to i32
  %14 = load i8, ptr %12, align 1, !tbaa !5
  %15 = zext i8 %14 to i32
  %16 = tail call noundef i32 @_ZL3minii(i32 noundef %13, i32 noundef %15)
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %12, i64 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %2, ptr nonnull align 1 %18, i64 %17, i1 false)
  br label %19

19:                                               ; preds = %.thread, %8
  %.0 = phi i64 [ %17, %.thread ], [ 0, %8 ]
  ret i64 %.0
}

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) }
attributes #2 = { inlinehint 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" }

!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 = !{!"_ZTS13__Bt_Adv_Data", !7, i64 0, !8, i64 2}
!7 = !{!"_ZTS20__Bt_Adv_Data_Header", !8, i64 0, !8, i64 1}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass