; LLVM IR from philanc/luazen :: src/lzma (LzmaDec)

; 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.CLzmaDec = type { %struct._CLzmaProps, ptr, ptr, ptr, i64, i64, ptr, i32, i32, i32, i32, [4 x i32], i32, i32, i32, i32, [20 x i8] }
%struct._CLzmaProps = type { i8, i8, i8, i8, i32 }

; Function Attrs: nounwind uwtable
declare dso_local i32 @LzmaDec_DecodeToDic(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef, ptr 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @LzmaDec_DecodeToBuf(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, ptr noundef %6) #0 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store i32 %5, ptr %14, align 4, !tbaa !9
  store ptr %6, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = load i64, ptr %24, align 8, !tbaa !11
  store i64 %25, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %26 = load ptr, ptr %13, align 8, !tbaa !5
  %27 = load i64, ptr %26, align 8, !tbaa !11
  store i64 %27, ptr %17, align 8, !tbaa !11
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 0, ptr %28, align 8, !tbaa !11
  %29 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 0, ptr %29, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %115, %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %31 = load i64, ptr %17, align 8, !tbaa !11
  store i64 %31, ptr %18, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #3
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.CLzmaDec, ptr %32, i32 0, i32 5
  %34 = load i64, ptr %33, align 8, !tbaa !13
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.CLzmaDec, ptr %35, i32 0, i32 4
  %37 = load i64, ptr %36, align 8, !tbaa !16
  %38 = icmp eq i64 %34, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %30
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.CLzmaDec, ptr %40, i32 0, i32 5
  store i64 0, ptr %41, align 8, !tbaa !13
  br label %42

42:                                               ; preds = %39, %30
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.CLzmaDec, ptr %43, i32 0, i32 5
  %45 = load i64, ptr %44, align 8, !tbaa !13
  store i64 %45, ptr %20, align 8, !tbaa !11
  %46 = load i64, ptr %16, align 8, !tbaa !11
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.CLzmaDec, ptr %47, i32 0, i32 4
  %49 = load i64, ptr %48, align 8, !tbaa !16
  %50 = load i64, ptr %20, align 8, !tbaa !11
  %51 = sub i64 %49, %50
  %52 = icmp ugt i64 %46, %51
  br i1 %52, label %53, label %57

53:                                               ; preds = %42
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.CLzmaDec, ptr %54, i32 0, i32 4
  %56 = load i64, ptr %55, align 8, !tbaa !16
  store i64 %56, ptr %19, align 8, !tbaa !11
  store i32 0, ptr %21, align 4, !tbaa !9
  br label %62

57:                                               ; preds = %42
  %58 = load i64, ptr %20, align 8, !tbaa !11
  %59 = load i64, ptr %16, align 8, !tbaa !11
  %60 = add i64 %58, %59
  store i64 %60, ptr %19, align 8, !tbaa !11
  %61 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %61, ptr %21, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %57, %53
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = load i64, ptr %19, align 8, !tbaa !11
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = load i32, ptr %21, align 4, !tbaa !9
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  %68 = call i32 @LzmaDec_DecodeToDic(ptr noundef %63, i64 noundef %64, ptr noundef %65, ptr noundef %18, i32 noundef %66, ptr noundef %67)
  store i32 %68, ptr %22, align 4, !tbaa !9
  %69 = load i64, ptr %18, align 8, !tbaa !11
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 %69
  store ptr %71, ptr %12, align 8, !tbaa !5
  %72 = load i64, ptr %18, align 8, !tbaa !11
  %73 = load i64, ptr %17, align 8, !tbaa !11
  %74 = sub i64 %73, %72
  store i64 %74, ptr %17, align 8, !tbaa !11
  %75 = load i64, ptr %18, align 8, !tbaa !11
  %76 = load ptr, ptr %13, align 8, !tbaa !5
  %77 = load i64, ptr %76, align 8, !tbaa !11
  %78 = add i64 %77, %75
  store i64 %78, ptr %76, align 8, !tbaa !11
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.CLzmaDec, ptr %79, i32 0, i32 5
  %81 = load i64, ptr %80, align 8, !tbaa !13
  %82 = load i64, ptr %20, align 8, !tbaa !11
  %83 = sub i64 %81, %82
  store i64 %83, ptr %19, align 8, !tbaa !11
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.CLzmaDec, ptr %85, i32 0, i32 3
  %87 = load ptr, ptr %86, align 8, !tbaa !17
  %88 = load i64, ptr %20, align 8, !tbaa !11
  %89 = getelementptr inbounds i8, ptr %87, i64 %88
  %90 = load i64, ptr %19, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %84, ptr align 1 %89, i64 %90, i1 false)
  %91 = load i64, ptr %19, align 8, !tbaa !11
  %92 = load ptr, ptr %10, align 8, !tbaa !5
  %93 = getelementptr inbounds i8, ptr %92, i64 %91
  store ptr %93, ptr %10, align 8, !tbaa !5
  %94 = load i64, ptr %19, align 8, !tbaa !11
  %95 = load i64, ptr %16, align 8, !tbaa !11
  %96 = sub i64 %95, %94
  store i64 %96, ptr %16, align 8, !tbaa !11
  %97 = load i64, ptr %19, align 8, !tbaa !11
  %98 = load ptr, ptr %11, align 8, !tbaa !5
  %99 = load i64, ptr %98, align 8, !tbaa !11
  %100 = add i64 %99, %97
  store i64 %100, ptr %98, align 8, !tbaa !11
  %101 = load i32, ptr %22, align 4, !tbaa !9
  %102 = icmp ne i32 %101, 0
  br i1 %102, label %103, label %105

103:                                              ; preds = %62
  %104 = load i32, ptr %22, align 4, !tbaa !9
  store i32 %104, ptr %8, align 4
  store i32 1, ptr %23, align 4
  br label %113

105:                                              ; preds = %62
  %106 = load i64, ptr %19, align 8, !tbaa !11
  %107 = icmp eq i64 %106, 0
  br i1 %107, label %111, label %108

108:                                              ; preds = %105
  %109 = load i64, ptr %16, align 8, !tbaa !11
  %110 = icmp eq i64 %109, 0
  br i1 %110, label %111, label %112

111:                                              ; preds = %108, %105
  store i32 0, ptr %8, align 4
  store i32 1, ptr %23, align 4
  br label %113

112:                                              ; preds = %108
  store i32 0, ptr %23, align 4
  br label %113

113:                                              ; preds = %112, %111, %103
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  %114 = load i32, ptr %23, align 4
  switch i32 %114, label %116 [
    i32 0, label %115
  ]

115:                                              ; preds = %113
  br label %30

116:                                              ; preds = %113
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  %117 = load i32, ptr %8, align 4
  ret i32 %117
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 40}
!14 = !{!"", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 40, !6, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !7, i64 72, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !7, i64 104}
!15 = !{!"_CLzmaProps", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !10, i64 4}
!16 = !{!14, !12, i64 32}
!17 = !{!14, !6, i64 24}


; 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 @LzmaDec_DecodeToDic(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @LzmaDec_DecodeToBuf(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef %2, ptr noundef %3, ptr nocapture noundef %4, i32 noundef %5, ptr noundef %6) local_unnamed_addr #0 {
  %8 = alloca i64, align 8
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = load i64, ptr %4, align 8, !tbaa !5
  store i64 0, ptr %2, align 8, !tbaa !5
  store i64 0, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  br label %14

14:                                               ; preds = %34, %7
  %.048 = phi ptr [ %3, %7 ], [ %38, %34 ]
  %.047 = phi i64 [ %9, %7 ], [ %35, %34 ]
  %.046 = phi i64 [ %10, %7 ], [ %37, %34 ]
  %.044 = phi ptr [ %1, %7 ], [ %36, %34 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #3
  store i64 %.046, ptr %8, align 8, !tbaa !5
  %15 = load i64, ptr %11, align 8, !tbaa !9
  %16 = load i64, ptr %12, align 8, !tbaa !14
  %17 = icmp eq i64 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %18, %14
  %20 = phi i64 [ 0, %18 ], [ %15, %14 ]
  %21 = sub i64 %16, %20
  %22 = icmp ugt i64 %.047, %21
  %23 = add i64 %20, %.047
  %.045 = select i1 %22, i64 %16, i64 %23
  %.043 = select i1 %22, i32 0, i32 %5
  %24 = call i32 @LzmaDec_DecodeToDic(ptr noundef nonnull %0, i64 noundef %.045, ptr noundef %.048, ptr noundef nonnull %8, i32 noundef %.043, ptr noundef %6)
  %25 = load i64, ptr %8, align 8, !tbaa !5
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = add i64 %26, %25
  store i64 %27, ptr %4, align 8, !tbaa !5
  %28 = load i64, ptr %11, align 8, !tbaa !9
  %29 = sub i64 %28, %20
  %30 = load ptr, ptr %13, align 8, !tbaa !15
  %31 = getelementptr inbounds i8, ptr %30, i64 %20
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %.044, ptr align 1 %31, i64 %29, i1 false)
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = add i64 %32, %29
  store i64 %33, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %34, label %.thread

.thread:                                          ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #3
  br label %.loopexit

34:                                               ; preds = %19
  %35 = sub i64 %.047, %29
  %36 = getelementptr inbounds i8, ptr %.044, i64 %29
  %37 = sub i64 %.046, %25
  %38 = getelementptr inbounds i8, ptr %.048, i64 %25
  %39 = icmp ne i64 %28, %20
  %40 = icmp ne i64 %35, 0
  %or.cond.not = select i1 %39, i1 %40, i1 false
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #3
  br i1 %or.cond.not, label %14, label %.loopexit

.loopexit:                                        ; preds = %34, %.thread
  ret i32 %24
}

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 40}
!10 = !{!"", !11, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !6, i64 32, !6, i64 40, !13, i64 48, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !7, i64 72, !12, i64 88, !12, i64 92, !12, i64 96, !12, i64 100, !7, i64 104}
!11 = !{!"_CLzmaProps", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !12, i64 4}
!12 = !{!"int", !7, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!10, !6, i64 32}
!15 = !{!10, !13, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass