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

@symtab = external dso_local global [4000 x %struct.Sym], align 16
@.str.9 = external hidden unnamed_addr constant [18 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

; Function Attrs: nounwind uwtable
declare dso_local void @panic(ptr noundef, ...) #1

; 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) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @findsym(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @getsym(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %struct.Value, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = call ptr @findsym(i64 noundef %5)
  store ptr %6, ptr %3, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !9
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %34

9:                                                ; preds = %1
  store ptr @symtab, ptr %3, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %20, %9
  %11 = load ptr, ptr %3, align 8, !tbaa !9
  %12 = icmp ult ptr %11, getelementptr inbounds ([4000 x %struct.Sym], ptr @symtab, i64 0, i64 4000)
  br i1 %12, label %13, label %23

13:                                               ; preds = %10
  %14 = load ptr, ptr %3, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.Sym, ptr %14, i32 0, i32 0
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %13
  br label %24

19:                                               ; preds = %13
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %3, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.Sym, ptr %21, i32 1
  store ptr %22, ptr %3, align 8, !tbaa !9
  br label %10, !llvm.loop !14

23:                                               ; preds = %10
  call void (ptr, ...) @panic(ptr noundef @.str.9)
  br label %24

24:                                               ; preds = %23, %18
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %26 = load ptr, ptr %3, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.Sym, ptr %26, i32 0, i32 0
  store i64 %25, ptr %27, align 8, !tbaa !11
  %28 = load ptr, ptr %3, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.Sym, ptr %28, i32 0, i32 1
  store i32 0, ptr %29, align 8, !tbaa !16
  %30 = load ptr, ptr %3, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.Sym, ptr %30, i32 0, i32 2
  %32 = getelementptr inbounds %struct.Value, ptr %4, i32 0, i32 0
  store i64 0, ptr %32, align 8, !tbaa !17
  %33 = getelementptr inbounds %struct.Value, ptr %4, i32 0, i32 1
  store i32 0, ptr %33, align 8, !tbaa !19
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %31, ptr align 8 %4, i64 16, i1 false), !tbaa.struct !20
  br label %34

34:                                               ; preds = %24, %1
  %35 = load ptr, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %35
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"Sym", !6, i64 0, !13, i64 8, !7, i64 16, !10, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!12, !13, i64 8}
!17 = !{!18, !6, i64 0}
!18 = !{!"Value", !6, i64 0, !13, i64 8}
!19 = !{!18, !13, i64 8}
!20 = !{i64 0, i64 8, !5, i64 8, i64 4, !21}
!21 = !{!13, !13, 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"

%struct.Sym = type { i64, i32, %union.anon, ptr }
%union.anon = type { %struct.Value }
%struct.Value = type { i64, i32 }

@symtab = external dso_local global [4000 x %struct.Sym], align 16
@.str.9 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @panic(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @findsym(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @getsym(i64 noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @findsym(i64 noundef %0)
  %3 = icmp eq ptr %2, null
  br i1 %3, label %.preheader, label %19

.preheader.1:                                     ; preds = %.preheader
  %.0.add = add nuw nsw i64 %.0.idx12, 40
  %.0.ptr13.1 = getelementptr inbounds i8, ptr @symtab, i64 %.0.add
  %4 = load i64, ptr %.0.ptr13.1, align 8, !tbaa !5
  %5 = icmp eq i64 %4, 0
  br i1 %5, label %.loopexit.loopexit, label %.preheader.2

.preheader.2:                                     ; preds = %.preheader.1
  %.0.add.1 = add nuw nsw i64 %.0.idx12, 80
  %.0.ptr13.2 = getelementptr inbounds i8, ptr @symtab, i64 %.0.add.1
  %6 = load i64, ptr %.0.ptr13.2, align 8, !tbaa !5
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %.loopexit.loopexit, label %.preheader.3

.preheader.3:                                     ; preds = %.preheader.2
  %.0.add.2 = add nuw nsw i64 %.0.idx12, 120
  %.0.ptr13.3 = getelementptr inbounds i8, ptr @symtab, i64 %.0.add.2
  %8 = load i64, ptr %.0.ptr13.3, align 8, !tbaa !5
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %.loopexit.loopexit, label %.preheader.4

.preheader.4:                                     ; preds = %.preheader.3
  %.0.add.3 = add nuw nsw i64 %.0.idx12, 160
  %.0.ptr13.4 = getelementptr inbounds i8, ptr @symtab, i64 %.0.add.3
  %10 = load i64, ptr %.0.ptr13.4, align 8, !tbaa !5
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %.loopexit.loopexit, label %12

12:                                               ; preds = %.preheader.4
  %.0.add.4 = add nuw nsw i64 %.0.idx12, 200
  %13 = icmp ult i64 %.0.idx12, 159800
  br i1 %13, label %.preheader, label %16, !llvm.loop !12

.preheader:                                       ; preds = %1, %12
  %.0.idx12 = phi i64 [ %.0.add.4, %12 ], [ 0, %1 ]
  %.0.ptr13 = getelementptr inbounds i8, ptr @symtab, i64 %.0.idx12
  %14 = load i64, ptr %.0.ptr13, align 8, !tbaa !5
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %.loopexit.loopexit, label %.preheader.1

16:                                               ; preds = %12
  tail call void (ptr, ...) @panic(ptr noundef nonnull @.str.9)
  br label %.loopexit

.loopexit.loopexit:                               ; preds = %.preheader.4, %.preheader.3, %.preheader.2, %.preheader.1, %.preheader
  %.0.idx12.lcssa = phi i64 [ %.0.idx12, %.preheader ], [ %.0.add, %.preheader.1 ], [ %.0.add.1, %.preheader.2 ], [ %.0.add.2, %.preheader.3 ], [ %.0.add.3, %.preheader.4 ]
  %.0.ptr13.le = getelementptr inbounds i8, ptr @symtab, i64 %.0.idx12.lcssa
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %16
  %.0.ptr11 = phi ptr [ getelementptr inbounds (i8, ptr @symtab, i64 160000), %16 ], [ %.0.ptr13.le, %.loopexit.loopexit ]
  store i64 %0, ptr %.0.ptr11, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.0.ptr11, i64 8
  store i32 0, ptr %17, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %.0.ptr11, i64 16
  store i64 0, ptr %18, align 8, !tbaa !15
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %.0.ptr11, i64 24
  store i32 0, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !16
  br label %19

19:                                               ; preds = %.loopexit, %1
  %.1 = phi ptr [ %.0.ptr11, %.loopexit ], [ %2, %1 ]
  ret ptr %.1
}

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

!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, !7, i64 0}
!6 = !{!"Sym", !7, i64 0, !10, i64 8, !8, i64 16, !11, i64 32}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !10, i64 8}
!15 = !{!7, !7, i64 0}
!16 = !{!10, !10, i64 0}


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