; LLVM IR from fwip/fastqz :: libzpaq.ll (ZN7libzpaq9Predictor4findERNS_5ArrayIhEEij)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7libzpaq6memsetEPvim(ptr noundef, i32 noundef, i64 noundef) #0

; 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK7libzpaq5ArrayIhE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20), i64 noundef) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN7libzpaq9Predictor4findERNS_5ArrayIhEEij(ptr noundef nonnull align 8 dereferenceable(110620) %0, ptr noundef nonnull align 8 dereferenceable(20) %1, i32 noundef %2, i32 noundef %3) #2 align 2 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %15 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = lshr i32 %16, %17
  %19 = and i32 %18, 255
  store i32 %19, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = mul i32 %20, 16
  %22 = zext i32 %21 to i64
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = call noundef i64 @_ZNK7libzpaq5ArrayIhE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %23)
  %25 = sub i64 %24, 16
  %26 = and i64 %22, %25
  store i64 %26, ptr %11, align 8, !tbaa !11
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i64, ptr %11, align 8, !tbaa !11
  %29 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %27, i64 noundef %28)
  %30 = load i8, ptr %29, align 1, !tbaa !13
  %31 = zext i8 %30 to i32
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = icmp eq i32 %31, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %4
  %35 = load i64, ptr %11, align 8, !tbaa !11
  store i64 %35, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %137

36:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %37 = load i64, ptr %11, align 8, !tbaa !11
  %38 = xor i64 %37, 16
  store i64 %38, ptr %13, align 8, !tbaa !11
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i64, ptr %13, align 8, !tbaa !11
  %41 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %39, i64 noundef %40)
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = zext i8 %42 to i32
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = icmp eq i32 %43, %44
  br i1 %45, label %46, label %48

46:                                               ; preds = %36
  %47 = load i64, ptr %13, align 8, !tbaa !11
  store i64 %47, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %136

48:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %49 = load i64, ptr %11, align 8, !tbaa !11
  %50 = xor i64 %49, 32
  store i64 %50, ptr %14, align 8, !tbaa !11
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load i64, ptr %14, align 8, !tbaa !11
  %53 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %51, i64 noundef %52)
  %54 = load i8, ptr %53, align 1, !tbaa !13
  %55 = zext i8 %54 to i32
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = icmp eq i32 %55, %56
  br i1 %57, label %58, label %60

58:                                               ; preds = %48
  %59 = load i64, ptr %14, align 8, !tbaa !11
  store i64 %59, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %135

60:                                               ; preds = %48
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load i64, ptr %11, align 8, !tbaa !11
  %63 = add i64 %62, 1
  %64 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %61, i64 noundef %63)
  %65 = load i8, ptr %64, align 1, !tbaa !13
  %66 = zext i8 %65 to i32
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load i64, ptr %13, align 8, !tbaa !11
  %69 = add i64 %68, 1
  %70 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %67, i64 noundef %69)
  %71 = load i8, ptr %70, align 1, !tbaa !13
  %72 = zext i8 %71 to i32
  %73 = icmp sle i32 %66, %72
  br i1 %73, label %74, label %99

74:                                               ; preds = %60
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = load i64, ptr %11, align 8, !tbaa !11
  %77 = add i64 %76, 1
  %78 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %75, i64 noundef %77)
  %79 = load i8, ptr %78, align 1, !tbaa !13
  %80 = zext i8 %79 to i32
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = load i64, ptr %14, align 8, !tbaa !11
  %83 = add i64 %82, 1
  %84 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %81, i64 noundef %83)
  %85 = load i8, ptr %84, align 1, !tbaa !13
  %86 = zext i8 %85 to i32
  %87 = icmp sle i32 %80, %86
  br i1 %87, label %88, label %99

88:                                               ; preds = %74
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = load i64, ptr %11, align 8, !tbaa !11
  %91 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %89, i64 noundef %90)
  %92 = call noundef ptr @_ZN7libzpaq6memsetEPvim(ptr noundef %91, i32 noundef 0, i64 noundef 16)
  %93 = load i32, ptr %10, align 4, !tbaa !9
  %94 = trunc i32 %93 to i8
  %95 = load ptr, ptr %7, align 8, !tbaa !5
  %96 = load i64, ptr %11, align 8, !tbaa !11
  %97 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %95, i64 noundef %96)
  store i8 %94, ptr %97, align 1, !tbaa !13
  %98 = load i64, ptr %11, align 8, !tbaa !11
  store i64 %98, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %135

99:                                               ; preds = %74, %60
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = load i64, ptr %13, align 8, !tbaa !11
  %102 = add i64 %101, 1
  %103 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %100, i64 noundef %102)
  %104 = load i8, ptr %103, align 1, !tbaa !13
  %105 = zext i8 %104 to i32
  %106 = load ptr, ptr %7, align 8, !tbaa !5
  %107 = load i64, ptr %14, align 8, !tbaa !11
  %108 = add i64 %107, 1
  %109 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %106, i64 noundef %108)
  %110 = load i8, ptr %109, align 1, !tbaa !13
  %111 = zext i8 %110 to i32
  %112 = icmp slt i32 %105, %111
  br i1 %112, label %113, label %124

113:                                              ; preds = %99
  %114 = load ptr, ptr %7, align 8, !tbaa !5
  %115 = load i64, ptr %13, align 8, !tbaa !11
  %116 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %114, i64 noundef %115)
  %117 = call noundef ptr @_ZN7libzpaq6memsetEPvim(ptr noundef %116, i32 noundef 0, i64 noundef 16)
  %118 = load i32, ptr %10, align 4, !tbaa !9
  %119 = trunc i32 %118 to i8
  %120 = load ptr, ptr %7, align 8, !tbaa !5
  %121 = load i64, ptr %13, align 8, !tbaa !11
  %122 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %120, i64 noundef %121)
  store i8 %119, ptr %122, align 1, !tbaa !13
  %123 = load i64, ptr %13, align 8, !tbaa !11
  store i64 %123, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %135

124:                                              ; preds = %99
  %125 = load ptr, ptr %7, align 8, !tbaa !5
  %126 = load i64, ptr %14, align 8, !tbaa !11
  %127 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %125, i64 noundef %126)
  %128 = call noundef ptr @_ZN7libzpaq6memsetEPvim(ptr noundef %127, i32 noundef 0, i64 noundef 16)
  %129 = load i32, ptr %10, align 4, !tbaa !9
  %130 = trunc i32 %129 to i8
  %131 = load ptr, ptr %7, align 8, !tbaa !5
  %132 = load i64, ptr %14, align 8, !tbaa !11
  %133 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %131, i64 noundef %132)
  store i8 %130, ptr %133, align 1, !tbaa !13
  %134 = load i64, ptr %14, align 8, !tbaa !11
  store i64 %134, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %135

135:                                              ; preds = %124, %113, %88, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %136

136:                                              ; preds = %135, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %137

137:                                              ; preds = %136, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %138 = load i64, ptr %5, align 8
  ret i64 %138
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}


; 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 nounwind uwtable
declare dso_local noundef ptr @_ZN7libzpaq6memsetEPvim(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK7libzpaq5ArrayIhE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i64 0, 4294967296) i64 @_ZN7libzpaq9Predictor4findERNS_5ArrayIhEEij(ptr nocapture noundef nonnull readnone align 8 dereferenceable(110620) %0, ptr noundef nonnull align 8 dereferenceable(20) %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 align 2 {
  %5 = lshr i32 %3, %2
  %6 = shl i32 %3, 4
  %7 = zext i32 %6 to i64
  %8 = tail call noundef i64 @_ZNK7libzpaq5ArrayIhE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %1)
  %9 = add i64 %8, 4294967280
  %10 = and i64 %9, %7
  %11 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %1, i64 noundef %10)
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = trunc i32 %5 to i8
  %14 = icmp eq i8 %12, %13
  br i1 %14, label %47, label %15

15:                                               ; preds = %4
  %16 = xor i64 %10, 16
  %17 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %1, i64 noundef %16)
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = icmp eq i8 %18, %13
  br i1 %19, label %47, label %20

20:                                               ; preds = %15
  %21 = xor i64 %10, 32
  %22 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %1, i64 noundef %21)
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = icmp eq i8 %23, %13
  br i1 %24, label %47, label %25

25:                                               ; preds = %20
  %26 = or disjoint i64 %10, 1
  %27 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %1, i64 noundef %26)
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = or disjoint i64 %16, 1
  %30 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %1, i64 noundef %29)
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %.not = icmp ugt i8 %28, %31
  br i1 %.not, label %._crit_edge, label %32

._crit_edge:                                      ; preds = %25
  %.pre = or disjoint i64 %21, 1
  br label %38

32:                                               ; preds = %25
  %33 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %1, i64 noundef %26)
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %35 = or disjoint i64 %21, 1
  %36 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %1, i64 noundef %35)
  %37 = load i8, ptr %36, align 1, !tbaa !5
  %.not50 = icmp ugt i8 %34, %37
  br i1 %.not50, label %38, label %.sink.split

38:                                               ; preds = %._crit_edge, %32
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %35, %32 ]
  %39 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %1, i64 noundef %29)
  %40 = load i8, ptr %39, align 1, !tbaa !5
  %41 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %1, i64 noundef %.pre-phi)
  %42 = load i8, ptr %41, align 1, !tbaa !5
  %43 = icmp ult i8 %40, %42
  %. = select i1 %43, i64 %16, i64 %21
  br label %.sink.split

.sink.split:                                      ; preds = %38, %32
  %.sink52 = phi i64 [ %10, %32 ], [ %., %38 ]
  %44 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %1, i64 noundef %.sink52)
  %45 = tail call noundef ptr @_ZN7libzpaq6memsetEPvim(ptr noundef nonnull %44, i32 noundef 0, i64 noundef 16)
  %46 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %1, i64 noundef %.sink52)
  store i8 %13, ptr %46, align 1, !tbaa !5
  br label %47

47:                                               ; preds = %.sink.split, %15, %20, %4
  %.2 = phi i64 [ %10, %4 ], [ %16, %15 ], [ %21, %20 ], [ %.sink52, %.sink.split ]
  ret i64 %.2
}

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

!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++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass