; LLVM IR from DanEngelbrecht/longtail :: lib/lz4/ext (lz4frame)

; 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.LZ4F_cctx_s = type { %struct.LZ4F_CustomMem, %struct.LZ4F_preferences_t, i32, i32, ptr, i64, i64, ptr, ptr, i64, i64, %struct.XXH32_state_s, ptr, i16, i16, i32 }
%struct.LZ4F_CustomMem = type { ptr, ptr, ptr, ptr }
%struct.LZ4F_preferences_t = type { %struct.LZ4F_frameInfo_t, i32, i32, i32, [3 x i32] }
%struct.LZ4F_frameInfo_t = type { i32, i32, i32, i32, i64, i32, i32 }
%struct.XXH32_state_s = type { i32, i32, i32, i32, i32, i32, [4 x i32], i32, i32 }
%union.LZ4_stream_u = type { %struct.LZ4_stream_t_internal }
%struct.LZ4_stream_t_internal = type { [4096 x i32], ptr, ptr, i32, i32, 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @LZ4F_compressFrame_usingCDict(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @LZ4F_compressFrame(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca %struct.LZ4F_cctx_s, align 8
  %13 = alloca %union.LZ4_stream_u, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 216, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 16416, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store ptr %12, ptr %14, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %12, i8 0, i64 216, i1 false)
  %15 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %12, i32 0, i32 2
  store i32 100, ptr %15, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %12, i32 0, i32 6
  store i64 5242880, ptr %16, align 8, !tbaa !20
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %24, label %19

19:                                               ; preds = %5
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.LZ4F_preferences_t, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !21
  %23 = icmp slt i32 %22, 2
  br i1 %23, label %24, label %32

24:                                               ; preds = %19, %5
  %25 = call ptr @LZ4_initStream(ptr noundef %13, i64 noundef 16416)
  %26 = load ptr, ptr %14, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %26, i32 0, i32 12
  store ptr %13, ptr %27, align 8, !tbaa !22
  %28 = load ptr, ptr %14, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %28, i32 0, i32 13
  store i16 1, ptr %29, align 8, !tbaa !23
  %30 = load ptr, ptr %14, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %30, i32 0, i32 14
  store i16 1, ptr %31, align 2, !tbaa !24
  br label %32

32:                                               ; preds = %24, %19
  %33 = load ptr, ptr %14, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = call i64 @LZ4F_compressFrame_usingCDict(ptr noundef %33, ptr noundef %34, i64 noundef %35, ptr noundef %36, i64 noundef %37, ptr noundef null, ptr noundef %38)
  store i64 %39, ptr %11, align 8, !tbaa !9
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %53

42:                                               ; preds = %32
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.LZ4F_preferences_t, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !21
  %46 = icmp sge i32 %45, 2
  br i1 %46, label %47, label %53

47:                                               ; preds = %42
  %48 = load ptr, ptr %14, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %48, i32 0, i32 12
  %50 = load ptr, ptr %49, align 8, !tbaa !22
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %51, i32 0, i32 0
  call void @LZ4F_free(ptr noundef %50, ptr noundef byval(%struct.LZ4F_CustomMem) align 8 %52)
  br label %53

53:                                               ; preds = %47, %42, %32
  %54 = load i64, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 16416, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 216, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  ret i64 %54
}

declare ptr @LZ4_initStream(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @LZ4F_free(ptr noundef, ptr noundef byval(%struct.LZ4F_CustomMem) align 8) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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, !16, i64 88}
!12 = !{!"LZ4F_cctx_s", !13, i64 0, !14, i64 32, !16, i64 88, !16, i64 92, !6, i64 96, !10, i64 104, !10, i64 112, !6, i64 120, !6, i64 128, !10, i64 136, !10, i64 144, !18, i64 152, !6, i64 200, !19, i64 208, !19, i64 210, !16, i64 212}
!13 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"", !15, i64 0, !16, i64 32, !16, i64 36, !16, i64 40, !7, i64 44}
!15 = !{!"", !16, i64 0, !16, i64 4, !16, i64 8, !16, i64 12, !17, i64 16, !16, i64 24, !16, i64 28}
!16 = !{!"int", !7, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = !{!"XXH32_state_s", !16, i64 0, !16, i64 4, !16, i64 8, !16, i64 12, !16, i64 16, !16, i64 20, !7, i64 24, !16, i64 40, !16, i64 44}
!19 = !{!"short", !7, i64 0}
!20 = !{!12, !10, i64 112}
!21 = !{!14, !16, i64 32}
!22 = !{!12, !6, i64 200}
!23 = !{!12, !19, i64 208}
!24 = !{!12, !19, i64 210}


; 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.LZ4F_cctx_s = type { %struct.LZ4F_CustomMem, %struct.LZ4F_preferences_t, i32, i32, ptr, i64, i64, ptr, ptr, i64, i64, %struct.XXH32_state_s, ptr, i16, i16, i32 }
%struct.LZ4F_CustomMem = type { ptr, ptr, ptr, ptr }
%struct.LZ4F_preferences_t = type { %struct.LZ4F_frameInfo_t, i32, i32, i32, [3 x i32] }
%struct.LZ4F_frameInfo_t = type { i32, i32, i32, i32, i64, i32, i32 }
%struct.XXH32_state_s = type { i32, i32, i32, i32, i32, i32, [4 x i32], i32, i32 }
%union.LZ4_stream_u = type { %struct.LZ4_stream_t_internal }
%struct.LZ4_stream_t_internal = type { [4096 x i32], ptr, ptr, i32, i32, i32 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @LZ4F_compressFrame(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = alloca %struct.LZ4F_cctx_s, align 8
  %7 = alloca %union.LZ4_stream_u, align 8
  call void @llvm.lifetime.start.p0(i64 216, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 16416, ptr nonnull %7) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(216) %6, i8 0, i64 216, i1 false)
  %8 = getelementptr inbounds i8, ptr %6, i64 88
  store i32 100, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %6, i64 112
  store i64 5242880, ptr %9, align 8, !tbaa !18
  %10 = icmp eq ptr %4, null
  br i1 %10, label %16, label %11

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %4, i64 32
  %13 = load i32, ptr %12, align 8, !tbaa !19
  %14 = icmp slt i32 %13, 2
  br i1 %14, label %16, label %.thread

.thread:                                          ; preds = %11
  %15 = call i64 @LZ4F_compressFrame_usingCDict(ptr noundef nonnull %6, ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef null, ptr noundef nonnull %4)
  br label %22

16:                                               ; preds = %5, %11
  %17 = call ptr @LZ4_initStream(ptr noundef nonnull %7, i64 noundef 16416) #4
  %18 = getelementptr inbounds i8, ptr %6, i64 200
  store ptr %7, ptr %18, align 8, !tbaa !20
  %19 = getelementptr inbounds i8, ptr %6, i64 208
  store i16 1, ptr %19, align 8, !tbaa !21
  %20 = getelementptr inbounds i8, ptr %6, i64 210
  store i16 1, ptr %20, align 2, !tbaa !22
  %21 = call i64 @LZ4F_compressFrame_usingCDict(ptr noundef nonnull %6, ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef null, ptr noundef %4)
  br i1 %10, label %30, label %22

22:                                               ; preds = %.thread, %16
  %23 = phi i64 [ %15, %.thread ], [ %21, %16 ]
  %24 = getelementptr inbounds i8, ptr %4, i64 32
  %25 = load i32, ptr %24, align 8, !tbaa !19
  %26 = icmp sgt i32 %25, 1
  br i1 %26, label %27, label %30

27:                                               ; preds = %22
  %28 = getelementptr inbounds i8, ptr %6, i64 200
  %29 = load ptr, ptr %28, align 8, !tbaa !20
  call void @LZ4F_free(ptr noundef %29, ptr noundef nonnull byval(%struct.LZ4F_CustomMem) align 8 %6)
  br label %30

30:                                               ; preds = %27, %22, %16
  %31 = phi i64 [ %23, %27 ], [ %23, %22 ], [ %21, %16 ]
  call void @llvm.lifetime.end.p0(i64 16416, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 216, ptr nonnull %6) #4
  ret i64 %31
}

declare ptr @LZ4_initStream(ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @LZ4F_free(ptr noundef, ptr noundef byval(%struct.LZ4F_CustomMem) align 8) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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, !13, i64 88}
!6 = !{!"LZ4F_cctx_s", !7, i64 0, !11, i64 32, !13, i64 88, !13, i64 92, !8, i64 96, !15, i64 104, !15, i64 112, !8, i64 120, !8, i64 128, !15, i64 136, !15, i64 144, !16, i64 152, !8, i64 200, !17, i64 208, !17, i64 210, !13, i64 212}
!7 = !{!"", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"", !12, i64 0, !13, i64 32, !13, i64 36, !13, i64 40, !9, i64 44}
!12 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !14, i64 16, !13, i64 24, !13, i64 28}
!13 = !{!"int", !9, i64 0}
!14 = !{!"long long", !9, i64 0}
!15 = !{!"long", !9, i64 0}
!16 = !{!"XXH32_state_s", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !9, i64 24, !13, i64 40, !13, i64 44}
!17 = !{!"short", !9, i64 0}
!18 = !{!6, !15, i64 112}
!19 = !{!11, !13, i64 32}
!20 = !{!6, !8, i64 200}
!21 = !{!6, !17, i64 208}
!22 = !{!6, !17, i64 210}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass