; LLVM IR from mncoppola/rpef :: utilities_src/squashfs2.1/lzma/C/7zip/Compress/LZ (LZInWindow)

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

%class.CLZInWindow = type { ptr, ptr, ptr, i32, i8, ptr, ptr, i32, i32, i32, i32, i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11CLZInWindow4FreeEv(ptr noundef nonnull align 8 dereferenceable(72)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN11CLZInWindow6CreateEjjj(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 9
  store i32 %13, ptr %14, align 8, !tbaa !11
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 10
  store i32 %15, ptr %16, align 4, !tbaa !14
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 11
  store i32 %17, ptr %18, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = add i32 %19, %20
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = add i32 %21, %22
  store i32 %23, ptr %10, align 4, !tbaa !9
  %24 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = icmp eq ptr %25, null
  br i1 %26, label %32, label %27

27:                                               ; preds = %4
  %28 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 7
  %29 = load i32, ptr %28, align 8, !tbaa !17
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = icmp ne i32 %29, %30
  br i1 %31, label %32, label %45

32:                                               ; preds = %27, %4
  call void @_ZN11CLZInWindow4FreeEv(ptr noundef nonnull align 8 dereferenceable(72) %12)
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 7
  store i32 %33, ptr %34, align 8, !tbaa !17
  %35 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 7
  %36 = load i32, ptr %35, align 8, !tbaa !17
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %44

38:                                               ; preds = %32
  %39 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 7
  %40 = load i32, ptr %39, align 8, !tbaa !17
  %41 = zext i32 %40 to i64
  %42 = call noundef ptr @_Z7MyAllocm(i64 noundef %41) #3
  %43 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 1
  store ptr %42, ptr %43, align 8, !tbaa !16
  br label %44

44:                                               ; preds = %38, %32
  br label %45

45:                                               ; preds = %44, %27
  %46 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 7
  %49 = load i32, ptr %48, align 8, !tbaa !17
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds i8, ptr %47, i64 %50
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = zext i32 %52 to i64
  %54 = sub i64 0, %53
  %55 = getelementptr inbounds i8, ptr %51, i64 %54
  %56 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 5
  store ptr %55, ptr %56, align 8, !tbaa !18
  %57 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 7
  %58 = load i32, ptr %57, align 8, !tbaa !17
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %45
  store i1 true, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %65

61:                                               ; preds = %45
  %62 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = icmp ne ptr %63, null
  store i1 %64, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %65

65:                                               ; preds = %61, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %66 = load i1, ptr %5, align 1
  ret i1 %66
}

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

; Function Attrs: nounwind
declare noundef ptr @_Z7MyAllocm(i64 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 = { mustprogress 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 "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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 56}
!12 = !{!"_ZTS11CLZInWindow", !6, i64 8, !6, i64 16, !10, i64 24, !13, i64 28, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68}
!13 = !{!"bool", !7, i64 0}
!14 = !{!12, !10, i64 60}
!15 = !{!12, !10, i64 64}
!16 = !{!12, !6, i64 8}
!17 = !{!12, !10, i64 48}
!18 = !{!12, !6, i64 32}


; 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: mustprogress nounwind uwtable
declare dso_local void @_ZN11CLZInWindow4FreeEv(ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN11CLZInWindow6CreateEjjj(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 %1, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 %2, ptr %6, align 4, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 %3, ptr %7, align 8, !tbaa !13
  %8 = add i32 %2, %1
  %9 = add i32 %8, %3
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load ptr, ptr %10, align 8
  %12 = icmp ne ptr %11, null
  %13 = getelementptr inbounds i8, ptr %0, i64 48
  %14 = load i32, ptr %13, align 8
  %.not = icmp eq i32 %14, %9
  %or.cond = select i1 %12, i1 %.not, i1 false
  br i1 %or.cond, label %19, label %15

15:                                               ; preds = %4
  tail call void @_ZN11CLZInWindow4FreeEv(ptr noundef nonnull align 8 dereferenceable(72) %0)
  store i32 %9, ptr %13, align 8, !tbaa !14
  %.not11 = icmp eq i32 %9, 0
  br i1 %.not11, label %._crit_edge, label %16

._crit_edge:                                      ; preds = %15
  %.pre = load ptr, ptr %10, align 8
  br label %19

16:                                               ; preds = %15
  %17 = zext i32 %9 to i64
  %18 = tail call noundef ptr @_Z7MyAllocm(i64 noundef %17) #2
  store ptr %18, ptr %10, align 8, !tbaa !15
  %.pre13 = load i32, ptr %13, align 8, !tbaa !14
  br label %19

19:                                               ; preds = %._crit_edge, %4, %16
  %20 = phi i32 [ 0, %._crit_edge ], [ %9, %4 ], [ %.pre13, %16 ]
  %21 = phi ptr [ %.pre, %._crit_edge ], [ %11, %4 ], [ %18, %16 ]
  %22 = zext i32 %20 to i64
  %23 = getelementptr inbounds i8, ptr %21, i64 %22
  %24 = zext i32 %2 to i64
  %25 = sub nsw i64 0, %24
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %26, ptr %27, align 8, !tbaa !16
  %28 = icmp eq i32 %20, 0
  %29 = icmp ne ptr %21, null
  %.0 = select i1 %28, i1 true, i1 %29
  ret i1 %.0
}

; Function Attrs: nounwind
declare noundef ptr @_Z7MyAllocm(i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { nounwind "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 = { 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, !10, i64 56}
!6 = !{!"_ZTS11CLZInWindow", !7, i64 8, !7, i64 16, !10, i64 24, !11, i64 28, !7, i64 32, !7, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !10, i64 60}
!13 = !{!6, !10, i64 64}
!14 = !{!6, !10, i64 48}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !7, i64 32}


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