; LLVM IR from DanEngelbrecht/longtail :: lib/zstd/ext/compress (zstdmt_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.ZSTDMT_CCtx_s = type { ptr, ptr, ptr, ptr, ptr, %struct.ZSTD_CCtx_params_s, i64, i64, i32, %struct.inBuff_t, %struct.roundBuff_t, %struct.serialState_t, %struct.rsyncState_t, i32, i32, i32, i32, i32, i64, i64, i64, %struct.ZSTD_customMem, ptr, ptr, i8 }
%struct.ZSTD_CCtx_params_s = type { i32, %struct.ZSTD_compressionParameters, %struct.ZSTD_frameParameters, i32, i32, i64, i32, i32, i32, i32, i64, i32, i32, %struct.ldmParams_t, i32, i32, i32, i32, i32, i32, i32, i32, %struct.ZSTD_customMem, i32, i32, ptr, ptr, i64, i32 }
%struct.ZSTD_compressionParameters = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.ZSTD_frameParameters = type { i32, i32, i32 }
%struct.ldmParams_t = type { i32, i32, i32, i32, i32, i32 }
%struct.inBuff_t = type { %struct.range_t, %struct.buffer_s, i64 }
%struct.range_t = type { ptr, i64 }
%struct.buffer_s = type { ptr, i64 }
%struct.roundBuff_t = type { ptr, i64, i64 }
%struct.serialState_t = type { i32, i32, %struct.ZSTD_CCtx_params_s, %struct.ldmState_t, %struct.XXH64_state_s, i32, i32, i32, %struct.ZSTD_window_t }
%struct.ldmState_t = type { %struct.ZSTD_window_t, ptr, i32, ptr, [64 x i64], [64 x %struct.ldmMatchCandidate_t] }
%struct.ldmMatchCandidate_t = type { ptr, i32, i32, ptr }
%struct.XXH64_state_s = type { i64, [4 x i64], [4 x i64], i32, i32, i64 }
%struct.ZSTD_window_t = type { ptr, ptr, ptr, i32, i32, i32 }
%struct.rsyncState_t = type { i64, i64, i64 }
%struct.ZSTD_customMem = type { ptr, ptr, ptr }
%struct.ZSTDMT_jobDescription = type { i64, i64, i32, i32, ptr, ptr, ptr, ptr, %struct.buffer_s, %struct.range_t, %struct.range_t, i32, i32, i32, %struct.ZSTD_CCtx_params_s, ptr, i64, i64, 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 i32 @ERR_isError(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTDMT_toFlushNow(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ZSTDMT_CCtx_s, ptr %12, i32 0, i32 14
  %14 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %14, ptr %5, align 4, !tbaa !28
  %15 = load i32, ptr %5, align 4, !tbaa !28
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ZSTDMT_CCtx_s, ptr %16, i32 0, i32 15
  %18 = load i32, ptr %17, align 8, !tbaa !29
  %19 = icmp eq i32 %15, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %1
  store i64 0, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %71

21:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %22 = load i32, ptr %5, align 4, !tbaa !28
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ZSTDMT_CCtx_s, ptr %23, i32 0, i32 13
  %25 = load i32, ptr %24, align 8, !tbaa !30
  %26 = and i32 %22, %25
  store i32 %26, ptr %7, align 4, !tbaa !28
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ZSTDMT_CCtx_s, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !31
  %30 = load i32, ptr %7, align 4, !tbaa !28
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds %struct.ZSTDMT_jobDescription, ptr %29, i64 %31
  store ptr %32, ptr %8, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ZSTDMT_jobDescription, ptr %33, i32 0, i32 2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ZSTDMT_jobDescription, ptr %35, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !32
  store i64 %37, ptr %9, align 8, !tbaa !34
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %38 = load i64, ptr %9, align 8, !tbaa !34
  %39 = call i32 @ERR_isError(i64 noundef %38)
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %21
  br label %44

42:                                               ; preds = %21
  %43 = load i64, ptr %9, align 8, !tbaa !34
  br label %44

44:                                               ; preds = %42, %41
  %45 = phi i64 [ 0, %41 ], [ %43, %42 ]
  store i64 %45, ptr %10, align 8, !tbaa !34
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %46 = load i64, ptr %9, align 8, !tbaa !34
  %47 = call i32 @ERR_isError(i64 noundef %46)
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %44
  br label %54

50:                                               ; preds = %44
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ZSTDMT_jobDescription, ptr %51, i32 0, i32 17
  %53 = load i64, ptr %52, align 8, !tbaa !35
  br label %54

54:                                               ; preds = %50, %49
  %55 = phi i64 [ 0, %49 ], [ %53, %50 ]
  store i64 %55, ptr %11, align 8, !tbaa !34
  %56 = load i64, ptr %10, align 8, !tbaa !34
  %57 = load i64, ptr %11, align 8, !tbaa !34
  %58 = sub i64 %56, %57
  store i64 %58, ptr %4, align 8, !tbaa !34
  %59 = load i64, ptr %4, align 8, !tbaa !34
  %60 = icmp eq i64 %59, 0
  br i1 %60, label %61, label %62

61:                                               ; preds = %54
  br label %62

62:                                               ; preds = %61, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ZSTDMT_CCtx_s, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !31
  %66 = load i32, ptr %7, align 4, !tbaa !28
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds %struct.ZSTDMT_jobDescription, ptr %65, i64 %67
  %69 = getelementptr inbounds %struct.ZSTDMT_jobDescription, ptr %68, i32 0, i32 2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %70 = load i64, ptr %4, align 8, !tbaa !34
  store i64 %70, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %71

71:                                               ; preds = %62, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %72 = load i64, ptr %2, align 8
  ret i64 %72
}

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 = { 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, !12, i64 2852}
!10 = !{!"ZSTDMT_CCtx_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !15, i64 256, !15, i64 264, !12, i64 272, !18, i64 280, !21, i64 320, !22, i64 344, !26, i64 2824, !12, i64 2848, !12, i64 2852, !12, i64 2856, !12, i64 2860, !12, i64 2864, !27, i64 2872, !27, i64 2880, !27, i64 2888, !17, i64 2896, !6, i64 2920, !6, i64 2928, !12, i64 2936}
!11 = !{!"ZSTD_CCtx_params_s", !12, i64 0, !13, i64 4, !14, i64 32, !12, i64 44, !12, i64 48, !15, i64 56, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !15, i64 80, !12, i64 88, !12, i64 92, !16, i64 96, !12, i64 120, !12, i64 124, !12, i64 128, !12, i64 132, !12, i64 136, !12, i64 140, !12, i64 144, !12, i64 148, !17, i64 152, !12, i64 176, !12, i64 180, !6, i64 184, !6, i64 192, !15, i64 200, !12, i64 208}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24}
!14 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!15 = !{!"long", !7, i64 0}
!16 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!17 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!"", !19, i64 0, !20, i64 16, !15, i64 32}
!19 = !{!"", !6, i64 0, !15, i64 8}
!20 = !{!"buffer_s", !6, i64 0, !15, i64 8}
!21 = !{!"", !6, i64 0, !15, i64 8, !15, i64 16}
!22 = !{!"", !12, i64 0, !12, i64 4, !11, i64 8, !23, i64 224, !25, i64 2336, !12, i64 2424, !12, i64 2428, !12, i64 2432, !24, i64 2440}
!23 = !{!"", !24, i64 0, !6, i64 40, !12, i64 48, !6, i64 56, !7, i64 64, !7, i64 576}
!24 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !12, i64 28, !12, i64 32}
!25 = !{!"XXH64_state_s", !15, i64 0, !7, i64 8, !7, i64 40, !12, i64 72, !12, i64 76, !15, i64 80}
!26 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16}
!27 = !{!"long long", !7, i64 0}
!28 = !{!12, !12, i64 0}
!29 = !{!10, !12, i64 2856}
!30 = !{!10, !12, i64 2848}
!31 = !{!10, !6, i64 8}
!32 = !{!33, !15, i64 8}
!33 = !{!"", !15, i64 0, !15, i64 8, !12, i64 16, !12, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !20, i64 56, !19, i64 72, !19, i64 88, !12, i64 104, !12, i64 108, !12, i64 112, !11, i64 120, !6, i64 336, !27, i64 344, !15, i64 352, !12, i64 360}
!34 = !{!15, !15, i64 0}
!35 = !{!33, !15, i64 352}


; 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.ZSTDMT_jobDescription = type { i64, i64, i32, i32, ptr, ptr, ptr, ptr, %struct.buffer_s, %struct.range_t, %struct.range_t, i32, i32, i32, %struct.ZSTD_CCtx_params_s, ptr, i64, i64, i32 }
%struct.buffer_s = type { ptr, i64 }
%struct.range_t = type { ptr, i64 }
%struct.ZSTD_CCtx_params_s = type { i32, %struct.ZSTD_compressionParameters, %struct.ZSTD_frameParameters, i32, i32, i64, i32, i32, i32, i32, i64, i32, i32, %struct.ldmParams_t, i32, i32, i32, i32, i32, i32, i32, i32, %struct.ZSTD_customMem, i32, i32, ptr, ptr, i64, i32 }
%struct.ZSTD_compressionParameters = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.ZSTD_frameParameters = type { i32, i32, i32 }
%struct.ldmParams_t = type { i32, i32, i32, i32, i32, i32 }
%struct.ZSTD_customMem = type { ptr, ptr, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTDMT_toFlushNow(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 2852
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 2856
  %5 = load i32, ptr %4, align 8, !tbaa !27
  %6 = icmp eq i32 %3, %5
  br i1 %6, label %26, label %7

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 2848
  %9 = load i32, ptr %8, align 8, !tbaa !28
  %10 = and i32 %9, %3
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !29
  %13 = zext i32 %10 to i64
  %14 = getelementptr inbounds %struct.ZSTDMT_jobDescription, ptr %12, i64 %13
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !30
  %17 = tail call i32 @ERR_isError(i64 noundef %16)
  %.not = icmp eq i32 %17, 0
  %18 = select i1 %.not, i64 %16, i64 0
  %19 = tail call i32 @ERR_isError(i64 noundef %16)
  %.not20 = icmp eq i32 %19, 0
  br i1 %.not20, label %20, label %23

20:                                               ; preds = %7
  %21 = getelementptr inbounds i8, ptr %14, i64 352
  %22 = load i64, ptr %21, align 8, !tbaa !32
  br label %23

23:                                               ; preds = %7, %20
  %24 = phi i64 [ %22, %20 ], [ 0, %7 ]
  %25 = sub i64 %18, %24
  br label %26

26:                                               ; preds = %1, %23
  %.0 = phi i64 [ %25, %23 ], [ 0, %1 ]
  ret i64 %.0
}

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

!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, !11, i64 2852}
!6 = !{!"ZSTDMT_CCtx_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !14, i64 256, !14, i64 264, !11, i64 272, !17, i64 280, !20, i64 320, !21, i64 344, !25, i64 2824, !11, i64 2848, !11, i64 2852, !11, i64 2856, !11, i64 2860, !11, i64 2864, !26, i64 2872, !26, i64 2880, !26, i64 2888, !16, i64 2896, !7, i64 2920, !7, i64 2928, !11, i64 2936}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"ZSTD_CCtx_params_s", !11, i64 0, !12, i64 4, !13, i64 32, !11, i64 44, !11, i64 48, !14, i64 56, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !14, i64 80, !11, i64 88, !11, i64 92, !15, i64 96, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !11, i64 148, !16, i64 152, !11, i64 176, !11, i64 180, !7, i64 184, !7, i64 192, !14, i64 200, !11, i64 208}
!11 = !{!"int", !8, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!13 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}
!14 = !{!"long", !8, i64 0}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!16 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!17 = !{!"", !18, i64 0, !19, i64 16, !14, i64 32}
!18 = !{!"", !7, i64 0, !14, i64 8}
!19 = !{!"buffer_s", !7, i64 0, !14, i64 8}
!20 = !{!"", !7, i64 0, !14, i64 8, !14, i64 16}
!21 = !{!"", !11, i64 0, !11, i64 4, !10, i64 8, !22, i64 224, !24, i64 2336, !11, i64 2424, !11, i64 2428, !11, i64 2432, !23, i64 2440}
!22 = !{!"", !23, i64 0, !7, i64 40, !11, i64 48, !7, i64 56, !8, i64 64, !8, i64 576}
!23 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !11, i64 24, !11, i64 28, !11, i64 32}
!24 = !{!"XXH64_state_s", !14, i64 0, !8, i64 8, !8, i64 40, !11, i64 72, !11, i64 76, !14, i64 80}
!25 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16}
!26 = !{!"long long", !8, i64 0}
!27 = !{!6, !11, i64 2856}
!28 = !{!6, !11, i64 2848}
!29 = !{!6, !7, i64 8}
!30 = !{!31, !14, i64 8}
!31 = !{!"", !14, i64 0, !14, i64 8, !11, i64 16, !11, i64 20, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !19, i64 56, !18, i64 72, !18, i64 88, !11, i64 104, !11, i64 108, !11, i64 112, !10, i64 120, !7, i64 336, !26, i64 344, !14, i64 352, !11, i64 360}
!32 = !{!31, !14, i64 352}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass