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

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN3P3D8Graphics10parseUntilERNS0_5LexerENS1_5Token4TypeES4_(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 noundef signext %1, i8 noundef signext %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca %"struct.P3D::Graphics::Lexer::Token", align 8
  %9 = alloca i32, align 4
  %10 = alloca %"struct.P3D::Graphics::Lexer::Token", align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 -1, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #4
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN3P3D8Graphics5Lexer4nextEv(ptr dead_on_unwind writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8 %8, ptr noundef nonnull align 8 dereferenceable(16) %11) #4
  br label %12

12:                                               ; preds = %46, %3
  %13 = getelementptr inbounds %"struct.P3D::Graphics::Lexer::Token", ptr %8, i32 0, i32 0
  %14 = load i8, ptr %13, align 8, !tbaa !13
  %15 = sext i8 %14 to i32
  %16 = icmp ne i32 %15, 28
  br i1 %16, label %17, label %48

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

24:                                               ; preds = %17
  %25 = load i32, ptr %7, align 4, !tbaa !11
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %7, align 4, !tbaa !11
  br label %46

27:                                               ; preds = %17
  %28 = getelementptr inbounds %"struct.P3D::Graphics::Lexer::Token", ptr %8, i32 0, i32 0
  %29 = load i8, ptr %28, align 8, !tbaa !13
  %30 = sext i8 %29 to i32
  %31 = load i8, ptr %6, align 1, !tbaa !9
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %30, %32
  br i1 %33, label %34, label %45

34:                                               ; preds = %27
  %35 = load i32, ptr %7, align 4, !tbaa !11
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  store i32 1, ptr %9, align 4
  br label %49

38:                                               ; preds = %34
  %39 = load i32, ptr %7, align 4, !tbaa !11
  %40 = icmp sgt i32 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %38
  %42 = load i32, ptr %7, align 4, !tbaa !11
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr %7, align 4, !tbaa !11
  br label %44

44:                                               ; preds = %41, %38
  br label %45

45:                                               ; preds = %44, %27
  br label %46

46:                                               ; preds = %45, %24
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #4
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN3P3D8Graphics5Lexer4nextEv(ptr dead_on_unwind writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8 %10, ptr noundef nonnull align 8 dereferenceable(16) %47) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %10, i64 24, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #4
  br label %12, !llvm.loop !19

48:                                               ; preds = %12
  store i32 0, ptr %9, align 4
  br label %49

49:                                               ; preds = %48, %37
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %50 = load i32, ptr %9, align 4
  switch i32 %50, label %52 [
    i32 0, label %51
    i32 1, label %51
  ]

51:                                               ; preds = %49, %49
  ret void

52:                                               ; preds = %49
  unreachable
}

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

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

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTSN3P3D8Graphics5Lexer5TokenE", !10, i64 0, !15, i64 8}
!15 = !{!"_ZTSN3P3D8Graphics5Lexer5RangeE", !16, i64 0, !16, i64 8}
!16 = !{!"long", !7, i64 0}
!17 = !{i64 0, i64 1, !9, i64 8, i64 8, !18, i64 16, i64 8, !18}
!18 = !{!16, !16, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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 nounwind uwtable
define dso_local void @_ZN3P3D8Graphics10parseUntilERNS0_5LexerENS1_5Token4TypeES4_(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 noundef signext %1, i8 noundef signext %2) local_unnamed_addr #1 {
  %4 = alloca %"struct.P3D::Graphics::Lexer::Token", align 8
  %5 = alloca %"struct.P3D::Graphics::Lexer::Token", align 8
  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
  %6 = load i8, ptr %4, align 8, !tbaa !5
  %.not8 = icmp eq i8 %6, 28
  br i1 %.not8, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %18
  %7 = phi i8 [ %19, %18 ], [ %6, %3 ]
  %.09 = phi i32 [ %.1, %18 ], [ -1, %3 ]
  %8 = icmp eq i8 %7, %1
  br i1 %8, label %9, label %11

9:                                                ; preds = %.lr.ph
  %10 = add nsw i32 %.09, 1
  br label %18

11:                                               ; preds = %.lr.ph
  %12 = icmp eq i8 %7, %2
  br i1 %12, label %13, label %18

13:                                               ; preds = %11
  %14 = icmp eq i32 %.09, 0
  br i1 %14, label %._crit_edge, label %15

15:                                               ; preds = %13
  %16 = icmp sgt i32 %.09, 0
  %17 = sext i1 %16 to i32
  %spec.select = add nsw i32 %.09, %17
  br label %18

18:                                               ; preds = %15, %11, %9
  %.1 = phi i32 [ %10, %9 ], [ %.09, %11 ], [ %spec.select, %15 ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #4
  call void @_ZN3P3D8Graphics5Lexer4nextEv(ptr dead_on_unwind nonnull writable sret(%"struct.P3D::Graphics::Lexer::Token") align 8 %5, ptr noundef nonnull align 8 dereferenceable(16) %0) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(24) %5, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #4
  %19 = load i8, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i8 %19, 28
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

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

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

; 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 #3

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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,ReassociatePass,SROAPass,SimplifyCFGPass