; LLVM IR from catid/Zpng :: zstd (zstd_compress)

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

34:                                               ; preds = %79, %1
  %35 = load i32, ptr %8, align 4, !tbaa !16
  %36 = load i32, ptr %7, align 4, !tbaa !16
  %37 = icmp ult i32 %35, %36
  br i1 %37, label %38, label %82

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

79:                                               ; preds = %38
  %80 = load i32, ptr %8, align 4, !tbaa !16
  %81 = add i32 %80, 1
  store i32 %81, ptr %8, align 4, !tbaa !16
  br label %34, !llvm.loop !23

82:                                               ; preds = %34
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.seqStore_t, ptr %83, i32 0, i32 7
  %85 = load i32, ptr %84, align 8, !tbaa !25
  %86 = icmp eq i32 %85, 1
  br i1 %86, label %87, label %94

87:                                               ; preds = %82
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = load ptr, ptr %2, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.seqStore_t, ptr %89, i32 0, i32 8
  %91 = load i32, ptr %90, align 4, !tbaa !26
  %92 = zext i32 %91 to i64
  %93 = getelementptr inbounds i8, ptr %88, i64 %92
  store i8 35, ptr %93, align 1, !tbaa !21
  br label %94

94:                                               ; preds = %87, %82
  %95 = load ptr, ptr %2, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.seqStore_t, ptr %95, i32 0, i32 7
  %97 = load i32, ptr %96, align 8, !tbaa !25
  %98 = icmp eq i32 %97, 2
  br i1 %98, label %99, label %106

99:                                               ; preds = %94
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = load ptr, ptr %2, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.seqStore_t, ptr %101, i32 0, i32 8
  %103 = load i32, ptr %102, align 4, !tbaa !26
  %104 = zext i32 %103 to i64
  %105 = getelementptr inbounds i8, ptr %100, i64 %104
  store i8 52, ptr %105, align 1, !tbaa !21
  br label %106

106:                                              ; preds = %99, %94
  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 void
}

; 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 60}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 32}
!13 = !{!10, !6, i64 48}
!14 = !{!10, !6, i64 40}
!15 = !{!10, !6, i64 8}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !19, i64 4}
!18 = !{!"seqDef_s", !11, i64 0, !19, i64 4, !19, i64 6}
!19 = !{!"short", !7, i64 0}
!20 = !{!18, !19, i64 6}
!21 = !{!7, !7, i64 0}
!22 = !{!18, !11, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!10, !11, i64 56}
!26 = !{!10, !11, i64 60}


; 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: nounwind uwtable
define dso_local void @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 !11
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = ptrtoint ptr %10 to i64
  %12 = ptrtoint ptr %2 to i64
  %13 = sub i64 %11, %12
  %14 = and i64 %13, 34359738360
  %.not = icmp eq i64 %14, 0
  br i1 %.not, 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, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %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 !15
  %19 = zext i16 %18 to i32
  %20 = getelementptr inbounds i8, ptr %16, i64 6
  %21 = load i16, ptr %20, align 2, !tbaa !18
  %22 = zext i16 %21 to i32
  %23 = tail call i32 @ZSTD_LLcode(i32 noundef %19)
  %24 = trunc i32 %23 to i8
  %25 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv
  store i8 %24, ptr %25, align 1, !tbaa !19
  %26 = load i32, ptr %16, align 4, !tbaa !20
  %27 = tail call i32 @ZSTD_highbit32(i32 noundef %26)
  %28 = trunc i32 %27 to i8
  %29 = getelementptr inbounds i8, ptr %6, i64 %indvars.iv
  store i8 %28, ptr %29, align 1, !tbaa !19
  %30 = tail call i32 @ZSTD_MLcode(i32 noundef %22)
  %31 = trunc i32 %30 to i8
  %32 = getelementptr inbounds i8, ptr %8, i64 %indvars.iv
  store i8 %31, ptr %32, align 1, !tbaa !19
  %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 !21

._crit_edge:                                      ; preds = %.lr.ph, %1
  %33 = getelementptr inbounds i8, ptr %0, i64 56
  %34 = load i32, ptr %33, align 8, !tbaa !23
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %36, label %41

36:                                               ; preds = %._crit_edge
  %37 = getelementptr inbounds i8, ptr %0, i64 60
  %38 = load i32, ptr %37, align 4, !tbaa !24
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %4, i64 %39
  store i8 35, ptr %40, align 1, !tbaa !19
  %.pr = load i32, ptr %33, align 8, !tbaa !23
  br label %41

41:                                               ; preds = %36, %._crit_edge
  %42 = phi i32 [ %.pr, %36 ], [ %34, %._crit_edge ]
  %43 = icmp eq i32 %42, 2
  br i1 %43, label %44, label %49

44:                                               ; preds = %41
  %45 = getelementptr inbounds i8, ptr %0, i64 60
  %46 = load i32, ptr %45, align 4, !tbaa !24
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %8, i64 %47
  store i8 52, ptr %48, align 1, !tbaa !19
  br label %49

49:                                               ; preds = %44, %41
  ret void
}

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


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