; 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_dctx_s = type { %struct.LZ4F_frameInfo_t, i32, i32, i64, i64, i64, ptr, i64, i64, ptr, ptr, i64, ptr, i64, i64, %struct.XXH32_state_s, %struct.XXH32_state_s, [19 x i8] }
%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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; 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 dso_local i64 @LZ4F_headerSize(ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @LZ4F_getFrameInfo(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.LZ4F_dctx_s, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = icmp ugt i32 %17, 1
  br i1 %18, label %19, label %26

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 0, ptr %11, align 8, !tbaa !16
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %20, align 8, !tbaa !16
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.LZ4F_dctx_s, ptr %22, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %21, ptr align 8 %23, i64 32, i1 false), !tbaa.struct !17
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = call i64 @LZ4F_decompress(ptr noundef %24, ptr noundef null, ptr noundef %10, ptr noundef null, ptr noundef %11, ptr noundef null)
  store i64 %25, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %72

26:                                               ; preds = %4
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.LZ4F_dctx_s, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 1
  br i1 %30, label %31, label %34

31:                                               ; preds = %26
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %32, align 8, !tbaa !16
  %33 = call i64 @err0r(i32 noundef 19)
  store i64 %33, ptr %5, align 8
  br label %72

34:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = load i64, ptr %36, align 8, !tbaa !16
  %38 = call i64 @LZ4F_headerSize(ptr noundef %35, i64 noundef %37)
  store i64 %38, ptr %12, align 8, !tbaa !16
  %39 = load i64, ptr %12, align 8, !tbaa !16
  %40 = call i32 @LZ4F_isError(i64 noundef %39)
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %45

42:                                               ; preds = %34
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %43, align 8, !tbaa !16
  %44 = load i64, ptr %12, align 8, !tbaa !16
  store i64 %44, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %71

45:                                               ; preds = %34
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load i64, ptr %46, align 8, !tbaa !16
  %48 = load i64, ptr %12, align 8, !tbaa !16
  %49 = icmp ult i64 %47, %48
  br i1 %49, label %50, label %53

50:                                               ; preds = %45
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %51, align 8, !tbaa !16
  %52 = call i64 @err0r(i32 noundef 12)
  store i64 %52, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %71

53:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load i64, ptr %12, align 8, !tbaa !16
  %57 = call i64 @LZ4F_decodeHeader(ptr noundef %54, ptr noundef %55, i64 noundef %56)
  store i64 %57, ptr %14, align 8, !tbaa !16
  %58 = load i64, ptr %14, align 8, !tbaa !16
  %59 = call i32 @LZ4F_isError(i64 noundef %58)
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %63

61:                                               ; preds = %53
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %62, align 8, !tbaa !16
  br label %66

63:                                               ; preds = %53
  %64 = load i64, ptr %14, align 8, !tbaa !16
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %64, ptr %65, align 8, !tbaa !16
  store i64 4, ptr %14, align 8, !tbaa !16
  br label %66

66:                                               ; preds = %63, %61
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.LZ4F_dctx_s, ptr %68, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %67, ptr align 8 %69, i64 32, i1 false), !tbaa.struct !17
  %70 = load i64, ptr %14, align 8, !tbaa !16
  store i64 %70, ptr %5, align 8
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %71

71:                                               ; preds = %66, %50, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %72

72:                                               ; preds = %71, %31, %19
  %73 = load i64, ptr %5, align 8
  ret i64 %73
}

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

; Function Attrs: nounwind uwtable
declare hidden i64 @LZ4F_decodeHeader(ptr noundef, ptr noundef, i64 noundef) #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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 36}
!10 = !{!"LZ4F_dctx_s", !11, i64 0, !12, i64 32, !12, i64 36, !14, i64 40, !14, i64 48, !14, i64 56, !6, i64 64, !14, i64 72, !14, i64 80, !6, i64 88, !6, i64 96, !14, i64 104, !6, i64 112, !14, i64 120, !14, i64 128, !15, i64 136, !15, i64 184, !7, i64 232}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !13, i64 16, !12, i64 24, !12, i64 28}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"XXH32_state_s", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !7, i64 24, !12, i64 40, !12, i64 44}
!16 = !{!14, !14, i64 0}
!17 = !{i64 0, i64 4, !18, i64 4, i64 4, !18, i64 8, i64 4, !18, i64 12, i64 4, !18, i64 16, i64 8, !19, i64 24, i64 4, !18, i64 28, i64 4, !18}
!18 = !{!12, !12, i64 0}
!19 = !{!13, !13, 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 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; 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) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @LZ4F_getFrameInfo(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = getelementptr inbounds i8, ptr %0, i64 36
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = icmp ugt i32 %8, 1
  br i1 %9, label %10, label %12

10:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  store i64 0, ptr %5, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store i64 0, ptr %6, align 8, !tbaa !15
  store i64 0, ptr %3, align 8, !tbaa !15
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(32) %0, i64 32, i1 false), !tbaa.struct !16
  %11 = call i64 @LZ4F_decompress(ptr noundef nonnull %0, ptr noundef null, ptr noundef nonnull %5, ptr noundef null, ptr noundef nonnull %6, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  br label %29

12:                                               ; preds = %4
  %13 = icmp eq i32 %8, 1
  br i1 %13, label %14, label %16

14:                                               ; preds = %12
  store i64 0, ptr %3, align 8, !tbaa !15
  %15 = tail call i64 @err0r(i32 noundef 19)
  br label %29

16:                                               ; preds = %12
  %17 = load i64, ptr %3, align 8, !tbaa !15
  %18 = tail call i64 @LZ4F_headerSize(ptr noundef %2, i64 noundef %17)
  %19 = tail call i32 @LZ4F_isError(i64 noundef %18)
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %21, label %20

20:                                               ; preds = %16
  store i64 0, ptr %3, align 8, !tbaa !15
  br label %29

21:                                               ; preds = %16
  %22 = load i64, ptr %3, align 8, !tbaa !15
  %23 = icmp ult i64 %22, %18
  br i1 %23, label %24, label %26

24:                                               ; preds = %21
  store i64 0, ptr %3, align 8, !tbaa !15
  %25 = tail call i64 @err0r(i32 noundef 12)
  br label %29

26:                                               ; preds = %21
  %27 = tail call i64 @LZ4F_decodeHeader(ptr noundef nonnull %0, ptr noundef %2, i64 noundef %18)
  %28 = tail call i32 @LZ4F_isError(i64 noundef %27)
  %.not28 = icmp eq i32 %28, 0
  %. = select i1 %.not28, i64 %27, i64 0
  %.29 = select i1 %.not28, i64 4, i64 %27
  store i64 %., ptr %3, align 8, !tbaa !15
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(32) %0, i64 32, i1 false), !tbaa.struct !16
  br label %29

29:                                               ; preds = %20, %24, %26, %14, %10
  %.1 = phi i64 [ %11, %10 ], [ %15, %14 ], [ %18, %20 ], [ %25, %24 ], [ %.29, %26 ]
  ret i64 %.1
}

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

; Function Attrs: nounwind uwtable
declare hidden i64 @LZ4F_decodeHeader(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !8, i64 36}
!6 = !{!"LZ4F_dctx_s", !7, i64 0, !8, i64 32, !8, i64 36, !12, i64 40, !12, i64 48, !12, i64 56, !13, i64 64, !12, i64 72, !12, i64 80, !13, i64 88, !13, i64 96, !12, i64 104, !13, i64 112, !12, i64 120, !12, i64 128, !14, i64 136, !14, i64 184, !9, i64 232}
!7 = !{!"", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !11, i64 16, !8, i64 24, !8, i64 28}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long long", !9, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!"XXH32_state_s", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !8, i64 16, !8, i64 20, !9, i64 24, !8, i64 40, !8, i64 44}
!15 = !{!12, !12, i64 0}
!16 = !{i64 0, i64 4, !17, i64 4, i64 4, !17, i64 8, i64 4, !17, i64 12, i64 4, !17, i64 16, i64 8, !18, i64 24, i64 4, !17, i64 28, i64 4, !17}
!17 = !{!8, !8, i64 0}
!18 = !{!11, !11, i64 0}


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