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

; 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::cli::commandHandler" = type { ptr, ptr, ptr, ptr, i64, i64, i16, ptr }
%"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 }

; 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 ptr @_ZNK3qOS3cli14commandHandler9getArgPtrEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store ptr null, ptr %5, align 8, !tbaa !5
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = icmp ugt i64 %10, 0
  br i1 %11, label %12, label %68

12:                                               ; preds = %2
  %13 = getelementptr inbounds %"class.qOS::cli::commandHandler", ptr %9, i32 0, i32 6
  %14 = load i16, ptr %13, align 8, !tbaa !11
  %15 = zext i16 %14 to i32
  %16 = icmp eq i32 256, %15
  br i1 %16, label %17, label %67

17:                                               ; preds = %12
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = icmp eq i64 1, %18
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  %21 = getelementptr inbounds %"class.qOS::cli::commandHandler", ptr %9, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  store ptr %22, ptr %5, align 8, !tbaa !5
  br label %66

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  %24 = load i64, ptr %4, align 8, !tbaa !9
  %25 = add i64 %24, -1
  store i64 %25, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %61, %23
  %27 = getelementptr inbounds %"class.qOS::cli::commandHandler", ptr %9, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %28, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !15
  %32 = sext i8 %31 to i32
  %33 = icmp ne i32 0, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %26
  store i32 2, ptr %8, align 4
  br label %64

35:                                               ; preds = %26
  %36 = getelementptr inbounds %"class.qOS::cli::commandHandler", ptr %9, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = getelementptr inbounds %"class.qOS::commandLineInterface", ptr %37, i32 0, i32 8
  %39 = load i8, ptr %38, align 8, !tbaa !17
  %40 = sext i8 %39 to i32
  %41 = getelementptr inbounds %"class.qOS::cli::commandHandler", ptr %9, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %42, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !15
  %46 = sext i8 %45 to i32
  %47 = icmp eq i32 %40, %46
  br i1 %47, label %48, label %60

48:                                               ; preds = %35
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = add i64 %49, 1
  store i64 %50, ptr %6, align 8, !tbaa !9
  %51 = load i64, ptr %4, align 8, !tbaa !9
  %52 = icmp uge i64 %50, %51
  br i1 %52, label %53, label %59

53:                                               ; preds = %48
  %54 = getelementptr inbounds %"class.qOS::cli::commandHandler", ptr %9, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !14
  %56 = load i64, ptr %7, align 8, !tbaa !9
  %57 = add i64 %56, 1
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  store ptr %58, ptr %5, align 8, !tbaa !5
  store i32 2, ptr %8, align 4
  br label %64

59:                                               ; preds = %48
  br label %60

60:                                               ; preds = %59, %35
  br label %61

61:                                               ; preds = %60
  %62 = load i64, ptr %7, align 8, !tbaa !9
  %63 = add i64 %62, 1
  store i64 %63, ptr %7, align 8, !tbaa !9
  br label %26, !llvm.loop !23

64:                                               ; preds = %53, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %65

65:                                               ; preds = %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %66

66:                                               ; preds = %65, %20
  br label %67

67:                                               ; preds = %66, %12
  br label %68

68:                                               ; preds = %67, %2
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret ptr %69
}

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 = !{!12, !13, i64 48}
!12 = !{!"_ZTSN3qOS3cli14commandHandlerE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 40, !13, i64 48, !6, i64 56}
!13 = !{!"_ZTSN3qOS3cli11commandTypeE", !7, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !6, i64 0}
!17 = !{!18, !7, i64 208}
!18 = !{!"_ZTSN3qOS20commandLineInterfaceE", !19, i64 0, !21, i64 48, !12, 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}
!19 = !{!"_ZTSN3qOS3cli5inputE", !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !20, i64 40}
!20 = !{!"bool", !7, i64 0}
!21 = !{!"_ZTSN3qOS4listE", !22, i64 0, !6, i64 32, !6, i64 40, !10, i64 48}
!22 = !{!"_ZTSN3qOS4nodeE", !6, i64 8, !6, i64 16, !6, i64 24}
!23 = distinct !{!23, !24}
!24 = !{!"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 ptr @_ZNK3qOS3cli14commandHandler9getArgPtrEm(ptr nocapture noundef nonnull readonly align 8 dereferenceable(64) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %.not = icmp ne i64 %1, 0
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = load i16, ptr %3, align 8
  %5 = icmp eq i16 %4, 256
  %or.cond = select i1 %.not, i1 %5, i1 false
  br i1 %or.cond, label %6, label %.loopexit

6:                                                ; preds = %2
  %7 = icmp eq i64 %1, 1
  br i1 %7, label %8, label %11

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  br label %.loopexit

11:                                               ; preds = %6
  %12 = add i64 %1, -1
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = load i8, ptr %14, align 1, !tbaa !12
  %.not1621 = icmp eq i8 %15, 0
  br i1 %.not1621, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %16 = load ptr, ptr %0, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %16, i64 208
  %18 = load i8, ptr %17, align 8, !tbaa !14
  br label %19

19:                                               ; preds = %.lr.ph, %27
  %20 = phi i8 [ %15, %.lr.ph ], [ %30, %27 ]
  %.023 = phi i64 [ 0, %.lr.ph ], [ %28, %27 ]
  %.01022 = phi i64 [ 0, %.lr.ph ], [ %.1, %27 ]
  %21 = icmp eq i8 %18, %20
  br i1 %21, label %22, label %27

22:                                               ; preds = %19
  %23 = add i64 %.01022, 1
  %.not17 = icmp ult i64 %23, %12
  br i1 %.not17, label %27, label %24

24:                                               ; preds = %22
  %25 = getelementptr inbounds i8, ptr %14, i64 %.023
  %26 = getelementptr i8, ptr %25, i64 1
  br label %.loopexit

27:                                               ; preds = %19, %22
  %.1 = phi i64 [ %23, %22 ], [ %.01022, %19 ]
  %28 = add i64 %.023, 1
  %29 = getelementptr inbounds i8, ptr %14, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !12
  %.not16 = icmp eq i8 %30, 0
  br i1 %.not16, label %.loopexit, label %19, !llvm.loop !20

.loopexit:                                        ; preds = %27, %11, %24, %8, %2
  %.112 = phi ptr [ %10, %8 ], [ null, %2 ], [ %26, %24 ], [ null, %11 ], [ null, %27 ]
  ret ptr %.112
}

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


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