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

@itemp = external dso_local global i32, align 4
@item = external dso_local global [262144 x i64], align 16
@blocksz = external dso_local global i32, align 4
@blockreloc = external dso_local global i64, align 8
@relocp = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @startblock() #0 {
  %1 = load i32, ptr @blocksz, align 4, !tbaa !5
  %2 = icmp ne i32 %1, 0
  br i1 %2, label %3, label %16

3:                                                ; preds = %0
  %4 = load i32, ptr @blocksz, align 4, !tbaa !5
  %5 = sub nsw i32 18, %4
  %6 = mul nsw i32 2, %5
  %7 = load i64, ptr @blockreloc, align 8, !tbaa !9
  %8 = zext i32 %6 to i64
  %9 = shl i64 %7, %8
  store i64 %9, ptr @blockreloc, align 8, !tbaa !9
  %10 = load i64, ptr @blockreloc, align 8, !tbaa !9
  %11 = load i32, ptr @relocp, align 4, !tbaa !5
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds [262144 x i64], ptr @item, i64 0, i64 %12
  store i64 %10, ptr %13, align 8, !tbaa !9
  %14 = load i32, ptr @itemp, align 4, !tbaa !5
  %15 = add i32 %14, 1
  store i32 %15, ptr @itemp, align 4, !tbaa !5
  store i32 %14, ptr @relocp, align 4, !tbaa !5
  store i64 0, ptr @blockreloc, align 8, !tbaa !9
  store i32 0, ptr @blocksz, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %3, %0
  ret void
}

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

@itemp = external dso_local local_unnamed_addr global i32, align 4
@item = external dso_local local_unnamed_addr global [262144 x i64], align 16
@blocksz = external dso_local local_unnamed_addr global i32, align 4
@blockreloc = external dso_local local_unnamed_addr global i64, align 8
@relocp = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @startblock() local_unnamed_addr #0 {
  %1 = load i32, ptr @blocksz, align 4, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %13, label %2

2:                                                ; preds = %0
  %3 = shl i32 %1, 1
  %4 = sub i32 36, %3
  %5 = load i64, ptr @blockreloc, align 8, !tbaa !9
  %6 = zext nneg i32 %4 to i64
  %7 = shl i64 %5, %6
  %8 = load i32, ptr @relocp, align 4, !tbaa !5
  %9 = zext i32 %8 to i64
  %10 = getelementptr inbounds [262144 x i64], ptr @item, i64 0, i64 %9
  store i64 %7, ptr %10, align 8, !tbaa !9
  %11 = load i32, ptr @itemp, align 4, !tbaa !5
  %12 = add i32 %11, 1
  store i32 %12, ptr @itemp, align 4, !tbaa !5
  store i32 %11, ptr @relocp, align 4, !tbaa !5
  store i64 0, ptr @blockreloc, align 8, !tbaa !9
  store i32 0, ptr @blocksz, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %2, %0
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, 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 = !{!"int", !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: DSEPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass