; LLVM IR from intel/qpl :: sources/isal/igzip (igzip_icf_body)

; 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.deflate_icf = type { i32 }

@__const.qpl_set_long_icf_fg_base.dist_start = external hidden unnamed_addr constant [32 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local void @qpl_set_long_icf_fg_base(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca [32 x i32], align 16
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %17, i64 %18
  store ptr %19, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %20, i64 %21
  store ptr %22, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 128, ptr %16) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %16, ptr align 16 @__const.qpl_set_long_icf_fg_base.dist_start, i64 128, i1 false)
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 288
  %26 = icmp ugt ptr %23, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %4
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 288
  store ptr %29, ptr %10, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %27, %4
  br label %31

31:                                               ; preds = %102, %30
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = icmp ult ptr %32, %33
  br i1 %34, label %35, label %107

35:                                               ; preds = %31
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i32, ptr %36, align 4
  %38 = lshr i32 %37, 10
  %39 = and i32 %38, 511
  store i32 %39, ptr %11, align 4, !tbaa !11
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load i32, ptr %40, align 4
  %42 = lshr i32 %41, 19
  store i32 %42, ptr %12, align 4, !tbaa !11
  %43 = load i32, ptr %11, align 4, !tbaa !11
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds [32 x i32], ptr %16, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = load i32, ptr %12, align 4, !tbaa !11
  %48 = add i32 %46, %47
  store i32 %48, ptr %13, align 4, !tbaa !11
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i32, ptr %49, align 4
  %51 = and i32 %50, 1023
  store i32 %51, ptr %14, align 4, !tbaa !11
  %52 = load i32, ptr %14, align 4, !tbaa !11
  %53 = icmp uge i32 %52, 262
  br i1 %53, label %54, label %102

54:                                               ; preds = %35
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i64 8
  %57 = load i32, ptr %13, align 4, !tbaa !11
  %58 = zext i32 %57 to i64
  %59 = sub i64 0, %58
  %60 = getelementptr inbounds i8, ptr %56, i64 %59
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 8
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 8
  %66 = ptrtoint ptr %63 to i64
  %67 = ptrtoint ptr %65 to i64
  %68 = sub i64 %66, %67
  %69 = trunc i64 %68 to i32
  %70 = call i32 @compare(ptr noundef %60, ptr noundef %62, i32 noundef %69)
  %71 = add nsw i32 %70, 254
  %72 = add nsw i32 %71, 8
  store i32 %72, ptr %15, align 4, !tbaa !11
  br label %73

73:                                               ; preds = %91, %54
  %74 = load i32, ptr %15, align 4, !tbaa !11
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = load i32, ptr %75, align 4
  %77 = and i32 %76, 1023
  %78 = icmp ugt i32 %74, %77
  br i1 %78, label %79, label %82

79:                                               ; preds = %73
  %80 = load i32, ptr %15, align 4, !tbaa !11
  %81 = icmp uge i32 %80, 258
  br label %82

82:                                               ; preds = %79, %73
  %83 = phi i1 [ false, %73 ], [ %81, %79 ]
  br i1 %83, label %84, label %101

84:                                               ; preds = %82
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  %86 = load i32, ptr %15, align 4, !tbaa !11
  %87 = icmp ugt i32 %86, 512
  br i1 %87, label %88, label %89

88:                                               ; preds = %84
  br label %91

89:                                               ; preds = %84
  %90 = load i32, ptr %15, align 4, !tbaa !11
  br label %91

91:                                               ; preds = %89, %88
  %92 = phi i32 [ 512, %88 ], [ %90, %89 ]
  %93 = load i32, ptr %11, align 4, !tbaa !11
  %94 = load i32, ptr %12, align 4, !tbaa !11
  call void @write_deflate_icf(ptr noundef %85, i32 noundef %92, i32 noundef %93, i32 noundef %94)
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.deflate_icf, ptr %95, i32 1
  store ptr %96, ptr %8, align 8, !tbaa !5
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds i8, ptr %97, i32 1
  store ptr %98, ptr %5, align 8, !tbaa !5
  %99 = load i32, ptr %15, align 4, !tbaa !11
  %100 = add i32 %99, -1
  store i32 %100, ptr %15, align 4, !tbaa !11
  br label %73, !llvm.loop !13

101:                                              ; preds = %82
  br label %102

102:                                              ; preds = %101, %35
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.deflate_icf, ptr %103, i32 1
  store ptr %104, ptr %8, align 8, !tbaa !5
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = getelementptr inbounds i8, ptr %105, i32 1
  store ptr %106, ptr %5, align 8, !tbaa !5
  br label %31, !llvm.loop !15

107:                                              ; preds = %31
  call void @llvm.lifetime.end.p0(i64 128, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @compare(ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @write_deflate_icf(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #3

; 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@__const.qpl_set_long_icf_fg_base.dist_start = external hidden unnamed_addr constant [32 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local void @qpl_set_long_icf_fg_base(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 %1
  %6 = icmp sgt i64 %1, 0
  br i1 %6, label %.lr.ph45, label %._crit_edge

.lr.ph45:                                         ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 %2
  %8 = getelementptr inbounds i8, ptr %5, i64 288
  %9 = icmp ugt ptr %7, %8
  %spec.select = select i1 %9, ptr %8, ptr %7
  %10 = ptrtoint ptr %spec.select to i64
  br label %11

11:                                               ; preds = %.lr.ph45, %.loopexit
  %.03344 = phi ptr [ %0, %.lr.ph45 ], [ %47, %.loopexit ]
  %.03443 = phi ptr [ %3, %.lr.ph45 ], [ %46, %.loopexit ]
  %12 = load i32, ptr %.03443, align 4
  %13 = lshr i32 %12, 10
  %14 = and i32 %13, 511
  %15 = lshr i32 %12, 19
  %16 = and i32 %12, 1022
  %17 = icmp ugt i32 %16, 261
  br i1 %17, label %18, label %.loopexit

18:                                               ; preds = %11
  %19 = zext nneg i32 %14 to i64
  %20 = getelementptr inbounds [32 x i32], ptr @__const.qpl_set_long_icf_fg_base.dist_start, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add i32 %21, %15
  %23 = getelementptr inbounds i8, ptr %.03344, i64 8
  %24 = zext i32 %22 to i64
  %25 = sub nsw i64 0, %24
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = ptrtoint ptr %23 to i64
  %28 = sub i64 %10, %27
  %29 = trunc i64 %28 to i32
  %30 = tail call i32 @compare(ptr noundef nonnull %26, ptr noundef nonnull %23, i32 noundef %29)
  %31 = add nsw i32 %30, 262
  %32 = load i32, ptr %.03443, align 4
  %33 = and i32 %32, 1023
  %34 = icmp ugt i32 %31, %33
  %35 = icmp ugt i32 %31, 257
  %36 = and i1 %35, %34
  br i1 %36, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %18, %.lr.ph
  %.041 = phi i32 [ %40, %.lr.ph ], [ %31, %18 ]
  %.140 = phi ptr [ %39, %.lr.ph ], [ %.03344, %18 ]
  %.13539 = phi ptr [ %38, %.lr.ph ], [ %.03443, %18 ]
  %37 = tail call i32 @llvm.umin.i32(i32 %.041, i32 512)
  tail call void @write_deflate_icf(ptr noundef nonnull %.13539, i32 noundef %37, i32 noundef %14, i32 noundef %15)
  %38 = getelementptr inbounds i8, ptr %.13539, i64 4
  %39 = getelementptr inbounds i8, ptr %.140, i64 1
  %40 = add i32 %.041, -1
  %41 = load i32, ptr %38, align 4
  %42 = and i32 %41, 1023
  %43 = icmp ugt i32 %40, %42
  %44 = icmp ugt i32 %40, 257
  %45 = and i1 %44, %43
  br i1 %45, label %.lr.ph, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph, %18, %11
  %.236 = phi ptr [ %.03443, %11 ], [ %.03443, %18 ], [ %38, %.lr.ph ]
  %.2 = phi ptr [ %.03344, %11 ], [ %.03344, %18 ], [ %39, %.lr.ph ]
  %46 = getelementptr inbounds i8, ptr %.236, i64 4
  %47 = getelementptr inbounds i8, ptr %.2, i64 1
  %48 = icmp ult ptr %47, %5
  br i1 %48, label %11, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %4
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @compare(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @write_deflate_icf(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #2

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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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