; LLVM IR from CerebusOSS/CereLink :: Central/Instrument.ll (ZN10Instrument12CachedPacket13CheckForReplyEPv)

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

%"class.Instrument::CachedPacket" = type { i32, i32, i32, i32, i32, [2048 x i8], i32 }
%struct.cbPKT_GENERIC = type { %struct.cbPKT_HEADER, [252 x i32] }
%struct.cbPKT_HEADER = type { i64, i16, i16, i16, i8, i8 }
%struct.cbPKT_CHANINFO = type { %struct.cbPKT_HEADER, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.cbSCALING, %struct.cbFILTDESC, %struct.cbSCALING, %struct.cbFILTDESC, [16 x i8], i32, [4 x i32], %struct.cbSCALING, %struct.cbSCALING, i32, i32, i32, i32, %union.anon, i8, [2 x i8], i8, i16, i16, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32, [5 x %struct.cbMANUALUNITMAPPING], [5 x [4 x %struct.cbHOOP]] }
%struct.cbFILTDESC = type { [16 x i8], i32, i32, i32, i32, i32, i32 }
%struct.cbSCALING = type { i16, i16, i32, i32, i32, [8 x i8] }
%union.anon = type { %struct.anon }
%struct.anon = type { i16, i16, i32 }
%struct.cbMANUALUNITMAPPING = type { i16, [3 x i16], [3 x [3 x i16]], i16, i32 }
%struct.cbHOOP = type { i16, i16, i16, i16 }

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

; 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
define dso_local void @_ZN10Instrument12CachedPacket13CheckForReplyEPv(ptr noundef nonnull align 4 dereferenceable(2072) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  %11 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %14, label %80

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %15, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %16 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %10, i32 0, i32 5
  %17 = getelementptr inbounds [2048 x i8], ptr %16, i64 0, i64 0
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.cbPKT_GENERIC, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %19, i32 0, i32 2
  %21 = load i16, ptr %20, align 1, !tbaa !13
  %22 = zext i16 %21 to i32
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.cbPKT_GENERIC, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %24, i32 0, i32 2
  %26 = load i16, ptr %25, align 1, !tbaa !13
  %27 = zext i16 %26 to i32
  %28 = and i32 %27, -129
  %29 = icmp ne i32 %22, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %14
  store i32 1, ptr %7, align 4
  br label %77

31:                                               ; preds = %14
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.cbPKT_GENERIC, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %33, i32 0, i32 1
  %35 = load i16, ptr %34, align 1, !tbaa !18
  %36 = zext i16 %35 to i32
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.cbPKT_GENERIC, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %38, i32 0, i32 1
  %40 = load i16, ptr %39, align 1, !tbaa !18
  %41 = zext i16 %40 to i32
  %42 = icmp ne i32 %36, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %31
  store i32 1, ptr %7, align 4
  br label %77

44:                                               ; preds = %31
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.cbPKT_GENERIC, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %46, i32 0, i32 2
  %48 = load i16, ptr %47, align 1, !tbaa !13
  %49 = zext i16 %48 to i32
  %50 = and i32 %49, 192
  %51 = icmp eq i32 %50, 192
  br i1 %51, label %52, label %75

52:                                               ; preds = %44
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.cbPKT_GENERIC, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %54, i32 0, i32 3
  %56 = load i16, ptr %55, align 1, !tbaa !19
  %57 = icmp ne i16 %56, 0
  br i1 %57, label %58, label %74

58:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %59, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %60 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %10, i32 0, i32 5
  %61 = getelementptr inbounds [2048 x i8], ptr %60, i64 0, i64 0
  store ptr %61, ptr %9, align 8, !tbaa !5
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %62, i32 0, i32 1
  %64 = load i32, ptr %63, align 1, !tbaa !20
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.cbPKT_CHANINFO, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 1, !tbaa !20
  %68 = icmp ne i32 %64, %67
  br i1 %68, label %69, label %70

69:                                               ; preds = %58
  store i32 1, ptr %7, align 4
  br label %71

70:                                               ; preds = %58
  store i32 0, ptr %7, align 4
  br label %71

71:                                               ; preds = %70, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %72 = load i32, ptr %7, align 4
  switch i32 %72, label %77 [
    i32 0, label %73
  ]

73:                                               ; preds = %71
  br label %74

74:                                               ; preds = %73, %52
  br label %75

75:                                               ; preds = %74, %44
  %76 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %10, i32 0, i32 0
  store i32 0, ptr %76, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  br label %77

77:                                               ; preds = %75, %71, %43, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  %78 = load i32, ptr %7, align 4
  switch i32 %78, label %81 [
    i32 0, label %79
    i32 1, label %80
  ]

79:                                               ; preds = %77
  br label %80

80:                                               ; preds = %79, %77, %2
  ret void

81:                                               ; preds = %77
  unreachable
}

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 = { 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, !11, i64 0}
!10 = !{!"_ZTSN10Instrument12CachedPacketE", !11, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !7, i64 20, !12, i64 2068}
!11 = !{!"_ZTSN10Instrument8ModeTypeE", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !17, i64 10}
!14 = !{!"_ZTS13cbPKT_GENERIC", !15, i64 0, !7, i64 16}
!15 = !{!"_ZTS12cbPKT_HEADER", !16, i64 0, !17, i64 8, !17, i64 10, !17, i64 12, !7, i64 14, !7, i64 15}
!16 = !{!"long", !7, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!14, !17, i64 8}
!19 = !{!14, !17, i64 12}
!20 = !{!21, !12, i64 16}
!21 = !{!"_ZTS14cbPKT_CHANINFO", !15, i64 0, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !22, i64 56, !23, i64 80, !22, i64 120, !23, i64 144, !7, i64 184, !12, i64 200, !7, i64 204, !22, i64 220, !22, i64 244, !12, i64 268, !12, i64 272, !12, i64 276, !12, i64 280, !7, i64 284, !7, i64 292, !7, i64 293, !7, i64 295, !17, i64 296, !17, i64 298, !12, i64 300, !12, i64 304, !12, i64 308, !12, i64 312, !12, i64 316, !12, i64 320, !12, i64 324, !12, i64 328, !12, i64 332, !12, i64 336, !12, i64 340, !12, i64 344, !12, i64 348, !17, i64 352, !17, i64 354, !12, i64 356, !7, i64 360, !7, i64 520}
!22 = !{!"_ZTS9cbSCALING", !17, i64 0, !17, i64 2, !12, i64 4, !12, i64 8, !12, i64 12, !7, i64 16}
!23 = !{!"_ZTS10cbFILTDESC", !7, i64 0, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN10Instrument12CachedPacket13CheckForReplyEPv(ptr nocapture noundef nonnull align 4 dereferenceable(2072) %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 align 2 {
  %3 = load i32, ptr %0, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %5, label %29

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 10
  %7 = load i16, ptr %6, align 1, !tbaa !11
  %8 = zext i16 %7 to i32
  %9 = getelementptr inbounds i8, ptr %0, i64 30
  %10 = load i16, ptr %9, align 2, !tbaa !11
  %11 = zext i16 %10 to i32
  %12 = and i32 %11, 65407
  %.not = icmp eq i32 %12, %8
  br i1 %.not, label %13, label %29

13:                                               ; preds = %5
  %14 = getelementptr inbounds i8, ptr %1, i64 8
  %15 = load i16, ptr %14, align 1, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %0, i64 28
  %17 = load i16, ptr %16, align 4, !tbaa !16
  %.not11 = icmp eq i16 %15, %17
  br i1 %.not11, label %18, label %29

18:                                               ; preds = %13
  %19 = and i32 %11, 192
  %20 = icmp ne i32 %19, 192
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  %22 = load i16, ptr %21, align 4
  %.not12 = icmp eq i16 %22, 0
  %or.cond = select i1 %20, i1 true, i1 %.not12
  br i1 %or.cond, label %28, label %23

23:                                               ; preds = %18
  %24 = getelementptr inbounds i8, ptr %1, i64 16
  %25 = load i32, ptr %24, align 1, !tbaa !17
  %26 = getelementptr inbounds i8, ptr %0, i64 36
  %27 = load i32, ptr %26, align 4, !tbaa !17
  %.not13 = icmp eq i32 %25, %27
  br i1 %.not13, label %28, label %29

28:                                               ; preds = %23, %18
  store i32 0, ptr %0, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %28, %23, %5, %13, %2
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !7, i64 0}
!6 = !{!"_ZTSN10Instrument12CachedPacketE", !7, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !8, i64 20, !10, i64 2068}
!7 = !{!"_ZTSN10Instrument8ModeTypeE", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !15, i64 10}
!12 = !{!"_ZTS13cbPKT_GENERIC", !13, i64 0, !8, i64 16}
!13 = !{!"_ZTS12cbPKT_HEADER", !14, i64 0, !15, i64 8, !15, i64 10, !15, i64 12, !8, i64 14, !8, i64 15}
!14 = !{!"long", !8, i64 0}
!15 = !{!"short", !8, i64 0}
!16 = !{!12, !15, i64 8}
!17 = !{!18, !10, i64 16}
!18 = !{!"_ZTS14cbPKT_CHANINFO", !13, i64 0, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !19, i64 56, !20, i64 80, !19, i64 120, !20, i64 144, !8, i64 184, !10, i64 200, !8, i64 204, !19, i64 220, !19, i64 244, !10, i64 268, !10, i64 272, !10, i64 276, !10, i64 280, !8, i64 284, !8, i64 292, !8, i64 293, !8, i64 295, !15, i64 296, !15, i64 298, !10, i64 300, !10, i64 304, !10, i64 308, !10, i64 312, !10, i64 316, !10, i64 320, !10, i64 324, !10, i64 328, !10, i64 332, !10, i64 336, !10, i64 340, !10, i64 344, !10, i64 348, !15, i64 352, !15, i64 354, !10, i64 356, !8, i64 360, !8, i64 520}
!19 = !{!"_ZTS9cbSCALING", !15, i64 0, !15, i64 2, !10, i64 4, !10, i64 8, !10, i64 12, !8, i64 16}
!20 = !{!"_ZTS10cbFILTDESC", !8, i64 0, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass