; LLVM IR from narke/Aragveli :: src/extra/drivers (pci)

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

@pci_devices = external dso_local global [16 x %struct.pci_device], align 16

; 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: nounwind uwtable
define dso_local { i64, i16 } @pci_device_lookup(i16 noundef zeroext %0, i16 noundef zeroext %1) #1 {
  %3 = alloca %struct.pci_device, align 2
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca { i64, i16 }, align 8
  store i16 %0, ptr %4, align 2, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %38, %2
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 15
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %7, align 4
  br label %41

13:                                               ; preds = %9
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [16 x %struct.pci_device], ptr @pci_devices, i64 0, i64 %15
  %17 = getelementptr inbounds %struct.pci_device, ptr %16, i32 0, i32 3
  %18 = load i16, ptr %17, align 2, !tbaa !11
  %19 = zext i16 %18 to i32
  %20 = load i16, ptr %4, align 2, !tbaa !5
  %21 = zext i16 %20 to i32
  %22 = icmp eq i32 %19, %21
  br i1 %22, label %23, label %37

23:                                               ; preds = %13
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [16 x %struct.pci_device], ptr @pci_devices, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.pci_device, ptr %26, i32 0, i32 4
  %28 = load i16, ptr %27, align 2, !tbaa !13
  %29 = zext i16 %28 to i32
  %30 = load i16, ptr %5, align 2, !tbaa !5
  %31 = zext i16 %30 to i32
  %32 = icmp eq i32 %29, %31
  br i1 %32, label %33, label %37

33:                                               ; preds = %23
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [16 x %struct.pci_device], ptr @pci_devices, i64 0, i64 %35
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %3, ptr align 2 %36, i64 10, i1 false), !tbaa.struct !14
  store i32 1, ptr %7, align 4
  br label %41

37:                                               ; preds = %23, %13
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !16

41:                                               ; preds = %33, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %42 = load i32, ptr %7, align 4
  switch i32 %42, label %52 [
    i32 2, label %43
    i32 1, label %50
  ]

43:                                               ; preds = %41
  %44 = getelementptr inbounds %struct.pci_device, ptr %3, i32 0, i32 0
  store i8 0, ptr %44, align 2, !tbaa !18
  %45 = getelementptr inbounds %struct.pci_device, ptr %3, i32 0, i32 1
  store i8 0, ptr %45, align 1, !tbaa !19
  %46 = getelementptr inbounds %struct.pci_device, ptr %3, i32 0, i32 2
  store i8 0, ptr %46, align 2, !tbaa !20
  %47 = getelementptr inbounds %struct.pci_device, ptr %3, i32 0, i32 3
  store i16 0, ptr %47, align 2, !tbaa !11
  %48 = getelementptr inbounds %struct.pci_device, ptr %3, i32 0, i32 4
  store i16 0, ptr %48, align 2, !tbaa !13
  %49 = getelementptr inbounds %struct.pci_device, ptr %3, i32 0, i32 5
  store i16 0, ptr %49, align 2, !tbaa !21
  br label %50

50:                                               ; preds = %43, %41
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 2 %3, i64 10, i1 false)
  %51 = load { i64, i16 }, ptr %8, align 8
  ret { i64, i16 } %51

52:                                               ; preds = %41
  unreachable
}

; 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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 4}
!12 = !{!"pci_device", !7, i64 0, !7, i64 1, !7, i64 2, !6, i64 4, !6, i64 6, !6, i64 8}
!13 = !{!12, !6, i64 6}
!14 = !{i64 0, i64 1, !15, i64 1, i64 1, !15, i64 2, i64 1, !15, i64 4, i64 2, !5, i64 6, i64 2, !5, i64 8, i64 2, !5}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!12, !7, i64 0}
!19 = !{!12, !7, i64 1}
!20 = !{!12, !7, i64 2}
!21 = !{!12, !6, i64 8}


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

@pci_devices = external dso_local local_unnamed_addr global [16 x %struct.pci_device], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local { i64, i16 } @pci_device_lookup(i16 noundef zeroext %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 4), align 4, !tbaa !5
  %4 = icmp eq i16 %3, %0
  %5 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 6), align 2
  %6 = icmp eq i16 %5, %1
  %or.cond = select i1 %4, i1 %6, i1 false
  br i1 %or.cond, label %77, label %7

7:                                                ; preds = %2
  %8 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 14), align 2, !tbaa !5
  %9 = icmp eq i16 %8, %0
  %10 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 16), align 16
  %11 = icmp eq i16 %10, %1
  %or.cond28 = select i1 %9, i1 %11, i1 false
  br i1 %or.cond28, label %77, label %12

12:                                               ; preds = %7
  %13 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 24), align 8, !tbaa !5
  %14 = icmp eq i16 %13, %0
  %15 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 26), align 2
  %16 = icmp eq i16 %15, %1
  %or.cond30 = select i1 %14, i1 %16, i1 false
  br i1 %or.cond30, label %77, label %17

17:                                               ; preds = %12
  %18 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 34), align 2, !tbaa !5
  %19 = icmp eq i16 %18, %0
  %20 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 36), align 4
  %21 = icmp eq i16 %20, %1
  %or.cond32 = select i1 %19, i1 %21, i1 false
  br i1 %or.cond32, label %77, label %22

22:                                               ; preds = %17
  %23 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 44), align 4, !tbaa !5
  %24 = icmp eq i16 %23, %0
  %25 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 46), align 2
  %26 = icmp eq i16 %25, %1
  %or.cond34 = select i1 %24, i1 %26, i1 false
  br i1 %or.cond34, label %77, label %27

27:                                               ; preds = %22
  %28 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 54), align 2, !tbaa !5
  %29 = icmp eq i16 %28, %0
  %30 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 56), align 8
  %31 = icmp eq i16 %30, %1
  %or.cond36 = select i1 %29, i1 %31, i1 false
  br i1 %or.cond36, label %77, label %32

32:                                               ; preds = %27
  %33 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 64), align 16, !tbaa !5
  %34 = icmp eq i16 %33, %0
  %35 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 66), align 2
  %36 = icmp eq i16 %35, %1
  %or.cond38 = select i1 %34, i1 %36, i1 false
  br i1 %or.cond38, label %77, label %37

37:                                               ; preds = %32
  %38 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 74), align 2, !tbaa !5
  %39 = icmp eq i16 %38, %0
  %40 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 76), align 4
  %41 = icmp eq i16 %40, %1
  %or.cond40 = select i1 %39, i1 %41, i1 false
  br i1 %or.cond40, label %77, label %42

42:                                               ; preds = %37
  %43 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 84), align 4, !tbaa !5
  %44 = icmp eq i16 %43, %0
  %45 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 86), align 2
  %46 = icmp eq i16 %45, %1
  %or.cond42 = select i1 %44, i1 %46, i1 false
  br i1 %or.cond42, label %77, label %47

47:                                               ; preds = %42
  %48 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 94), align 2, !tbaa !5
  %49 = icmp eq i16 %48, %0
  %50 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 96), align 16
  %51 = icmp eq i16 %50, %1
  %or.cond44 = select i1 %49, i1 %51, i1 false
  br i1 %or.cond44, label %77, label %52

52:                                               ; preds = %47
  %53 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 104), align 8, !tbaa !5
  %54 = icmp eq i16 %53, %0
  %55 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 106), align 2
  %56 = icmp eq i16 %55, %1
  %or.cond46 = select i1 %54, i1 %56, i1 false
  br i1 %or.cond46, label %77, label %57

57:                                               ; preds = %52
  %58 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 114), align 2, !tbaa !5
  %59 = icmp eq i16 %58, %0
  %60 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 116), align 4
  %61 = icmp eq i16 %60, %1
  %or.cond48 = select i1 %59, i1 %61, i1 false
  br i1 %or.cond48, label %77, label %62

62:                                               ; preds = %57
  %63 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 124), align 4, !tbaa !5
  %64 = icmp eq i16 %63, %0
  %65 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 126), align 2
  %66 = icmp eq i16 %65, %1
  %or.cond50 = select i1 %64, i1 %66, i1 false
  br i1 %or.cond50, label %77, label %67

67:                                               ; preds = %62
  %68 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 134), align 2, !tbaa !5
  %69 = icmp eq i16 %68, %0
  %70 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 136), align 8
  %71 = icmp eq i16 %70, %1
  %or.cond52 = select i1 %69, i1 %71, i1 false
  br i1 %or.cond52, label %77, label %72

72:                                               ; preds = %67
  %73 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 144), align 16, !tbaa !5
  %74 = icmp eq i16 %73, %0
  %75 = load i16, ptr getelementptr inbounds (i8, ptr @pci_devices, i64 146), align 2
  %76 = icmp eq i16 %75, %1
  %or.cond54 = select i1 %74, i1 %76, i1 false
  br i1 %or.cond54, label %77, label %.loopexit

77:                                               ; preds = %72, %67, %62, %57, %52, %47, %42, %37, %32, %27, %22, %17, %12, %7, %2
  %.lcssa = phi ptr [ @pci_devices, %2 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 10), %7 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 20), %12 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 30), %17 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 40), %22 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 50), %27 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 60), %32 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 70), %37 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 80), %42 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 90), %47 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 100), %52 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 110), %57 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 120), %62 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 130), %67 ], [ getelementptr inbounds (i8, ptr @pci_devices, i64 140), %72 ]
  %.sroa.08.0.copyload = load i64, ptr %.lcssa, align 2
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %.lcssa, i64 8
  %.sroa.7.0.copyload = load i16, ptr %.sroa.7.0..sroa_idx, align 2, !tbaa !10
  br label %.loopexit

.loopexit:                                        ; preds = %72, %77
  %.sroa.7.1 = phi i16 [ %.sroa.7.0.copyload, %77 ], [ 0, %72 ]
  %.sroa.08.sroa.0.0.insert.insert = phi i64 [ %.sroa.08.0.copyload, %77 ], [ 0, %72 ]
  %.fca.0.insert = insertvalue { i64, i16 } poison, i64 %.sroa.08.sroa.0.0.insert.insert, 0
  %.fca.1.insert = insertvalue { i64, i16 } %.fca.0.insert, i16 %.sroa.7.1, 1
  ret { i64, i16 } %.fca.1.insert
}

attributes #0 = { mustprogress nofree norecurse nosync 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" }

!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 4}
!6 = !{!"pci_device", !7, i64 0, !7, i64 1, !7, i64 2, !9, i64 4, !9, i64 6, !9, i64 8}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!9, !9, i64 0}


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