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

; 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_Base_Uuid_Tbl_Entry = type { [16 x i8], i8 }

@_ZL15s_BtBaseUuidTbl = external hidden global [4 x %struct.__Bt_Base_Uuid_Tbl_Entry], align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @BtUuidFindBase(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %32, %1
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = icmp slt i32 %7, 4
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  store i32 2, ptr %5, align 4
  br label %35

10:                                               ; preds = %6
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [4 x %struct.__Bt_Base_Uuid_Tbl_Entry], ptr @_ZL15s_BtBaseUuidTbl, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.__Bt_Base_Uuid_Tbl_Entry, ptr %13, i32 0, i32 1
  %15 = load i8, ptr %14, align 1, !tbaa !11, !range !14, !noundef !15
  %16 = trunc i8 %15 to i1
  %17 = zext i1 %16 to i32
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %31

19:                                               ; preds = %10
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [4 x %struct.__Bt_Base_Uuid_Tbl_Entry], ptr @_ZL15s_BtBaseUuidTbl, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.__Bt_Base_Uuid_Tbl_Entry, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds [16 x i8], ptr %23, i64 0, i64 0
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = call i32 @memcmp(ptr noundef %24, ptr noundef %25, i64 noundef 16) #4
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %19
  %29 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %29, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %35

30:                                               ; preds = %19
  br label %31

31:                                               ; preds = %30, %10
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %4, align 4, !tbaa !9
  br label %6, !llvm.loop !16

35:                                               ; preds = %28, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %36 = load i32, ptr %5, align 4
  switch i32 %36, label %40 [
    i32 2, label %37
    i32 1, label %38
  ]

37:                                               ; preds = %35
  store i32 -1, ptr %2, align 4
  br label %38

38:                                               ; preds = %37, %35
  %39 = load i32, ptr %2, align 4
  ret i32 %39

40:                                               ; preds = %35
  unreachable
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #2

; 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 willreturn memory(read) "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 = { nounwind }
attributes #4 = { nounwind willreturn memory(read) }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 16}
!12 = !{!"_ZTS24__Bt_Base_Uuid_Tbl_Entry", !7, i64 0, !13, i64 16}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !17}
!17 = !{!"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_Base_Uuid_Tbl_Entry = type { [16 x i8], i8 }

@_ZL15s_BtBaseUuidTbl = external hidden global [4 x %struct.__Bt_Base_Uuid_Tbl_Entry], align 4

; Function Attrs: mustprogress nofree nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i32 @BtUuidFindBase(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 16), align 4, !tbaa !5, !range !10, !noundef !11
  %3 = trunc nuw i8 %2 to i1
  br i1 %3, label %4, label %6

4:                                                ; preds = %1
  %bcmp = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) @_ZL15s_BtBaseUuidTbl, ptr noundef nonnull dereferenceable(16) %0, i64 16)
  %5 = icmp eq i32 %bcmp, 0
  br i1 %5, label %22, label %6

6:                                                ; preds = %1, %4
  %7 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 33), align 1, !tbaa !5, !range !10, !noundef !11
  %8 = trunc nuw i8 %7 to i1
  br i1 %8, label %9, label %11

9:                                                ; preds = %6
  %bcmp.1 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 17), ptr noundef nonnull dereferenceable(16) %0, i64 16)
  %10 = icmp eq i32 %bcmp.1, 0
  br i1 %10, label %22, label %11

11:                                               ; preds = %9, %6
  %12 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 50), align 2, !tbaa !5, !range !10, !noundef !11
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  %bcmp.2 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 34), ptr noundef nonnull dereferenceable(16) %0, i64 16)
  %15 = icmp eq i32 %bcmp.2, 0
  br i1 %15, label %22, label %16

16:                                               ; preds = %14, %11
  %17 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 67), align 1, !tbaa !5, !range !10, !noundef !11
  %18 = trunc nuw i8 %17 to i1
  br i1 %18, label %19, label %21

19:                                               ; preds = %16
  %bcmp.3 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 51), ptr noundef nonnull dereferenceable(16) %0, i64 16)
  %20 = icmp eq i32 %bcmp.3, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %19, %16
  br label %22

22:                                               ; preds = %21, %19, %14, %9, %4
  %spec.select = phi i32 [ 0, %4 ], [ 1, %9 ], [ 2, %14 ], [ 3, %19 ], [ -1, %21 ]
  ret i32 %spec.select
}

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #1

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

!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, !9, i64 16}
!6 = !{!"_ZTS24__Bt_Base_Uuid_Tbl_Entry", !7, i64 0, !9, i64 16}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"bool", !7, i64 0}
!10 = !{i8 0, i8 2}
!11 = !{}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass