; LLVM IR from ThePhysicsGuys/Physics3D :: graphics/shader/lexer.ll (ZN3P3D8Graphics5Lexer4peekEm)

; 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.P3D::Graphics::Lexer::Token" = type { i8, %"struct.P3D::Graphics::Lexer::Range" }
%"struct.P3D::Graphics::Lexer::Range" = type { i64, i64 }
%"class.P3D::Graphics::Lexer" = type { i64, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3P3D8Graphics5Lexer4peekEm(ptr dead_on_unwind noalias writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %1, i64 noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca %"struct.P3D::Graphics::Lexer::Token", align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  store i64 %2, ptr %5, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  br label %10

10:                                               ; preds = %13, %3
  %11 = call noundef signext i8 @_ZNK3P3D8Graphics5Lexer8peekCharEm(ptr noundef nonnull align 8 dereferenceable(16) %9, i64 noundef 0) #3
  %12 = call noundef zeroext i1 @_ZN3P3D8Graphics5Lexer7isSpaceEc(i8 noundef signext %11) #3
  br i1 %12, label %13, label %15

13:                                               ; preds = %10
  %14 = call noundef signext i8 @_ZN3P3D8Graphics5Lexer7popCharEv(ptr noundef nonnull align 8 dereferenceable(16) %9) #3
  br label %10, !llvm.loop !11

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %16 = getelementptr inbounds %"class.P3D::Graphics::Lexer", ptr %9, i32 0, i32 0
  %17 = load i64, ptr %16, align 8, !tbaa !13
  store i64 %17, ptr %6, align 8, !tbaa !9
  call void @_ZN3P3D8Graphics5Lexer4nextEv(ptr dead_on_unwind writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %24, %15
  %19 = load i64, ptr %7, align 8, !tbaa !9
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %27

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #3
  call void @_ZN3P3D8Graphics5Lexer4nextEv(ptr dead_on_unwind writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8 %8, ptr noundef nonnull align 8 dereferenceable(16) %9) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %8, i64 24, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #3
  br label %24

24:                                               ; preds = %23
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = add i64 %25, 1
  store i64 %26, ptr %7, align 8, !tbaa !9
  br label %18, !llvm.loop !18

27:                                               ; preds = %22
  %28 = load i64, ptr %6, align 8, !tbaa !9
  %29 = getelementptr inbounds %"class.P3D::Graphics::Lexer", ptr %9, i32 0, i32 0
  store i64 %28, ptr %29, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3P3D8Graphics5Lexer7isSpaceEc(i8 noundef signext) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZNK3P3D8Graphics5Lexer8peekCharEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZN3P3D8Graphics5Lexer7popCharEv(ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3P3D8Graphics5Lexer4nextEv(ptr dead_on_unwind noalias writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8, ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTSN3P3D8Graphics5LexerE", !10, i64 0, !6, i64 8}
!15 = !{i64 0, i64 1, !16, i64 8, i64 8, !9, i64 16, i64 8, !9}
!16 = !{!17, !17, i64 0}
!17 = !{!"_ZTSN3P3D8Graphics5Lexer5Token4TypeE", !7, i64 0}
!18 = distinct !{!18, !12}


; 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.P3D::Graphics::Lexer::Token" = type { i8, %"struct.P3D::Graphics::Lexer::Range" }
%"struct.P3D::Graphics::Lexer::Range" = type { i64, i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3P3D8Graphics5Lexer4peekEm(ptr dead_on_unwind noalias writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %1, i64 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = alloca %"struct.P3D::Graphics::Lexer::Token", align 8
  %5 = tail call noundef signext i8 @_ZNK3P3D8Graphics5Lexer8peekCharEm(ptr noundef nonnull align 8 dereferenceable(16) %1, i64 noundef 0) #3
  %6 = tail call noundef zeroext i1 @_ZN3P3D8Graphics5Lexer7isSpaceEc(i8 noundef signext %5) #3
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %7 = tail call noundef signext i8 @_ZN3P3D8Graphics5Lexer7popCharEv(ptr noundef nonnull align 8 dereferenceable(16) %1) #3
  %8 = tail call noundef signext i8 @_ZNK3P3D8Graphics5Lexer8peekCharEm(ptr noundef nonnull align 8 dereferenceable(16) %1, i64 noundef 0) #3
  %9 = tail call noundef zeroext i1 @_ZN3P3D8Graphics5Lexer7isSpaceEc(i8 noundef signext %8) #3
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %3
  %10 = load i64, ptr %1, align 8, !tbaa !7
  tail call void @_ZN3P3D8Graphics5Lexer4nextEv(ptr dead_on_unwind writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %1) #3
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge7, label %.lr.ph6

._crit_edge7:                                     ; preds = %.lr.ph6, %._crit_edge
  store i64 %10, ptr %1, align 8, !tbaa !7
  ret void

.lr.ph6:                                          ; preds = %._crit_edge, %.lr.ph6
  %.04 = phi i64 [ %11, %.lr.ph6 ], [ 0, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #3
  call void @_ZN3P3D8Graphics5Lexer4nextEv(ptr dead_on_unwind nonnull writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8 %4, ptr noundef nonnull align 8 dereferenceable(16) %1) #3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %4, i64 24, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  %11 = add nuw i64 %.04, 1
  %exitcond.not = icmp eq i64 %11, %2
  br i1 %exitcond.not, label %._crit_edge7, label %.lr.ph6, !llvm.loop !17
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3P3D8Graphics5Lexer7isSpaceEc(i8 noundef signext) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZNK3P3D8Graphics5Lexer8peekCharEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZN3P3D8Graphics5Lexer7popCharEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3P3D8Graphics5Lexer4nextEv(ptr dead_on_unwind noalias writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8, ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass