; 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 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
declare hidden ptr @LZ4F_selectCompression(i32 noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @LZ4F_flush(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 ptr, 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) #2
  %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) #2
  %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) #2
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %17, i32 0, i32 8
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %4
  store i64 0, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %126

22:                                               ; preds = %4
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !19
  %26 = icmp ne i32 %25, 1
  br i1 %26, label %27, label %29

27:                                               ; preds = %22
  %28 = call i64 @err0r(i32 noundef 1)
  store i64 %28, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %126

29:                                               ; preds = %22
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %31, i32 0, i32 8
  %33 = load i64, ptr %32, align 8, !tbaa !11
  %34 = add i64 %33, 4
  %35 = add i64 %34, 4
  %36 = icmp ult i64 %30, %35
  br i1 %36, label %37, label %39

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

39:                                               ; preds = %29
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %struct.LZ4F_preferences_t, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.LZ4F_frameInfo_t, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !20
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %46, i32 0, i32 0
  %48 = getelementptr inbounds %struct.LZ4F_preferences_t, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 8, !tbaa !21
  %50 = call ptr @LZ4F_selectCompression(i32 noundef %45, i32 noundef %49)
  store ptr %50, ptr %12, align 8, !tbaa !5
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %52, i32 0, i32 7
  %54 = load ptr, ptr %53, align 8, !tbaa !22
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %55, i32 0, i32 8
  %57 = load i64, ptr %56, align 8, !tbaa !11
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %59, i32 0, i32 11
  %61 = load ptr, ptr %60, align 8, !tbaa !23
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %62, i32 0, i32 0
  %64 = getelementptr inbounds %struct.LZ4F_preferences_t, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 8, !tbaa !21
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !24
  %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 6
  %73 = load i32, ptr %72, align 4, !tbaa !25
  %74 = call i64 @LZ4F_makeBlock(ptr noundef %51, ptr noundef %54, i64 noundef %57, ptr noundef %58, ptr noundef %61, i32 noundef %65, ptr noundef %68, i32 noundef %73)
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = getelementptr inbounds i8, ptr %75, i64 %74
  store ptr %76, ptr %11, align 8, !tbaa !5
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds %struct.LZ4F_preferences_t, ptr %78, i32 0, i32 0
  %80 = getelementptr inbounds %struct.LZ4F_frameInfo_t, ptr %79, i32 0, i32 1
  %81 = load i32, ptr %80, align 4, !tbaa !20
  %82 = icmp eq i32 %81, 0
  br i1 %82, label %83, label %91

83:                                               ; preds = %39
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %84, i32 0, i32 8
  %86 = load i64, ptr %85, align 8, !tbaa !11
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %87, i32 0, i32 7
  %89 = load ptr, ptr %88, align 8, !tbaa !22
  %90 = getelementptr inbounds i8, ptr %89, i64 %86
  store ptr %90, ptr %88, align 8, !tbaa !22
  br label %91

91:                                               ; preds = %83, %39
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %92, i32 0, i32 8
  store i64 0, ptr %93, align 8, !tbaa !11
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %94, i32 0, i32 7
  %96 = load ptr, ptr %95, align 8, !tbaa !22
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %97, i32 0, i32 4
  %99 = load i64, ptr %98, align 8, !tbaa !26
  %100 = getelementptr inbounds i8, ptr %96, i64 %99
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %101, i32 0, i32 6
  %103 = load ptr, ptr %102, align 8, !tbaa !27
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %104, i32 0, i32 5
  %106 = load i64, ptr %105, align 8, !tbaa !28
  %107 = getelementptr inbounds i8, ptr %103, i64 %106
  %108 = icmp ugt ptr %100, %107
  br i1 %108, label %109, label %120

109:                                              ; preds = %91
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %110 = load ptr, ptr %6, align 8, !tbaa !5
  %111 = call i32 @LZ4F_localSaveDict(ptr noundef %110)
  store i32 %111, ptr %14, align 4, !tbaa !29
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %112, i32 0, i32 6
  %114 = load ptr, ptr %113, align 8, !tbaa !27
  %115 = load i32, ptr %14, align 4, !tbaa !29
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds i8, ptr %114, i64 %116
  %118 = load ptr, ptr %6, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.LZ4F_cctx_s, ptr %118, i32 0, i32 7
  store ptr %117, ptr %119, align 8, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %120

120:                                              ; preds = %109, %91
  %121 = load ptr, ptr %11, align 8, !tbaa !5
  %122 = load ptr, ptr %10, align 8, !tbaa !5
  %123 = ptrtoint ptr %121 to i64
  %124 = ptrtoint ptr %122 to i64
  %125 = sub i64 %123, %124
  store i64 %125, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %126

126:                                              ; preds = %120, %37, %27, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %127 = load i64, ptr %5, align 8
  ret i64 %127
}

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 = { 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, !10, i64 104}
!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 = !{!12, !15, i64 60}
!20 = !{!12, !15, i64 4}
!21 = !{!12, !15, i64 32}
!22 = !{!12, !6, i64 96}
!23 = !{!12, !6, i64 168}
!24 = !{!12, !6, i64 64}
!25 = !{!12, !15, i64 28}
!26 = !{!12, !10, i64 72}
!27 = !{!12, !6, i64 88}
!28 = !{!12, !10, i64 80}
!29 = !{!15, !15, i64 0}


; 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 hidden i64 @err0r(i32 noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @LZ4F_flush(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr nocapture noundef readnone %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 104
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %56, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 60
  %10 = load i32, ptr %9, align 4, !tbaa !17
  %.not = icmp eq i32 %10, 1
  br i1 %.not, label %13, label %11

11:                                               ; preds = %8
  %12 = tail call i64 @err0r(i32 noundef 1)
  br label %56

13:                                               ; preds = %8
  %14 = add i64 %6, 8
  %15 = icmp ugt i64 %14, %2
  br i1 %15, label %16, label %18

16:                                               ; preds = %13
  %17 = tail call i64 @err0r(i32 noundef 11)
  br label %56

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !18
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  %22 = load i32, ptr %21, align 8, !tbaa !19
  %23 = tail call ptr @LZ4F_selectCompression(i32 noundef %20, i32 noundef %22)
  %24 = getelementptr inbounds i8, ptr %0, i64 96
  %25 = load ptr, ptr %24, align 8, !tbaa !20
  %26 = load i64, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %0, i64 168
  %28 = load ptr, ptr %27, align 8, !tbaa !21
  %29 = load i32, ptr %21, align 8, !tbaa !19
  %30 = getelementptr inbounds i8, ptr %0, i64 64
  %31 = load ptr, ptr %30, align 8, !tbaa !22
  %32 = getelementptr inbounds i8, ptr %0, i64 28
  %33 = load i32, ptr %32, align 4, !tbaa !23
  %34 = tail call i64 @LZ4F_makeBlock(ptr noundef %1, ptr noundef %25, i64 noundef %26, ptr noundef %23, ptr noundef %28, i32 noundef %29, ptr noundef %31, i32 noundef %33)
  %35 = load i32, ptr %19, align 4, !tbaa !18
  %36 = icmp eq i32 %35, 0
  %.pre = load ptr, ptr %24, align 8, !tbaa !20
  br i1 %36, label %37, label %40

37:                                               ; preds = %18
  %38 = load i64, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %.pre, i64 %38
  store ptr %39, ptr %24, align 8, !tbaa !20
  br label %40

40:                                               ; preds = %37, %18
  %41 = phi ptr [ %39, %37 ], [ %.pre, %18 ]
  store i64 0, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %0, i64 72
  %43 = load i64, ptr %42, align 8, !tbaa !24
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  %45 = getelementptr inbounds i8, ptr %0, i64 88
  %46 = load ptr, ptr %45, align 8, !tbaa !25
  %47 = getelementptr inbounds i8, ptr %0, i64 80
  %48 = load i64, ptr %47, align 8, !tbaa !26
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  %50 = icmp ugt ptr %44, %49
  br i1 %50, label %51, label %56

51:                                               ; preds = %40
  %52 = tail call i32 @LZ4F_localSaveDict(ptr noundef nonnull %0)
  %53 = load ptr, ptr %45, align 8, !tbaa !25
  %54 = sext i32 %52 to i64
  %55 = getelementptr inbounds i8, ptr %53, i64 %54
  store ptr %55, ptr %24, align 8, !tbaa !20
  br label %56

56:                                               ; preds = %40, %51, %4, %16, %11
  %.0 = phi i64 [ %12, %11 ], [ %17, %16 ], [ 0, %4 ], [ %34, %51 ], [ %34, %40 ]
  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, !14, i64 104}
!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, !9, i64 4}
!19 = !{!6, !9, i64 32}
!20 = !{!6, !13, i64 96}
!21 = !{!6, !13, i64 168}
!22 = !{!6, !13, i64 64}
!23 = !{!6, !9, i64 28}
!24 = !{!6, !14, i64 72}
!25 = !{!6, !13, i64 88}
!26 = !{!6, !14, i64 80}


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