; LLVM IR from facebookresearch/habitat-sim :: src/deps/basis-universal/encoder/lodepng.ll (Z18lodepng_chunk_findPhPKhPKc)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_Z25lodepng_chunk_type_equalsPKhPKc(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z18lodepng_chunk_nextPh(ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z18lodepng_chunk_findPhPKhPKc(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %21, %3
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 12
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = icmp uge ptr %10, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %8
  store ptr null, ptr %4, align 8
  br label %24

14:                                               ; preds = %8
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = call noundef zeroext i8 @_Z25lodepng_chunk_type_equalsPKhPKc(ptr noundef %15, ptr noundef %16)
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %14
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %20, ptr %4, align 8
  br label %24

21:                                               ; preds = %14
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call noundef ptr @_Z18lodepng_chunk_nextPh(ptr noundef %22)
  store ptr %23, ptr %5, align 8, !tbaa !5
  br label %8, !llvm.loop !9

24:                                               ; preds = %19, %13
  %25 = load ptr, ptr %4, align 8
  ret ptr %25
}

attributes #0 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_Z25lodepng_chunk_type_equalsPKhPKc(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z18lodepng_chunk_nextPh(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z18lodepng_chunk_findPhPKhPKc(ptr noundef %0, ptr noundef readnone %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %.not9 = icmp ult ptr %4, %1
  br i1 %.not9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %6
  %.0710 = phi ptr [ %7, %6 ], [ %0, %3 ]
  %5 = tail call noundef zeroext i8 @_Z25lodepng_chunk_type_equalsPKhPKc(ptr noundef %.0710, ptr noundef %2)
  %.not8 = icmp eq i8 %5, 0
  br i1 %.not8, label %6, label %._crit_edge

6:                                                ; preds = %.lr.ph
  %7 = tail call noundef ptr @_Z18lodepng_chunk_nextPh(ptr noundef %.0710)
  %8 = getelementptr inbounds i8, ptr %7, i64 12
  %.not = icmp ult ptr %8, %1
  br i1 %.not, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %6, %.lr.ph, %3
  %.0 = phi ptr [ null, %3 ], [ %.0710, %.lr.ph ], [ null, %6 ]
  ret ptr %.0
}

attributes #0 = { 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass