; 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_autocompl = type { [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
define dso_local void @shell_init(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.shell, ptr %14, i32 0, i32 4
  %16 = getelementptr inbounds [50 x i8], ptr %15, i64 0, i64 0
  store i8 0, ptr %16, align 2, !tbaa !11
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.shell, ptr %17, i32 0, i32 2
  store i32 0, ptr %18, align 8, !tbaa !12
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.shell, ptr %19, i32 0, i32 0
  store i32 0, ptr %20, align 8, !tbaa !16
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.shell, ptr %21, i32 0, i32 3
  %23 = getelementptr inbounds [50 x i8], ptr %22, i64 0, i64 0
  store i8 0, ptr %23, align 4, !tbaa !11
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.shell, ptr %24, i32 0, i32 1
  store i32 0, ptr %25, align 4, !tbaa !17
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.shell, ptr %27, i32 0, i32 17
  store ptr %26, ptr %28, align 8, !tbaa !18
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.shell, ptr %30, i32 0, i32 18
  store i32 %29, ptr %31, align 8, !tbaa !19
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.shell, ptr %33, i32 0, i32 14
  store ptr %32, ptr %34, align 8, !tbaa !20
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.shell, ptr %35, i32 0, i32 12
  store i32 0, ptr %36, align 4, !tbaa !21
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.shell, ptr %38, i32 0, i32 11
  store i32 %37, ptr %39, align 8, !tbaa !22
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.shell, ptr %40, i32 0, i32 13
  store i8 0, ptr %41, align 8, !tbaa !23
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.shell, ptr %42, i32 0, i32 6
  store i8 0, ptr %43, align 2, !tbaa !24
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.shell, ptr %45, i32 0, i32 10
  store ptr %44, ptr %46, align 8, !tbaa !25
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.shell, ptr %47, i32 0, i32 9
  store i32 0, ptr %48, align 4, !tbaa !26
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.shell, ptr %49, i32 0, i32 8
  store i32 0, ptr %50, align 8, !tbaa !27
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.shell, ptr %51, i32 0, i32 15
  call void @INIT_LIST_HEAD(ptr noundef %52)
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %66, %6
  %54 = load i32, ptr %13, align 4, !tbaa !9
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %57, label %69

57:                                               ; preds = %53
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.shell, ptr %58, i32 0, i32 10
  %60 = load ptr, ptr %59, align 8, !tbaa !25
  %61 = load i32, ptr %13, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds %struct.shell_autocompl, ptr %60, i64 %62
  %64 = getelementptr inbounds %struct.shell_autocompl, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds [50 x i8], ptr %64, i64 0, i64 0
  store i8 0, ptr %65, align 1, !tbaa !11
  br label %66

66:                                               ; preds = %57
  %67 = load i32, ptr %13, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %13, align 4, !tbaa !9
  br label %53, !llvm.loop !28

69:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @INIT_LIST_HEAD(ptr noundef) #2

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 = { inlinehint 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 }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 8}
!13 = !{!"shell", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 12, !7, i64 62, !7, i64 112, !14, i64 162, !10, i64 164, !10, i64 168, !10, i64 172, !6, i64 176, !10, i64 184, !10, i64 188, !14, i64 192, !6, i64 200, !15, i64 208, !6, i64 224, !6, i64 232, !10, i64 240}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!"list_head", !6, i64 0, !6, i64 8}
!16 = !{!13, !10, i64 0}
!17 = !{!13, !10, i64 4}
!18 = !{!13, !6, i64 232}
!19 = !{!13, !10, i64 240}
!20 = !{!13, !6, i64 200}
!21 = !{!13, !10, i64 188}
!22 = !{!13, !10, i64 184}
!23 = !{!13, !14, i64 192}
!24 = !{!13, !14, i64 162}
!25 = !{!13, !6, i64 176}
!26 = !{!13, !10, i64 172}
!27 = !{!13, !10, i64 168}
!28 = distinct !{!28, !29}
!29 = !{!"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_autocompl = type { [50 x i8] }

; Function Attrs: nounwind uwtable
define dso_local void @shell_init(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = getelementptr inbounds i8, ptr %0, i64 62
  store i8 0, ptr %7, align 2, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 232
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(13) %0, i8 0, i64 13, i1 false)
  store ptr %1, ptr %8, align 8, !tbaa !8
  %9 = getelementptr inbounds i8, ptr %0, i64 240
  store i32 %2, ptr %9, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %0, i64 200
  store ptr %3, ptr %10, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %0, i64 188
  store i32 0, ptr %11, align 4, !tbaa !16
  %12 = getelementptr inbounds i8, ptr %0, i64 184
  store i32 %4, ptr %12, align 8, !tbaa !17
  %13 = getelementptr inbounds i8, ptr %0, i64 192
  store i8 0, ptr %13, align 8, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %0, i64 162
  store i8 0, ptr %14, align 2, !tbaa !19
  %15 = getelementptr inbounds i8, ptr %0, i64 176
  store ptr %5, ptr %15, align 8, !tbaa !20
  %16 = getelementptr inbounds i8, ptr %0, i64 172
  store i32 0, ptr %16, align 4, !tbaa !21
  %17 = getelementptr inbounds i8, ptr %0, i64 168
  store i32 0, ptr %17, align 8, !tbaa !22
  %18 = getelementptr inbounds i8, ptr %0, i64 208
  tail call void @INIT_LIST_HEAD(ptr noundef nonnull %18)
  %19 = icmp sgt i32 %2, 0
  br i1 %19, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6
  %wide.trip.count = zext nneg i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %20 = icmp ult i32 %2, 4
  br i1 %20, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %21 = load ptr, ptr %15, align 8, !tbaa !20
  %22 = getelementptr inbounds %struct.shell_autocompl, ptr %21, i64 %indvars.iv
  store i8 0, ptr %22, align 1, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %23 = load ptr, ptr %15, align 8, !tbaa !20
  %24 = getelementptr inbounds %struct.shell_autocompl, ptr %23, i64 %indvars.iv.next
  store i8 0, ptr %24, align 1, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %25 = load ptr, ptr %15, align 8, !tbaa !20
  %26 = getelementptr inbounds %struct.shell_autocompl, ptr %25, i64 %indvars.iv.next.1
  store i8 0, ptr %26, align 1, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %27 = load ptr, ptr %15, align 8, !tbaa !20
  %28 = getelementptr inbounds %struct.shell_autocompl, ptr %27, i64 %indvars.iv.next.2
  store i8 0, ptr %28, align 1, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !23

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %29 = load ptr, ptr %15, align 8, !tbaa !20
  %30 = getelementptr inbounds %struct.shell_autocompl, ptr %29, i64 %indvars.iv.epil
  store i8 0, ptr %30, align 1, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !25

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %6
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { inlinehint 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) }

!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 = !{!9, !12, i64 232}
!9 = !{!"shell", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 12, !6, i64 62, !6, i64 112, !11, i64 162, !10, i64 164, !10, i64 168, !10, i64 172, !12, i64 176, !10, i64 184, !10, i64 188, !11, i64 192, !12, i64 200, !13, i64 208, !12, i64 224, !12, i64 232, !10, i64 240}
!10 = !{!"int", !6, i64 0}
!11 = !{!"_Bool", !6, i64 0}
!12 = !{!"any pointer", !6, i64 0}
!13 = !{!"list_head", !12, i64 0, !12, i64 8}
!14 = !{!9, !10, i64 240}
!15 = !{!9, !12, i64 200}
!16 = !{!9, !10, i64 188}
!17 = !{!9, !10, i64 184}
!18 = !{!9, !11, i64 192}
!19 = !{!9, !11, i64 162}
!20 = !{!9, !12, i64 176}
!21 = !{!9, !10, i64 172}
!22 = !{!9, !10, i64 168}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass