; LLVM IR from aap/librw :: src/plg.ll (ZN2rw10PluginList10streamSkipEPNS_6StreamE)

; 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

declare noundef zeroext i1 @_ZN2rw9findChunkEPNS_6StreamEjPjS2_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #1

declare noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef, ptr noundef) #1

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

11:                                               ; preds = %2
  store i32 1, ptr %7, align 4
  br label %33

12:                                               ; preds = %2
  br label %13

13:                                               ; preds = %20, %12
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %16, label %32

16:                                               ; preds = %13
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef %17, ptr noundef %6)
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  store i32 1, ptr %7, align 4
  br label %33

20:                                               ; preds = %16
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %6, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = load ptr, ptr %21, align 8, !tbaa !13
  %25 = getelementptr inbounds ptr, ptr %24, i64 5
  %26 = load ptr, ptr %25, align 8
  call void %26(ptr noundef nonnull align 8 dereferenceable(8) %21, i32 noundef %23, i32 noundef 1)
  %27 = getelementptr inbounds %"struct.rw::ChunkHeaderInfo", ptr %6, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = add i32 12, %28
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = sub i32 %30, %29
  store i32 %31, ptr %5, align 4, !tbaa !9
  br label %13, !llvm.loop !15

32:                                               ; preds = %13
  store i32 0, ptr %7, align 4
  br label %33

33:                                               ; preds = %32, %19, %11
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %34 = load i32, ptr %7, align 4
  switch i32 %34, label %36 [
    i32 0, label %35
    i32 1, label %35
  ]

35:                                               ; preds = %33, %33
  ret void

36:                                               ; preds = %33
  unreachable
}

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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTSN2rw15ChunkHeaderInfoE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !8, 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"

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

declare noundef zeroext i1 @_ZN2rw9findChunkEPNS_6StreamEjPjS2_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw10PluginList10streamSkipEPNS_6StreamE(ptr nocapture noundef nonnull readnone align 8 dereferenceable(24) %0, ptr noundef %1) local_unnamed_addr #2 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca %"struct.rw::ChunkHeaderInfo", align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  %5 = call noundef zeroext i1 @_ZN2rw9findChunkEPNS_6StreamEjPjS2_(ptr noundef %1, i32 noundef 3, ptr noundef nonnull %3, ptr noundef null)
  %6 = load i32, ptr %3, align 4
  %7 = icmp sgt i32 %6, 0
  %or.cond = select i1 %5, i1 %7, i1 false
  br i1 %or.cond, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %2
  %8 = getelementptr inbounds i8, ptr %4, i64 4
  br label %9

9:                                                ; preds = %.preheader, %11
  %10 = call noundef zeroext i1 @_ZN2rw19readChunkHeaderInfoEPNS_6StreamEPNS_15ChunkHeaderInfoE(ptr noundef %1, ptr noundef nonnull %4)
  br i1 %10, label %11, label %.loopexit

11:                                               ; preds = %9
  %12 = load i32, ptr %8, align 4, !tbaa !5
  %13 = load ptr, ptr %1, align 8, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %13, i64 40
  %15 = load ptr, ptr %14, align 8
  call void %15(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %12, i32 noundef 1)
  %16 = load i32, ptr %8, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !12
  %reass.sub = sub i32 %17, %16
  %18 = add i32 %reass.sub, -12
  store i32 %18, ptr %3, align 4, !tbaa !12
  %.old4 = icmp sgt i32 %18, 0
  br i1 %.old4, label %9, label %.loopexit

.loopexit:                                        ; preds = %11, %9, %2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret void
}

attributes #0 = { mustprogress 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, !7, i64 4}
!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 = !{!11, !11, i64 0}
!11 = !{!"vtable pointer", !9, i64 0}
!12 = !{!7, !7, i64 0}


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