; 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_CustomMem = type { ptr, ptr, ptr, ptr }
%struct.LZ4F_CDict_s = type { %struct.LZ4F_CustomMem, ptr, ptr, ptr }

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @LZ4F_createCDict_advanced(ptr noundef byval(%struct.LZ4F_CustomMem) align 8 %0, ptr noundef %1, i64 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %10, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %11 = call ptr @LZ4F_malloc(i64 noundef 56, ptr noundef byval(%struct.LZ4F_CustomMem) align 8 %0)
  store ptr %11, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %88

15:                                               ; preds = %3
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %16, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %17, ptr align 8 %0, i64 32, i1 false), !tbaa.struct !11
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = icmp ugt i64 %18, 65536
  br i1 %19, label %20, label %25

20:                                               ; preds = %15
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = sub i64 %21, 65536
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 %22
  store ptr %24, ptr %7, align 8, !tbaa !5
  store i64 65536, ptr %6, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %20, %15
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = call ptr @LZ4F_malloc(i64 noundef %26, ptr noundef byval(%struct.LZ4F_CustomMem) align 8 %0)
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %28, i32 0, i32 1
  store ptr %27, ptr %29, align 8, !tbaa !12
  %30 = call ptr @LZ4F_malloc(i64 noundef 16416, ptr noundef byval(%struct.LZ4F_CustomMem) align 8 %0)
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %31, i32 0, i32 2
  store ptr %30, ptr %32, align 8, !tbaa !15
  %33 = call ptr @LZ4F_malloc(i64 noundef 262200, ptr noundef byval(%struct.LZ4F_CustomMem) align 8 %0)
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %34, i32 0, i32 3
  store ptr %33, ptr %35, align 8, !tbaa !16
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !12
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %50

40:                                               ; preds = %25
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %50

45:                                               ; preds = %40
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = icmp ne ptr %48, null
  br i1 %49, label %52, label %50

50:                                               ; preds = %45, %40, %25
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  call void @LZ4F_freeCDict(ptr noundef %51)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %88

52:                                               ; preds = %45
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !12
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %55, ptr align 1 %56, i64 %57, i1 false)
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  %61 = call ptr @LZ4_initStream(ptr noundef %60, i64 noundef 16416)
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %62, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !15
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !12
  %68 = load i64, ptr %6, align 8, !tbaa !9
  %69 = trunc i64 %68 to i32
  %70 = call i32 @LZ4_loadDictSlow(ptr noundef %64, ptr noundef %67, i32 noundef %69)
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %71, i32 0, i32 3
  %73 = load ptr, ptr %72, align 8, !tbaa !16
  %74 = call ptr @LZ4_initStreamHC(ptr noundef %73, i64 noundef 262200)
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %75, i32 0, i32 3
  %77 = load ptr, ptr %76, align 8, !tbaa !16
  call void @LZ4_setCompressionLevel(ptr noundef %77, i32 noundef 9)
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %78, i32 0, i32 3
  %80 = load ptr, ptr %79, align 8, !tbaa !16
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.LZ4F_CDict_s, ptr %81, i32 0, i32 1
  %83 = load ptr, ptr %82, align 8, !tbaa !12
  %84 = load i64, ptr %6, align 8, !tbaa !9
  %85 = trunc i64 %84 to i32
  %86 = call i32 @LZ4_loadDictHC(ptr noundef %80, ptr noundef %83, i32 noundef %85)
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %87, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %88

88:                                               ; preds = %52, %50, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %89 = load ptr, ptr %4, align 8
  ret ptr %89
}

; Function Attrs: nounwind uwtable
declare hidden ptr @LZ4F_malloc(i64 noundef, ptr noundef byval(%struct.LZ4F_CustomMem) align 8) #3

; Function Attrs: nounwind uwtable
declare dso_local void @LZ4F_freeCDict(ptr noundef) #3

declare i32 @LZ4_loadDictSlow(ptr noundef, ptr noundef, i32 noundef) #2

declare ptr @LZ4_initStreamHC(ptr noundef, i64 noundef) #2

declare void @LZ4_setCompressionLevel(ptr noundef, i32 noundef) #2

declare i32 @LZ4_loadDictHC(ptr noundef, ptr noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 8, !5, i64 24, i64 8, !5}
!12 = !{!13, !6, i64 32}
!13 = !{!"LZ4F_CDict_s", !14, i64 0, !6, i64 32, !6, i64 40, !6, i64 48}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!13, !6, i64 40}
!16 = !{!13, !6, i64 48}


; 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_CustomMem = type { ptr, ptr, ptr, ptr }

; Function Attrs: mustprogress 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) #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @LZ4F_createCDict_advanced(ptr noundef byval(%struct.LZ4F_CustomMem) align 8 %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = tail call ptr @LZ4F_malloc(i64 noundef 56, ptr noundef nonnull byval(%struct.LZ4F_CustomMem) align 8 %0)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %32, label %5

5:                                                ; preds = %3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %4, ptr noundef nonnull align 8 dereferenceable(32) %0, i64 32, i1 false), !tbaa.struct !5
  %6 = icmp ugt i64 %2, 65536
  %7 = getelementptr i8, ptr %1, i64 %2
  %8 = getelementptr i8, ptr %7, i64 -65536
  %.028 = tail call i64 @llvm.umin.i64(i64 %2, i64 65536)
  %.027 = select i1 %6, ptr %8, ptr %1
  %9 = tail call ptr @LZ4F_malloc(i64 noundef %.028, ptr noundef nonnull byval(%struct.LZ4F_CustomMem) align 8 %0)
  %10 = getelementptr inbounds i8, ptr %4, i64 32
  store ptr %9, ptr %10, align 8, !tbaa !10
  %11 = tail call ptr @LZ4F_malloc(i64 noundef 16416, ptr noundef nonnull byval(%struct.LZ4F_CustomMem) align 8 %0)
  %12 = getelementptr inbounds i8, ptr %4, i64 40
  store ptr %11, ptr %12, align 8, !tbaa !13
  %13 = tail call ptr @LZ4F_malloc(i64 noundef 262200, ptr noundef nonnull byval(%struct.LZ4F_CustomMem) align 8 %0)
  %14 = getelementptr inbounds i8, ptr %4, i64 48
  store ptr %13, ptr %14, align 8, !tbaa !14
  %15 = load ptr, ptr %10, align 8, !tbaa !10
  %.not32 = icmp eq ptr %15, null
  br i1 %.not32, label %18, label %16

16:                                               ; preds = %5
  %17 = load ptr, ptr %12, align 8, !tbaa !13
  %.not33 = icmp eq ptr %17, null
  %.not34 = icmp eq ptr %13, null
  %or.cond = select i1 %.not33, i1 true, i1 %.not34
  br i1 %or.cond, label %18, label %19

18:                                               ; preds = %16, %5
  tail call void @LZ4F_freeCDict(ptr noundef nonnull %4)
  br label %32

19:                                               ; preds = %16
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %15, ptr align 1 %.027, i64 %.028, i1 false)
  %20 = load ptr, ptr %12, align 8, !tbaa !13
  %21 = tail call ptr @LZ4_initStream(ptr noundef %20, i64 noundef 16416) #4
  %22 = load ptr, ptr %12, align 8, !tbaa !13
  %23 = load ptr, ptr %10, align 8, !tbaa !10
  %24 = trunc nuw nsw i64 %.028 to i32
  %25 = tail call i32 @LZ4_loadDictSlow(ptr noundef %22, ptr noundef %23, i32 noundef %24) #4
  %26 = load ptr, ptr %14, align 8, !tbaa !14
  %27 = tail call ptr @LZ4_initStreamHC(ptr noundef %26, i64 noundef 262200) #4
  %28 = load ptr, ptr %14, align 8, !tbaa !14
  tail call void @LZ4_setCompressionLevel(ptr noundef %28, i32 noundef 9) #4
  %29 = load ptr, ptr %14, align 8, !tbaa !14
  %30 = load ptr, ptr %10, align 8, !tbaa !10
  %31 = tail call i32 @LZ4_loadDictHC(ptr noundef %29, ptr noundef %30, i32 noundef %24) #4
  br label %32

32:                                               ; preds = %3, %19, %18
  %.0 = phi ptr [ %4, %19 ], [ null, %18 ], [ null, %3 ]
  ret ptr %.0
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @LZ4F_freeCDict(ptr noundef) local_unnamed_addr #2

declare i32 @LZ4_loadDictSlow(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @LZ4_initStreamHC(ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @LZ4_setCompressionLevel(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @LZ4_loadDictHC(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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 = !{i64 0, i64 8, !6, i64 8, i64 8, !6, i64 16, i64 8, !6, i64 24, i64 8, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 32}
!11 = !{!"LZ4F_CDict_s", !12, i64 0, !7, i64 32, !7, i64 40, !7, i64 48}
!12 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!13 = !{!11, !7, i64 40}
!14 = !{!11, !7, i64 48}


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