; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Compress (Bcj2Coder)

; 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.NCompress::NBcj2::CBaseCoder" = type { [5 x ptr], [5 x i32], [5 x 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

declare void @MyFree(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NBcj210CBaseCoder5AllocEb(ptr noundef nonnull align 8 dereferenceable(80) %0, i1 noundef zeroext %1) #2 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  %12 = zext i1 %1 to i8
  store i8 %12, ptr %5, align 1, !tbaa !9
  %13 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %14 = load i8, ptr %5, align 1, !tbaa !9, !range !11, !noundef !12
  %15 = trunc i8 %14 to i1
  %16 = zext i1 %15 to i64
  %17 = select i1 %15, i32 5, i32 4
  store i32 %17, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !13
  br label %18

18:                                               ; preds = %93, %2
  %19 = load i32, ptr %7, align 4, !tbaa !13
  %20 = load i32, ptr %6, align 4, !tbaa !13
  %21 = icmp ult i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  store i32 2, ptr %8, align 4
  br label %96

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %24 = getelementptr inbounds %"class.NCompress::NBcj2::CBaseCoder", ptr %13, i32 0, i32 2
  %25 = load i32, ptr %7, align 4, !tbaa !13
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [5 x i32], ptr %24, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !13
  store i32 %28, ptr %9, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 1, ptr %10, align 4, !tbaa !13
  %29 = load i32, ptr %9, align 4, !tbaa !13
  %30 = icmp ult i32 %29, 1
  br i1 %30, label %31, label %32

31:                                               ; preds = %23
  store i32 1, ptr %9, align 4, !tbaa !13
  br label %32

32:                                               ; preds = %31, %23
  %33 = getelementptr inbounds %"class.NCompress::NBcj2::CBaseCoder", ptr %13, i32 0, i32 0
  %34 = load i32, ptr %7, align 4, !tbaa !13
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [5 x ptr], ptr %33, i64 0, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %47

39:                                               ; preds = %32
  %40 = load i32, ptr %9, align 4, !tbaa !13
  %41 = getelementptr inbounds %"class.NCompress::NBcj2::CBaseCoder", ptr %13, i32 0, i32 1
  %42 = load i32, ptr %7, align 4, !tbaa !13
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds [5 x i32], ptr %41, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !13
  %46 = icmp ne i32 %40, %45
  br i1 %46, label %47, label %89

47:                                               ; preds = %39, %32
  %48 = getelementptr inbounds %"class.NCompress::NBcj2::CBaseCoder", ptr %13, i32 0, i32 0
  %49 = load i32, ptr %7, align 4, !tbaa !13
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds [5 x ptr], ptr %48, i64 0, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %64

54:                                               ; preds = %47
  %55 = getelementptr inbounds %"class.NCompress::NBcj2::CBaseCoder", ptr %13, i32 0, i32 0
  %56 = load i32, ptr %7, align 4, !tbaa !13
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds [5 x ptr], ptr %55, i64 0, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  call void @MyFree(ptr noundef %59)
  %60 = getelementptr inbounds %"class.NCompress::NBcj2::CBaseCoder", ptr %13, i32 0, i32 0
  %61 = load i32, ptr %7, align 4, !tbaa !13
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds [5 x ptr], ptr %60, i64 0, i64 %62
  store ptr null, ptr %63, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %54, %47
  %65 = getelementptr inbounds %"class.NCompress::NBcj2::CBaseCoder", ptr %13, i32 0, i32 1
  %66 = load i32, ptr %7, align 4, !tbaa !13
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds [5 x i32], ptr %65, i64 0, i64 %67
  store i32 0, ptr %68, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %69 = load i32, ptr %9, align 4, !tbaa !13
  %70 = zext i32 %69 to i64
  %71 = call ptr @MyAlloc(i64 noundef %70)
  store ptr %71, ptr %11, align 8, !tbaa !5
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = getelementptr inbounds %"class.NCompress::NBcj2::CBaseCoder", ptr %13, i32 0, i32 0
  %74 = load i32, ptr %7, align 4, !tbaa !13
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds [5 x ptr], ptr %73, i64 0, i64 %75
  store ptr %72, ptr %76, align 8, !tbaa !5
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = icmp ne ptr %77, null
  br i1 %78, label %80, label %79

79:                                               ; preds = %64
  store i32 -2147024882, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %86

80:                                               ; preds = %64
  %81 = load i32, ptr %9, align 4, !tbaa !13
  %82 = getelementptr inbounds %"class.NCompress::NBcj2::CBaseCoder", ptr %13, i32 0, i32 1
  %83 = load i32, ptr %7, align 4, !tbaa !13
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds [5 x i32], ptr %82, i64 0, i64 %84
  store i32 %81, ptr %85, align 4, !tbaa !13
  store i32 0, ptr %8, align 4
  br label %86

86:                                               ; preds = %80, %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %87 = load i32, ptr %8, align 4
  switch i32 %87, label %90 [
    i32 0, label %88
  ]

88:                                               ; preds = %86
  br label %89

89:                                               ; preds = %88, %39
  store i32 0, ptr %8, align 4
  br label %90

90:                                               ; preds = %89, %86
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %91 = load i32, ptr %8, align 4
  switch i32 %91, label %96 [
    i32 0, label %92
  ]

92:                                               ; preds = %90
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %7, align 4, !tbaa !13
  %95 = add i32 %94, 1
  store i32 %95, ptr %7, align 4, !tbaa !13
  br label %18, !llvm.loop !15

96:                                               ; preds = %90, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %97 = load i32, ptr %8, align 4
  switch i32 %97, label %99 [
    i32 2, label %98
  ]

98:                                               ; preds = %96
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %99

99:                                               ; preds = %98, %96
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %100 = load i32, ptr %3, align 4
  ret i32 %100
}

declare ptr @MyAlloc(i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

declare void @MyFree(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress5NBcj210CBaseCoder5AllocEb(ptr nocapture noundef nonnull align 8 dereferenceable(80) %0, i1 noundef zeroext %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 60
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %wide.trip.count = select i1 %1, i64 5, i64 4
  br label %5

5:                                                ; preds = %2, %.critedge34
  %indvars.iv = phi i64 [ 0, %2 ], [ %indvars.iv.next, %.critedge34 ]
  %6 = getelementptr inbounds [5 x i32], ptr %3, i64 0, i64 %indvars.iv
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %spec.store.select = tail call i32 @llvm.umax.i32(i32 %7, i32 1)
  %8 = getelementptr inbounds [5 x ptr], ptr %0, i64 0, i64 %indvars.iv
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %.thread, label %10

10:                                               ; preds = %5
  %11 = getelementptr inbounds [5 x i32], ptr %4, i64 0, i64 %indvars.iv
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %.not30 = icmp eq i32 %spec.store.select, %12
  br i1 %.not30, label %.critedge34, label %13

13:                                               ; preds = %10
  tail call void @MyFree(ptr noundef nonnull %9)
  store ptr null, ptr %8, align 8, !tbaa !9
  br label %.thread

.thread:                                          ; preds = %5, %13
  %14 = getelementptr inbounds [5 x i32], ptr %4, i64 0, i64 %indvars.iv
  store i32 0, ptr %14, align 4, !tbaa !5
  %15 = zext i32 %spec.store.select to i64
  %16 = tail call ptr @MyAlloc(i64 noundef %15)
  store ptr %16, ptr %8, align 8, !tbaa !9
  %.not32.not = icmp eq ptr %16, null
  br i1 %.not32.not, label %.critedge, label %17

17:                                               ; preds = %.thread
  store i32 %spec.store.select, ptr %14, align 4, !tbaa !5
  br label %.critedge34

.critedge34:                                      ; preds = %17, %10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge, label %5, !llvm.loop !11

.critedge:                                        ; preds = %.thread, %.critedge34
  %spec.select = phi i32 [ -2147024882, %.thread ], [ 0, %.critedge34 ]
  ret i32 %spec.select
}

declare ptr @MyAlloc(i64 noundef) local_unnamed_addr #0

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

attributes #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 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 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass