; 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.isal_zstream = type { ptr, i32, i32, ptr, i32, i32, ptr, i32, i32, ptr, i16, i16, i16, i16, %struct.isal_zstate }
%struct.isal_zstate = type { i32, i32, i32, i32, i32, i32, %struct.BitBuf2, i32, i8, i8, i8, i8, i16, i32, [16 x i8], i32, i32, i32, i32, [65824 x i8], [8192 x i16] }
%struct.BitBuf2 = type { i64, i32, ptr, ptr, ptr }
%struct.level_buf = type { %struct.hufftables_icf, %struct.isal_mod_hist, i32, i32, [328 x i8], ptr, i64, ptr, %union.anon.4 }
%struct.hufftables_icf = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { [31 x %struct.huff_code], [513 x %struct.huff_code] }
%struct.huff_code = type { %union.anon.0 }
%union.anon.0 = type { %struct.anon.1 }
%struct.anon.1 = type { i32 }
%struct.isal_mod_hist = type { [30 x i32], [513 x i32] }
%union.anon.4 = type { %struct.hash_map_buf }
%struct.hash_map_buf = type { [32768 x i16], ptr, ptr, [4096 x %struct.deflate_icf], [288 x %struct.deflate_icf] }
%struct.deflate_icf = type { i32 }

; Function Attrs: nounwind uwtable
declare dso_local void @qpl_set_long_icf_fg_base(ptr noundef, i64 noundef, i64 noundef, ptr 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: nounwind uwtable
declare dso_local i64 @qpl_gen_icf_map_h1_base(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @qpl_icf_body_hash1_fillgreedy_lazy(ptr noundef %0) #0 {
  %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 ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.isal_zstream, ptr %10, i32 0, i32 9
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !16
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.level_buf, ptr %13, i32 0, i32 8
  %15 = getelementptr inbounds %struct.hash_map_buf, ptr %14, i32 0, i32 3
  %16 = getelementptr inbounds [4096 x %struct.deflate_icf], ptr %15, i64 0, i64 0
  store ptr %16, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.level_buf, ptr %18, i32 0, i32 8
  %20 = getelementptr inbounds %struct.hash_map_buf, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !17
  store ptr %21, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.level_buf, ptr %22, i32 0, i32 8
  %24 = getelementptr inbounds %struct.hash_map_buf, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  store ptr %25, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call ptr @compress_icf_map_g(ptr noundef %26, ptr noundef %27, ptr noundef %28)
  store ptr %29, ptr %4, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %51, %1
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = icmp uge ptr %31, %32
  br i1 %33, label %34, label %90

34:                                               ; preds = %30
  store i32 4096, ptr %8, align 4, !tbaa !16
  %35 = load i32, ptr %8, align 4, !tbaa !16
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.isal_zstream, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !18
  %39 = icmp ugt i32 %35, %38
  br i1 %39, label %40, label %44

40:                                               ; preds = %34
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.isal_zstream, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 8, !tbaa !18
  br label %46

44:                                               ; preds = %34
  %45 = load i32, ptr %8, align 4, !tbaa !16
  br label %46

46:                                               ; preds = %44, %40
  %47 = phi i32 [ %43, %40 ], [ %45, %44 ]
  store i32 %47, ptr %8, align 4, !tbaa !16
  %48 = load i32, ptr %8, align 4, !tbaa !16
  %49 = icmp ule i32 %48, 288
  br i1 %49, label %50, label %51

50:                                               ; preds = %46
  br label %90

51:                                               ; preds = %46
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !16
  %55 = zext i32 %54 to i64
  %56 = call i64 @qpl_gen_icf_map_h1_base(ptr noundef %52, ptr noundef %53, i64 noundef %55)
  %57 = trunc i64 %56 to i32
  store i32 %57, ptr %9, align 4, !tbaa !16
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.isal_zstream, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !19
  %61 = load i32, ptr %9, align 4, !tbaa !16
  %62 = zext i32 %61 to i64
  %63 = load i32, ptr %8, align 4, !tbaa !16
  %64 = zext i32 %63 to i64
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  call void @qpl_set_long_icf_fg_base(ptr noundef %60, i64 noundef %62, i64 noundef %64, ptr noundef %65)
  %66 = load i32, ptr %9, align 4, !tbaa !16
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.isal_zstream, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !19
  %70 = zext i32 %66 to i64
  %71 = getelementptr inbounds i8, ptr %69, i64 %70
  store ptr %71, ptr %68, align 8, !tbaa !19
  %72 = load i32, ptr %9, align 4, !tbaa !16
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.isal_zstream, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 8, !tbaa !18
  %76 = sub i32 %75, %72
  store i32 %76, ptr %74, align 8, !tbaa !18
  %77 = load i32, ptr %9, align 4, !tbaa !16
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.isal_zstream, ptr %78, i32 0, i32 2
  %80 = load i32, ptr %79, align 4, !tbaa !20
  %81 = add i32 %80, %77
  store i32 %81, ptr %79, align 4, !tbaa !20
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = load i32, ptr %9, align 4, !tbaa !16
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds %struct.deflate_icf, ptr %82, i64 %84
  store ptr %85, ptr %5, align 8, !tbaa !5
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = call ptr @compress_icf_map_g(ptr noundef %86, ptr noundef %87, ptr noundef %88)
  store ptr %89, ptr %4, align 8, !tbaa !5
  br label %30, !llvm.loop !21

90:                                               ; preds = %50, %30
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.level_buf, ptr %92, i32 0, i32 8
  %94 = getelementptr inbounds %struct.hash_map_buf, ptr %93, i32 0, i32 1
  store ptr %91, ptr %94, align 8, !tbaa !17
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.level_buf, ptr %96, i32 0, i32 8
  %98 = getelementptr inbounds %struct.hash_map_buf, ptr %97, i32 0, i32 2
  store ptr %95, ptr %98, align 8, !tbaa !17
  %99 = load ptr, ptr %2, align 8, !tbaa !5
  call void @icf_body_next_state(ptr noundef %99)
  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 8, 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: nounwind uwtable
declare hidden ptr @compress_icf_map_g(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @icf_body_next_state(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 48}
!10 = !{!"isal_zstream", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !11, i64 24, !11, i64 28, !6, i64 32, !11, i64 40, !11, i64 44, !6, i64 48, !12, i64 56, !12, i64 58, !12, i64 60, !12, i64 62, !13, i64 64}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!"isal_zstate", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !14, i64 24, !11, i64 64, !7, i64 68, !7, i64 69, !7, i64 70, !7, i64 71, !12, i64 72, !11, i64 76, !7, i64 80, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !7, i64 112, !7, i64 65936}
!14 = !{!"BitBuf2", !15, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !11, i64 8}
!19 = !{!10, !6, i64 0}
!20 = !{!10, !11, i64 12}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: nounwind uwtable
declare dso_local void @qpl_set_long_icf_fg_base(ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @qpl_gen_icf_map_h1_base(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @qpl_icf_body_hash1_fillgreedy_lazy(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 48
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 70264
  %5 = getelementptr inbounds i8, ptr %3, i64 70248
  %6 = load ptr, ptr %5, align 8, !tbaa !15
  %7 = getelementptr inbounds i8, ptr %3, i64 70256
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  %9 = tail call ptr @compress_icf_map_g(ptr noundef %0, ptr noundef %6, ptr noundef %8)
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %.not40 = icmp ult ptr %9, %8
  br i1 %.not40, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %11 = getelementptr inbounds i8, ptr %0, i64 12
  %12 = load i32, ptr %10, align 8, !tbaa !16
  %13 = icmp ult i32 %12, 289
  br i1 %13, label %._crit_edge, label %.lr.ph47

14:                                               ; preds = %.lr.ph47
  %15 = load i32, ptr %10, align 8, !tbaa !16
  %16 = icmp ult i32 %15, 289
  br i1 %16, label %._crit_edge, label %.lr.ph47, !llvm.loop !17

.lr.ph47:                                         ; preds = %.lr.ph, %14
  %17 = phi i32 [ %15, %14 ], [ %12, %.lr.ph ]
  %. = tail call i32 @llvm.umin.i32(i32 %17, i32 4096)
  %18 = zext nneg i32 %. to i64
  %19 = tail call i64 @qpl_gen_icf_map_h1_base(ptr noundef nonnull %0, ptr noundef nonnull %4, i64 noundef %18)
  %20 = trunc i64 %19 to i32
  %21 = load ptr, ptr %0, align 8, !tbaa !19
  %22 = and i64 %19, 4294967295
  tail call void @qpl_set_long_icf_fg_base(ptr noundef %21, i64 noundef %22, i64 noundef %18, ptr noundef nonnull %4)
  %23 = load ptr, ptr %0, align 8, !tbaa !19
  %24 = getelementptr inbounds i8, ptr %23, i64 %22
  store ptr %24, ptr %0, align 8, !tbaa !19
  %25 = load i32, ptr %10, align 8, !tbaa !16
  %26 = sub i32 %25, %20
  store i32 %26, ptr %10, align 8, !tbaa !16
  %27 = load i32, ptr %11, align 4, !tbaa !20
  %28 = add i32 %27, %20
  store i32 %28, ptr %11, align 4, !tbaa !20
  %29 = getelementptr inbounds %struct.deflate_icf, ptr %4, i64 %22
  %30 = tail call ptr @compress_icf_map_g(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %29)
  %.not = icmp ult ptr %30, %29
  br i1 %.not, label %._crit_edge, label %14, !llvm.loop !17

._crit_edge:                                      ; preds = %14, %.lr.ph47, %.lr.ph, %1
  %.037.lcssa = phi ptr [ %9, %1 ], [ %9, %.lr.ph ], [ %30, %.lr.ph47 ], [ %30, %14 ]
  %.0.lcssa = phi ptr [ %8, %1 ], [ %8, %.lr.ph ], [ %29, %.lr.ph47 ], [ %29, %14 ]
  store ptr %.037.lcssa, ptr %5, align 8, !tbaa !15
  store ptr %.0.lcssa, ptr %7, align 8, !tbaa !15
  tail call void @icf_body_next_state(ptr noundef nonnull %0)
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden ptr @compress_icf_map_g(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @icf_body_next_state(ptr 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, !7, i64 48}
!6 = !{!"isal_zstream", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !10, i64 24, !10, i64 28, !7, i64 32, !10, i64 40, !10, i64 44, !7, i64 48, !11, i64 56, !11, i64 58, !11, i64 60, !11, i64 62, !12, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"isal_zstate", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !13, i64 24, !10, i64 64, !8, i64 68, !8, i64 69, !8, i64 70, !8, i64 71, !11, i64 72, !10, i64 76, !8, i64 80, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !8, i64 112, !8, i64 65936}
!13 = !{!"BitBuf2", !14, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!14 = !{!"long", !8, i64 0}
!15 = !{!8, !8, i64 0}
!16 = !{!6, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !7, i64 0}
!20 = !{!6, !10, i64 12}


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