; LLVM IR from aap/librw :: src/base.ll (ZN2rw9findChunkEPNS_6StreamEjPjS2_)

; 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.rw::ChunkHeaderInfo" = type { i32, i32, 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: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2rw9findChunkEPNS_6StreamEjPjS2_(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %"struct.rw::ChunkHeaderInfo", align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #2
  br label %12

12:                                               ; preds = %40, %4
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef %13, ptr noundef %10)
  br i1 %14, label %15, label %47

15:                                               ; preds = %12
  %16 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %10, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  store i1 false, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %48

20:                                               ; preds = %15
  %21 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %10, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = icmp eq i32 %22, %23
  br i1 %24, label %25, label %40

25:                                               ; preds = %20
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %32

28:                                               ; preds = %25
  %29 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %10, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %30, ptr %31, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %28, %25
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %39

35:                                               ; preds = %32
  %36 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %10, i32 0, i32 2
  %37 = load i32, ptr %36, align 4, !tbaa !14
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %37, ptr %38, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %35, %32
  store i1 true, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %48

40:                                               ; preds = %20
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %10, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !13
  %44 = load ptr, ptr %41, align 8, !tbaa !15
  %45 = getelementptr inbounds ptr, ptr %44, i64 5
  %46 = load ptr, ptr %45, align 8
  call void %46(ptr noundef nonnull align 8 dereferenceable(8) %41, i32 noundef %43, i32 noundef 1)
  br label %12, !llvm.loop !17

47:                                               ; preds = %12
  store i1 false, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %48

48:                                               ; preds = %47, %39, %19
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #2
  %49 = load i1, ptr %5, align 1
  ret i1 %49
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 0}
!12 = !{!"_ZTSN2rw15ChunkHeaderInfoE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%"struct.rw::ChunkHeaderInfo" = type { i32, i32, i32, i32 }

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN2rw9findChunkEPNS_6StreamEjPjS2_(ptr noundef %0, i32 noundef %1, ptr noundef writeonly %2, ptr noundef writeonly %3) local_unnamed_addr #1 {
  %5 = alloca %"struct.rw::ChunkHeaderInfo", align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #2
  %6 = call noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef %0, ptr noundef nonnull %5)
  br i1 %6, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %4
  %7 = getelementptr inbounds i8, ptr %5, i64 4
  br label %8

8:                                                ; preds = %.lr.ph, %20
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %8
  %12 = icmp eq i32 %9, %1
  br i1 %12, label %13, label %20

13:                                               ; preds = %11
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %16, label %14

14:                                               ; preds = %13
  %15 = load i32, ptr %7, align 4, !tbaa !10
  store i32 %15, ptr %2, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %14, %13
  %.not10 = icmp eq ptr %3, null
  br i1 %.not10, label %.loopexit, label %17

17:                                               ; preds = %16
  %18 = getelementptr inbounds i8, ptr %5, i64 8
  %19 = load i32, ptr %18, align 4, !tbaa !12
  store i32 %19, ptr %3, align 4, !tbaa !11
  br label %.loopexit

20:                                               ; preds = %11
  %21 = load i32, ptr %7, align 4, !tbaa !10
  %22 = load ptr, ptr %0, align 8, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %22, i64 40
  %24 = load ptr, ptr %23, align 8
  call void %24(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %21, i32 noundef 1)
  %25 = call noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef nonnull %0, ptr noundef nonnull %5)
  br i1 %25, label %8, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %8, %20, %4, %16, %17
  %.0 = phi i1 [ true, %17 ], [ true, %16 ], [ false, %4 ], [ false, %20 ], [ false, %8 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #2
  ret i1 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN2rw15ChunkHeaderInfoE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !9, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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