; LLVM IR from Aeternum-Veritas/Merry :: legacy/decoder/src (merry_branch_predictor)

; 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.MerryPredictor = type { [8 x %struct._LocalIndex_], i8, i8, i64 }
%struct._LocalIndex_ = type { [8 x i8] }

; 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 void @merry_predictor_init(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = call i64 @time(ptr noundef null) #3
  %7 = trunc i64 %6 to i32
  call void @srand(i32 noundef %7) #3
  %8 = call i32 @rand() #3
  %9 = trunc i32 %8 to i8
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.MerryPredictor, ptr %10, i32 0, i32 1
  store i8 %9, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !12
  br label %12

12:                                               ; preds = %37, %1
  %13 = load i32, ptr %3, align 4, !tbaa !12
  %14 = icmp slt i32 %13, 8
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %40

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %17

17:                                               ; preds = %33, %16
  %18 = load i32, ptr %5, align 4, !tbaa !12
  %19 = icmp slt i32 %18, 8
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %36

21:                                               ; preds = %17
  %22 = call i32 @rand() #3
  %23 = trunc i32 %22 to i8
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MerryPredictor, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %3, align 4, !tbaa !12
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [8 x %struct._LocalIndex_], ptr %25, i64 0, i64 %27
  %29 = getelementptr inbounds %struct._LocalIndex_, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %5, align 4, !tbaa !12
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [8 x i8], ptr %29, i64 0, i64 %31
  store i8 %23, ptr %32, align 1, !tbaa !14
  br label %33

33:                                               ; preds = %21
  %34 = load i32, ptr %5, align 4, !tbaa !12
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %5, align 4, !tbaa !12
  br label %17, !llvm.loop !15

36:                                               ; preds = %20
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %3, align 4, !tbaa !12
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %3, align 4, !tbaa !12
  br label %12, !llvm.loop !17

40:                                               ; preds = %15
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.MerryPredictor, ptr %41, i32 0, i32 2
  store i8 0, ptr %42, align 1, !tbaa !18
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.MerryPredictor, ptr %43, i32 0, i32 3
  store i64 0, ptr %44, align 8, !tbaa !19
  ret void
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) #2

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @rand() #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 = { nounwind "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 64}
!10 = !{!"MerryPredictor", !7, i64 0, !7, i64 64, !7, i64 65, !11, i64 72}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{!10, !7, i64 65}
!19 = !{!10, !11, i64 72}


; 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: nounwind uwtable
define dso_local void @merry_predictor_init(ptr nocapture noundef writeonly %0) local_unnamed_addr #0 {
.preheader:
  %1 = tail call i64 @time(ptr noundef null) #2
  %2 = trunc i64 %1 to i32
  tail call void @srand(i32 noundef %2) #2
  %3 = tail call i32 @rand() #2
  %4 = trunc i32 %3 to i8
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  store i8 %4, ptr %5, align 8, !tbaa !5
  %6 = tail call i32 @rand() #2
  %7 = trunc i32 %6 to i8
  store i8 %7, ptr %0, align 1, !tbaa !10
  %8 = tail call i32 @rand() #2
  %9 = trunc i32 %8 to i8
  %10 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 %9, ptr %10, align 1, !tbaa !10
  %11 = tail call i32 @rand() #2
  %12 = trunc i32 %11 to i8
  %13 = getelementptr inbounds i8, ptr %0, i64 2
  store i8 %12, ptr %13, align 1, !tbaa !10
  %14 = tail call i32 @rand() #2
  %15 = trunc i32 %14 to i8
  %16 = getelementptr inbounds i8, ptr %0, i64 3
  store i8 %15, ptr %16, align 1, !tbaa !10
  %17 = tail call i32 @rand() #2
  %18 = trunc i32 %17 to i8
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  store i8 %18, ptr %19, align 1, !tbaa !10
  %20 = tail call i32 @rand() #2
  %21 = trunc i32 %20 to i8
  %22 = getelementptr inbounds i8, ptr %0, i64 5
  store i8 %21, ptr %22, align 1, !tbaa !10
  %23 = tail call i32 @rand() #2
  %24 = trunc i32 %23 to i8
  %25 = getelementptr inbounds i8, ptr %0, i64 6
  store i8 %24, ptr %25, align 1, !tbaa !10
  %26 = tail call i32 @rand() #2
  %27 = trunc i32 %26 to i8
  %28 = getelementptr inbounds i8, ptr %0, i64 7
  store i8 %27, ptr %28, align 1, !tbaa !10
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  %30 = tail call i32 @rand() #2
  %31 = trunc i32 %30 to i8
  store i8 %31, ptr %29, align 1, !tbaa !10
  %32 = tail call i32 @rand() #2
  %33 = trunc i32 %32 to i8
  %34 = getelementptr inbounds i8, ptr %0, i64 9
  store i8 %33, ptr %34, align 1, !tbaa !10
  %35 = tail call i32 @rand() #2
  %36 = trunc i32 %35 to i8
  %37 = getelementptr inbounds i8, ptr %0, i64 10
  store i8 %36, ptr %37, align 1, !tbaa !10
  %38 = tail call i32 @rand() #2
  %39 = trunc i32 %38 to i8
  %40 = getelementptr inbounds i8, ptr %0, i64 11
  store i8 %39, ptr %40, align 1, !tbaa !10
  %41 = tail call i32 @rand() #2
  %42 = trunc i32 %41 to i8
  %43 = getelementptr inbounds i8, ptr %0, i64 12
  store i8 %42, ptr %43, align 1, !tbaa !10
  %44 = tail call i32 @rand() #2
  %45 = trunc i32 %44 to i8
  %46 = getelementptr inbounds i8, ptr %0, i64 13
  store i8 %45, ptr %46, align 1, !tbaa !10
  %47 = tail call i32 @rand() #2
  %48 = trunc i32 %47 to i8
  %49 = getelementptr inbounds i8, ptr %0, i64 14
  store i8 %48, ptr %49, align 1, !tbaa !10
  %50 = tail call i32 @rand() #2
  %51 = trunc i32 %50 to i8
  %52 = getelementptr inbounds i8, ptr %0, i64 15
  store i8 %51, ptr %52, align 1, !tbaa !10
  %53 = getelementptr inbounds i8, ptr %0, i64 16
  %54 = tail call i32 @rand() #2
  %55 = trunc i32 %54 to i8
  store i8 %55, ptr %53, align 1, !tbaa !10
  %56 = tail call i32 @rand() #2
  %57 = trunc i32 %56 to i8
  %58 = getelementptr inbounds i8, ptr %0, i64 17
  store i8 %57, ptr %58, align 1, !tbaa !10
  %59 = tail call i32 @rand() #2
  %60 = trunc i32 %59 to i8
  %61 = getelementptr inbounds i8, ptr %0, i64 18
  store i8 %60, ptr %61, align 1, !tbaa !10
  %62 = tail call i32 @rand() #2
  %63 = trunc i32 %62 to i8
  %64 = getelementptr inbounds i8, ptr %0, i64 19
  store i8 %63, ptr %64, align 1, !tbaa !10
  %65 = tail call i32 @rand() #2
  %66 = trunc i32 %65 to i8
  %67 = getelementptr inbounds i8, ptr %0, i64 20
  store i8 %66, ptr %67, align 1, !tbaa !10
  %68 = tail call i32 @rand() #2
  %69 = trunc i32 %68 to i8
  %70 = getelementptr inbounds i8, ptr %0, i64 21
  store i8 %69, ptr %70, align 1, !tbaa !10
  %71 = tail call i32 @rand() #2
  %72 = trunc i32 %71 to i8
  %73 = getelementptr inbounds i8, ptr %0, i64 22
  store i8 %72, ptr %73, align 1, !tbaa !10
  %74 = tail call i32 @rand() #2
  %75 = trunc i32 %74 to i8
  %76 = getelementptr inbounds i8, ptr %0, i64 23
  store i8 %75, ptr %76, align 1, !tbaa !10
  %77 = getelementptr inbounds i8, ptr %0, i64 24
  %78 = tail call i32 @rand() #2
  %79 = trunc i32 %78 to i8
  store i8 %79, ptr %77, align 1, !tbaa !10
  %80 = tail call i32 @rand() #2
  %81 = trunc i32 %80 to i8
  %82 = getelementptr inbounds i8, ptr %0, i64 25
  store i8 %81, ptr %82, align 1, !tbaa !10
  %83 = tail call i32 @rand() #2
  %84 = trunc i32 %83 to i8
  %85 = getelementptr inbounds i8, ptr %0, i64 26
  store i8 %84, ptr %85, align 1, !tbaa !10
  %86 = tail call i32 @rand() #2
  %87 = trunc i32 %86 to i8
  %88 = getelementptr inbounds i8, ptr %0, i64 27
  store i8 %87, ptr %88, align 1, !tbaa !10
  %89 = tail call i32 @rand() #2
  %90 = trunc i32 %89 to i8
  %91 = getelementptr inbounds i8, ptr %0, i64 28
  store i8 %90, ptr %91, align 1, !tbaa !10
  %92 = tail call i32 @rand() #2
  %93 = trunc i32 %92 to i8
  %94 = getelementptr inbounds i8, ptr %0, i64 29
  store i8 %93, ptr %94, align 1, !tbaa !10
  %95 = tail call i32 @rand() #2
  %96 = trunc i32 %95 to i8
  %97 = getelementptr inbounds i8, ptr %0, i64 30
  store i8 %96, ptr %97, align 1, !tbaa !10
  %98 = tail call i32 @rand() #2
  %99 = trunc i32 %98 to i8
  %100 = getelementptr inbounds i8, ptr %0, i64 31
  store i8 %99, ptr %100, align 1, !tbaa !10
  %101 = getelementptr inbounds i8, ptr %0, i64 32
  %102 = tail call i32 @rand() #2
  %103 = trunc i32 %102 to i8
  store i8 %103, ptr %101, align 1, !tbaa !10
  %104 = tail call i32 @rand() #2
  %105 = trunc i32 %104 to i8
  %106 = getelementptr inbounds i8, ptr %0, i64 33
  store i8 %105, ptr %106, align 1, !tbaa !10
  %107 = tail call i32 @rand() #2
  %108 = trunc i32 %107 to i8
  %109 = getelementptr inbounds i8, ptr %0, i64 34
  store i8 %108, ptr %109, align 1, !tbaa !10
  %110 = tail call i32 @rand() #2
  %111 = trunc i32 %110 to i8
  %112 = getelementptr inbounds i8, ptr %0, i64 35
  store i8 %111, ptr %112, align 1, !tbaa !10
  %113 = tail call i32 @rand() #2
  %114 = trunc i32 %113 to i8
  %115 = getelementptr inbounds i8, ptr %0, i64 36
  store i8 %114, ptr %115, align 1, !tbaa !10
  %116 = tail call i32 @rand() #2
  %117 = trunc i32 %116 to i8
  %118 = getelementptr inbounds i8, ptr %0, i64 37
  store i8 %117, ptr %118, align 1, !tbaa !10
  %119 = tail call i32 @rand() #2
  %120 = trunc i32 %119 to i8
  %121 = getelementptr inbounds i8, ptr %0, i64 38
  store i8 %120, ptr %121, align 1, !tbaa !10
  %122 = tail call i32 @rand() #2
  %123 = trunc i32 %122 to i8
  %124 = getelementptr inbounds i8, ptr %0, i64 39
  store i8 %123, ptr %124, align 1, !tbaa !10
  %125 = getelementptr inbounds i8, ptr %0, i64 40
  %126 = tail call i32 @rand() #2
  %127 = trunc i32 %126 to i8
  store i8 %127, ptr %125, align 1, !tbaa !10
  %128 = tail call i32 @rand() #2
  %129 = trunc i32 %128 to i8
  %130 = getelementptr inbounds i8, ptr %0, i64 41
  store i8 %129, ptr %130, align 1, !tbaa !10
  %131 = tail call i32 @rand() #2
  %132 = trunc i32 %131 to i8
  %133 = getelementptr inbounds i8, ptr %0, i64 42
  store i8 %132, ptr %133, align 1, !tbaa !10
  %134 = tail call i32 @rand() #2
  %135 = trunc i32 %134 to i8
  %136 = getelementptr inbounds i8, ptr %0, i64 43
  store i8 %135, ptr %136, align 1, !tbaa !10
  %137 = tail call i32 @rand() #2
  %138 = trunc i32 %137 to i8
  %139 = getelementptr inbounds i8, ptr %0, i64 44
  store i8 %138, ptr %139, align 1, !tbaa !10
  %140 = tail call i32 @rand() #2
  %141 = trunc i32 %140 to i8
  %142 = getelementptr inbounds i8, ptr %0, i64 45
  store i8 %141, ptr %142, align 1, !tbaa !10
  %143 = tail call i32 @rand() #2
  %144 = trunc i32 %143 to i8
  %145 = getelementptr inbounds i8, ptr %0, i64 46
  store i8 %144, ptr %145, align 1, !tbaa !10
  %146 = tail call i32 @rand() #2
  %147 = trunc i32 %146 to i8
  %148 = getelementptr inbounds i8, ptr %0, i64 47
  store i8 %147, ptr %148, align 1, !tbaa !10
  %149 = getelementptr inbounds i8, ptr %0, i64 48
  %150 = tail call i32 @rand() #2
  %151 = trunc i32 %150 to i8
  store i8 %151, ptr %149, align 1, !tbaa !10
  %152 = tail call i32 @rand() #2
  %153 = trunc i32 %152 to i8
  %154 = getelementptr inbounds i8, ptr %0, i64 49
  store i8 %153, ptr %154, align 1, !tbaa !10
  %155 = tail call i32 @rand() #2
  %156 = trunc i32 %155 to i8
  %157 = getelementptr inbounds i8, ptr %0, i64 50
  store i8 %156, ptr %157, align 1, !tbaa !10
  %158 = tail call i32 @rand() #2
  %159 = trunc i32 %158 to i8
  %160 = getelementptr inbounds i8, ptr %0, i64 51
  store i8 %159, ptr %160, align 1, !tbaa !10
  %161 = tail call i32 @rand() #2
  %162 = trunc i32 %161 to i8
  %163 = getelementptr inbounds i8, ptr %0, i64 52
  store i8 %162, ptr %163, align 1, !tbaa !10
  %164 = tail call i32 @rand() #2
  %165 = trunc i32 %164 to i8
  %166 = getelementptr inbounds i8, ptr %0, i64 53
  store i8 %165, ptr %166, align 1, !tbaa !10
  %167 = tail call i32 @rand() #2
  %168 = trunc i32 %167 to i8
  %169 = getelementptr inbounds i8, ptr %0, i64 54
  store i8 %168, ptr %169, align 1, !tbaa !10
  %170 = tail call i32 @rand() #2
  %171 = trunc i32 %170 to i8
  %172 = getelementptr inbounds i8, ptr %0, i64 55
  store i8 %171, ptr %172, align 1, !tbaa !10
  %173 = getelementptr inbounds i8, ptr %0, i64 56
  %174 = tail call i32 @rand() #2
  %175 = trunc i32 %174 to i8
  store i8 %175, ptr %173, align 1, !tbaa !10
  %176 = tail call i32 @rand() #2
  %177 = trunc i32 %176 to i8
  %178 = getelementptr inbounds i8, ptr %0, i64 57
  store i8 %177, ptr %178, align 1, !tbaa !10
  %179 = tail call i32 @rand() #2
  %180 = trunc i32 %179 to i8
  %181 = getelementptr inbounds i8, ptr %0, i64 58
  store i8 %180, ptr %181, align 1, !tbaa !10
  %182 = tail call i32 @rand() #2
  %183 = trunc i32 %182 to i8
  %184 = getelementptr inbounds i8, ptr %0, i64 59
  store i8 %183, ptr %184, align 1, !tbaa !10
  %185 = tail call i32 @rand() #2
  %186 = trunc i32 %185 to i8
  %187 = getelementptr inbounds i8, ptr %0, i64 60
  store i8 %186, ptr %187, align 1, !tbaa !10
  %188 = tail call i32 @rand() #2
  %189 = trunc i32 %188 to i8
  %190 = getelementptr inbounds i8, ptr %0, i64 61
  store i8 %189, ptr %190, align 1, !tbaa !10
  %191 = tail call i32 @rand() #2
  %192 = trunc i32 %191 to i8
  %193 = getelementptr inbounds i8, ptr %0, i64 62
  store i8 %192, ptr %193, align 1, !tbaa !10
  %194 = tail call i32 @rand() #2
  %195 = trunc i32 %194 to i8
  %196 = getelementptr inbounds i8, ptr %0, i64 63
  store i8 %195, ptr %196, align 1, !tbaa !10
  %197 = getelementptr inbounds i8, ptr %0, i64 65
  store i8 0, ptr %197, align 1, !tbaa !11
  %198 = getelementptr inbounds i8, ptr %0, i64 72
  store i64 0, ptr %198, align 8, !tbaa !12
  ret void
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #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 "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, !7, i64 64}
!6 = !{!"MerryPredictor", !7, i64 0, !7, i64 64, !7, i64 65, !9, i64 72}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 65}
!12 = !{!6, !9, i64 72}


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