; LLVM IR from fwip/fastqz :: libzpaq.ll (ZN7libzpaq12Decompresser12findFilenameEPNS_6WriterE)

; 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.libzpaq::Decompresser" = type { %"class.libzpaq::ZPAQL", %"class.libzpaq::Decoder", %"class.libzpaq::PostProcessor", i32, i32 }
%"class.libzpaq::ZPAQL" = type { ptr, ptr, %"class.libzpaq::Array.0", i32, i32, i32, [4 x i8], %"class.libzpaq::Array.0", %"class.libzpaq::Array", %"class.libzpaq::Array", %"class.libzpaq::Array.4", i32, i32, i32, i32, i32, i32, i32, i32, ptr }
%"class.libzpaq::Array.0" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::Array" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::Array.4" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::Decoder" = type { ptr, i32, i32, i32, [4 x i8], %"class.libzpaq::Predictor", %"class.libzpaq::Array.4" }
%"class.libzpaq::Predictor" = type <{ i32, i32, [256 x i32], [256 x i32], ptr, [256 x %"struct.libzpaq::Component"], [256 x i32], [1024 x i32], [4096 x i16], [32768 x i16], %"class.libzpaq::StateTable", ptr, i32, [4 x i8] }>
%"struct.libzpaq::Component" = type { i64, i64, i64, i64, i64, %"class.libzpaq::Array", %"class.libzpaq::Array.0", %"class.libzpaq::Array.2" }
%"class.libzpaq::Array.2" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::StateTable" = type { [1024 x i8] }
%"class.libzpaq::PostProcessor" = type { i32, i32, i32, i32, %"class.libzpaq::ZPAQL" }

@.str.33 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [32 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

declare void @_ZN7libzpaq5errorEPKc(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7libzpaq12Decompresser12findFilenameEPNS_6WriterE(ptr noundef nonnull align 8 dereferenceable(111080) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %9 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 1
  %10 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr %11, align 8, !tbaa !23
  %13 = getelementptr inbounds ptr, ptr %12, i64 0
  %14 = load ptr, ptr %13, align 8
  %15 = call noundef i32 %14(ptr noundef nonnull align 8 dereferenceable(8) %11)
  store i32 %15, ptr %6, align 4, !tbaa !25
  %16 = load i32, ptr %6, align 4, !tbaa !25
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %46

18:                                               ; preds = %2
  br label %19

19:                                               ; preds = %45, %18
  br label %20

20:                                               ; preds = %19
  %21 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 1
  %22 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = load ptr, ptr %23, align 8, !tbaa !23
  %25 = getelementptr inbounds ptr, ptr %24, i64 0
  %26 = load ptr, ptr %25, align 8
  %27 = call noundef i32 %26(ptr noundef nonnull align 8 dereferenceable(8) %23)
  store i32 %27, ptr %6, align 4, !tbaa !25
  %28 = load i32, ptr %6, align 4, !tbaa !25
  %29 = icmp eq i32 %28, -1
  br i1 %29, label %30, label %31

30:                                               ; preds = %20
  call void @_ZN7libzpaq5errorEPKc(ptr noundef @.str.33)
  br label %31

31:                                               ; preds = %30, %20
  %32 = load i32, ptr %6, align 4, !tbaa !25
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %31
  %35 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 3
  store i32 2, ptr %35, align 8, !tbaa !26
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %54

36:                                               ; preds = %31
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %45

39:                                               ; preds = %36
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i32, ptr %6, align 4, !tbaa !25
  %42 = load ptr, ptr %40, align 8, !tbaa !23
  %43 = getelementptr inbounds ptr, ptr %42, i64 0
  %44 = load ptr, ptr %43, align 8
  call void %44(ptr noundef nonnull align 8 dereferenceable(8) %40, i32 noundef %41)
  br label %45

45:                                               ; preds = %39, %36
  br label %19, !llvm.loop !27

46:                                               ; preds = %2
  %47 = load i32, ptr %6, align 4, !tbaa !25
  %48 = icmp eq i32 %47, 255
  br i1 %48, label %49, label %51

49:                                               ; preds = %46
  %50 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 3
  store i32 0, ptr %50, align 8, !tbaa !26
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %54

51:                                               ; preds = %46
  call void @_ZN7libzpaq5errorEPKc(ptr noundef @.str.34)
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %54

54:                                               ; preds = %53, %49, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %55 = load i1, ptr %3, align 1
  ret i1 %55
}

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, !6, i64 192}
!10 = !{!"_ZTSN7libzpaq12DecompresserE", !11, i64 0, !17, i64 192, !20, i64 110864, !21, i64 111072, !22, i64 111076}
!11 = !{!"_ZTSN7libzpaq5ZPAQLE", !6, i64 0, !6, i64 8, !12, i64 16, !14, i64 40, !14, i64 44, !14, i64 48, !12, i64 56, !15, i64 80, !15, i64 104, !16, i64 128, !14, i64 152, !14, i64 156, !14, i64 160, !14, i64 164, !14, i64 168, !14, i64 172, !14, i64 176, !14, i64 180, !6, i64 184}
!12 = !{!"_ZTSN7libzpaq5ArrayIhEE", !6, i64 0, !13, i64 8, !14, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTSN7libzpaq5ArrayIjEE", !6, i64 0, !13, i64 8, !14, i64 16}
!16 = !{!"_ZTSN7libzpaq5ArrayIcEE", !6, i64 0, !13, i64 8, !14, i64 16}
!17 = !{!"_ZTSN7libzpaq7DecoderE", !6, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !18, i64 24, !16, i64 110648}
!18 = !{!"_ZTSN7libzpaq9PredictorE", !14, i64 0, !14, i64 4, !7, i64 8, !7, i64 1032, !6, i64 2056, !7, i64 2064, !7, i64 30736, !7, i64 31760, !7, i64 35856, !7, i64 44048, !19, i64 109584, !6, i64 110608, !14, i64 110616}
!19 = !{!"_ZTSN7libzpaq10StateTableE", !7, i64 0}
!20 = !{!"_ZTSN7libzpaq13PostProcessorE", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !11, i64 16}
!21 = !{!"_ZTSN7libzpaq12DecompresserUt_E", !7, i64 0}
!22 = !{!"_ZTSN7libzpaq12DecompresserUt0_E", !7, i64 0}
!23 = !{!24, !24, i64 0}
!24 = !{!"vtable pointer", !8, i64 0}
!25 = !{!14, !14, i64 0}
!26 = !{!10, !21, i64 111072}
!27 = distinct !{!27, !28}
!28 = !{!"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"

@.str.33 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [32 x i8], align 1

declare void @_ZN7libzpaq5errorEPKc(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7libzpaq12Decompresser12findFilenameEPNS_6WriterE(ptr nocapture noundef nonnull align 8 dereferenceable(111080) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 192
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8, !tbaa !22
  %6 = load ptr, ptr %5, align 8
  %7 = tail call noundef i32 %6(ptr noundef nonnull align 8 dereferenceable(8) %4)
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %.preheader, label %23

.preheader:                                       ; preds = %2
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %.preheader.split.us, label %.preheader.split

.preheader.split.us:                              ; preds = %.preheader, %.preheader.split.us.backedge
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %9, align 8, !tbaa !22
  %11 = load ptr, ptr %10, align 8
  %12 = tail call noundef i32 %11(ptr noundef nonnull align 8 dereferenceable(8) %9)
  switch i32 %12, label %.preheader.split.us.backedge [
    i32 -1, label %13
    i32 0, label %.split.us
  ]

13:                                               ; preds = %.preheader.split.us
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.33)
  br label %.preheader.split.us.backedge

.preheader.split.us.backedge:                     ; preds = %13, %.preheader.split.us
  br label %.preheader.split.us, !llvm.loop !24

.preheader.split:                                 ; preds = %.preheader, %20
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %14, align 8, !tbaa !22
  %16 = load ptr, ptr %15, align 8
  %17 = tail call noundef i32 %16(ptr noundef nonnull align 8 dereferenceable(8) %14)
  switch i32 %17, label %20 [
    i32 -1, label %18
    i32 0, label %.split.us
  ]

18:                                               ; preds = %.preheader.split
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.33)
  br label %20

.split.us:                                        ; preds = %.preheader.split, %.preheader.split.us
  %19 = getelementptr inbounds i8, ptr %0, i64 111072
  store i32 2, ptr %19, align 8, !tbaa !26
  br label %28

20:                                               ; preds = %18, %.preheader.split
  %21 = load ptr, ptr %1, align 8, !tbaa !22
  %22 = load ptr, ptr %21, align 8
  tail call void %22(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %17)
  br label %.preheader.split, !llvm.loop !24

23:                                               ; preds = %2
  %24 = icmp eq i32 %7, 255
  br i1 %24, label %25, label %27

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %0, i64 111072
  store i32 0, ptr %26, align 8, !tbaa !26
  br label %28

27:                                               ; preds = %23
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.34)
  br label %28

28:                                               ; preds = %27, %25, %.split.us
  ret i1 %8
}

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

!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, !8, i64 192}
!6 = !{!"_ZTSN7libzpaq12DecompresserE", !7, i64 0, !16, i64 192, !19, i64 110864, !20, i64 111072, !21, i64 111076}
!7 = !{!"_ZTSN7libzpaq5ZPAQLE", !8, i64 0, !8, i64 8, !11, i64 16, !13, i64 40, !13, i64 44, !13, i64 48, !11, i64 56, !14, i64 80, !14, i64 104, !15, i64 128, !13, i64 152, !13, i64 156, !13, i64 160, !13, i64 164, !13, i64 168, !13, i64 172, !13, i64 176, !13, i64 180, !8, i64 184}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN7libzpaq5ArrayIhEE", !8, i64 0, !12, i64 8, !13, i64 16}
!12 = !{!"long", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!"_ZTSN7libzpaq5ArrayIjEE", !8, i64 0, !12, i64 8, !13, i64 16}
!15 = !{!"_ZTSN7libzpaq5ArrayIcEE", !8, i64 0, !12, i64 8, !13, i64 16}
!16 = !{!"_ZTSN7libzpaq7DecoderE", !8, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !17, i64 24, !15, i64 110648}
!17 = !{!"_ZTSN7libzpaq9PredictorE", !13, i64 0, !13, i64 4, !9, i64 8, !9, i64 1032, !8, i64 2056, !9, i64 2064, !9, i64 30736, !9, i64 31760, !9, i64 35856, !9, i64 44048, !18, i64 109584, !8, i64 110608, !13, i64 110616}
!18 = !{!"_ZTSN7libzpaq10StateTableE", !9, i64 0}
!19 = !{!"_ZTSN7libzpaq13PostProcessorE", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !7, i64 16}
!20 = !{!"_ZTSN7libzpaq12DecompresserUt_E", !9, i64 0}
!21 = !{!"_ZTSN7libzpaq12DecompresserUt0_E", !9, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !10, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!6, !20, i64 111072}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass