; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/cli.ll (ZNK3qOS20commandLineInterface9numOfArgsEPKc)

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

%"class.qOS::commandLineInterface" = type { %"class.qOS::cli::input.base", %"class.qOS::list", %"class.qOS::cli::commandHandler", ptr, ptr, ptr, ptr, ptr, i8, ptr, i64, ptr, ptr }
%"class.qOS::cli::input.base" = type <{ ptr, ptr, i64, i64, i64, i8 }>
%"class.qOS::list" = type { %"class.qOS::node", ptr, ptr, i64 }
%"class.qOS::node" = type { ptr, ptr, ptr, ptr }
%"class.qOS::cli::commandHandler" = type { ptr, ptr, ptr, ptr, i64, i64, i16, ptr }

; 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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZNK3qOS20commandLineInterface9numOfArgsEPKc(ptr noundef nonnull align 8 dereferenceable(248) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %24, %2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load i8, ptr %8, align 1, !tbaa !11
  %10 = sext i8 %9 to i32
  %11 = icmp ne i32 0, %10
  br i1 %11, label %12, label %25

12:                                               ; preds = %7
  %13 = getelementptr inbounds %"class.qOS::commandLineInterface", ptr %6, i32 0, i32 8
  %14 = load i8, ptr %13, align 8, !tbaa !12
  %15 = sext i8 %14 to i32
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i32 1
  store ptr %17, ptr %4, align 8, !tbaa !5
  %18 = load i8, ptr %16, align 1, !tbaa !11
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 %15, %19
  br i1 %20, label %21, label %24

21:                                               ; preds = %12
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = add i64 %22, 1
  store i64 %23, ptr %5, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %21, %12
  br label %7, !llvm.loop !20

25:                                               ; preds = %7
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = add i64 %26, 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i64 %27
}

attributes #0 = { nocallback nofree nosync 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 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 208}
!13 = !{!"_ZTSN3qOS20commandLineInterfaceE", !14, i64 0, !16, i64 48, !18, i64 104, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !7, i64 208, !6, i64 216, !10, i64 224, !6, i64 232, !6, i64 240}
!14 = !{!"_ZTSN3qOS3cli5inputE", !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !15, i64 40}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSN3qOS4listE", !17, i64 0, !6, i64 32, !6, i64 40, !10, i64 48}
!17 = !{!"_ZTSN3qOS4nodeE", !6, i64 8, !6, i64 16, !6, i64 24}
!18 = !{!"_ZTSN3qOS3cli14commandHandlerE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 40, !19, i64 48, !6, i64 56}
!19 = !{!"_ZTSN3qOS3cli11commandTypeE", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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 nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_ZNK3qOS20commandLineInterface9numOfArgsEPKc(ptr nocapture noundef nonnull readonly align 8 dereferenceable(248) %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 align 2 {
  %3 = load i8, ptr %1, align 1, !tbaa !5
  %.not6 = icmp eq i8 %3, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 208
  %5 = load i8, ptr %4, align 8, !tbaa !8
  br label %6

6:                                                ; preds = %.lr.ph, %6
  %7 = phi i8 [ %3, %.lr.ph ], [ %11, %6 ]
  %.08 = phi i64 [ 0, %.lr.ph ], [ %spec.select, %6 ]
  %.047 = phi ptr [ %1, %.lr.ph ], [ %8, %6 ]
  %8 = getelementptr inbounds i8, ptr %.047, i64 1
  %9 = icmp eq i8 %5, %7
  %10 = zext i1 %9 to i64
  %spec.select = add i64 %.08, %10
  %11 = load i8, ptr %8, align 1, !tbaa !5
  %.not = icmp eq i8 %11, 0
  br i1 %.not, label %._crit_edge.loopexit, label %6, !llvm.loop !18

._crit_edge.loopexit:                             ; preds = %6
  %12 = add i64 %spec.select, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.0.lcssa = phi i64 [ 1, %2 ], [ %12, %._crit_edge.loopexit ]
  ret i64 %.0.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !6, i64 208}
!9 = !{!"_ZTSN3qOS20commandLineInterfaceE", !10, i64 0, !14, i64 48, !16, i64 104, !11, i64 168, !11, i64 176, !11, i64 184, !11, i64 192, !11, i64 200, !6, i64 208, !11, i64 216, !12, i64 224, !11, i64 232, !11, i64 240}
!10 = !{!"_ZTSN3qOS3cli5inputE", !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !13, i64 40}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!"long", !6, i64 0}
!13 = !{!"bool", !6, i64 0}
!14 = !{!"_ZTSN3qOS4listE", !15, i64 0, !11, i64 32, !11, i64 40, !12, i64 48}
!15 = !{!"_ZTSN3qOS4nodeE", !11, i64 8, !11, i64 16, !11, i64 24}
!16 = !{!"_ZTSN3qOS3cli14commandHandlerE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !12, i64 40, !17, i64 48, !11, i64 56}
!17 = !{!"_ZTSN3qOS3cli11commandTypeE", !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass