; LLVM IR from rudi-cilibrasi/zlibcomplete :: lib/zlibtop.ll (ZN12zlibcomplete18ZLibBaseCompressorC2EiNS_15flush_parameterEi)

; 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.zlibcomplete::ZLibBaseCompressor" = type { [16384 x i8], [16384 x i8], i8, i8, %struct.z_stream_s }
%struct.z_stream_s = type { ptr, i32, i64, ptr, i32, i64, ptr, ptr, ptr, ptr, ptr, i32, i64, i64 }

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@_ZTISt9bad_alloc = external constant ptr

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12zlibcomplete18ZLibBaseCompressorC2EiNS_15flush_parameterEi(ptr noundef nonnull align 8 dereferenceable(32888) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca ptr, align 8
  %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
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  store i32 %3, ptr %8, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  %12 = getelementptr inbounds %"class.zlibcomplete::ZLibBaseCompressor", ptr %11, i32 0, i32 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %13 = getelementptr inbounds %"class.zlibcomplete::ZLibBaseCompressor", ptr %11, i32 0, i32 3
  store i8 0, ptr %13, align 1, !tbaa !13
  %14 = load i32, ptr %7, align 4, !tbaa !11
  %15 = icmp ne i32 %14, 0
  %16 = getelementptr inbounds %"class.zlibcomplete::ZLibBaseCompressor", ptr %11, i32 0, i32 2
  %17 = zext i1 %15 to i8
  store i8 %17, ptr %16, align 8, !tbaa !18
  %18 = getelementptr inbounds %"class.zlibcomplete::ZLibBaseCompressor", ptr %11, i32 0, i32 4
  %19 = getelementptr inbounds %struct.z_stream_s, ptr %18, i32 0, i32 8
  store ptr null, ptr %19, align 8, !tbaa !19
  %20 = getelementptr inbounds %"class.zlibcomplete::ZLibBaseCompressor", ptr %11, i32 0, i32 4
  %21 = getelementptr inbounds %struct.z_stream_s, ptr %20, i32 0, i32 9
  store ptr null, ptr %21, align 8, !tbaa !20
  %22 = getelementptr inbounds %"class.zlibcomplete::ZLibBaseCompressor", ptr %11, i32 0, i32 4
  %23 = getelementptr inbounds %struct.z_stream_s, ptr %22, i32 0, i32 10
  store ptr null, ptr %23, align 8, !tbaa !21
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 1
  br i1 %25, label %29, label %26

26:                                               ; preds = %4
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp sgt i32 %27, 9
  br i1 %28, label %29, label %30

29:                                               ; preds = %26, %4
  store i32 9, ptr %6, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %29, %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 9, ptr %10, align 4, !tbaa !9
  %31 = getelementptr inbounds %"class.zlibcomplete::ZLibBaseCompressor", ptr %11, i32 0, i32 4
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = call i32 @deflateInit2_(ptr noundef %31, i32 noundef %32, i32 noundef 8, i32 noundef %33, i32 noundef 9, i32 noundef 0, ptr noundef @.str, i32 noundef 112)
  store i32 %34, ptr %9, align 4, !tbaa !9
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %30
  %38 = call ptr @__cxa_allocate_exception(i64 8) #5
  call void @_ZNSt9bad_allocC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %38) #5
  call void @__cxa_throw(ptr %38, ptr @_ZTISt9bad_alloc, ptr @_ZNSt9bad_allocD1Ev) #6
  unreachable

39:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret void
}

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

declare i32 @deflateInit2_(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) #2

declare ptr @__cxa_allocate_exception(i64)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt9bad_allocC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 2

; Function Attrs: nounwind
declare void @_ZNSt9bad_allocD1Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #4

declare void @__cxa_throw(ptr, ptr, ptr)

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { noreturn }

!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, !12, i64 0}
!12 = !{!"_ZTSN12zlibcomplete15flush_parameterE", !7, i64 0}
!13 = !{!14, !15, i64 32769}
!14 = !{!"_ZTSN12zlibcomplete18ZLibBaseCompressorE", !7, i64 0, !7, i64 16384, !15, i64 32768, !15, i64 32769, !16, i64 32776}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTS10z_stream_s", !6, i64 0, !10, i64 8, !17, i64 16, !6, i64 24, !10, i64 32, !17, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !17, i64 96, !17, i64 104}
!17 = !{!"long", !7, i64 0}
!18 = !{!14, !15, i64 32768}
!19 = !{!14, !6, i64 32840}
!20 = !{!14, !6, i64 32848}
!21 = !{!14, !6, i64 32856}


; 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 [7 x i8], align 1
@_ZTISt9bad_alloc = external constant ptr

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12zlibcomplete18ZLibBaseCompressorC2EiNS_15flush_parameterEi(ptr noundef nonnull align 8 dereferenceable(32888) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 32769
  store i8 0, ptr %5, align 1, !tbaa !5
  %6 = icmp ne i32 %2, 0
  %7 = getelementptr inbounds i8, ptr %0, i64 32768
  %8 = zext i1 %6 to i8
  store i8 %8, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 32776
  %10 = getelementptr inbounds i8, ptr %0, i64 32840
  %11 = add i32 %1, -10
  %or.cond = icmp ult i32 %11, -9
  %spec.store.select = select i1 %or.cond, i32 9, i32 %1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %10, i8 0, i64 24, i1 false)
  %12 = tail call i32 @deflateInit2_(ptr noundef nonnull %9, i32 noundef %spec.store.select, i32 noundef 8, i32 noundef %3, i32 noundef 9, i32 noundef 0, ptr noundef nonnull @.str, i32 noundef 112)
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %15, label %13

13:                                               ; preds = %4
  %14 = tail call ptr @__cxa_allocate_exception(i64 8) #5
  tail call void @_ZNSt9bad_allocC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %14) #5
  tail call void @__cxa_throw(ptr nonnull %14, ptr nonnull @_ZTISt9bad_alloc, ptr nonnull @_ZNSt9bad_allocD1Ev) #6
  unreachable

15:                                               ; preds = %4
  ret void
}

declare i32 @deflateInit2_(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt9bad_allocC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: nounwind
declare void @_ZNSt9bad_allocD1Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { 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 #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 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 #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { noreturn }

!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, !9, i64 32769}
!6 = !{!"_ZTSN12zlibcomplete18ZLibBaseCompressorE", !7, i64 0, !7, i64 16384, !9, i64 32768, !9, i64 32769, !10, i64 32776}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"bool", !7, i64 0}
!10 = !{!"_ZTS10z_stream_s", !11, i64 0, !12, i64 8, !13, i64 16, !11, i64 24, !12, i64 32, !13, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !12, i64 88, !13, i64 96, !13, i64 104}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!6, !9, i64 32768}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass