; LLVM IR from aap/pdp6 :: fe6 (cmd)

; 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.anon = type { ptr, ptr }

@ops = external hidden global [20 x ptr], align 16
@cmdtab = external dso_local global [6 x %struct.anon], align 16
@lp = external hidden global ptr, align 8
@numops = external hidden global i32, align 4
@.str.16 = external hidden unnamed_addr constant [4 x i8], align 1

; 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

declare void @err(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @coloncmd(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %5, ptr @lp, align 8, !tbaa !5
  call void @splitops()
  %6 = load i32, ptr @numops, align 4, !tbaa !9
  %7 = icmp slt i32 %6, 1
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i32 1, ptr %4, align 4
  br label %38

9:                                                ; preds = %1
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %34, %9
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [6 x %struct.anon], ptr @cmdtab, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.anon, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 16, !tbaa !11
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %37

17:                                               ; preds = %10
  %18 = load ptr, ptr @ops, align 16, !tbaa !5
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [6 x %struct.anon], ptr @cmdtab, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.anon, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 16, !tbaa !11
  %24 = call i32 @strcasecmp(ptr noundef %18, ptr noundef %23) #5
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %33

26:                                               ; preds = %17
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [6 x %struct.anon], ptr @cmdtab, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.anon, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = load i32, ptr @numops, align 4, !tbaa !9
  call void %31(i32 noundef %32, ptr noundef @ops)
  store i32 1, ptr %4, align 4
  br label %38

33:                                               ; preds = %17
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %3, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %3, align 4, !tbaa !9
  br label %10, !llvm.loop !14

37:                                               ; preds = %10
  call void @err(ptr noundef @.str.16)
  store i32 0, ptr %4, align 4
  br label %38

38:                                               ; preds = %37, %26, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  %39 = load i32, ptr %4, align 4
  switch i32 %39, label %41 [
    i32 0, label %40
    i32 1, label %40
  ]

40:                                               ; preds = %38, %38
  ret void

41:                                               ; preds = %38
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden void @splitops() #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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) "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 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 #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, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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.anon = type { ptr, ptr }

@ops = external hidden global [20 x ptr], align 16
@cmdtab = external dso_local local_unnamed_addr global [6 x %struct.anon], align 16
@lp = external hidden local_unnamed_addr global ptr, align 8
@numops = external hidden local_unnamed_addr global i32, align 4
@.str.16 = external hidden unnamed_addr constant [4 x i8], align 1

declare void @err(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @coloncmd(ptr noundef %0) local_unnamed_addr #2 {
  store ptr %0, ptr @lp, align 8, !tbaa !5
  tail call void @splitops()
  %2 = load i32, ptr @numops, align 4, !tbaa !9
  %3 = icmp slt i32 %2, 1
  br i1 %3, label %15, label %.preheader

.preheader:                                       ; preds = %1
  %4 = load ptr, ptr @cmdtab, align 16, !tbaa !11
  %.not6 = icmp eq ptr %4, null
  br i1 %.not6, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %5 = load ptr, ptr @ops, align 16, !tbaa !5
  %6 = tail call i32 @strcasecmp(ptr noundef %5, ptr noundef nonnull %4) #3
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %._crit_edge14, label %.lr.ph13

.lr.ph13:                                         ; preds = %.lr.ph, %10
  %indvars.iv12 = phi i64 [ %indvars.iv.next, %10 ], [ 0, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv12, 1
  %8 = getelementptr inbounds [6 x %struct.anon], ptr @cmdtab, i64 0, i64 %indvars.iv.next
  %9 = load ptr, ptr %8, align 16, !tbaa !11
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %._crit_edge, label %10, !llvm.loop !13

10:                                               ; preds = %.lr.ph13
  %11 = tail call i32 @strcasecmp(ptr noundef %5, ptr noundef nonnull %9) #3
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %._crit_edge14, label %.lr.ph13, !llvm.loop !13

._crit_edge14:                                    ; preds = %10, %.lr.ph
  %.lcssa = phi ptr [ @cmdtab, %.lr.ph ], [ %8, %10 ]
  %13 = getelementptr inbounds i8, ptr %.lcssa, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  tail call void %14(i32 noundef %2, ptr noundef nonnull @ops) #4
  br label %15

._crit_edge:                                      ; preds = %.lr.ph13, %.preheader
  tail call void @err(ptr noundef nonnull @.str.16) #4
  br label %15

15:                                               ; preds = %1, %._crit_edge, %._crit_edge14
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @splitops() local_unnamed_addr #2

attributes #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(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 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !6, i64 8}


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