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

; 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.CBenchmarkOutStream = type { %struct.ISequentialOutStream, %class.CMyUnknownImp, i32, ptr, i32, ptr }
%struct.ISequentialOutStream = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%class.CMyUnknownImp = type { i32 }

@.str = external hidden unnamed_addr constant [24 x i8], align 1

; 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN19CBenchmarkOutStream5WriteEPKvjPj(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) unnamed_addr #1 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %38, %4
  %14 = load i32, ptr %10, align 4, !tbaa !9
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = icmp ult i32 %14, %15
  br i1 %16, label %17, label %23

17:                                               ; preds = %13
  %18 = getelementptr inbounds %class.CBenchmarkOutStream, ptr %12, i32 0, i32 4
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds %class.CBenchmarkOutStream, ptr %12, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !16
  %22 = icmp ult i32 %19, %21
  br label %23

23:                                               ; preds = %17, %13
  %24 = phi i1 [ false, %13 ], [ %22, %17 ]
  br i1 %24, label %25, label %41

25:                                               ; preds = %23
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %26, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !17
  %31 = getelementptr inbounds %class.CBenchmarkOutStream, ptr %12, i32 0, i32 5
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  %33 = getelementptr inbounds %class.CBenchmarkOutStream, ptr %12, i32 0, i32 4
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = add i32 %34, 1
  store i32 %35, ptr %33, align 8, !tbaa !11
  %36 = zext i32 %34 to i64
  %37 = getelementptr inbounds i8, ptr %32, i64 %36
  store i8 %30, ptr %37, align 1, !tbaa !17
  br label %38

38:                                               ; preds = %25
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = add i32 %39, 1
  store i32 %40, ptr %10, align 4, !tbaa !9
  br label %13, !llvm.loop !19

41:                                               ; preds = %23
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %47

44:                                               ; preds = %41
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %45, ptr %46, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %44, %41
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = icmp ne i32 %48, %49
  br i1 %50, label %51, label %55

51:                                               ; preds = %47
  %52 = getelementptr inbounds %class.CBenchmarkOutStream, ptr %12, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !21
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef @.str) #3
  store i32 -2147467259, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %56

55:                                               ; preds = %47
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %56

56:                                               ; preds = %55, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %57 = load i32, ptr %5, align 4
  ret i32 %57
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 24}
!12 = !{!"_ZTS19CBenchmarkOutStream", !13, i64 0, !15, i64 8, !10, i64 12, !6, i64 16, !10, i64 24, !6, i64 32}
!13 = !{!"_ZTS20ISequentialOutStream", !14, i64 0}
!14 = !{!"_ZTS8IUnknown"}
!15 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!16 = !{!12, !10, i64 12}
!17 = !{!7, !7, i64 0}
!18 = !{!12, !6, i64 32}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !6, i64 16}


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

@.str = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noundef range(i32 -2147467259, 1) i32 @_ZN19CBenchmarkOutStream5WriteEPKvjPj(ptr nocapture noundef nonnull align 8 dereferenceable(40) %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr noundef writeonly %3) unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %.not18 = icmp eq i32 %2, 0
  br i1 %.not18, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %wide.trip.count = zext i32 %2 to i64
  br label %8

8:                                                ; preds = %.lr.ph, %12
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %12 ]
  %9 = load i32, ptr %5, align 8, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !14
  %11 = icmp ult i32 %9, %10
  br i1 %11, label %12, label %.critedge.loopexit.split.loop.exit20

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  %14 = load i8, ptr %13, align 1, !tbaa !15
  %15 = load ptr, ptr %7, align 8, !tbaa !16
  %16 = add nuw i32 %9, 1
  store i32 %16, ptr %5, align 8, !tbaa !5
  %17 = zext i32 %9 to i64
  %18 = getelementptr inbounds i8, ptr %15, i64 %17
  store i8 %14, ptr %18, align 1, !tbaa !15
  %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 %8, !llvm.loop !17

.critedge.loopexit.split.loop.exit20:             ; preds = %8
  %19 = trunc nuw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %12, %.critedge.loopexit.split.loop.exit20, %4
  %.0.lcssa = phi i32 [ 0, %4 ], [ %19, %.critedge.loopexit.split.loop.exit20 ], [ %2, %12 ]
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %21, label %20

20:                                               ; preds = %.critedge
  store i32 %.0.lcssa, ptr %3, align 4, !tbaa !19
  br label %21

21:                                               ; preds = %20, %.critedge
  %.not14 = icmp eq i32 %.0.lcssa, %2
  br i1 %.not14, label %26, label %22

22:                                               ; preds = %21
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !20
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str) #2
  br label %26

26:                                               ; preds = %21, %22
  %.011 = phi i32 [ -2147467259, %22 ], [ 0, %21 ]
  ret i32 %.011
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { mustprogress nofree 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 = { nofree 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 24}
!6 = !{!"_ZTS19CBenchmarkOutStream", !7, i64 0, !9, i64 8, !10, i64 12, !13, i64 16, !10, i64 24, !13, i64 32}
!7 = !{!"_ZTS20ISequentialOutStream", !8, i64 0}
!8 = !{!"_ZTS8IUnknown"}
!9 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!10 = !{!"int", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"any pointer", !11, i64 0}
!14 = !{!6, !10, i64 12}
!15 = !{!11, !11, i64 0}
!16 = !{!6, !13, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!10, !10, i64 0}
!20 = !{!6, !13, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass