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

; 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_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
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %2
  %12 = call i64 @err0r(i32 noundef 15)
  store i64 %12, ptr %3, align 8
  br label %53

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

16:                                               ; preds = %13
  %17 = call i64 @err0r(i32 noundef 12)
  store i64 %17, ptr %3, align 8
  br label %53

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

23:                                               ; preds = %18
  store i64 8, ptr %3, align 8
  br label %53

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

28:                                               ; preds = %24
  %29 = call i64 @err0r(i32 noundef 13)
  store i64 %29, ptr %3, align 8
  br label %53

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

53:                                               ; preds = %30, %28, %23, %16, %11
  %54 = load i64, ptr %3, align 8
  ret i64 %54
}

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