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

; 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.CPpmd7 = type { ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, i32, [38 x i8], [128 x i8], [38 x i32], [256 x i8], [256 x i8], [256 x i8], %struct.CPpmd_See, [25 x [16 x %struct.CPpmd_See]], [128 x [64 x i16]] }
%struct.CPpmd_See = type { i16, i8, i8 }
%struct.CPpmd7_Context_ = type { i16, i16, i32, 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
define dso_local ptr @Ppmd7_MakeEscFreq(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.CPpmd7, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.CPpmd7_Context_, ptr %12, i32 0, i32 0
  %14 = load i16, ptr %13, align 4, !tbaa !15
  %15 = zext i16 %14 to i32
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = sub i32 %15, %16
  store i32 %17, ptr %8, align 4, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.CPpmd7, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.CPpmd7_Context_, ptr %20, i32 0, i32 0
  %22 = load i16, ptr %21, align 4, !tbaa !15
  %23 = zext i16 %22 to i32
  %24 = icmp ne i32 %23, 256
  br i1 %24, label %25, label %118

25:                                               ; preds = %3
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.CPpmd7, ptr %26, i32 0, i32 25
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.CPpmd7, ptr %28, i32 0, i32 21
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = sub i64 %31, 1
  %33 = getelementptr inbounds [256 x i8], ptr %29, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !17
  %35 = zext i8 %34 to i32
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds [25 x [16 x %struct.CPpmd_See]], ptr %27, i64 0, i64 %36
  %38 = getelementptr inbounds [16 x %struct.CPpmd_See], ptr %37, i64 0, i64 0
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.CPpmd7, ptr %40, i32 0, i32 12
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.CPpmd7, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.CPpmd7_Context_, ptr %45, i32 0, i32 3
  %47 = load i32, ptr %46, align 4, !tbaa !19
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %42, i64 %48
  %50 = getelementptr inbounds %struct.CPpmd7_Context_, ptr %49, i32 0, i32 0
  %51 = load i16, ptr %50, align 4, !tbaa !15
  %52 = zext i16 %51 to i32
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.CPpmd7, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.CPpmd7_Context_, ptr %55, i32 0, i32 0
  %57 = load i16, ptr %56, align 4, !tbaa !15
  %58 = zext i16 %57 to i32
  %59 = sub i32 %52, %58
  %60 = icmp ult i32 %39, %59
  %61 = zext i1 %60 to i32
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds %struct.CPpmd_See, ptr %38, i64 %62
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.CPpmd7, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !11
  %67 = getelementptr inbounds %struct.CPpmd7_Context_, ptr %66, i32 0, i32 1
  %68 = load i16, ptr %67, align 2, !tbaa !20
  %69 = zext i16 %68 to i32
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.CPpmd7, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !11
  %73 = getelementptr inbounds %struct.CPpmd7_Context_, ptr %72, i32 0, i32 0
  %74 = load i16, ptr %73, align 4, !tbaa !15
  %75 = zext i16 %74 to i32
  %76 = mul nsw i32 11, %75
  %77 = icmp slt i32 %69, %76
  %78 = zext i1 %77 to i32
  %79 = mul i32 2, %78
  %80 = zext i32 %79 to i64
  %81 = getelementptr inbounds %struct.CPpmd_See, ptr %63, i64 %80
  %82 = load i32, ptr %5, align 4, !tbaa !9
  %83 = load i32, ptr %8, align 4, !tbaa !9
  %84 = icmp ugt i32 %82, %83
  %85 = zext i1 %84 to i32
  %86 = mul i32 4, %85
  %87 = zext i32 %86 to i64
  %88 = getelementptr inbounds %struct.CPpmd_See, ptr %81, i64 %87
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.CPpmd7, ptr %89, i32 0, i32 7
  %91 = load i32, ptr %90, align 8, !tbaa !21
  %92 = zext i32 %91 to i64
  %93 = getelementptr inbounds %struct.CPpmd_See, ptr %88, i64 %92
  store ptr %93, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.CPpmd_See, ptr %94, i32 0, i32 0
  %96 = load i16, ptr %95, align 1, !tbaa !22
  %97 = zext i16 %96 to i32
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.CPpmd_See, ptr %98, i32 0, i32 1
  %100 = load i8, ptr %99, align 1, !tbaa !23
  %101 = zext i8 %100 to i32
  %102 = ashr i32 %97, %101
  store i32 %102, ptr %9, align 4, !tbaa !9
  %103 = load ptr, ptr %7, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.CPpmd_See, ptr %103, i32 0, i32 0
  %105 = load i16, ptr %104, align 1, !tbaa !22
  %106 = zext i16 %105 to i32
  %107 = load i32, ptr %9, align 4, !tbaa !9
  %108 = sub i32 %106, %107
  %109 = trunc i32 %108 to i16
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.CPpmd_See, ptr %110, i32 0, i32 0
  store i16 %109, ptr %111, align 1, !tbaa !22
  %112 = load i32, ptr %9, align 4, !tbaa !9
  %113 = load i32, ptr %9, align 4, !tbaa !9
  %114 = icmp eq i32 %113, 0
  %115 = zext i1 %114 to i32
  %116 = add i32 %112, %115
  %117 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %116, ptr %117, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %122

118:                                              ; preds = %3
  %119 = load ptr, ptr %4, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.CPpmd7, ptr %119, i32 0, i32 24
  store ptr %120, ptr %7, align 8, !tbaa !5
  %121 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 1, ptr %121, align 4, !tbaa !9
  br label %122

122:                                              ; preds = %118, %25
  %123 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret ptr %123
}

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 = { 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, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !10, i64 104, !7, i64 108, !7, i64 146, !7, i64 276, !7, i64 428, !7, i64 684, !7, i64 940, !13, i64 1196, !7, i64 1200, !7, i64 2800}
!13 = !{!"", !14, i64 0, !7, i64 2, !7, i64 3}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !14, i64 0}
!16 = !{!"CPpmd7_Context_", !14, i64 0, !14, i64 2, !10, i64 4, !10, i64 8}
!17 = !{!7, !7, i64 0}
!18 = !{!12, !6, i64 64}
!19 = !{!16, !10, i64 8}
!20 = !{!16, !14, i64 2}
!21 = !{!12, !10, i64 40}
!22 = !{!13, !14, i64 0}
!23 = !{!13, !7, i64 2}


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

