; 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

; 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
define dso_local ptr @findsym(i64 noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store ptr @symtab, ptr %4, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %18, %1
  %7 = load ptr, ptr %4, align 8, !tbaa !9
  %8 = icmp ult ptr %7, getelementptr inbounds ([4000 x %struct.Sym], ptr @symtab, i64 0, i64 4000)
  br i1 %8, label %9, label %21

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

15:                                               ; preds = %9
  %16 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %16, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %22

17:                                               ; preds = %9
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.Sym, ptr %19, i32 1
  store ptr %20, ptr %4, align 8, !tbaa !9
  br label %6, !llvm.loop !14

21:                                               ; preds = %6
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %22

22:                                               ; preds = %21, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %23 = load ptr, ptr %2, align 8
  ret ptr %23
}

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


; 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

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local ptr @findsym(i64 noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %17, %1
  %.0.idx8 = phi i64 [ 0, %1 ], [ %.0.add.4, %17 ]
  %.0.ptr = getelementptr inbounds i8, ptr @symtab, i64 %.0.idx8
  %3 = load i64, ptr %.0.ptr, align 8, !tbaa !5
  %4 = icmp eq i64 %3, %0
  br i1 %4, label %.split.loop.exit.split.loop.exit10, label %5

5:                                                ; preds = %2
  %.0.add = add nuw nsw i64 %.0.idx8, 40
  %.0.ptr.1 = getelementptr inbounds i8, ptr @symtab, i64 %.0.add
  %6 = load i64, ptr %.0.ptr.1, align 8, !tbaa !5
  %7 = icmp eq i64 %6, %0
  br i1 %7, label %.split.loop.exit.split.loop.exit10, label %8

8:                                                ; preds = %5
  %.0.add.1 = add nuw nsw i64 %.0.idx8, 80
  %.0.ptr.2 = getelementptr inbounds i8, ptr @symtab, i64 %.0.add.1
  %9 = load i64, ptr %.0.ptr.2, align 8, !tbaa !5
  %10 = icmp eq i64 %9, %0
  br i1 %10, label %.split.loop.exit.split.loop.exit10, label %11

11:                                               ; preds = %8
  %.0.add.2 = add nuw nsw i64 %.0.idx8, 120
  %.0.ptr.3 = getelementptr inbounds i8, ptr @symtab, i64 %.0.add.2
  %12 = load i64, ptr %.0.ptr.3, align 8, !tbaa !5
  %13 = icmp eq i64 %12, %0
  br i1 %13, label %.split.loop.exit.split.loop.exit10, label %14

14:                                               ; preds = %11
  %.0.add.3 = add nuw nsw i64 %.0.idx8, 160
  %.0.ptr.4 = getelementptr inbounds i8, ptr @symtab, i64 %.0.add.3
  %15 = load i64, ptr %.0.ptr.4, align 8, !tbaa !5
  %16 = icmp eq i64 %15, %0
  br i1 %16, label %.split.loop.exit.split.loop.exit10, label %17

17:                                               ; preds = %14
  %.0.add.4 = add nuw nsw i64 %.0.idx8, 200
  %18 = icmp ult i64 %.0.idx8, 159800
  br i1 %18, label %2, label %.split.loop.exit, !llvm.loop !12

.split.loop.exit.split.loop.exit10:               ; preds = %14, %11, %8, %5, %2
  %.0.idx8.lcssa = phi i64 [ %.0.idx8, %2 ], [ %.0.add, %5 ], [ %.0.add.1, %8 ], [ %.0.add.2, %11 ], [ %.0.add.3, %14 ]
  %.0.ptr.le = getelementptr inbounds i8, ptr @symtab, i64 %.0.idx8.lcssa
  br label %.split.loop.exit

.split.loop.exit:                                 ; preds = %17, %.split.loop.exit.split.loop.exit10
  %.05 = phi ptr [ %.0.ptr.le, %.split.loop.exit.split.loop.exit10 ], [ null, %17 ]
  ret ptr %.05
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: none, inaccessiblemem: none) 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"}


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