; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/C (Lzma2Dec)

; 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.CLzma2Dec = type { i32, i8, i8, i8, i8, i32, i32, %struct.CLzmaDec }
%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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @Lzma2Dec_DecodeToDic(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @Lzma2Dec_DecodeToBuf(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, ptr noundef %6) #1 {
  %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 = %119, %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.CLzma2Dec, ptr %32, i32 0, i32 7
  %34 = getelementptr inbounds %struct.CLzmaDec, ptr %33, i32 0, i32 5
  %35 = load i64, ptr %34, align 8, !tbaa !13
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.CLzma2Dec, ptr %36, i32 0, i32 7
  %38 = getelementptr inbounds %struct.CLzmaDec, ptr %37, i32 0, i32 4
  %39 = load i64, ptr %38, align 8, !tbaa !17
  %40 = icmp eq i64 %35, %39
  br i1 %40, label %41, label %45

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

45:                                               ; preds = %41, %30
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.CLzma2Dec, ptr %46, i32 0, i32 7
  %48 = getelementptr inbounds %struct.CLzmaDec, ptr %47, i32 0, i32 5
  %49 = load i64, ptr %48, align 8, !tbaa !13
  store i64 %49, ptr %20, align 8, !tbaa !11
  store i32 0, ptr %21, align 4, !tbaa !9
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.CLzma2Dec, ptr %50, i32 0, i32 7
  %52 = getelementptr inbounds %struct.CLzmaDec, ptr %51, i32 0, i32 4
  %53 = load i64, ptr %52, align 8, !tbaa !17
  %54 = load i64, ptr %20, align 8, !tbaa !11
  %55 = sub i64 %53, %54
  store i64 %55, ptr %19, align 8, !tbaa !11
  %56 = load i64, ptr %19, align 8, !tbaa !11
  %57 = load i64, ptr %16, align 8, !tbaa !11
  %58 = icmp uge i64 %56, %57
  br i1 %58, label %59, label %62

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

107:                                              ; preds = %62
  %108 = load i32, ptr %22, align 4, !tbaa !9
  store i32 %108, ptr %8, align 4
  store i32 1, ptr %23, align 4
  br label %117

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

112:                                              ; preds = %109
  %113 = load i64, ptr %16, align 8, !tbaa !11
  %114 = icmp eq i64 %113, 0
  br i1 %114, label %115, label %116

115:                                              ; preds = %112, %109
  store i32 0, ptr %8, align 4
  store i32 1, ptr %23, align 4
  br label %117

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

117:                                              ; preds = %116, %115, %107
  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
  %118 = load i32, ptr %23, align 4
  switch i32 %118, label %120 [
    i32 0, label %119
  ]

119:                                              ; preds = %117
  br label %30

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

; 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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 56}
!14 = !{!"", !10, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !10, i64 12, !15, i64 16}
!15 = !{!"", !16, 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}
!16 = !{!"_CLzmaProps", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !10, i64 4}
!17 = !{!14, !12, i64 48}
!18 = !{!14, !6, i64 40}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @Lzma2Dec_DecodeToDic(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @Lzma2Dec_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 #1 {
  %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 56
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  br label %14

14:                                               ; preds = %33, %7
  %.048 = phi ptr [ %3, %7 ], [ %37, %33 ]
  %.047 = phi i64 [ %9, %7 ], [ %34, %33 ]
  %.046 = phi i64 [ %10, %7 ], [ %36, %33 ]
  %.044 = phi ptr [ %1, %7 ], [ %35, %33 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  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 !15
  %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
  %.not = icmp ult i64 %21, %.047
  %spec.select = call i64 @llvm.umin.i64(i64 %21, i64 %.047)
  %spec.select52 = select i1 %.not, i32 0, i32 %5
  %22 = add i64 %spec.select, %20
  %23 = call i32 @Lzma2Dec_DecodeToDic(ptr noundef nonnull %0, i64 noundef %22, ptr noundef %.048, ptr noundef nonnull %8, i32 noundef %spec.select52, ptr noundef %6)
  %24 = load i64, ptr %8, align 8, !tbaa !5
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = add i64 %25, %24
  store i64 %26, ptr %4, align 8, !tbaa !5
  %27 = load i64, ptr %11, align 8, !tbaa !9
  %28 = sub i64 %27, %20
  %29 = load ptr, ptr %13, align 8, !tbaa !16
  %30 = getelementptr inbounds i8, ptr %29, i64 %20
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %.044, ptr align 1 %30, i64 %28, i1 false)
  %31 = load i64, ptr %2, align 8, !tbaa !5
  %32 = add i64 %31, %28
  store i64 %32, ptr %2, align 8, !tbaa !5
  %.not51 = icmp eq i32 %23, 0
  br i1 %.not51, label %33, label %.thread

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

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

.loopexit:                                        ; preds = %33, %.thread
  ret i32 %23
}

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #3

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


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