%struct.CPpmd_See = type { i16, i8, i8 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local nonnull ptr @Ppmd7_MakeEscFreq(ptr noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = load i16, ptr %4, align 4, !tbaa !13
  %.not = icmp eq i16 %5, 256
  br i1 %.not, label %52, label %6

6:                                                ; preds = %3
  %7 = zext i16 %5 to i32
  %8 = sub i32 %7, %1
  %9 = getelementptr inbounds i8, ptr %0, i64 1200
  %10 = getelementptr inbounds i8, ptr %0, i64 428
  %11 = zext i32 %8 to i64
  %12 = add nsw i64 %11, -1
  %13 = getelementptr inbounds [256 x i8], ptr %10, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !15
  %15 = zext i8 %14 to i64
  %16 = getelementptr inbounds [25 x [16 x %struct.CPpmd_See]], ptr %9, i64 0, i64 %15
  %17 = getelementptr inbounds i8, ptr %0, i64 64
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %4, i64 8
  %20 = load i32, ptr %19, align 4, !tbaa !17
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %18, i64 %21
  %23 = load i16, ptr %22, align 4, !tbaa !13
  %24 = zext i16 %23 to i32
  %25 = sub nsw i32 %24, %7
  %26 = icmp ult i32 %8, %25
  %27 = zext i1 %26 to i64
  %28 = getelementptr inbounds %struct.CPpmd_See, ptr %16, i64 %27
  %29 = getelementptr inbounds i8, ptr %4, i64 2
  %30 = load i16, ptr %29, align 2, !tbaa !18
  %31 = zext i16 %30 to i32
  %32 = mul nuw nsw i32 %7, 11
  %33 = icmp ugt i32 %32, %31
  %34 = select i1 %33, i64 2, i64 0
  %35 = getelementptr inbounds %struct.CPpmd_See, ptr %28, i64 %34
  %36 = icmp ult i32 %8, %1
  %37 = select i1 %36, i64 4, i64 0
  %38 = getelementptr inbounds %struct.CPpmd_See, ptr %35, i64 %37
  %39 = getelementptr inbounds i8, ptr %0, i64 40
  %40 = load i32, ptr %39, align 8, !tbaa !19
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds %struct.CPpmd_See, ptr %38, i64 %41
  %43 = load i16, ptr %42, align 1, !tbaa !20
  %44 = zext i16 %43 to i32
  %45 = getelementptr inbounds i8, ptr %42, i64 2
  %46 = load i8, ptr %45, align 1, !tbaa !21
  %47 = zext nneg i8 %46 to i32
  %48 = lshr i32 %44, %47
  %49 = trunc nuw i32 %48 to i16
  %50 = sub i16 %43, %49
  store i16 %50, ptr %42, align 1, !tbaa !20
  %51 = tail call i32 @llvm.umax.i32(i32 %48, i32 1)
  br label %54

52:                                               ; preds = %3
  %53 = getelementptr inbounds i8, ptr %0, i64 1196
  br label %54

54:                                               ; preds = %52, %6
  %storemerge = phi i32 [ 1, %52 ], [ %51, %6 ]
  %.0 = phi ptr [ %53, %52 ], [ %42, %6 ]
  store i32 %storemerge, ptr %2, align 4, !tbaa !22
  ret ptr %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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 speculatable willreturn memory(none) }

!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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !10, i64 104, !8, i64 108, !8, i64 146, !8, i64 276, !8, i64 428, !8, i64 684, !8, i64 940, !11, i64 1196, !8, i64 1200, !8, i64 2800}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !12, i64 0, !8, i64 2, !8, i64 3}
!12 = !{!"short", !8, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"CPpmd7_Context_", !12, i64 0, !12, i64 2, !10, i64 4, !10, i64 8}
!15 = !{!8, !8, i64 0}
!16 = !{!6, !7, i64 64}
!17 = !{!14, !10, i64 8}
!18 = !{!14, !12, i64 2}
!19 = !{!6, !10, i64 40}
!20 = !{!11, !12, i64 0}
!21 = !{!11, !8, i64 2}
!22 = !{!10, !10, i64 0}


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