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

@apr = external hidden global ptr, align 8
@stdin = external global ptr, align 8
@.str.44 = external hidden unnamed_addr constant [3 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
declare dso_local void @commandline(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @cli(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr null, ptr @apr, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %33, %2
  store ptr null, ptr %6, align 8, !tbaa !5
  store i64 0, ptr %5, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr @stdin, align 8, !tbaa !5
  %10 = icmp eq ptr %8, %9
  br i1 %10, label %11, label %13

11:                                               ; preds = %7
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str.44)
  br label %13

13:                                               ; preds = %11, %7
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call i64 @getline(ptr noundef %6, ptr noundef %5, ptr noundef %14)
  %16 = icmp slt i64 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void

18:                                               ; preds = %13
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %30

21:                                               ; preds = %18
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds ptr, ptr %22, i64 0
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = call i32 @chansend(ptr noundef %24, ptr noundef %6)
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds ptr, ptr %26, i64 1
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = call i32 @chanrecv(ptr noundef %28, ptr noundef %6)
  br label %33

30:                                               ; preds = %18
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  call void @commandline(ptr noundef %31)
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %32) #4
  br label %33

33:                                               ; preds = %30, %21
  br label %7
}

declare i64 @getline(ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @chansend(ptr noundef, ptr noundef) #1

declare i32 @chanrecv(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr 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 "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 }

!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 = !{!"long", !7, i64 0}


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

@apr = external hidden local_unnamed_addr global ptr, align 8
@stdin = external local_unnamed_addr global ptr, align 8
@.str.44 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

; 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 dso_local void @commandline(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @cli(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  store ptr null, ptr @apr, align 8, !tbaa !5
  %.not = icmp eq ptr %1, null
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  br i1 %.not, label %.split.us, label %.split

.split.us:                                        ; preds = %2, %13
  store ptr null, ptr %4, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !9
  %6 = load ptr, ptr @stdin, align 8, !tbaa !5
  %7 = icmp eq ptr %6, %0
  br i1 %7, label %8, label %10

8:                                                ; preds = %.split.us
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.44)
  br label %10

10:                                               ; preds = %8, %.split.us
  %11 = call i64 @getline(ptr noundef nonnull %4, ptr noundef nonnull %3, ptr noundef %0) #5
  %12 = icmp slt i64 %11, 0
  br i1 %12, label %.split6.us, label %13

13:                                               ; preds = %10
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  call void @commandline(ptr noundef %14)
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %15) #5
  br label %.split.us

.split:                                           ; preds = %2, %23
  store ptr null, ptr %4, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !9
  %16 = load ptr, ptr @stdin, align 8, !tbaa !5
  %17 = icmp eq ptr %16, %0
  br i1 %17, label %18, label %20

18:                                               ; preds = %.split
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.44)
  br label %20

20:                                               ; preds = %18, %.split
  %21 = call i64 @getline(ptr noundef nonnull %4, ptr noundef nonnull %3, ptr noundef %0) #5
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %.split6.us, label %23

.split6.us:                                       ; preds = %20, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  ret void

23:                                               ; preds = %20
  %24 = load ptr, ptr %1, align 8, !tbaa !5
  %25 = call i32 @chansend(ptr noundef %24, ptr noundef nonnull %4) #5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call i32 @chanrecv(ptr noundef %26, ptr noundef nonnull %4) #5
  br label %.split
}

declare i64 @getline(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @chansend(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @chanrecv(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { 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 = !{!"long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass