; LLVM IR from aap/pdp6 :: emu (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, ptr }

@cmdtab = external dso_local global [15 x %struct.anon], align 16
@lp = external hidden global ptr, align 8
@numops = external hidden global i32, align 4
@ops = external hidden global [20 x ptr], align 16
@.str.41 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [5 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

declare i32 @printf(ptr noundef, ...) #1

; 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 @commandline(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %8, ptr @lp, align 8, !tbaa !5
  call void @splitops()
  %9 = load i32, ptr @numops, align 4, !tbaa !9
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %95

11:                                               ; preds = %1
  %12 = load ptr, ptr @ops, align 16, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 0
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = sext i8 %14 to i32
  %16 = icmp ne i32 %15, 35
  br i1 %16, label %17, label %95

17:                                               ; preds = %11
  store i32 0, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %43, %17
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [15 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 8, !tbaa !12
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %46

25:                                               ; preds = %18
  %26 = load i32, ptr %3, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [15 x %struct.anon], ptr @cmdtab, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.anon, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  store ptr %30, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr @ops, align 16, !tbaa !5
  %32 = call i64 @strlen(ptr noundef %31) #5
  store i64 %32, ptr %6, align 8, !tbaa !14
  %33 = load ptr, ptr @ops, align 16, !tbaa !5
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load i64, ptr %6, align 8, !tbaa !14
  %36 = call i32 @strncmp(ptr noundef %33, ptr noundef %34, i64 noundef %35) #5
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %42

38:                                               ; preds = %25
  %39 = load i32, ptr %3, align 4, !tbaa !9
  store i32 %39, ptr %4, align 4, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %5, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %38, %25
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %3, align 4, !tbaa !9
  br label %18, !llvm.loop !16

46:                                               ; preds = %18
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %52

49:                                               ; preds = %46
  %50 = load ptr, ptr @ops, align 16, !tbaa !5
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.41, ptr noundef %50)
  br label %94

52:                                               ; preds = %46
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = icmp eq i32 %53, 1
  br i1 %54, label %55, label %62

55:                                               ; preds = %52
  %56 = load i32, ptr %4, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [15 x %struct.anon], ptr @cmdtab, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.anon, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !18
  %61 = load i32, ptr @numops, align 4, !tbaa !9
  call void %60(i32 noundef %61, ptr noundef @ops)
  br label %93

62:                                               ; preds = %52
  %63 = load ptr, ptr @ops, align 16, !tbaa !5
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.42, ptr noundef %63)
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %89, %62
  %66 = load i32, ptr %3, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [15 x %struct.anon], ptr @cmdtab, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.anon, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !12
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %92

72:                                               ; preds = %65
  %73 = load i32, ptr %3, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [15 x %struct.anon], ptr @cmdtab, i64 0, i64 %74
  %76 = getelementptr inbounds %struct.anon, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !12
  store ptr %77, ptr %7, align 8, !tbaa !5
  %78 = load ptr, ptr @ops, align 16, !tbaa !5
  %79 = call i64 @strlen(ptr noundef %78) #5
  store i64 %79, ptr %6, align 8, !tbaa !14
  %80 = load ptr, ptr @ops, align 16, !tbaa !5
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = load i64, ptr %6, align 8, !tbaa !14
  %83 = call i32 @strncmp(ptr noundef %80, ptr noundef %81, i64 noundef %82) #5
  %84 = icmp eq i32 %83, 0
  br i1 %84, label %85, label %88

85:                                               ; preds = %72
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.43, ptr noundef %86)
  br label %88

88:                                               ; preds = %85, %72
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %3, align 4, !tbaa !9
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %3, align 4, !tbaa !9
  br label %65, !llvm.loop !19

92:                                               ; preds = %65
  br label %93

93:                                               ; preds = %92, %55
  br label %94

94:                                               ; preds = %93, %49
  br label %95

95:                                               ; preds = %94, %11, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  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 4, ptr %3) #4
  ret void
}

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

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #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 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) "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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!13, !6, i64 8}
!19 = distinct !{!19, !17}


; 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, ptr }

@cmdtab = external dso_local local_unnamed_addr global [15 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
@ops = external hidden global [20 x ptr], align 16
@.str.41 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

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

3:                                                ; preds = %1
  %4 = load ptr, ptr @ops, align 16, !tbaa !5
  %5 = load i8, ptr %4, align 1, !tbaa !11
  %.not22 = icmp eq i8 %5, 35
  br i1 %.not22, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %3
  %6 = load ptr, ptr @cmdtab, align 16, !tbaa !12
  %.not2326 = icmp eq ptr %6, null
  br i1 %.not2326, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #3
  br label %8

8:                                                ; preds = %.lr.ph, %8
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %8 ]
  %9 = phi ptr [ %6, %.lr.ph ], [ %15, %8 ]
  %.029 = phi i32 [ 0, %.lr.ph ], [ %spec.select25, %8 ]
  %.01628 = phi i32 [ undef, %.lr.ph ], [ %spec.select, %8 ]
  %10 = tail call i32 @strncmp(ptr noundef nonnull %4, ptr noundef nonnull %9, i64 noundef %7) #3
  %11 = icmp eq i32 %10, 0
  %12 = trunc nuw nsw i64 %indvars.iv to i32
  %spec.select = select i1 %11, i32 %12, i32 %.01628
  %13 = zext i1 %11 to i32
  %spec.select25 = add nuw nsw i32 %.029, %13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = getelementptr inbounds [15 x %struct.anon], ptr @cmdtab, i64 0, i64 %indvars.iv.next
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %.not23 = icmp eq ptr %15, null
  br i1 %.not23, label %._crit_edge, label %8, !llvm.loop !14

._crit_edge:                                      ; preds = %8
  switch i32 %spec.select25, label %21 [
    i32 0, label %._crit_edge.thread
    i32 1, label %17
  ]

._crit_edge.thread:                               ; preds = %.preheader, %._crit_edge
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.41, ptr noundef nonnull %4)
  br label %.loopexit

17:                                               ; preds = %._crit_edge
  %18 = sext i32 %spec.select to i64
  %19 = getelementptr inbounds [15 x %struct.anon], ptr @cmdtab, i64 0, i64 %18, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  tail call void %20(i32 noundef %2, ptr noundef nonnull @ops) #4
  br label %.loopexit

21:                                               ; preds = %._crit_edge
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.42, ptr noundef nonnull %4)
  %23 = load ptr, ptr @cmdtab, align 16, !tbaa !12
  %.not2431 = icmp eq ptr %23, null
  br i1 %.not2431, label %.loopexit, label %.lr.ph34.preheader

.lr.ph34.preheader:                               ; preds = %21
  %.pre39 = load ptr, ptr @ops, align 16, !tbaa !5
  br label %.lr.ph34

.lr.ph34:                                         ; preds = %.lr.ph34.preheader, %31
  %24 = phi ptr [ %.pre39, %.lr.ph34.preheader ], [ %32, %31 ]
  %indvars.iv36 = phi i64 [ 0, %.lr.ph34.preheader ], [ %indvars.iv.next37, %31 ]
  %25 = phi ptr [ %23, %.lr.ph34.preheader ], [ %34, %31 ]
  %26 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %24) #3
  %27 = tail call i32 @strncmp(ptr noundef %24, ptr noundef nonnull %25, i64 noundef %26) #3
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %.lr.ph34
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.43, ptr noundef nonnull %25)
  %.pre = load ptr, ptr @ops, align 16, !tbaa !5
  br label %31

31:                                               ; preds = %.lr.ph34, %29
  %32 = phi ptr [ %24, %.lr.ph34 ], [ %.pre, %29 ]
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %33 = getelementptr inbounds [15 x %struct.anon], ptr @cmdtab, i64 0, i64 %indvars.iv.next37
  %34 = load ptr, ptr %33, align 8, !tbaa !12
  %.not24 = icmp eq ptr %34, null
  br i1 %.not24, label %.loopexit, label %.lr.ph34, !llvm.loop !17

.loopexit:                                        ; preds = %31, %21, %._crit_edge.thread, %17, %3, %1
  ret void
}

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

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

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

attributes #0 = { nofree nounwind "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 = { 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 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 #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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!13, !6, i64 8}
!17 = distinct !{!17, !15}


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