; LLVM IR from marcinbor85/microshell :: src/src/commands (ush_cmd_ls)

; 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.ush_object = type { ptr, i32, i32, i32, ptr, i64, i64, i32, i64, i64, i64, i8, ptr, ptr, ptr, %struct.ush_node_object, ptr, ptr, ptr, i64, i64, ptr, i64, i32, i32, ptr, ptr, ptr, i64, i64, i64 }
%struct.ush_node_object = type { ptr, i64, ptr, ptr, ptr, ptr }
%struct.ush_descriptor = type { ptr, ptr, i64, ptr, i64, i64, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @ush_buildin_cmd_ls_callback(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load i32, ptr %7, align 4, !tbaa !9
  switch i32 %13, label %46 [
    i32 1, label %14
    i32 2, label %20
  ]

14:                                               ; preds = %4
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ush_object, ptr %15, i32 0, i32 14
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ush_object, ptr %18, i32 0, i32 16
  store ptr %17, ptr %19, align 8, !tbaa !16
  br label %48

20:                                               ; preds = %4
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ush_object, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %24 = getelementptr inbounds %struct.ush_descriptor, ptr %23, i32 0, i32 5
  %25 = load i64, ptr %24, align 8, !tbaa !18
  %26 = call ptr @llvm.stacksave.p0()
  store ptr %26, ptr %9, align 8
  %27 = alloca i8, i64 %25, align 16
  store i64 %25, ptr %10, align 8
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds ptr, ptr %29, i64 1
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  call void @ush_node_get_absolute_path(ptr noundef %28, ptr noundef %31, ptr noundef %27)
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = call ptr @ush_node_get_by_path(ptr noundef %32, ptr noundef %27)
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ush_object, ptr %34, i32 0, i32 16
  store ptr %33, ptr %35, align 8, !tbaa !16
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ush_object, ptr %36, i32 0, i32 16
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %42

40:                                               ; preds = %20
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  call void @ush_print_status(ptr noundef %41, i32 noundef 1)
  store i32 1, ptr %11, align 4
  br label %43

42:                                               ; preds = %20
  store i32 2, ptr %11, align 4
  br label %43

43:                                               ; preds = %42, %40
  %44 = load ptr, ptr %9, align 8
  call void @llvm.stackrestore.p0(ptr %44)
  %45 = load i32, ptr %11, align 4
  switch i32 %45, label %52 [
    i32 1, label %51
    i32 2, label %48
  ]

46:                                               ; preds = %4
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  call void @ush_print_status(ptr noundef %47, i32 noundef 6)
  br label %51

48:                                               ; preds = %43, %14
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  call void @ush_process_start(ptr noundef %49, ptr noundef %50)
  br label %51

51:                                               ; preds = %48, %46, %43
  ret void

52:                                               ; preds = %43
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

declare void @ush_node_get_absolute_path(ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @ush_node_get_by_path(ptr noundef, ptr noundef) #2

declare void @ush_print_status(ptr noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

declare void @ush_process_start(ptr noundef, ptr noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 104}
!12 = !{!"ush_object", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24, !13, i64 32, !13, i64 40, !10, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !14, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !15, i64 112, !6, i64 160, !6, i64 168, !6, i64 176, !13, i64 184, !13, i64 192, !6, i64 200, !13, i64 208, !10, i64 216, !10, i64 220, !6, i64 224, !6, i64 232, !6, i64 240, !13, i64 248, !13, i64 256, !13, i64 264}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!"ush_node_object", !6, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!16 = !{!12, !6, i64 160}
!17 = !{!12, !6, i64 0}
!18 = !{!19, !13, i64 40}
!19 = !{!"ush_descriptor", !6, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !13, i64 32, !13, i64 40, !6, i64 48, !6, i64 56}


; 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: nounwind uwtable
define dso_local void @ush_buildin_cmd_ls_callback(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  switch i32 %2, label %21 [
    i32 1, label %5
    i32 2, label %9
  ]

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 104
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 160
  store ptr %7, ptr %8, align 8, !tbaa !14
  br label %22

9:                                                ; preds = %4
  %10 = load ptr, ptr %0, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %10, i64 40
  %12 = load i64, ptr %11, align 8, !tbaa !16
  %13 = tail call ptr @llvm.stacksave.p0()
  %14 = alloca i8, i64 %12, align 16
  %15 = getelementptr inbounds i8, ptr %3, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  call void @ush_node_get_absolute_path(ptr noundef nonnull %0, ptr noundef %16, ptr noundef nonnull %14) #3
  %17 = call ptr @ush_node_get_by_path(ptr noundef nonnull %0, ptr noundef nonnull %14) #3
  %18 = getelementptr inbounds i8, ptr %0, i64 160
  store ptr %17, ptr %18, align 8, !tbaa !14
  %19 = icmp eq ptr %17, null
  br i1 %19, label %.thread, label %20

.thread:                                          ; preds = %9
  call void @ush_print_status(ptr noundef nonnull %0, i32 noundef 1) #3
  call void @llvm.stackrestore.p0(ptr %13)
  br label %23

20:                                               ; preds = %9
  call void @llvm.stackrestore.p0(ptr %13)
  br label %22

21:                                               ; preds = %4
  tail call void @ush_print_status(ptr noundef %0, i32 noundef 6) #3
  br label %23

22:                                               ; preds = %20, %5
  call void @ush_process_start(ptr noundef nonnull %0, ptr noundef %1) #3
  br label %23

23:                                               ; preds = %.thread, %22, %21
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

declare void @ush_node_get_absolute_path(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @ush_node_get_by_path(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @ush_print_status(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

declare void @ush_process_start(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #2 = { "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 }

!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 104}
!6 = !{!"ush_object", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 24, !11, i64 32, !11, i64 40, !10, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !12, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !13, i64 112, !7, i64 160, !7, i64 168, !7, i64 176, !11, i64 184, !11, i64 192, !7, i64 200, !11, i64 208, !10, i64 216, !10, i64 220, !7, i64 224, !7, i64 232, !7, i64 240, !11, i64 248, !11, i64 256, !11, i64 264}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!"ush_node_object", !7, i64 0, !11, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!14 = !{!6, !7, i64 160}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !11, i64 40}
!17 = !{!"ush_descriptor", !7, i64 0, !7, i64 8, !11, i64 16, !7, i64 24, !11, i64 32, !11, i64 40, !7, i64 48, !7, i64 56}
!18 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass