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

; 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_file_descriptor = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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 }

@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @ush_buildin_cmd_echo_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 ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  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
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !11
  %16 = load i32, ptr %7, align 4, !tbaa !9
  switch i32 %16, label %76 [
    i32 4, label %17
    i32 2, label %43
    i32 1, label %54
  ]

17:                                               ; preds = %4
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds ptr, ptr %18, i64 2
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = call i32 @strcmp(ptr noundef %20, ptr noundef @.str) #5
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %17
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  call void @ush_print_status(ptr noundef %24, i32 noundef 6)
  br label %78

25:                                               ; preds = %17
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds ptr, ptr %27, i64 3
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = call ptr @ush_file_find_by_name(ptr noundef %26, ptr noundef %29)
  store ptr %30, ptr %9, align 8, !tbaa !5
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %35

33:                                               ; preds = %25
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  call void @ush_print_status(ptr noundef %34, i32 noundef 11)
  br label %78

35:                                               ; preds = %25
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ush_file_descriptor, ptr %36, i32 0, i32 5
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %42

40:                                               ; preds = %35
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  call void @ush_print_status(ptr noundef %41, i32 noundef 8)
  br label %78

42:                                               ; preds = %35
  br label %43

43:                                               ; preds = %42, %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds ptr, ptr %44, i64 1
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  store ptr %46, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = call i64 @strlen(ptr noundef %47) #5
  store i64 %48, ptr %13, align 8, !tbaa !11
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = load i64, ptr %13, align 8, !tbaa !11
  %52 = call i64 @ush_utils_decode_ascii(ptr noundef %49, ptr noundef %50, i64 noundef %51)
  store i64 %52, ptr %11, align 8, !tbaa !11
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %53, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %54

54:                                               ; preds = %43, %4
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %65

57:                                               ; preds = %54
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ush_file_descriptor, ptr %58, i32 0, i32 5
  %60 = load ptr, ptr %59, align 8, !tbaa !13
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = load i64, ptr %11, align 8, !tbaa !11
  call void %60(ptr noundef %61, ptr noundef %62, ptr noundef %63, i64 noundef %64)
  br label %75

65:                                               ; preds = %54
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %71

68:                                               ; preds = %65
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  call void @ush_print(ptr noundef %69, ptr noundef %70)
  br label %74

71:                                               ; preds = %65
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.ush_object, ptr %72, i32 0, i32 1
  store i32 0, ptr %73, align 8, !tbaa !15
  br label %74

74:                                               ; preds = %71, %68
  br label %75

75:                                               ; preds = %74, %57
  br label %78

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

78:                                               ; preds = %76, %75, %40, %33, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

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

declare ptr @ush_file_find_by_name(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

declare i64 @ush_utils_decode_ascii(ptr noundef, ptr noundef, i64 noundef) #3

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

declare void @ush_print(ptr noundef, ptr noundef) #3

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 memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 40}
!14 = !{!"ush_file_descriptor", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!15 = !{!16, !10, i64 8}
!16 = !{!"ush_object", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24, !12, i64 32, !12, i64 40, !10, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !17, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !18, i64 112, !6, i64 160, !6, i64 168, !6, i64 176, !12, i64 184, !12, i64 192, !6, i64 200, !12, i64 208, !10, i64 216, !10, i64 220, !6, i64 224, !6, i64 232, !6, i64 240, !12, i64 248, !12, i64 256, !12, i64 264}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!"ush_node_object", !6, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}


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

@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @ush_buildin_cmd_echo_callback(ptr noundef %0, ptr nocapture noundef readnone %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  switch i32 %2, label %32 [
    i32 4, label %5
    i32 2, label %21
    i32 1, label %.thread37
  ]

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %3, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %7, ptr noundef nonnull dereferenceable(1) @.str) #3
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %10, label %9

9:                                                ; preds = %5
  tail call void @ush_print_status(ptr noundef %0, i32 noundef 6) #4
  br label %33

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %3, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = tail call ptr @ush_file_find_by_name(ptr noundef %0, ptr noundef %12) #4
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %10
  tail call void @ush_print_status(ptr noundef %0, i32 noundef 11) #4
  br label %33

16:                                               ; preds = %10
  %17 = getelementptr inbounds i8, ptr %13, i64 40
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  tail call void @ush_print_status(ptr noundef %0, i32 noundef 8) #4
  br label %33

21:                                               ; preds = %4, %16
  %.0 = phi ptr [ null, %4 ], [ %13, %16 ]
  %22 = getelementptr inbounds i8, ptr %3, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %23) #3
  %25 = tail call i64 @ush_utils_decode_ascii(ptr noundef %23, ptr noundef %23, i64 noundef %24) #4
  %.not30 = icmp eq ptr %.0, null
  br i1 %.not30, label %29, label %26

26:                                               ; preds = %21
  %27 = getelementptr inbounds i8, ptr %.0, i64 40
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  tail call void %28(ptr noundef %0, ptr noundef nonnull %.0, ptr noundef %23, i64 noundef %25) #4
  br label %33

29:                                               ; preds = %21
  %.not31 = icmp eq ptr %23, null
  br i1 %.not31, label %.thread37, label %30

30:                                               ; preds = %29
  tail call void @ush_print(ptr noundef %0, ptr noundef nonnull %23) #4
  br label %33

.thread37:                                        ; preds = %4, %29
  %31 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 0, ptr %31, align 8, !tbaa !11
  br label %33

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

33:                                               ; preds = %26, %.thread37, %30, %32, %20, %15, %9
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

declare i64 @ush_utils_decode_ascii(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @ush_print(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 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 #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 willreturn memory(read) }
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/C++ TBAA"}
!9 = !{!10, !6, i64 40}
!10 = !{!"ush_file_descriptor", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!12, !13, i64 8}
!12 = !{!"ush_object", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !6, i64 24, !14, i64 32, !14, i64 40, !13, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !15, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !16, i64 112, !6, i64 160, !6, i64 168, !6, i64 176, !14, i64 184, !14, i64 192, !6, i64 200, !14, i64 208, !13, i64 216, !13, i64 220, !6, i64 224, !6, i64 232, !6, i64 240, !14, i64 248, !14, i64 256, !14, i64 264}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"ush_node_object", !6, i64 0, !14, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}


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