; LLVM IR from ThePhysicsGuys/Physics3D :: graphics/shader/parser.ll (ZN3P3D8Graphics10parseUntilERNS0_5LexerENS1_5Token4TypeE)

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

; 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) #0

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3P3D8Graphics10parseUntilERNS0_5LexerENS1_5Token4TypeE(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 noundef signext %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca %"struct.P3D::Graphics::Lexer::Token", align 8
  %6 = alloca i32, align 4
  %7 = alloca %"struct.P3D::Graphics::Lexer::Token", align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN3P3D8Graphics5Lexer4nextEv(ptr dead_on_unwind writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8 %5, ptr noundef nonnull align 8 dereferenceable(16) %8) #4
  br label %9

9:                                                ; preds = %22, %2
  %10 = getelementptr inbounds %"struct.P3D::Graphics::Lexer::Token", ptr %5, i32 0, i32 0
  %11 = load i8, ptr %10, align 8, !tbaa !11
  %12 = sext i8 %11 to i32
  %13 = icmp ne i32 %12, 28
  br i1 %13, label %14, label %24

14:                                               ; preds = %9
  %15 = getelementptr inbounds %"struct.P3D::Graphics::Lexer::Token", ptr %5, i32 0, i32 0
  %16 = load i8, ptr %15, align 8, !tbaa !11
  %17 = sext i8 %16 to i32
  %18 = load i8, ptr %4, align 1, !tbaa !9
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 %17, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %14
  store i32 1, ptr %6, align 4
  br label %25

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

24:                                               ; preds = %9
  store i32 0, ptr %6, align 4
  br label %25

25:                                               ; preds = %24, %21
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #4
  %26 = load i32, ptr %6, align 4
  switch i32 %26, label %28 [
    i32 0, label %27
    i32 1, label %27
  ]

27:                                               ; preds = %25, %25
  ret void

28:                                               ; preds = %25
  unreachable
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "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 = { 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 #4 = { 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 = !{!"_ZTSN3P3D8Graphics5Lexer5Token4TypeE", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN3P3D8Graphics5Lexer5TokenE", !10, i64 0, !13, i64 8}
!13 = !{!"_ZTSN3P3D8Graphics5Lexer5RangeE", !14, i64 0, !14, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{i64 0, i64 1, !9, i64 8, i64 8, !16, i64 16, i64 8, !16}
!16 = !{!14, !14, 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.P3D::Graphics::Lexer::Token" = type { i8, %"struct.P3D::Graphics::Lexer::Range" }
%"struct.P3D::Graphics::Lexer::Range" = type { i64, i64 }

; 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) #0

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3P3D8Graphics10parseUntilERNS0_5LexerENS1_5Token4TypeE(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 noundef signext %1) local_unnamed_addr #3 {
  %3 = alloca %"struct.P3D::Graphics::Lexer::Token", align 8
  %4 = alloca %"struct.P3D::Graphics::Lexer::Token", align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  call void @_ZN3P3D8Graphics5Lexer4nextEv(ptr dead_on_unwind nonnull writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8 %3, ptr noundef nonnull align 8 dereferenceable(16) %0) #4
  %5 = load i8, ptr %3, align 8, !tbaa !5
  %.not2 = icmp eq i8 %5, 28
  %6 = icmp eq i8 %5, %1
  %or.cond3 = or i1 %.not2, %6
  br i1 %or.cond3, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  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) %0) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %4, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  %7 = load i8, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i8 %7, 28
  %8 = icmp eq i8 %7, %1
  %or.cond = or i1 %.not, %8
  br i1 %or.cond, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %2
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  ret void
}

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


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