; LLVM IR from indygreg/python-zstandard :: zstd (zstd)

; 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.seqStore_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i32, i32 }
%struct.seqDef_s = type { i32, i16, i16 }

; 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: inlinehint nounwind uwtable
declare hidden i32 @ZSTD_highbit32(i32 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @MEM_32bits() #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ZSTD_seqToCodes(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.seqStore_t, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  store ptr %15, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.seqStore_t, ptr %16, i32 0, i32 4
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  store ptr %18, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.seqStore_t, ptr %19, i32 0, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  store ptr %21, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.seqStore_t, ptr %22, i32 0, i32 5
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  store ptr %24, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.seqStore_t, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.seqStore_t, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = ptrtoint ptr %27 to i64
  %32 = ptrtoint ptr %30 to i64
  %33 = sub i64 %31, %32
  %34 = sdiv exact i64 %33, 8
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %7, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !17
  store i32 0, ptr %8, align 4, !tbaa !17
  br label %36

36:                                               ; preds = %93, %1
  %37 = load i32, ptr %8, align 4, !tbaa !17
  %38 = load i32, ptr %7, align 4, !tbaa !17
  %39 = icmp ult i32 %37, %38
  br i1 %39, label %40, label %96

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !17
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds %struct.seqDef_s, ptr %41, i64 %43
  %45 = getelementptr inbounds %struct.seqDef_s, ptr %44, i32 0, i32 1
  %46 = load i16, ptr %45, align 4, !tbaa !18
  %47 = zext i16 %46 to i32
  store i32 %47, ptr %10, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !17
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds %struct.seqDef_s, ptr %48, i64 %50
  %52 = getelementptr inbounds %struct.seqDef_s, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 4, !tbaa !21
  %54 = call i32 @ZSTD_highbit32(i32 noundef %53)
  store i32 %54, ptr %11, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = load i32, ptr %8, align 4, !tbaa !17
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds %struct.seqDef_s, ptr %55, i64 %57
  %59 = getelementptr inbounds %struct.seqDef_s, ptr %58, i32 0, i32 2
  %60 = load i16, ptr %59, align 2, !tbaa !22
  %61 = zext i16 %60 to i32
  store i32 %61, ptr %12, align 4, !tbaa !17
  %62 = load i32, ptr %10, align 4, !tbaa !17
  %63 = call i32 @ZSTD_LLcode(i32 noundef %62)
  %64 = trunc i32 %63 to i8
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !17
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds i8, ptr %65, i64 %67
  store i8 %64, ptr %68, align 1, !tbaa !23
  %69 = load i32, ptr %11, align 4, !tbaa !17
  %70 = trunc i32 %69 to i8
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load i32, ptr %8, align 4, !tbaa !17
  %73 = zext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  store i8 %70, ptr %74, align 1, !tbaa !23
  %75 = load i32, ptr %12, align 4, !tbaa !17
  %76 = call i32 @ZSTD_MLcode(i32 noundef %75)
  %77 = trunc i32 %76 to i8
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = load i32, ptr %8, align 4, !tbaa !17
  %80 = zext i32 %79 to i64
  %81 = getelementptr inbounds i8, ptr %78, i64 %80
  store i8 %77, ptr %81, align 1, !tbaa !23
  %82 = call i32 @MEM_32bits()
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %92

84:                                               ; preds = %40
  %85 = load i32, ptr %11, align 4, !tbaa !17
  %86 = call i32 @MEM_32bits()
  %87 = icmp ne i32 %86, 0
  %88 = zext i1 %87 to i64
  %89 = select i1 %87, i32 25, i32 57
  %90 = icmp uge i32 %85, %89
  br i1 %90, label %91, label %92

91:                                               ; preds = %84
  store i32 1, ptr %9, align 4, !tbaa !17
  br label %92

92:                                               ; preds = %91, %84, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %8, align 4, !tbaa !17
  %95 = add i32 %94, 1
  store i32 %95, ptr %8, align 4, !tbaa !17
  br label %36, !llvm.loop !24

96:                                               ; preds = %36
  %97 = load ptr, ptr %2, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.seqStore_t, ptr %97, i32 0, i32 9
  %99 = load i32, ptr %98, align 8, !tbaa !26
  %100 = icmp eq i32 %99, 1
  br i1 %100, label %101, label %108

101:                                              ; preds = %96
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = load ptr, ptr %2, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.seqStore_t, ptr %103, i32 0, i32 10
  %105 = load i32, ptr %104, align 4, !tbaa !27
  %106 = zext i32 %105 to i64
  %107 = getelementptr inbounds i8, ptr %102, i64 %106
  store i8 35, ptr %107, align 1, !tbaa !23
  br label %108

108:                                              ; preds = %101, %96
  %109 = load ptr, ptr %2, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.seqStore_t, ptr %109, i32 0, i32 9
  %111 = load i32, ptr %110, align 8, !tbaa !26
  %112 = icmp eq i32 %111, 2
  br i1 %112, label %113, label %120

113:                                              ; preds = %108
  %114 = load ptr, ptr %6, align 8, !tbaa !5
  %115 = load ptr, ptr %2, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.seqStore_t, ptr %115, i32 0, i32 10
  %117 = load i32, ptr %116, align 4, !tbaa !27
  %118 = zext i32 %117 to i64
  %119 = getelementptr inbounds i8, ptr %114, i64 %118
  store i8 52, ptr %119, align 1, !tbaa !23
  br label %120

120:                                              ; preds = %113, %108
  %121 = load i32, ptr %9, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i32 %121
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ZSTD_LLcode(i32 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ZSTD_MLcode(i32 noundef) #1

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


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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ZSTD_highbit32(i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @MEM_32bits() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ZSTD_seqToCodes(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load ptr, ptr %3, align 8, !tbaa !12
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load ptr, ptr %5, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = ptrtoint ptr %10 to i64
  %12 = ptrtoint ptr %2 to i64
  %13 = sub i64 %11, %12
  %14 = and i64 %13, 34359738360
  %.not36 = icmp eq i64 %14, 0
  br i1 %.not36, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %15 = lshr exact i64 %13, 3
  %wide.trip.count = and i64 %15, 4294967295
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %37
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %37 ]
  %.03134 = phi i32 [ 0, %.lr.ph.preheader ], [ %.1, %37 ]
  %16 = getelementptr inbounds %struct.seqDef_s, ptr %2, i64 %indvars.iv
  %17 = getelementptr inbounds i8, ptr %16, i64 4
  %18 = load i16, ptr %17, align 4, !tbaa !16
  %19 = zext i16 %18 to i32
  %20 = load i32, ptr %16, align 4, !tbaa !19
  %21 = tail call i32 @ZSTD_highbit32(i32 noundef %20)
  %22 = getelementptr inbounds i8, ptr %16, i64 6
  %23 = load i16, ptr %22, align 2, !tbaa !20
  %24 = zext i16 %23 to i32
  %25 = tail call i32 @ZSTD_LLcode(i32 noundef %19)
  %26 = trunc i32 %25 to i8
  %27 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv
  store i8 %26, ptr %27, align 1, !tbaa !21
  %28 = trunc i32 %21 to i8
  %29 = getelementptr inbounds i8, ptr %6, i64 %indvars.iv
  store i8 %28, ptr %29, align 1, !tbaa !21
  %30 = tail call i32 @ZSTD_MLcode(i32 noundef %24)
  %31 = trunc i32 %30 to i8
  %32 = getelementptr inbounds i8, ptr %8, i64 %indvars.iv
  store i8 %31, ptr %32, align 1, !tbaa !21
  %33 = tail call i32 @MEM_32bits()
  %.not = icmp eq i32 %33, 0
  br i1 %.not, label %37, label %34

34:                                               ; preds = %.lr.ph
  %35 = tail call i32 @MEM_32bits()
  %.not32 = icmp eq i32 %35, 0
  %36 = select i1 %.not32, i32 57, i32 25
  %.not33 = icmp ult i32 %21, %36
  %spec.select = select i1 %.not33, i32 %.03134, i32 1
  br label %37

37:                                               ; preds = %34, %.lr.ph
  %.1 = phi i32 [ %.03134, %.lr.ph ], [ %spec.select, %34 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !22

._crit_edge:                                      ; preds = %37, %1
  %.031.lcssa = phi i32 [ 0, %1 ], [ %.1, %37 ]
  %38 = getelementptr inbounds i8, ptr %0, i64 72
  %39 = load i32, ptr %38, align 8, !tbaa !24
  %40 = icmp eq i32 %39, 1
  br i1 %40, label %41, label %46

41:                                               ; preds = %._crit_edge
  %42 = getelementptr inbounds i8, ptr %0, i64 76
  %43 = load i32, ptr %42, align 4, !tbaa !25
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %4, i64 %44
  store i8 35, ptr %45, align 1, !tbaa !21
  %.pr = load i32, ptr %38, align 8, !tbaa !24
  br label %46

46:                                               ; preds = %41, %._crit_edge
  %47 = phi i32 [ %.pr, %41 ], [ %39, %._crit_edge ]
  %48 = icmp eq i32 %47, 2
  br i1 %48, label %49, label %54

49:                                               ; preds = %46
  %50 = getelementptr inbounds i8, ptr %0, i64 76
  %51 = load i32, ptr %50, align 4, !tbaa !25
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %8, i64 %52
  store i8 52, ptr %53, align 1, !tbaa !21
  br label %54

54:                                               ; preds = %49, %46
  ret i32 %.031.lcssa
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ZSTD_LLcode(i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ZSTD_MLcode(i32 noundef) local_unnamed_addr #0

attributes #0 = { inlinehint 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 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !10, i64 64, !11, i64 72, !11, i64 76}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 32}
!13 = !{!6, !7, i64 48}
!14 = !{!6, !7, i64 40}
!15 = !{!6, !7, i64 8}
!16 = !{!17, !18, i64 4}
!17 = !{!"seqDef_s", !11, i64 0, !18, i64 4, !18, i64 6}
!18 = !{!"short", !8, i64 0}
!19 = !{!17, !11, i64 0}
!20 = !{!17, !18, i64 6}
!21 = !{!8, !8, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!6, !11, i64 72}
!25 = !{!6, !11, i64 76}


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