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

@pci_devices_idx = external dso_local global i8, align 1
@.str.18 = external hidden unnamed_addr constant [40 x i8], align 1

; 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
declare dso_local zeroext i16 @pci_get_vendor_id(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @pci_get_device_id(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @pci_get_device_class_id(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #1

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

8:                                                ; preds = %81, %0
  %9 = load i16, ptr %1, align 2, !tbaa !5
  %10 = zext i16 %9 to i32
  %11 = icmp slt i32 %10, 256
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  store i32 2, ptr %2, align 4
  br label %84

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #3
  store i16 0, ptr %3, align 2, !tbaa !5
  br label %14

14:                                               ; preds = %75, %13
  %15 = load i16, ptr %3, align 2, !tbaa !5
  %16 = zext i16 %15 to i32
  %17 = icmp slt i32 %16, 32
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 5, ptr %2, align 4
  br label %78

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #3
  store i16 0, ptr %4, align 2, !tbaa !5
  br label %20

20:                                               ; preds = %69, %19
  %21 = load i16, ptr %4, align 2, !tbaa !5
  %22 = zext i16 %21 to i32
  %23 = icmp slt i32 %22, 8
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 8, ptr %2, align 4
  br label %72

25:                                               ; preds = %20
  %26 = load i8, ptr @pci_devices_idx, align 1, !tbaa !9
  %27 = zext i8 %26 to i32
  %28 = icmp sgt i32 %27, 15
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  call void (ptr, ...) @printf(ptr noundef @.str.18)
  store i32 1, ptr %2, align 4
  br label %72

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #3
  %31 = load i16, ptr %1, align 2, !tbaa !5
  %32 = trunc i16 %31 to i8
  %33 = load i16, ptr %3, align 2, !tbaa !5
  %34 = trunc i16 %33 to i8
  %35 = load i16, ptr %4, align 2, !tbaa !5
  %36 = trunc i16 %35 to i8
  %37 = call zeroext i16 @pci_get_vendor_id(i8 noundef zeroext %32, i8 noundef zeroext %34, i8 noundef zeroext %36)
  store i16 %37, ptr %5, align 2, !tbaa !5
  %38 = load i16, ptr %5, align 2, !tbaa !5
  %39 = zext i16 %38 to i32
  %40 = icmp eq i32 %39, 65535
  br i1 %40, label %41, label %42

41:                                               ; preds = %30
  store i32 10, ptr %2, align 4
  br label %66

42:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #3
  %43 = load i16, ptr %1, align 2, !tbaa !5
  %44 = trunc i16 %43 to i8
  %45 = load i16, ptr %3, align 2, !tbaa !5
  %46 = trunc i16 %45 to i8
  %47 = load i16, ptr %4, align 2, !tbaa !5
  %48 = trunc i16 %47 to i8
  %49 = call zeroext i16 @pci_get_device_id(i8 noundef zeroext %44, i8 noundef zeroext %46, i8 noundef zeroext %48)
  store i16 %49, ptr %6, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  %50 = load i16, ptr %1, align 2, !tbaa !5
  %51 = trunc i16 %50 to i8
  %52 = load i16, ptr %3, align 2, !tbaa !5
  %53 = trunc i16 %52 to i8
  %54 = load i16, ptr %4, align 2, !tbaa !5
  %55 = trunc i16 %54 to i8
  %56 = call zeroext i16 @pci_get_device_class_id(i8 noundef zeroext %51, i8 noundef zeroext %53, i8 noundef zeroext %55)
  store i16 %56, ptr %7, align 2, !tbaa !5
  %57 = load i16, ptr %1, align 2, !tbaa !5
  %58 = trunc i16 %57 to i8
  %59 = load i16, ptr %3, align 2, !tbaa !5
  %60 = trunc i16 %59 to i8
  %61 = load i16, ptr %5, align 2, !tbaa !5
  %62 = load i16, ptr %6, align 2, !tbaa !5
  %63 = load i16, ptr %7, align 2, !tbaa !5
  %64 = load i16, ptr %4, align 2, !tbaa !5
  %65 = trunc i16 %64 to i8
  call void @pci_device_add(i8 noundef zeroext %58, i8 noundef zeroext %60, i16 noundef zeroext %61, i16 noundef zeroext %62, i16 noundef zeroext %63, i8 noundef zeroext %65)
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  store i32 0, ptr %2, align 4
  br label %66

66:                                               ; preds = %42, %41
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #3
  %67 = load i32, ptr %2, align 4
  switch i32 %67, label %87 [
    i32 0, label %68
    i32 10, label %69
  ]

68:                                               ; preds = %66
  br label %69

69:                                               ; preds = %68, %66
  %70 = load i16, ptr %4, align 2, !tbaa !5
  %71 = add i16 %70, 1
  store i16 %71, ptr %4, align 2, !tbaa !5
  br label %20, !llvm.loop !10

72:                                               ; preds = %29, %24
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #3
  %73 = load i32, ptr %2, align 4
  switch i32 %73, label %78 [
    i32 8, label %74
  ]

74:                                               ; preds = %72
  br label %75

75:                                               ; preds = %74
  %76 = load i16, ptr %3, align 2, !tbaa !5
  %77 = add i16 %76, 1
  store i16 %77, ptr %3, align 2, !tbaa !5
  br label %14, !llvm.loop !12

78:                                               ; preds = %72, %18
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #3
  %79 = load i32, ptr %2, align 4
  switch i32 %79, label %84 [
    i32 5, label %80
  ]

80:                                               ; preds = %78
  br label %81

81:                                               ; preds = %80
  %82 = load i16, ptr %1, align 2, !tbaa !5
  %83 = add i16 %82, 1
  store i16 %83, ptr %1, align 2, !tbaa !5
  br label %8, !llvm.loop !13

84:                                               ; preds = %78, %12
  call void @llvm.lifetime.end.p0(i64 2, ptr %1) #3
  %85 = load i32, ptr %2, align 4
  switch i32 %85, label %87 [
    i32 2, label %86
    i32 1, label %86
  ]

86:                                               ; preds = %84, %84
  ret void

87:                                               ; preds = %84, %66
  unreachable
}

declare void @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare hidden void @pci_device_add(i8 noundef zeroext, i8 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i8 noundef zeroext) #1

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 = { "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 }

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}


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

@pci_devices_idx = external dso_local local_unnamed_addr global i8, align 1
@.str.18 = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @pci_get_vendor_id(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @pci_get_device_id(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @pci_get_device_class_id(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @pci_scan() local_unnamed_addr #0 {
  br label %.preheader30

.preheader30:                                     ; preds = %0, %.critedge29
  %.033 = phi i16 [ 0, %0 ], [ %76, %.critedge29 ]
  %1 = trunc nuw i16 %.033 to i8
  br label %.preheader

.preheader:                                       ; preds = %.preheader30, %.critedge
  %.02632 = phi i16 [ 0, %.preheader30 ], [ %74, %.critedge ]
  %2 = trunc nuw i16 %.02632 to i8
  %3 = load i8, ptr @pci_devices_idx, align 1, !tbaa !5
  %4 = icmp ugt i8 %3, 15
  br i1 %4, label %75, label %5

5:                                                ; preds = %.preheader
  %6 = tail call zeroext i16 @pci_get_vendor_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 0)
  %7 = icmp eq i16 %6, -1
  br i1 %7, label %11, label %8

8:                                                ; preds = %5
  %9 = tail call zeroext i16 @pci_get_device_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 0)
  %10 = tail call zeroext i16 @pci_get_device_class_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 0)
  tail call void @pci_device_add(i8 noundef zeroext %1, i8 noundef zeroext %2, i16 noundef zeroext %6, i16 noundef zeroext %9, i16 noundef zeroext %10, i8 noundef zeroext 0)
  br label %11

11:                                               ; preds = %5, %8
  %12 = load i8, ptr @pci_devices_idx, align 1, !tbaa !5
  %13 = icmp ugt i8 %12, 15
  br i1 %13, label %75, label %14

14:                                               ; preds = %11
  %15 = tail call zeroext i16 @pci_get_vendor_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 1)
  %16 = icmp eq i16 %15, -1
  br i1 %16, label %20, label %17

17:                                               ; preds = %14
  %18 = tail call zeroext i16 @pci_get_device_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 1)
  %19 = tail call zeroext i16 @pci_get_device_class_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 1)
  tail call void @pci_device_add(i8 noundef zeroext %1, i8 noundef zeroext %2, i16 noundef zeroext %15, i16 noundef zeroext %18, i16 noundef zeroext %19, i8 noundef zeroext 1)
  br label %20

20:                                               ; preds = %17, %14
  %21 = load i8, ptr @pci_devices_idx, align 1, !tbaa !5
  %22 = icmp ugt i8 %21, 15
  br i1 %22, label %75, label %23

23:                                               ; preds = %20
  %24 = tail call zeroext i16 @pci_get_vendor_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 2)
  %25 = icmp eq i16 %24, -1
  br i1 %25, label %29, label %26

26:                                               ; preds = %23
  %27 = tail call zeroext i16 @pci_get_device_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 2)
  %28 = tail call zeroext i16 @pci_get_device_class_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 2)
  tail call void @pci_device_add(i8 noundef zeroext %1, i8 noundef zeroext %2, i16 noundef zeroext %24, i16 noundef zeroext %27, i16 noundef zeroext %28, i8 noundef zeroext 2)
  br label %29

29:                                               ; preds = %26, %23
  %30 = load i8, ptr @pci_devices_idx, align 1, !tbaa !5
  %31 = icmp ugt i8 %30, 15
  br i1 %31, label %75, label %32

32:                                               ; preds = %29
  %33 = tail call zeroext i16 @pci_get_vendor_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 3)
  %34 = icmp eq i16 %33, -1
  br i1 %34, label %38, label %35

35:                                               ; preds = %32
  %36 = tail call zeroext i16 @pci_get_device_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 3)
  %37 = tail call zeroext i16 @pci_get_device_class_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 3)
  tail call void @pci_device_add(i8 noundef zeroext %1, i8 noundef zeroext %2, i16 noundef zeroext %33, i16 noundef zeroext %36, i16 noundef zeroext %37, i8 noundef zeroext 3)
  br label %38

38:                                               ; preds = %35, %32
  %39 = load i8, ptr @pci_devices_idx, align 1, !tbaa !5
  %40 = icmp ugt i8 %39, 15
  br i1 %40, label %75, label %41

41:                                               ; preds = %38
  %42 = tail call zeroext i16 @pci_get_vendor_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 4)
  %43 = icmp eq i16 %42, -1
  br i1 %43, label %47, label %44

44:                                               ; preds = %41
  %45 = tail call zeroext i16 @pci_get_device_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 4)
  %46 = tail call zeroext i16 @pci_get_device_class_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 4)
  tail call void @pci_device_add(i8 noundef zeroext %1, i8 noundef zeroext %2, i16 noundef zeroext %42, i16 noundef zeroext %45, i16 noundef zeroext %46, i8 noundef zeroext 4)
  br label %47

47:                                               ; preds = %44, %41
  %48 = load i8, ptr @pci_devices_idx, align 1, !tbaa !5
  %49 = icmp ugt i8 %48, 15
  br i1 %49, label %75, label %50

50:                                               ; preds = %47
  %51 = tail call zeroext i16 @pci_get_vendor_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 5)
  %52 = icmp eq i16 %51, -1
  br i1 %52, label %56, label %53

53:                                               ; preds = %50
  %54 = tail call zeroext i16 @pci_get_device_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 5)
  %55 = tail call zeroext i16 @pci_get_device_class_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 5)
  tail call void @pci_device_add(i8 noundef zeroext %1, i8 noundef zeroext %2, i16 noundef zeroext %51, i16 noundef zeroext %54, i16 noundef zeroext %55, i8 noundef zeroext 5)
  br label %56

56:                                               ; preds = %53, %50
  %57 = load i8, ptr @pci_devices_idx, align 1, !tbaa !5
  %58 = icmp ugt i8 %57, 15
  br i1 %58, label %75, label %59

59:                                               ; preds = %56
  %60 = tail call zeroext i16 @pci_get_vendor_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 6)
  %61 = icmp eq i16 %60, -1
  br i1 %61, label %65, label %62

62:                                               ; preds = %59
  %63 = tail call zeroext i16 @pci_get_device_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 6)
  %64 = tail call zeroext i16 @pci_get_device_class_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 6)
  tail call void @pci_device_add(i8 noundef zeroext %1, i8 noundef zeroext %2, i16 noundef zeroext %60, i16 noundef zeroext %63, i16 noundef zeroext %64, i8 noundef zeroext 6)
  br label %65

65:                                               ; preds = %62, %59
  %66 = load i8, ptr @pci_devices_idx, align 1, !tbaa !5
  %67 = icmp ugt i8 %66, 15
  br i1 %67, label %75, label %68

68:                                               ; preds = %65
  %69 = tail call zeroext i16 @pci_get_vendor_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 7)
  %70 = icmp eq i16 %69, -1
  br i1 %70, label %.critedge, label %71

71:                                               ; preds = %68
  %72 = tail call zeroext i16 @pci_get_device_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 7)
  %73 = tail call zeroext i16 @pci_get_device_class_id(i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext 7)
  tail call void @pci_device_add(i8 noundef zeroext %1, i8 noundef zeroext %2, i16 noundef zeroext %69, i16 noundef zeroext %72, i16 noundef zeroext %73, i8 noundef zeroext 7)
  br label %.critedge

.critedge:                                        ; preds = %71, %68
  %74 = add nuw nsw i16 %.02632, 1
  %exitcond = icmp eq i16 %74, 32
  br i1 %exitcond, label %.critedge29, label %.preheader, !llvm.loop !8

75:                                               ; preds = %65, %56, %47, %38, %29, %20, %11, %.preheader
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.18) #2
  br label %.loopexit

.critedge29:                                      ; preds = %.critedge
  %76 = add nuw nsw i16 %.033, 1
  %exitcond34.not = icmp eq i16 %76, 256
  br i1 %exitcond34.not, label %.loopexit, label %.preheader30, !llvm.loop !10

.loopexit:                                        ; preds = %.critedge29, %75
  ret void
}

declare void @printf(ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @pci_device_add(i8 noundef zeroext, i8 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

attributes #0 = { 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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


; Effective O3 passes: ConstraintEliminationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass