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

; Function Attrs: nounwind uwtable
declare dso_local i32 @LZ4F_isError(i64 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @LZ4F_returnErrorCode(i32 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
define dso_local i64 @LZ4F_compressEnd(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #0 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %15, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %16, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load i64, ptr %8, align 8, !tbaa !9
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = call i64 @LZ4F_flush(ptr noundef %17, ptr noundef %18, i64 noundef %19, ptr noundef %20)
  store i64 %21, ptr %12, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %4
  %23 = load i64, ptr %12, align 8, !tbaa !9
  %24 = call i32 @LZ4F_isError(i64 noundef %23)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %22
  %27 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %27, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %101

28:                                               ; preds = %22
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = load i64, ptr %12, align 8, !tbaa !9
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 %31
  store ptr %33, ptr %11, align 8, !tbaa !5
  %34 = load i64, ptr %12, align 8, !tbaa !9
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = sub i64 %35, %34
  store i64 %36, ptr %8, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %30
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = icmp ult i64 %38, 4
  br i1 %39, label %40, label %42

40:                                               ; preds = %37
  %41 = call i64 @LZ4F_returnErrorCode(i32 noundef 11)
  store i64 %41, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %101

42:                                               ; preds = %37
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  call void @LZ4F_writeLE32(ptr noundef %45, i32 noundef 0)
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 4
  store ptr %47, ptr %11, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %48, i32 0, i32 1
  %50 = getelementptr inbounds %struct.LZ4F_preferences_t, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds %struct.LZ4F_frameInfo_t, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 8, !tbaa !11
  %53 = icmp eq i32 %52, 1
  br i1 %53, label %54, label %73

54:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %55, i32 0, i32 11
  %57 = call i32 @XXH32_digest(ptr noundef %56)
  store i32 %57, ptr %14, align 4, !tbaa !20
  br label %58

58:                                               ; preds = %54
  %59 = load i64, ptr %8, align 8, !tbaa !9
  %60 = icmp ult i64 %59, 8
  br i1 %60, label %61, label %63

61:                                               ; preds = %58
  %62 = call i64 @LZ4F_returnErrorCode(i32 noundef 11)
  store i64 %62, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %70

63:                                               ; preds = %58
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = load i32, ptr %14, align 4, !tbaa !20
  call void @LZ4F_writeLE32(ptr noundef %66, i32 noundef %67)
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 4
  store ptr %69, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %13, align 4
  br label %70

70:                                               ; preds = %65, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %71 = load i32, ptr %13, align 4
  switch i32 %71, label %101 [
    i32 0, label %72
  ]

72:                                               ; preds = %70
  br label %73

73:                                               ; preds = %72, %44
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %74, i32 0, i32 3
  store i32 0, ptr %75, align 4, !tbaa !21
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %76, i32 0, i32 1
  %78 = getelementptr inbounds %struct.LZ4F_preferences_t, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds %struct.LZ4F_frameInfo_t, ptr %78, i32 0, i32 4
  %80 = load i64, ptr %79, align 8, !tbaa !22
  %81 = icmp ne i64 %80, 0
  br i1 %81, label %82, label %95

82:                                               ; preds = %73
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %83, i32 0, i32 1
  %85 = getelementptr inbounds %struct.LZ4F_preferences_t, ptr %84, i32 0, i32 0
  %86 = getelementptr inbounds %struct.LZ4F_frameInfo_t, ptr %85, i32 0, i32 4
  %87 = load i64, ptr %86, align 8, !tbaa !22
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %88, i32 0, i32 10
  %90 = load i64, ptr %89, align 8, !tbaa !23
  %91 = icmp ne i64 %87, %90
  br i1 %91, label %92, label %94

92:                                               ; preds = %82
  %93 = call i64 @LZ4F_returnErrorCode(i32 noundef 14)
  store i64 %93, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %101

94:                                               ; preds = %82
  br label %95

95:                                               ; preds = %94, %73
  %96 = load ptr, ptr %11, align 8, !tbaa !5
  %97 = load ptr, ptr %10, align 8, !tbaa !5
  %98 = ptrtoint ptr %96 to i64
  %99 = ptrtoint ptr %97 to i64
  %100 = sub i64 %98, %99
  store i64 %100, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %101

101:                                              ; preds = %95, %92, %70, %40, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %102 = load i64, ptr %5, align 8
  ret i64 %102
}

; Function Attrs: nounwind uwtable
declare hidden void @LZ4F_writeLE32(ptr noundef, i32 noundef) #0

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

declare i32 @XXH32_digest(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 = { "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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !16, i64 40}
!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 = !{!16, !16, i64 0}
!21 = !{!12, !16, i64 92}
!22 = !{!12, !17, i64 48}
!23 = !{!12, !10, i64 144}


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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @LZ4F_compressEnd(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = tail call i64 @LZ4F_flush(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3)
  %6 = tail call i32 @LZ4F_isError(i64 noundef %5)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %38

7:                                                ; preds = %4
  %8 = sub i64 %2, %5
  %9 = icmp ult i64 %8, 4
  br i1 %9, label %10, label %12

10:                                               ; preds = %7
  %11 = tail call i64 @LZ4F_returnErrorCode(i32 noundef 11)
  br label %38

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %1, i64 %5
  tail call void @LZ4F_writeLE32(ptr noundef %13, i32 noundef 0)
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  %16 = load i32, ptr %15, align 8, !tbaa !5
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %25

18:                                               ; preds = %12
  %19 = getelementptr inbounds i8, ptr %0, i64 152
  %20 = tail call i32 @XXH32_digest(ptr noundef nonnull %19) #2
  %21 = icmp ugt i64 %8, 7
  br i1 %21, label %.thread, label %23

.thread:                                          ; preds = %18
  tail call void @LZ4F_writeLE32(ptr noundef nonnull %14, i32 noundef %20)
  %22 = getelementptr inbounds i8, ptr %13, i64 8
  br label %25

23:                                               ; preds = %18
  %24 = tail call i64 @LZ4F_returnErrorCode(i32 noundef 11)
  br label %38

25:                                               ; preds = %.thread, %12
  %.130 = phi ptr [ %14, %12 ], [ %22, %.thread ]
  %26 = getelementptr inbounds i8, ptr %0, i64 92
  store i32 0, ptr %26, align 4, !tbaa !18
  %27 = getelementptr inbounds i8, ptr %0, i64 48
  %28 = load i64, ptr %27, align 8, !tbaa !19
  %.not33 = icmp eq i64 %28, 0
  br i1 %.not33, label %34, label %29

29:                                               ; preds = %25
  %30 = getelementptr inbounds i8, ptr %0, i64 144
  %31 = load i64, ptr %30, align 8, !tbaa !20
  %.not34 = icmp eq i64 %28, %31
  br i1 %.not34, label %34, label %32

32:                                               ; preds = %29
  %33 = tail call i64 @LZ4F_returnErrorCode(i32 noundef 14)
  br label %38

34:                                               ; preds = %29, %25
  %35 = ptrtoint ptr %.130 to i64
  %36 = ptrtoint ptr %1 to i64
  %37 = sub i64 %35, %36
  br label %38

38:                                               ; preds = %23, %4, %34, %32, %10
  %.1 = phi i64 [ %11, %10 ], [ %33, %32 ], [ %37, %34 ], [ %24, %23 ], [ %5, %4 ]
  ret i64 %.1
}

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

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

declare i32 @XXH32_digest(ptr noundef) local_unnamed_addr #1

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 = { "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, !13, i64 40}
!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, !13, i64 92}
!19 = !{!6, !14, i64 48}
!20 = !{!6, !15, i64 144}


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