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

; 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_headerSize(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %14

12:                                               ; preds = %9
  %13 = call i64 @LZ4F_returnErrorCode(i32 noundef 15)
  store i64 %13, ptr %3, align 8
  br label %55

14:                                               ; preds = %9
  br label %15

15:                                               ; preds = %14
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = icmp ult i64 %16, 5
  br i1 %17, label %18, label %20

18:                                               ; preds = %15
  %19 = call i64 @LZ4F_returnErrorCode(i32 noundef 12)
  store i64 %19, ptr %3, align 8
  br label %55

20:                                               ; preds = %15
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call i32 @LZ4F_readLE32(ptr noundef %21)
  %23 = and i32 %22, -16
  %24 = icmp eq i32 %23, 407710288
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  store i64 8, ptr %3, align 8
  br label %55

26:                                               ; preds = %20
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = call i32 @LZ4F_readLE32(ptr noundef %27)
  %29 = icmp ne i32 %28, 407708164
  br i1 %29, label %30, label %32

30:                                               ; preds = %26
  %31 = call i64 @LZ4F_returnErrorCode(i32 noundef 13)
  store i64 %31, ptr %3, align 8
  br label %55

32:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 4
  %35 = load i8, ptr %34, align 1, !tbaa !11
  store i8 %35, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %36 = load i8, ptr %6, align 1, !tbaa !11
  %37 = zext i8 %36 to i32
  %38 = ashr i32 %37, 3
  %39 = and i32 %38, 1
  store i32 %39, ptr %7, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %40 = load i8, ptr %6, align 1, !tbaa !11
  %41 = zext i8 %40 to i32
  %42 = and i32 %41, 1
  store i32 %42, ptr %8, align 4, !tbaa !12
  %43 = load i32, ptr %7, align 4, !tbaa !12
  %44 = icmp ne i32 %43, 0
  %45 = zext i1 %44 to i64
  %46 = select i1 %44, i32 8, i32 0
  %47 = sext i32 %46 to i64
  %48 = add i64 7, %47
  %49 = load i32, ptr %8, align 4, !tbaa !12
  %50 = icmp ne i32 %49, 0
  %51 = zext i1 %50 to i64
  %52 = select i1 %50, i32 4, i32 0
  %53 = sext i32 %52 to i64
  %54 = add i64 %48, %53
  store i64 %54, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  br label %55

55:                                               ; preds = %32, %30, %25, %18, %12
  %56 = load i64, ptr %3, align 8
  ret i64 %56
}

; Function Attrs: nounwind uwtable
declare hidden i32 @LZ4F_readLE32(ptr 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 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, 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 @LZ4F_returnErrorCode(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @LZ4F_headerSize(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = tail call i64 @LZ4F_returnErrorCode(i32 noundef 15)
  br label %27

6:                                                ; preds = %2
  %7 = icmp ult i64 %1, 5
  br i1 %7, label %8, label %10

8:                                                ; preds = %6
  %9 = tail call i64 @LZ4F_returnErrorCode(i32 noundef 12)
  br label %27

10:                                               ; preds = %6
  %11 = tail call i32 @LZ4F_readLE32(ptr noundef nonnull %0)
  %12 = and i32 %11, -16
  %13 = icmp eq i32 %12, 407710288
  br i1 %13, label %27, label %14

14:                                               ; preds = %10
  %15 = tail call i32 @LZ4F_readLE32(ptr noundef nonnull %0)
  %.not = icmp eq i32 %15, 407708164
  br i1 %.not, label %18, label %16

16:                                               ; preds = %14
  %17 = tail call i64 @LZ4F_returnErrorCode(i32 noundef 13)
  br label %27

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = zext i8 %20 to i32
  %22 = and i32 %21, 8
  %23 = or disjoint i32 %22, 7
  %24 = shl nuw nsw i32 %21, 2
  %25 = and i32 %24, 4
  %narrow = add nuw nsw i32 %23, %25
  %26 = zext nneg i32 %narrow to i64
  br label %27

27:                                               ; preds = %10, %18, %16, %8, %4
  %.0 = phi i64 [ %5, %4 ], [ %9, %8 ], [ %17, %16 ], [ %26, %18 ], [ 8, %10 ]
  ret i64 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @LZ4F_readLE32(ptr 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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