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

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

@symp = external dso_local global i64, align 8
@symtab = external dso_local global [2000 x i64], 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 i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 4294967295, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %25, %1
  %8 = load i64, ptr %4, align 8, !tbaa !5
  %9 = load i64, ptr @symp, align 8, !tbaa !5
  %10 = icmp ult i64 %8, %9
  br i1 %10, label %11, label %28

11:                                               ; preds = %7
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds [2000 x i64], ptr @symtab, i64 0, i64 %12
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = and i64 %14, %15
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = and i64 %17, %18
  %20 = icmp eq i64 %16, %19
  br i1 %20, label %21, label %24

21:                                               ; preds = %11
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds [2000 x i64], ptr @symtab, i64 0, i64 %22
  store ptr %23, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %29

24:                                               ; preds = %11
  br label %25

25:                                               ; preds = %24
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = add i64 %26, 2
  store i64 %27, ptr %4, align 8, !tbaa !5
  br label %7, !llvm.loop !9

28:                                               ; preds = %7
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %29

29:                                               ; preds = %28, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %30 = load ptr, ptr %2, align 8
  ret ptr %30
}

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 = distinct !{!9, !10}
!10 = !{!"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"

@symp = external dso_local local_unnamed_addr global i64, align 8
@symtab = external dso_local global [2000 x i64], 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 {
  %2 = load i64, ptr @symp, align 8, !tbaa !5
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %.split.loop.exit, label %.lr.ph

.lr.ph:                                           ; preds = %1, %8
  %.0710 = phi i64 [ %9, %8 ], [ 0, %1 ]
  %3 = getelementptr inbounds [2000 x i64], ptr @symtab, i64 0, i64 %.0710
  %4 = load i64, ptr %3, align 16, !tbaa !5
  %5 = xor i64 %4, %0
  %6 = and i64 %5, 4294967295
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %.split.loop.exit.loopexit.split.loop.exit, label %8

8:                                                ; preds = %.lr.ph
  %9 = add i64 %.0710, 2
  %10 = icmp ult i64 %9, %2
  br i1 %10, label %.lr.ph, label %.split.loop.exit, !llvm.loop !9

.split.loop.exit.loopexit.split.loop.exit:        ; preds = %.lr.ph
  %11 = getelementptr inbounds [2000 x i64], ptr @symtab, i64 0, i64 %.0710
  br label %.split.loop.exit

.split.loop.exit:                                 ; preds = %8, %.split.loop.exit.loopexit.split.loop.exit, %1
  %.0 = phi ptr [ null, %1 ], [ %11, %.split.loop.exit.loopexit.split.loop.exit ], [ null, %8 ]
  ret ptr %.0
}

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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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