; LLVM IR from marcinbor85/microshell :: src/src (ush_utils)

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

; 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: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @ush_utils_get_last_arg(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call i64 @strlen(ptr noundef %7) #4
  store i64 %8, ptr %4, align 8, !tbaa !9
  %9 = load i64, ptr %4, align 8, !tbaa !9
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %12, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %52

13:                                               ; preds = %1
  %14 = load i64, ptr %4, align 8, !tbaa !9
  %15 = add i64 %14, -1
  store i64 %15, ptr %4, align 8, !tbaa !9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %16, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !11
  %20 = sext i8 %19 to i32
  %21 = icmp eq i32 %20, 32
  br i1 %21, label %22, label %27

22:                                               ; preds = %13
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i64, ptr %4, align 8, !tbaa !9
  %25 = add i64 %24, 1
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  store ptr %26, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %52

27:                                               ; preds = %13
  br label %28

28:                                               ; preds = %49, %27
  %29 = load i64, ptr %4, align 8, !tbaa !9
  %30 = icmp ugt i64 %29, 0
  br i1 %30, label %31, label %50

31:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load i64, ptr %4, align 8, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %32, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !11
  store i8 %35, ptr %6, align 1, !tbaa !11
  %36 = load i8, ptr %6, align 1, !tbaa !11
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 32
  br i1 %38, label %39, label %44

39:                                               ; preds = %31
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load i64, ptr %4, align 8, !tbaa !9
  %42 = add i64 %41, 1
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  store ptr %43, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %47

44:                                               ; preds = %31
  %45 = load i64, ptr %4, align 8, !tbaa !9
  %46 = add i64 %45, -1
  store i64 %46, ptr %4, align 8, !tbaa !9
  store i32 0, ptr %5, align 4
  br label %47

47:                                               ; preds = %44, %39
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  %48 = load i32, ptr %5, align 4
  switch i32 %48, label %52 [
    i32 0, label %49
  ]

49:                                               ; preds = %47
  br label %28, !llvm.loop !12

50:                                               ; preds = %28
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %51, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %52

52:                                               ; preds = %50, %47, %22, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %53 = load ptr, ptr %2, align 8
  ret ptr %53
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) "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 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 #3 = { nounwind }
attributes #4 = { nounwind willreturn memory(read) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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 nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind memory(argmem: read) uwtable
define dso_local ptr @ush_utils_get_last_arg(ptr noundef readonly %0) local_unnamed_addr #1 {
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #2
  %3 = icmp eq i64 %2, 0
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %1
  %5 = add i64 %2, -1
  %6 = getelementptr inbounds i8, ptr %0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = icmp eq i8 %7, 32
  br i1 %8, label %9, label %.preheader

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 %2
  br label %.loopexit

.preheader:                                       ; preds = %4, %11
  %.018 = phi i64 [ %14, %11 ], [ %5, %4 ]
  %.not = icmp eq i64 %.018, 0
  br i1 %.not, label %.loopexit, label %11

11:                                               ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %0, i64 %.018
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %.not21 = icmp eq i8 %13, 32
  %14 = add i64 %.018, -1
  br i1 %.not21, label %.loopexit.split.loop.exit, label %.preheader, !llvm.loop !8

.loopexit.split.loop.exit:                        ; preds = %11
  %15 = getelementptr inbounds i8, ptr %0, i64 %.018
  %16 = getelementptr i8, ptr %15, i64 1
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %.loopexit.split.loop.exit, %1, %9
  %.2 = phi ptr [ %10, %9 ], [ %0, %1 ], [ %16, %.loopexit.split.loop.exit ], [ %0, %.preheader ]
  ret ptr %.2
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nofree nounwind memory(argmem: read) 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 willreturn memory(read) }

!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/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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