; 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: 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: nounwind uwtable
declare hidden ptr @compress_icf_map_g(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @icf_body_next_state(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @qpl_icf_body_lazyhash1_fillgreedy_greedy(ptr noundef %0) #1 {
  %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) #4
  %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 %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %13 = load ptr, ptr %3, 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 %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %17, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = load ptr, ptr %3, 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 !16
  store ptr %21, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %22 = load ptr, ptr %3, 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 !16
  store ptr %25, ptr %7, align 8, !tbaa !5
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call ptr @compress_icf_map_g(ptr noundef %26, ptr noundef %27, ptr noundef %28)
  store ptr %29, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !17
  br label %30

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

34:                                               ; preds = %30
  store i32 4096, ptr %8, align 4, !tbaa !17
  %35 = load i32, ptr %8, align 4, !tbaa !17
  %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 !17
  br label %46

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

50:                                               ; preds = %46
  br label %89

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

89:                                               ; preds = %50, %30
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.level_buf, ptr %91, i32 0, i32 8
  %93 = getelementptr inbounds %struct.hash_map_buf, ptr %92, i32 0, i32 1
  store ptr %90, ptr %93, align 8, !tbaa !16
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.level_buf, ptr %95, i32 0, i32 8
  %97 = getelementptr inbounds %struct.hash_map_buf, ptr %96, i32 0, i32 2
  store ptr %94, ptr %97, align 8, !tbaa !16
  %98 = load ptr, ptr %2, align 8, !tbaa !5
  call void @icf_body_next_state(ptr noundef %98)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

declare i64 @qpl_gen_icf_map_lh1(ptr noundef, ptr noundef, i32 noundef) #3

declare void @qpl_set_long_icf_fg(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { "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, !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 = !{!7, !7, i64 0}
!17 = !{!11, !11, 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 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: nounwind uwtable
define dso_local void @qpl_icf_body_lazyhash1_fillgreedy_greedy(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 = tail call i64 @qpl_gen_icf_map_lh1(ptr noundef nonnull %0, ptr noundef nonnull %4, i32 noundef %.) #4
  %19 = trunc i64 %18 to i32
  %20 = load ptr, ptr %0, align 8, !tbaa !19
  %21 = and i64 %18, 4294967295
  %22 = zext nneg i32 %. to i64
  tail call void @qpl_set_long_icf_fg(ptr noundef %20, i64 noundef %21, i64 noundef %22, ptr noundef nonnull %4) #4
  %23 = load ptr, ptr %0, align 8, !tbaa !19
  %24 = getelementptr inbounds i8, ptr %23, i64 %21
  store ptr %24, ptr %0, align 8, !tbaa !19
  %25 = load i32, ptr %10, align 8, !tbaa !16
  %26 = sub i32 %25, %19
  store i32 %26, ptr %10, align 8, !tbaa !16
  %27 = load i32, ptr %11, align 4, !tbaa !20
  %28 = add i32 %27, %19
  store i32 %28, ptr %11, align 4, !tbaa !20
  %29 = getelementptr inbounds %struct.deflate_icf, ptr %4, i64 %21
  %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
}

declare i64 @qpl_gen_icf_map_lh1(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @qpl_set_long_icf_fg(ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

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

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