; LLVM IR from Mac-Rsh/mr-library :: source (device)

; 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.mr_dev_desc = type { ptr, i32, i32, %struct.mr_dev_call, %struct.mr_dev_call }
%struct.mr_dev_call = type { %struct.mr_list, ptr }
%struct.mr_list = type { ptr, ptr }
%struct.mr_dev = type { i32, [8 x i8], i32, i32, ptr, %struct.mr_list, %struct.mr_list, i64, i32, i32, %struct.mr_list, %struct.mr_list, ptr, ptr }
%struct.mr_dev_ops = type { ptr, ptr, ptr, ptr, ptr, ptr }

@desc_map = external hidden global [32 x %struct.mr_dev_desc], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @mr_dev_isr(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.mr_dev, ptr %14, i32 0, i32 7
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %3
  store i32 -6, ptr %4, align 4
  br label %121

19:                                               ; preds = %3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.mr_dev, ptr %20, i32 0, i32 12
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = getelementptr inbounds %struct.mr_dev_ops, ptr %22, i32 0, i32 5
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %45

26:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mr_dev, ptr %27, i32 0, i32 12
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = getelementptr inbounds %struct.mr_dev_ops, ptr %29, i32 0, i32 5
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = call i64 %31(ptr noundef %32, i32 noundef %33, ptr noundef %34)
  store i64 %35, ptr %8, align 8, !tbaa !18
  %36 = load i64, ptr %8, align 8, !tbaa !18
  %37 = icmp slt i64 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %26
  %39 = load i64, ptr %8, align 8, !tbaa !18
  %40 = trunc i64 %39 to i32
  store i32 %40, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %42

41:                                               ; preds = %26
  store i32 0, ptr %9, align 4
  br label %42

42:                                               ; preds = %41, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %43 = load i32, ptr %9, align 4
  switch i32 %43, label %123 [
    i32 0, label %44
    i32 1, label %121
  ]

44:                                               ; preds = %42
  br label %45

45:                                               ; preds = %44, %19
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = and i32 %46, 2130706432
  switch i32 %47, label %120 [
    i32 16777216, label %48
    i32 33554432, label %84
  ]

48:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.mr_dev, ptr %49, i32 0, i32 10
  %51 = getelementptr inbounds %struct.mr_list, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !19
  store ptr %52, ptr %10, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %79, %48
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.mr_dev, ptr %55, i32 0, i32 10
  %57 = icmp ne ptr %54, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %53
  store i32 3, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %83

59:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 sub (i64 0, i64 ptrtoint (ptr getelementptr inbounds (%struct.mr_dev_desc, ptr null, i32 0, i32 3) to i64))
  store ptr %61, ptr %11, align 8, !tbaa !5
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.mr_dev_desc, ptr %62, i32 0, i32 3
  %64 = getelementptr inbounds %struct.mr_dev_call, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !20
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %78

67:                                               ; preds = %59
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.mr_dev_desc, ptr %68, i32 0, i32 3
  %70 = getelementptr inbounds %struct.mr_dev_call, ptr %69, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !20
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = ptrtoint ptr %72 to i64
  %74 = sub i64 %73, ptrtoint (ptr @desc_map to i64)
  %75 = sdiv exact i64 %74, 64
  %76 = trunc i64 %75 to i32
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  call void %71(i32 noundef %76, ptr noundef %77)
  br label %78

78:                                               ; preds = %67, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %79

79:                                               ; preds = %78
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.mr_list, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !23
  store ptr %82, ptr %10, align 8, !tbaa !5
  br label %53, !llvm.loop !24

83:                                               ; preds = %58
  store i32 0, ptr %4, align 4
  br label %121

84:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.mr_dev, ptr %85, i32 0, i32 11
  %87 = getelementptr inbounds %struct.mr_list, ptr %86, i32 0, i32 0
  %88 = load ptr, ptr %87, align 8, !tbaa !26
  store ptr %88, ptr %12, align 8, !tbaa !5
  br label %89

89:                                               ; preds = %115, %84
  %90 = load ptr, ptr %12, align 8, !tbaa !5
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.mr_dev, ptr %91, i32 0, i32 11
  %93 = icmp ne ptr %90, %92
  br i1 %93, label %95, label %94

94:                                               ; preds = %89
  store i32 6, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %119

95:                                               ; preds = %89
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = getelementptr inbounds i8, ptr %96, i64 sub (i64 0, i64 ptrtoint (ptr getelementptr inbounds (%struct.mr_dev_desc, ptr null, i32 0, i32 4) to i64))
  store ptr %97, ptr %13, align 8, !tbaa !5
  %98 = load ptr, ptr %13, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.mr_dev_desc, ptr %98, i32 0, i32 4
  %100 = getelementptr inbounds %struct.mr_dev_call, ptr %99, i32 0, i32 1
  %101 = load ptr, ptr %100, align 8, !tbaa !27
  %102 = icmp ne ptr %101, null
  br i1 %102, label %103, label %114

103:                                              ; preds = %95
  %104 = load ptr, ptr %13, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.mr_dev_desc, ptr %104, i32 0, i32 4
  %106 = getelementptr inbounds %struct.mr_dev_call, ptr %105, i32 0, i32 1
  %107 = load ptr, ptr %106, align 8, !tbaa !27
  %108 = load ptr, ptr %13, align 8, !tbaa !5
  %109 = ptrtoint ptr %108 to i64
  %110 = sub i64 %109, ptrtoint (ptr @desc_map to i64)
  %111 = sdiv exact i64 %110, 64
  %112 = trunc i64 %111 to i32
  %113 = load ptr, ptr %7, align 8, !tbaa !5
  call void %107(i32 noundef %112, ptr noundef %113)
  br label %114

114:                                              ; preds = %103, %95
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  br label %115

115:                                              ; preds = %114
  %116 = load ptr, ptr %12, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.mr_list, ptr %116, i32 0, i32 0
  %118 = load ptr, ptr %117, align 8, !tbaa !23
  store ptr %118, ptr %12, align 8, !tbaa !5
  br label %89, !llvm.loop !28

119:                                              ; preds = %94
  store i32 0, ptr %4, align 4
  br label %121

120:                                              ; preds = %45
  store i32 -6, ptr %4, align 4
  br label %121

121:                                              ; preds = %120, %119, %83, %42, %18
  %122 = load i32, ptr %4, align 4
  ret i32 %122

123:                                              ; preds = %42
  unreachable
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !14, i64 64}
!12 = !{!"mr_dev", !10, i64 0, !7, i64 4, !10, i64 12, !10, i64 16, !6, i64 24, !13, i64 32, !13, i64 48, !14, i64 64, !10, i64 72, !10, i64 76, !13, i64 80, !13, i64 96, !6, i64 112, !6, i64 120}
!13 = !{!"mr_list", !6, i64 0, !6, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !6, i64 112}
!16 = !{!17, !6, i64 40}
!17 = !{!"mr_dev_ops", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!14, !14, i64 0}
!19 = !{!12, !6, i64 80}
!20 = !{!21, !6, i64 32}
!21 = !{!"mr_dev_desc", !6, i64 0, !10, i64 8, !10, i64 12, !22, i64 16, !22, i64 40}
!22 = !{!"mr_dev_call", !13, i64 0, !6, i64 16}
!23 = !{!13, !6, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!12, !6, i64 96}
!27 = !{!21, !6, i64 56}
!28 = distinct !{!28, !25}


