; LLVM IR from aap/pdp6 :: tools (as6)

; 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.Value = type { i64, i32 }
%struct.Sym = type { i64, i32, %union.anon, ptr }
%union.anon = type { %struct.Value }
%struct.Litword = type { %struct.Value, ptr }

@littabs = external dso_local global [9 x %struct.Value], align 16
@nlit = external dso_local global i32, align 4
@litlist = external dso_local global ptr, align 8
@dot = external dso_local global ptr, align 8

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare dso_local void @putv(i64 noundef, i32 noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @litOp() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %3 = load ptr, ptr @litlist, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  br i1 %4, label %5, label %11

5:                                                ; preds = %0
  %6 = load i32, ptr @nlit, align 4, !tbaa !9
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [9 x %struct.Value], ptr @littabs, i64 0, i64 %7
  %9 = load ptr, ptr @dot, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.Sym, ptr %9, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %8, ptr align 8 %10, i64 16, i1 false), !tbaa.struct !11
  br label %11

11:                                               ; preds = %5, %0
  %12 = load ptr, ptr @litlist, align 8, !tbaa !5
  store ptr %12, ptr %1, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %29, %11
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %31

16:                                               ; preds = %13
  %17 = load ptr, ptr %1, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Litword, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  store ptr %19, ptr %2, align 8, !tbaa !5
  %20 = load ptr, ptr %1, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Litword, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct.Value, ptr %21, i32 0, i32 0
  %23 = load i64, ptr %22, align 8, !tbaa !17
  %24 = load ptr, ptr %1, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Litword, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.Value, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !18
  call void @putv(i64 noundef %23, i32 noundef %27)
  %28 = load ptr, ptr %1, align 8, !tbaa !5
  call void @free(ptr noundef %28) #4
  br label %29

29:                                               ; preds = %16
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %30, ptr %1, align 8, !tbaa !5
  br label %13, !llvm.loop !19

31:                                               ; preds = %13
  %32 = load ptr, ptr @litlist, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = load i32, ptr @nlit, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr @nlit, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %34, %31
  store ptr null, ptr @litlist, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 8, !12, i64 8, i64 4, !9}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"Litword", !16, i64 0, !6, i64 16}
!16 = !{!"Value", !13, i64 0, !10, i64 8}
!17 = !{!15, !13, i64 0}
!18 = !{!15, !10, i64 8}
!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.Value = type { i64, i32 }

@littabs = external dso_local local_unnamed_addr global [9 x %struct.Value], align 16
@nlit = external dso_local local_unnamed_addr global i32, align 4
@litlist = external dso_local local_unnamed_addr global ptr, align 8
@dot = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
declare dso_local void @putv(i64 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @litOp() local_unnamed_addr #1 {
  %1 = load ptr, ptr @litlist, align 8, !tbaa !5
  %cond = icmp eq ptr %1, null
  br i1 %cond, label %._crit_edge.thread, label %2

2:                                                ; preds = %0
  %3 = load i32, ptr @nlit, align 4, !tbaa !9
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [9 x %struct.Value], ptr @littabs, i64 0, i64 %4
  %6 = load ptr, ptr @dot, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(16) %7, i64 16, i1 false), !tbaa.struct !11
  br label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.09 = phi ptr [ %9, %.lr.ph ], [ %1, %2 ]
  %8 = getelementptr inbounds i8, ptr %.09, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = load i64, ptr %.09, align 8, !tbaa !17
  %11 = getelementptr inbounds i8, ptr %.09, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !18
  tail call void @putv(i64 noundef %10, i32 noundef %12)
  tail call void @free(ptr noundef nonnull %.09) #3
  %.not6 = icmp eq ptr %9, null
  br i1 %.not6, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph
  %.pre = load ptr, ptr @litlist, align 8, !tbaa !5
  %13 = icmp eq ptr %.pre, null
  br i1 %13, label %._crit_edge.thread, label %14

14:                                               ; preds = %._crit_edge
  %15 = load i32, ptr @nlit, align 4, !tbaa !9
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @nlit, align 4, !tbaa !9
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0, %14, %._crit_edge
  store ptr null, ptr @litlist, align 8, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nocallback nofree 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 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 #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 = !{i64 0, i64 8, !12, i64 8, i64 4, !9}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"Litword", !16, i64 0, !6, i64 16}
!16 = !{!"Value", !13, i64 0, !10, i64 8}
!17 = !{!15, !13, i64 0}
!18 = !{!15, !10, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass