; LLVM IR from ebiggers/libdeflate :: lib (zlib_decompress)

; 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
define dso_local i32 @libdeflate_zlib_decompress_ex(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6) #0 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i16, align 2
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i64 %2, ptr %11, align 8, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !5
  store i64 %4, ptr %13, align 8, !tbaa !9
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %23, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %24 = load ptr, ptr %16, align 8, !tbaa !5
  %25 = load i64, ptr %11, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %24, i64 %25
  store ptr %26, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %18) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  %27 = load i64, ptr %11, align 8, !tbaa !9
  %28 = icmp ult i64 %27, 6
  br i1 %28, label %29, label %30

29:                                               ; preds = %7
  store i32 1, ptr %8, align 4
  store i32 1, ptr %22, align 4
  br label %109

30:                                               ; preds = %7
  %31 = load ptr, ptr %16, align 8, !tbaa !5
  %32 = call zeroext i16 @get_unaligned_be16(ptr noundef %31)
  store i16 %32, ptr %18, align 2, !tbaa !11
  %33 = load ptr, ptr %16, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 2
  store ptr %34, ptr %16, align 8, !tbaa !5
  %35 = load i16, ptr %18, align 2, !tbaa !11
  %36 = zext i16 %35 to i32
  %37 = srem i32 %36, 31
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %30
  store i32 1, ptr %8, align 4
  store i32 1, ptr %22, align 4
  br label %109

40:                                               ; preds = %30
  %41 = load i16, ptr %18, align 2, !tbaa !11
  %42 = zext i16 %41 to i32
  %43 = ashr i32 %42, 8
  %44 = and i32 %43, 15
  %45 = icmp ne i32 %44, 8
  br i1 %45, label %46, label %47

46:                                               ; preds = %40
  store i32 1, ptr %8, align 4
  store i32 1, ptr %22, align 4
  br label %109

47:                                               ; preds = %40
  %48 = load i16, ptr %18, align 2, !tbaa !11
  %49 = zext i16 %48 to i32
  %50 = ashr i32 %49, 12
  %51 = icmp sgt i32 %50, 7
  br i1 %51, label %52, label %53

52:                                               ; preds = %47
  store i32 1, ptr %8, align 4
  store i32 1, ptr %22, align 4
  br label %109

53:                                               ; preds = %47
  %54 = load i16, ptr %18, align 2, !tbaa !11
  %55 = zext i16 %54 to i32
  %56 = ashr i32 %55, 5
  %57 = and i32 %56, 1
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %53
  store i32 1, ptr %8, align 4
  store i32 1, ptr %22, align 4
  br label %109

60:                                               ; preds = %53
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = load ptr, ptr %16, align 8, !tbaa !5
  %63 = load ptr, ptr %17, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i64 -4
  %65 = load ptr, ptr %16, align 8, !tbaa !5
  %66 = ptrtoint ptr %64 to i64
  %67 = ptrtoint ptr %65 to i64
  %68 = sub i64 %66, %67
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = load i64, ptr %13, align 8, !tbaa !9
  %71 = load ptr, ptr %15, align 8, !tbaa !5
  %72 = call i32 @libdeflate_deflate_decompress_ex(ptr noundef %61, ptr noundef %62, i64 noundef %68, ptr noundef %69, i64 noundef %70, ptr noundef %19, ptr noundef %71)
  store i32 %72, ptr %21, align 4, !tbaa !13
  %73 = load i32, ptr %21, align 4, !tbaa !13
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %77

75:                                               ; preds = %60
  %76 = load i32, ptr %21, align 4, !tbaa !13
  store i32 %76, ptr %8, align 4
  store i32 1, ptr %22, align 4
  br label %109

77:                                               ; preds = %60
  %78 = load ptr, ptr %15, align 8, !tbaa !5
  %79 = icmp ne ptr %78, null
  br i1 %79, label %80, label %83

80:                                               ; preds = %77
  %81 = load ptr, ptr %15, align 8, !tbaa !5
  %82 = load i64, ptr %81, align 8, !tbaa !9
  store i64 %82, ptr %20, align 8, !tbaa !9
  br label %85

83:                                               ; preds = %77
  %84 = load i64, ptr %13, align 8, !tbaa !9
  store i64 %84, ptr %20, align 8, !tbaa !9
  br label %85

85:                                               ; preds = %83, %80
  %86 = load i64, ptr %19, align 8, !tbaa !9
  %87 = load ptr, ptr %16, align 8, !tbaa !5
  %88 = getelementptr inbounds i8, ptr %87, i64 %86
  store ptr %88, ptr %16, align 8, !tbaa !5
  %89 = load ptr, ptr %12, align 8, !tbaa !5
  %90 = load i64, ptr %20, align 8, !tbaa !9
  %91 = call i32 @libdeflate_adler32(i32 noundef 1, ptr noundef %89, i64 noundef %90)
  %92 = load ptr, ptr %16, align 8, !tbaa !5
  %93 = call i32 @get_unaligned_be32(ptr noundef %92)
  %94 = icmp ne i32 %91, %93
  br i1 %94, label %95, label %96

95:                                               ; preds = %85
  store i32 1, ptr %8, align 4
  store i32 1, ptr %22, align 4
  br label %109

96:                                               ; preds = %85
  %97 = load ptr, ptr %16, align 8, !tbaa !5
  %98 = getelementptr inbounds i8, ptr %97, i64 4
  store ptr %98, ptr %16, align 8, !tbaa !5
  %99 = load ptr, ptr %14, align 8, !tbaa !5
  %100 = icmp ne ptr %99, null
  br i1 %100, label %101, label %108

101:                                              ; preds = %96
  %102 = load ptr, ptr %16, align 8, !tbaa !5
  %103 = load ptr, ptr %10, align 8, !tbaa !5
  %104 = ptrtoint ptr %102 to i64
  %105 = ptrtoint ptr %103 to i64
  %106 = sub i64 %104, %105
  %107 = load ptr, ptr %14, align 8, !tbaa !5
  store i64 %106, ptr %107, align 8, !tbaa !9
  br label %108

108:                                              ; preds = %101, %96
  store i32 0, ptr %8, align 4
  store i32 1, ptr %22, align 4
  br label %109

109:                                              ; preds = %108, %95, %75, %59, %52, %46, %39, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  %110 = load i32, ptr %8, align 4
  ret i32 %110
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden zeroext i16 @get_unaligned_be16(ptr noundef) #2

declare i32 @libdeflate_deflate_decompress_ex(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #3

declare i32 @libdeflate_adler32(i32 noundef, ptr noundef, i64 noundef) #3

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

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

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 = { 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 = { "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 #4 = { 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, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"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
define dso_local i32 @libdeflate_zlib_decompress_ex(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef writeonly %5, ptr noundef %6) local_unnamed_addr #0 {
  %8 = alloca i64, align 8
  %9 = getelementptr inbounds i8, ptr %1, i64 %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  %10 = icmp ult i64 %2, 6
  br i1 %10, label %39, label %11

11:                                               ; preds = %7
  %12 = tail call zeroext i16 @get_unaligned_be16(ptr noundef %1)
  %13 = getelementptr inbounds i8, ptr %1, i64 2
  %14 = zext i16 %12 to i32
  %15 = urem i16 %12, 31
  %.not = icmp eq i16 %15, 0
  %16 = and i32 %14, 3840
  %.not35 = icmp eq i32 %16, 2048
  %or.cond.not43.not46 = and i1 %.not, %.not35
  %17 = icmp sgt i16 %12, -1
  %or.cond41.not45 = and i1 %17, %or.cond.not43.not46
  %18 = and i32 %14, 32
  %.not36 = icmp eq i32 %18, 0
  %or.cond42 = and i1 %.not36, %or.cond41.not45
  br i1 %or.cond42, label %19, label %39

19:                                               ; preds = %11
  %20 = getelementptr inbounds i8, ptr %9, i64 -4
  %21 = ptrtoint ptr %20 to i64
  %22 = ptrtoint ptr %13 to i64
  %23 = sub i64 %21, %22
  %24 = call i32 @libdeflate_deflate_decompress_ex(ptr noundef %0, ptr noundef nonnull %13, i64 noundef %23, ptr noundef %3, i64 noundef %4, ptr noundef nonnull %8, ptr noundef %6) #4
  %.not37 = icmp eq i32 %24, 0
  br i1 %.not37, label %25, label %39

25:                                               ; preds = %19
  %.not38 = icmp eq ptr %6, null
  br i1 %.not38, label %28, label %26

26:                                               ; preds = %25
  %27 = load i64, ptr %6, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %25, %26
  %.031 = phi i64 [ %27, %26 ], [ %4, %25 ]
  %29 = load i64, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %13, i64 %29
  %31 = call i32 @libdeflate_adler32(i32 noundef 1, ptr noundef %3, i64 noundef %.031) #4
  %32 = call i32 @get_unaligned_be32(ptr noundef nonnull %30)
  %.not39 = icmp eq i32 %31, %32
  br i1 %.not39, label %33, label %39

33:                                               ; preds = %28
  %.not40 = icmp eq ptr %5, null
  br i1 %.not40, label %39, label %34

34:                                               ; preds = %33
  %35 = getelementptr inbounds i8, ptr %30, i64 4
  %36 = ptrtoint ptr %35 to i64
  %37 = ptrtoint ptr %1 to i64
  %38 = sub i64 %36, %37
  store i64 %38, ptr %5, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %33, %34, %28, %19, %11, %7
  %.0 = phi i32 [ 1, %7 ], [ 1, %11 ], [ %24, %19 ], [ 1, %28 ], [ 0, %34 ], [ 0, %33 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  ret i32 %.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: alwaysinline nounwind uwtable
declare hidden zeroext i16 @get_unaligned_be16(ptr noundef) local_unnamed_addr #2

declare i32 @libdeflate_deflate_decompress_ex(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @libdeflate_adler32(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @get_unaligned_be32(ptr noundef) local_unnamed_addr #2

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

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


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