; 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 }
%struct.__Bt_Uuid16 = type <{ i8, i16 }>

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

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 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: mustprogress nounwind uwtable
declare dso_local i32 @BtUuidAddBase(ptr noundef) #2

; 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) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @BtUuid128To16(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 -1, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load i8, ptr %8, align 1
  %10 = and i8 %9, 63
  %11 = or i8 %10, -128
  store i8 %11, ptr %8, align 1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.__Bt_Uuid16, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 12
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %13, ptr align 1 %15, i64 2, i1 false)
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 12
  store i8 0, ptr %17, align 1, !tbaa !11
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 13
  store i8 0, ptr %19, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %46, %2
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = icmp slt i32 %21, 4
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 2, ptr %7, align 4
  br label %49

24:                                               ; preds = %20
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [4 x %struct.__Bt_Base_Uuid_Tbl_Entry], ptr @_ZL15s_BtBaseUuidTbl, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.__Bt_Base_Uuid_Tbl_Entry, ptr %27, i32 0, i32 1
  %29 = load i8, ptr %28, align 1, !tbaa !12, !range !15, !noundef !16
  %30 = trunc i8 %29 to i1
  %31 = zext i1 %30 to i32
  %32 = icmp eq i32 %31, 1
  br i1 %32, label %33, label %45

33:                                               ; preds = %24
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [4 x %struct.__Bt_Base_Uuid_Tbl_Entry], ptr @_ZL15s_BtBaseUuidTbl, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.__Bt_Base_Uuid_Tbl_Entry, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds [16 x i8], ptr %37, i64 0, i64 0
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = call i32 @memcmp(ptr noundef %38, ptr noundef %39, i64 noundef 16) #5
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %44

42:                                               ; preds = %33
  %43 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %43, ptr %5, align 4, !tbaa !9
  store i32 2, ptr %7, align 4
  br label %49

44:                                               ; preds = %33
  br label %45

45:                                               ; preds = %44, %24
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %6, align 4, !tbaa !9
  br label %20, !llvm.loop !17

49:                                               ; preds = %42, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = icmp eq i32 %51, -1
  br i1 %52, label %53, label %56

53:                                               ; preds = %50
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = call i32 @BtUuidAddBase(ptr noundef %54)
  store i32 %55, ptr %5, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %53, %50
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = trunc i32 %57 to i8
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = load i8, ptr %59, align 1
  %61 = and i8 %58, 63
  %62 = and i8 %60, -64
  %63 = or i8 %62, %61
  store i8 %63, ptr %59, align 1
  %64 = load i32, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %64
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 }
attributes #5 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !14, i64 16}
!13 = !{!"_ZTS24__Bt_Base_Uuid_Tbl_Entry", !7, i64 0, !14, i64 16}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"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 nounwind uwtable
declare dso_local i32 @BtUuidAddBase(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @BtUuid128To16(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i8, ptr %0, align 1
  %4 = and i8 %3, 63
  %5 = or disjoint i8 %4, -128
  store i8 %5, ptr %0, align 1
  %6 = getelementptr inbounds i8, ptr %0, i64 1
  %7 = getelementptr inbounds i8, ptr %1, i64 12
  %8 = load i16, ptr %7, align 1
  store i16 %8, ptr %6, align 1
  store i8 0, ptr %7, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %1, i64 13
  store i8 0, ptr %9, align 1, !tbaa !5
  %10 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 16), align 4, !tbaa !8, !range !11, !noundef !12
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %12, label %14

12:                                               ; preds = %2
  %bcmp = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) @_ZL15s_BtBaseUuidTbl, ptr noundef nonnull dereferenceable(16) %1, i64 16)
  %13 = icmp eq i32 %bcmp, 0
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %2, %12
  %15 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 33), align 1, !tbaa !8, !range !11, !noundef !12
  %16 = trunc nuw i8 %15 to i1
  br i1 %16, label %17, label %19

17:                                               ; preds = %14
  %bcmp.1 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 17), ptr noundef nonnull dereferenceable(16) %1, i64 16)
  %18 = icmp eq i32 %bcmp.1, 0
  br i1 %18, label %.loopexit, label %19

19:                                               ; preds = %17, %14
  %20 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 50), align 2, !tbaa !8, !range !11, !noundef !12
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %22, label %24

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

24:                                               ; preds = %22, %19
  %25 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 67), align 1, !tbaa !8, !range !11, !noundef !12
  %26 = trunc nuw i8 %25 to i1
  br i1 %26, label %27, label %29

27:                                               ; preds = %24
  %bcmp.3 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) getelementptr inbounds (i8, ptr @_ZL15s_BtBaseUuidTbl, i64 51), ptr noundef nonnull dereferenceable(16) %1, i64 16)
  %28 = icmp eq i32 %bcmp.3, 0
  br i1 %28, label %.loopexit, label %29

29:                                               ; preds = %27, %24
  %30 = tail call i32 @BtUuidAddBase(ptr noundef nonnull %1)
  br label %.loopexit

.loopexit:                                        ; preds = %12, %17, %22, %27, %29
  %.1 = phi i32 [ %30, %29 ], [ 0, %12 ], [ 1, %17 ], [ 2, %22 ], [ 3, %27 ]
  %31 = trunc i32 %.1 to i8
  %32 = load i8, ptr %0, align 1
  %33 = and i8 %31, 63
  %34 = and i8 %32, -64
  %35 = or disjoint i8 %34, %33
  store i8 %35, ptr %0, align 1
  ret i32 %.1
}

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #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 = { 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !10, i64 16}
!9 = !{!"_ZTS24__Bt_Base_Uuid_Tbl_Entry", !6, i64 0, !10, i64 16}
!10 = !{!"bool", !6, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}


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