; LLVM IR from tenok-rtos/tenok :: user/shell (shell)

; 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.shell = type { i32, i32, i32, [50 x i8], [50 x i8], [50 x i8], i8, i32, i32, i32, ptr, i32, i32, i8, ptr, %struct.list_head, ptr, ptr, i32 }
%struct.list_head = type { ptr, ptr }
%struct.shell_cmd = type { ptr, [50 x i8] }

; 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 uwtable
declare hidden void @shell_reset_line(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @shell_execute(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca [10 x ptr], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.shell, ptr %7, i32 0, i32 17
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  br label %66

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 80, ptr %3) #4
  call void @llvm.memset.p0.i64(ptr align 16 %3, i8 0, i64 80, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.shell, ptr %13, i32 0, i32 3
  %15 = getelementptr inbounds [50 x i8], ptr %14, i64 0, i64 0
  %16 = getelementptr inbounds [10 x ptr], ptr %3, i64 0, i64 0
  %17 = call i32 @shell_split_cmd_token(ptr noundef %15, ptr noundef %16)
  store i32 %17, ptr %4, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %18

18:                                               ; preds = %54, %12
  %19 = load i32, ptr %5, align 4, !tbaa !14
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.shell, ptr %20, i32 0, i32 18
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = icmp slt i32 %19, %22
  br i1 %23, label %24, label %57

24:                                               ; preds = %18
  %25 = getelementptr inbounds [10 x ptr], ptr %3, i64 0, i64 0
  %26 = load ptr, ptr %25, align 16, !tbaa !5
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.shell, ptr %27, i32 0, i32 17
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = load i32, ptr %5, align 4, !tbaa !14
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds %struct.shell_cmd, ptr %29, i64 %31
  %33 = getelementptr inbounds %struct.shell_cmd, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds [50 x i8], ptr %33, i64 0, i64 0
  %35 = call i32 @strcmp(ptr noundef %26, ptr noundef %34) #5
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %53

37:                                               ; preds = %24
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.shell, ptr %38, i32 0, i32 17
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = load i32, ptr %5, align 4, !tbaa !14
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.shell_cmd, ptr %40, i64 %42
  %44 = getelementptr inbounds %struct.shell_cmd, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  %46 = load i32, ptr %4, align 4, !tbaa !14
  %47 = getelementptr inbounds [10 x ptr], ptr %3, i64 0, i64 0
  %48 = call i32 %45(i32 noundef %46, ptr noundef %47)
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.shell, ptr %49, i32 0, i32 3
  %51 = getelementptr inbounds [50 x i8], ptr %50, i64 0, i64 0
  store i8 0, ptr %51, align 4, !tbaa !18
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  call void @shell_reset_line(ptr noundef %52)
  store i32 1, ptr %6, align 4
  br label %64

53:                                               ; preds = %24
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %5, align 4, !tbaa !14
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !14
  br label %18, !llvm.loop !19

57:                                               ; preds = %18
  %58 = load i32, ptr %4, align 4, !tbaa !14
  %59 = getelementptr inbounds [10 x ptr], ptr %3, i64 0, i64 0
  call void @shell_unknown_cmd_handler(i32 noundef %58, ptr noundef %59)
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.shell, ptr %60, i32 0, i32 3
  %62 = getelementptr inbounds [50 x i8], ptr %61, i64 0, i64 0
  store i8 0, ptr %62, align 4, !tbaa !18
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  call void @shell_reset_line(ptr noundef %63)
  store i32 0, ptr %6, align 4
  br label %64

64:                                               ; preds = %57, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 80, ptr %3) #4
  %65 = load i32, ptr %6, align 4
  switch i32 %65, label %67 [
    i32 0, label %66
    i32 1, label %66
  ]

66:                                               ; preds = %64, %64, %11
  ret void

67:                                               ; preds = %64
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @shell_split_cmd_token(ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden void @shell_unknown_cmd_handler(i32 noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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, !6, i64 232}
!10 = !{!"shell", !11, i64 0, !11, i64 4, !11, i64 8, !7, i64 12, !7, i64 62, !7, i64 112, !12, i64 162, !11, i64 164, !11, i64 168, !11, i64 172, !6, i64 176, !11, i64 184, !11, i64 188, !12, i64 192, !6, i64 200, !13, i64 208, !6, i64 224, !6, i64 232, !11, i64 240}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"list_head", !6, i64 0, !6, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 240}
!16 = !{!17, !6, i64 0}
!17 = !{!"shell_cmd", !6, i64 0, !7, i64 8}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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"

%struct.shell_cmd = type { ptr, [50 x i8] }

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

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

; Function Attrs: nounwind uwtable
declare hidden void @shell_reset_line(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @shell_execute(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca [10 x ptr], align 16
  %3 = getelementptr inbounds i8, ptr %0, i64 232
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %24, label %6

6:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %2) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(80) %2, i8 0, i64 80, i1 false)
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = call i32 @shell_split_cmd_token(ptr noundef nonnull %7, ptr noundef nonnull %2)
  %9 = getelementptr inbounds i8, ptr %0, i64 240
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6
  %12 = load ptr, ptr %2, align 16, !tbaa !14
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %wide.trip.count = zext nneg i32 %10 to i64
  br label %15

14:                                               ; preds = %15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %15, !llvm.loop !15

15:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %16 = getelementptr inbounds %struct.shell_cmd, ptr %13, i64 %indvars.iv
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) %17) #5
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %14

20:                                               ; preds = %15
  %21 = load ptr, ptr %16, align 8, !tbaa !17
  %22 = call i32 %21(i32 noundef %8, ptr noundef nonnull %2) #4
  br label %23

._crit_edge:                                      ; preds = %14, %6
  call void @shell_unknown_cmd_handler(i32 noundef %8, ptr noundef nonnull %2)
  br label %23

23:                                               ; preds = %._crit_edge, %20
  store i8 0, ptr %7, align 4, !tbaa !19
  call void @shell_reset_line(ptr noundef nonnull %0)
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %2) #4
  br label %24

24:                                               ; preds = %1, %23
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @shell_split_cmd_token(ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden void @shell_unknown_cmd_handler(i32 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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, !11, i64 232}
!6 = !{!"shell", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !8, i64 62, !8, i64 112, !10, i64 162, !7, i64 164, !7, i64 168, !7, i64 172, !11, i64 176, !7, i64 184, !7, i64 188, !10, i64 192, !11, i64 200, !12, i64 208, !11, i64 224, !11, i64 232, !7, i64 240}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"list_head", !11, i64 0, !11, i64 8}
!13 = !{!6, !7, i64 240}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !11, i64 0}
!18 = !{!"shell_cmd", !11, i64 0, !8, i64 8}
!19 = !{!8, !8, i64 0}


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