; LLVM IR from Iotic-Labs/py-lz4framed :: lz4 (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_preferences_t, i32, i32, ptr, i64, i64, ptr, ptr, i64, i64, %struct.XXH32_state_s, ptr, i16, i16 }
%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 @err0r(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
  %22 = load i64, ptr %12, align 8, !tbaa !9
  %23 = call i32 @LZ4F_isError(i64 noundef %22)
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %27

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

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

36:                                               ; preds = %27
  %37 = call i64 @err0r(i32 noundef 11)
  store i64 %37, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %94

38:                                               ; preds = %27
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  call void @LZ4F_writeLE32(ptr noundef %39, i32 noundef 0)
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 4
  store ptr %41, ptr %11, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.LZ4F_preferences_t, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds %struct.LZ4F_frameInfo_t, ptr %44, i32 0, i32 2
  %46 = load i32, ptr %45, align 8, !tbaa !11
  %47 = icmp eq i32 %46, 1
  br i1 %47, label %48, label %64

48:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %49, i32 0, i32 10
  %51 = call i32 @XXH32_digest(ptr noundef %50)
  store i32 %51, ptr %14, align 4, !tbaa !19
  %52 = load i64, ptr %8, align 8, !tbaa !9
  %53 = icmp ult i64 %52, 8
  br i1 %53, label %54, label %56

54:                                               ; preds = %48
  %55 = call i64 @err0r(i32 noundef 11)
  store i64 %55, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %61

56:                                               ; preds = %48
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = load i32, ptr %14, align 4, !tbaa !19
  call void @LZ4F_writeLE32(ptr noundef %57, i32 noundef %58)
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 4
  store ptr %60, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %13, align 4
  br label %61

61:                                               ; preds = %56, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %62 = load i32, ptr %13, align 4
  switch i32 %62, label %94 [
    i32 0, label %63
  ]

63:                                               ; preds = %61
  br label %64

64:                                               ; preds = %63, %38
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %65, i32 0, i32 2
  store i32 0, ptr %66, align 4, !tbaa !20
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %67, i32 0, i32 5
  store i64 0, ptr %68, align 8, !tbaa !21
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %69, i32 0, i32 0
  %71 = getelementptr inbounds %struct.LZ4F_preferences_t, ptr %70, i32 0, i32 0
  %72 = getelementptr inbounds %struct.LZ4F_frameInfo_t, ptr %71, i32 0, i32 4
  %73 = load i64, ptr %72, align 8, !tbaa !22
  %74 = icmp ne i64 %73, 0
  br i1 %74, label %75, label %88

75:                                               ; preds = %64
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %76, i32 0, i32 0
  %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 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %81, i32 0, i32 9
  %83 = load i64, ptr %82, align 8, !tbaa !23
  %84 = icmp ne i64 %80, %83
  br i1 %84, label %85, label %87

85:                                               ; preds = %75
  %86 = call i64 @err0r(i32 noundef 14)
  store i64 %86, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %94

87:                                               ; preds = %75
  br label %88

88:                                               ; preds = %87, %64
  %89 = load ptr, ptr %11, align 8, !tbaa !5
  %90 = load ptr, ptr %10, align 8, !tbaa !5
  %91 = ptrtoint ptr %89 to i64
  %92 = ptrtoint ptr %90 to i64
  %93 = sub i64 %91, %92
  store i64 %93, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %94

94:                                               ; preds = %88, %85, %61, %36, %25
  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
  %95 = load i64, ptr %5, align 8
  ret i64 %95
}

; 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, !15, i64 8}
!12 = !{!"LZ4F_cctx_s", !13, i64 0, !15, i64 56, !15, i64 60, !6, i64 64, !10, i64 72, !10, i64 80, !6, i64 88, !6, i64 96, !10, i64 104, !10, i64 112, !17, i64 120, !6, i64 168, !18, i64 176, !18, i64 178}
!13 = !{!"", !14, i64 0, !15, i64 32, !15, i64 36, !15, i64 40, !7, i64 44}
!14 = !{!"", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12, !16, i64 16, !15, i64 24, !15, i64 28}
!15 = !{!"int", !7, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = !{!"XXH32_state_s", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20, !7, i64 24, !15, i64 40, !15, i64 44}
!18 = !{!"short", !7, i64 0}
!19 = !{!15, !15, i64 0}
!20 = !{!12, !15, i64 60}
!21 = !{!12, !10, i64 80}
!22 = !{!12, !16, i64 16}
!23 = !{!12, !10, i64 112}


; 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 @err0r(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 %39

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 @err0r(i32 noundef 11)
  br label %39

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 8
  %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 120
  %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 @err0r(i32 noundef 11)
  br label %39

25:                                               ; preds = %.thread, %12
  %.131 = phi ptr [ %14, %12 ], [ %22, %.thread ]
  %26 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 0, ptr %26, align 4, !tbaa !17
  %27 = getelementptr inbounds i8, ptr %0, i64 80
  store i64 0, ptr %27, align 8, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  %29 = load i64, ptr %28, align 8, !tbaa !19
  %.not34 = icmp eq i64 %29, 0
  br i1 %.not34, label %35, label %30

30:                                               ; preds = %25
  %31 = getelementptr inbounds i8, ptr %0, i64 112
  %32 = load i64, ptr %31, align 8, !tbaa !20
  %.not35 = icmp eq i64 %29, %32
  br i1 %.not35, label %35, label %33

33:                                               ; preds = %30
  %34 = tail call i64 @err0r(i32 noundef 14)
  br label %39

35:                                               ; preds = %30, %25
  %36 = ptrtoint ptr %.131 to i64
  %37 = ptrtoint ptr %1 to i64
  %38 = sub i64 %36, %37
  br label %39

39:                                               ; preds = %23, %4, %35, %33, %10
  %.1 = phi i64 [ %11, %10 ], [ %34, %33 ], [ %38, %35 ], [ %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, !9, i64 8}
!6 = !{!"LZ4F_cctx_s", !7, i64 0, !9, i64 56, !9, i64 60, !13, i64 64, !14, i64 72, !14, i64 80, !13, i64 88, !13, i64 96, !14, i64 104, !14, i64 112, !15, i64 120, !13, i64 168, !16, i64 176, !16, i64 178}
!7 = !{!"", !8, i64 0, !9, i64 32, !9, i64 36, !9, i64 40, !10, i64 44}
!8 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !12, i64 16, !9, i64 24, !9, i64 28}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"long long", !10, i64 0}
!13 = !{!"any pointer", !10, i64 0}
!14 = !{!"long", !10, i64 0}
!15 = !{!"XXH32_state_s", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !9, i64 20, !10, i64 24, !9, i64 40, !9, i64 44}
!16 = !{!"short", !10, i64 0}
!17 = !{!6, !9, i64 60}
!18 = !{!6, !14, i64 80}
!19 = !{!6, !12, i64 16}
!20 = !{!6, !14, i64 112}


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