; LLVM IR from DanEngelbrecht/longtail :: lib/lz4/ext (lz4)

; 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.LZ4_streamDecode_t_internal = type { ptr, ptr, i64, i64 }

; 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: nounwind uwtable
declare dso_local i32 @LZ4_decompress_fast(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @LZ4_decompress_unsafe_generic(ptr noundef, ptr noundef, i32 noundef, i64 noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @LZ4_decompress_fast_continue(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  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 i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %13, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %14 = load ptr, ptr %10, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %14, i32 0, i32 3
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %38

18:                                               ; preds = %4
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = call i32 @LZ4_decompress_fast(ptr noundef %19, ptr noundef %20, i32 noundef %21)
  store i32 %22, ptr %11, align 4, !tbaa !9
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = icmp sle i32 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %18
  %26 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %26, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %119

27:                                               ; preds = %18
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %30, i32 0, i32 3
  store i64 %29, ptr %31, align 8, !tbaa !11
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %32, i64 %34
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %36, i32 0, i32 1
  store ptr %35, ptr %37, align 8, !tbaa !14
  br label %117

38:                                               ; preds = %4
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = icmp eq ptr %41, %42
  br i1 %43, label %44, label %75

44:                                               ; preds = %38
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %48, i32 0, i32 3
  %50 = load i64, ptr %49, align 8, !tbaa !11
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %54, i32 0, i32 2
  %56 = load i64, ptr %55, align 8, !tbaa !16
  %57 = call i32 @LZ4_decompress_unsafe_generic(ptr noundef %45, ptr noundef %46, i32 noundef %47, i64 noundef %50, ptr noundef %53, i64 noundef %56)
  store i32 %57, ptr %11, align 4, !tbaa !9
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = icmp sle i32 %58, 0
  br i1 %59, label %60, label %62

60:                                               ; preds = %44
  %61 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %61, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %119

62:                                               ; preds = %44
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %65, i32 0, i32 3
  %67 = load i64, ptr %66, align 8, !tbaa !11
  %68 = add i64 %67, %64
  store i64 %68, ptr %66, align 8, !tbaa !11
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %70, i32 0, i32 1
  %72 = load ptr, ptr %71, align 8, !tbaa !14
  %73 = sext i32 %69 to i64
  %74 = getelementptr inbounds i8, ptr %72, i64 %73
  store ptr %74, ptr %71, align 8, !tbaa !14
  br label %116

75:                                               ; preds = %38
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %76, i32 0, i32 3
  %78 = load i64, ptr %77, align 8, !tbaa !11
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %79, i32 0, i32 2
  store i64 %78, ptr %80, align 8, !tbaa !16
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %81, i32 0, i32 1
  %83 = load ptr, ptr %82, align 8, !tbaa !14
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %84, i32 0, i32 2
  %86 = load i64, ptr %85, align 8, !tbaa !16
  %87 = sub i64 0, %86
  %88 = getelementptr inbounds i8, ptr %83, i64 %87
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %89, i32 0, i32 0
  store ptr %88, ptr %90, align 8, !tbaa !15
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = load i32, ptr %9, align 4, !tbaa !9
  %94 = load ptr, ptr %10, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !15
  %97 = load ptr, ptr %10, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %97, i32 0, i32 2
  %99 = load i64, ptr %98, align 8, !tbaa !16
  %100 = call i32 @LZ4_decompress_fast_extDict(ptr noundef %91, ptr noundef %92, i32 noundef %93, ptr noundef %96, i64 noundef %99)
  store i32 %100, ptr %11, align 4, !tbaa !9
  %101 = load i32, ptr %11, align 4, !tbaa !9
  %102 = icmp sle i32 %101, 0
  br i1 %102, label %103, label %105

103:                                              ; preds = %75
  %104 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %104, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %119

105:                                              ; preds = %75
  %106 = load i32, ptr %9, align 4, !tbaa !9
  %107 = sext i32 %106 to i64
  %108 = load ptr, ptr %10, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %108, i32 0, i32 3
  store i64 %107, ptr %109, align 8, !tbaa !11
  %110 = load ptr, ptr %8, align 8, !tbaa !5
  %111 = load i32, ptr %9, align 4, !tbaa !9
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds i8, ptr %110, i64 %112
  %114 = load ptr, ptr %10, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %114, i32 0, i32 1
  store ptr %113, ptr %115, align 8, !tbaa !14
  br label %116

116:                                              ; preds = %105, %62
  br label %117

117:                                              ; preds = %116, %27
  %118 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %118, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %119

119:                                              ; preds = %117, %103, %60, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %120 = load i32, ptr %5, align 4
  ret i32 %120
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { alwaysinline 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 24}
!12 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !13, i64 16}


; 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 @LZ4_decompress_fast(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @LZ4_decompress_unsafe_generic(ptr noundef, ptr noundef, i32 noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

8:                                                ; preds = %4
  %9 = tail call i32 @LZ4_decompress_fast(ptr noundef %1, ptr noundef %2, i32 noundef %3)
  %10 = icmp slt i32 %9, 1
  br i1 %10, label %40, label %11

11:                                               ; preds = %8
  %12 = sext i32 %3 to i64
  store i64 %12, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %2, i64 %12
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %13, ptr %14, align 8, !tbaa !11
  br label %40

15:                                               ; preds = %4
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = icmp eq ptr %17, %2
  br i1 %18, label %19, label %31

19:                                               ; preds = %15
  %20 = load ptr, ptr %0, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load i64, ptr %21, align 8, !tbaa !13
  %23 = tail call i32 @LZ4_decompress_unsafe_generic(ptr noundef %1, ptr noundef %2, i32 noundef %3, i64 noundef %6, ptr noundef %20, i64 noundef %22)
  %24 = icmp slt i32 %23, 1
  br i1 %24, label %40, label %25

25:                                               ; preds = %19
  %26 = sext i32 %3 to i64
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = add i64 %27, %26
  store i64 %28, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %16, align 8, !tbaa !11
  %30 = getelementptr inbounds i8, ptr %29, i64 %26
  store ptr %30, ptr %16, align 8, !tbaa !11
  br label %40

31:                                               ; preds = %15
  %32 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %6, ptr %32, align 8, !tbaa !13
  %33 = sub i64 0, %6
  %34 = getelementptr inbounds i8, ptr %17, i64 %33
  store ptr %34, ptr %0, align 8, !tbaa !12
  %35 = tail call i32 @LZ4_decompress_fast_extDict(ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef nonnull %34, i64 noundef %6)
  %36 = icmp slt i32 %35, 1
  br i1 %36, label %40, label %37

37:                                               ; preds = %31
  %38 = sext i32 %3 to i64
  store i64 %38, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %2, i64 %38
  store ptr %39, ptr %16, align 8, !tbaa !11
  br label %40

40:                                               ; preds = %11, %37, %25, %31, %19, %8
  %.044 = phi i32 [ %9, %8 ], [ %23, %19 ], [ %35, %31 ], [ %9, %11 ], [ %23, %25 ], [ %35, %37 ]
  ret i32 %.044
}

; Function Attrs: nounwind uwtable
declare hidden i32 @LZ4_decompress_fast_extDict(ptr noundef, ptr noundef, i32 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 = { alwaysinline 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, !10, i64 24}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 16}


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