; 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.mr_dev_desc = type { ptr, i32, i32, %struct.mr_dev_call, %struct.mr_dev_call }
%struct.mr_dev_call = type { %struct.mr_list, ptr }
%struct.mr_list = type { ptr, ptr }

@desc_map = external hidden global [32 x %struct.mr_dev_desc], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @mr_dev_isr(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 112
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %9, i64 40
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %16, label %12

12:                                               ; preds = %7
  %13 = tail call i64 %11(ptr noundef nonnull %0, i32 noundef %1, ptr noundef %2) #1
  %14 = icmp sgt i64 %13, -1
  %15 = trunc i64 %13 to i32
  br i1 %14, label %16, label %.loopexit

16:                                               ; preds = %12, %7
  %17 = and i32 %1, 2130706432
  switch i32 %17, label %.loopexit [
    i32 16777216, label %18
    i32 33554432, label %29
  ]

18:                                               ; preds = %16
  %19 = getelementptr inbounds i8, ptr %0, i64 80
  %.03043 = load ptr, ptr %19, align 8, !tbaa !16
  %.not3744 = icmp eq ptr %.03043, %19
  br i1 %.not3744, label %.loopexit, label %.lr.ph46

.lr.ph46:                                         ; preds = %18, %28
  %.03045 = phi ptr [ %.030, %28 ], [ %.03043, %18 ]
  %20 = getelementptr inbounds i8, ptr %.03045, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !17
  %.not38 = icmp eq ptr %21, null
  br i1 %.not38, label %28, label %22

22:                                               ; preds = %.lr.ph46
  %23 = getelementptr inbounds i8, ptr %.03045, i64 -16
  %24 = ptrtoint ptr %23 to i64
  %25 = sub i64 %24, ptrtoint (ptr @desc_map to i64)
  %26 = lshr exact i64 %25, 6
  %27 = trunc i64 %26 to i32
  tail call void %21(i32 noundef %27, ptr noundef %2) #1
  br label %28

28:                                               ; preds = %22, %.lr.ph46
  %.030 = load ptr, ptr %.03045, align 8, !tbaa !16
  %.not37 = icmp eq ptr %.030, %19
  br i1 %.not37, label %.loopexit, label %.lr.ph46, !llvm.loop !20

29:                                               ; preds = %16
  %30 = getelementptr inbounds i8, ptr %0, i64 96
  %.02840 = load ptr, ptr %30, align 8, !tbaa !16
  %.not3541 = icmp eq ptr %.02840, %30
  br i1 %.not3541, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %29, %39
  %.02842 = phi ptr [ %.028, %39 ], [ %.02840, %29 ]
  %31 = getelementptr inbounds i8, ptr %.02842, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !22
  %.not36 = icmp eq ptr %32, null
  br i1 %.not36, label %39, label %33

33:                                               ; preds = %.lr.ph
  %34 = getelementptr inbounds i8, ptr %.02842, i64 -40
  %35 = ptrtoint ptr %34 to i64
  %36 = sub i64 %35, ptrtoint (ptr @desc_map to i64)
  %37 = lshr exact i64 %36, 6
  %38 = trunc i64 %37 to i32
  tail call void %32(i32 noundef %38, ptr noundef %2) #1
  br label %39

39:                                               ; preds = %33, %.lr.ph
  %.028 = load ptr, ptr %.02842, align 8, !tbaa !16
  %.not35 = icmp eq ptr %.028, %30
  br i1 %.not35, label %.loopexit, label %.lr.ph, !llvm.loop !23

.loopexit:                                        ; preds = %39, %28, %29, %18, %12, %16, %3
  %.1 = phi i32 [ %15, %12 ], [ -6, %3 ], [ -6, %16 ], [ 0, %18 ], [ 0, %29 ], [ 0, %28 ], [ 0, %39 ]
  ret i32 %.1
}

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 = { 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, !12, i64 64}
!6 = !{!"mr_dev", !7, i64 0, !8, i64 4, !7, i64 12, !7, i64 16, !10, i64 24, !11, i64 32, !11, i64 48, !12, i64 64, !7, i64 72, !7, i64 76, !11, i64 80, !11, i64 96, !10, i64 112, !10, i64 120}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"mr_list", !10, i64 0, !10, i64 8}
!12 = !{!"long", !8, i64 0}
!13 = !{!6, !10, i64 112}
!14 = !{!15, !10, i64 40}
!15 = !{!"mr_dev_ops", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!16 = !{!11, !10, i64 0}
!17 = !{!18, !10, i64 32}
!18 = !{!"mr_dev_desc", !10, i64 0, !7, i64 8, !7, i64 12, !19, i64 16, !19, i64 40}
!19 = !{!"mr_dev_call", !11, i64 0, !10, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!18, !10, i64 56}
!23 = distinct !{!23, !21}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass