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

@blocksz = external dso_local global i32, align 4
@itemsz = external dso_local global i32, align 4
@in = external dso_local global ptr, align 8
@block = external dso_local global [18 x i64], align 16
@rel = external dso_local global i32, align 4

; 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

declare i32 @left(i64 noundef) #1

declare i32 @right(i64 noundef) #1

declare i64 @fw(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @readblock(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr @blocksz, align 4, !tbaa !5
  %7 = load i32, ptr @itemsz, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i32 1, ptr %6, align 4
  br label %92

10:                                               ; preds = %1
  %11 = load ptr, ptr @in, align 8, !tbaa !9
  %12 = call i64 @readw(ptr noundef %11)
  store i64 %12, ptr %3, align 8, !tbaa !11
  store i32 18, ptr %4, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %22, %10
  %14 = load i32, ptr @itemsz, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %20

16:                                               ; preds = %13
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = add i32 %17, -1
  store i32 %18, ptr %4, align 4, !tbaa !5
  %19 = icmp ne i32 %17, 0
  br label %20

20:                                               ; preds = %16, %13
  %21 = phi i1 [ false, %13 ], [ %19, %16 ]
  br i1 %21, label %22, label %31

22:                                               ; preds = %20
  %23 = load ptr, ptr @in, align 8, !tbaa !9
  %24 = call i64 @readw(ptr noundef %23)
  %25 = load i32, ptr @blocksz, align 4, !tbaa !5
  %26 = add i32 %25, 1
  store i32 %26, ptr @blocksz, align 4, !tbaa !5
  %27 = zext i32 %25 to i64
  %28 = getelementptr inbounds [18 x i64], ptr @block, i64 0, i64 %27
  store i64 %24, ptr %28, align 8, !tbaa !11
  %29 = load i32, ptr @itemsz, align 4, !tbaa !5
  %30 = add i32 %29, -1
  store i32 %30, ptr @itemsz, align 4, !tbaa !5
  br label %13, !llvm.loop !13

31:                                               ; preds = %20
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %88, %31
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = icmp ult i32 %33, 18
  br i1 %34, label %35, label %91

35:                                               ; preds = %32
  %36 = load i64, ptr %3, align 8, !tbaa !11
  %37 = lshr i64 %36, 34
  %38 = and i64 %37, 3
  %39 = trunc i64 %38 to i32
  store i32 %39, ptr %5, align 4, !tbaa !5
  %40 = load i64, ptr %3, align 8, !tbaa !11
  %41 = shl i64 %40, 2
  store i64 %41, ptr %3, align 8, !tbaa !11
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %87

44:                                               ; preds = %35
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = and i32 %45, 1
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %65

48:                                               ; preds = %44
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds [18 x i64], ptr @block, i64 0, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !11
  %53 = call i32 @left(i64 noundef %52)
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds [18 x i64], ptr @block, i64 0, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !11
  %58 = call i32 @right(i64 noundef %57)
  %59 = load i32, ptr @rel, align 4, !tbaa !5
  %60 = add i32 %58, %59
  %61 = call i64 @fw(i32 noundef %53, i32 noundef %60)
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds [18 x i64], ptr @block, i64 0, i64 %63
  store i64 %61, ptr %64, align 8, !tbaa !11
  br label %65

65:                                               ; preds = %48, %44
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = and i32 %66, 2
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %86

69:                                               ; preds = %65
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = zext i32 %70 to i64
  %72 = getelementptr inbounds [18 x i64], ptr @block, i64 0, i64 %71
  %73 = load i64, ptr %72, align 8, !tbaa !11
  %74 = call i32 @left(i64 noundef %73)
  %75 = load i32, ptr @rel, align 4, !tbaa !5
  %76 = add i32 %74, %75
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds [18 x i64], ptr @block, i64 0, i64 %78
  %80 = load i64, ptr %79, align 8, !tbaa !11
  %81 = call i32 @right(i64 noundef %80)
  %82 = call i64 @fw(i32 noundef %76, i32 noundef %81)
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds [18 x i64], ptr @block, i64 0, i64 %84
  store i64 %82, ptr %85, align 8, !tbaa !11
  br label %86

86:                                               ; preds = %69, %65
  br label %87

87:                                               ; preds = %86, %35
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %4, align 4, !tbaa !5
  %90 = add i32 %89, 1
  store i32 %90, ptr %4, align 4, !tbaa !5
  br label %32, !llvm.loop !15

91:                                               ; preds = %32
  store i32 0, ptr %6, align 4
  br label %92

92:                                               ; preds = %91, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %93 = load i32, ptr %6, align 4
  switch i32 %93, label %95 [
    i32 0, label %94
    i32 1, label %94
  ]

94:                                               ; preds = %92, %92
  ret void

95:                                               ; preds = %92
  unreachable
}

declare i64 @readw(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 }

!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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@blocksz = external dso_local local_unnamed_addr global i32, align 4
@itemsz = external dso_local local_unnamed_addr global i32, align 4
@in = external dso_local local_unnamed_addr global ptr, align 8
@block = external dso_local local_unnamed_addr global [18 x i64], align 16
@rel = external dso_local local_unnamed_addr global i32, align 4

declare i32 @left(i64 noundef) local_unnamed_addr #0

declare i32 @right(i64 noundef) local_unnamed_addr #0

declare i64 @fw(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @readblock(i32 noundef %0) local_unnamed_addr #1 {
  store i32 0, ptr @blocksz, align 4, !tbaa !5
  %2 = load i32, ptr @itemsz, align 4, !tbaa !5
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr @in, align 8, !tbaa !9
  %6 = tail call i64 @readw(ptr noundef %5) #2
  %7 = load i32, ptr @itemsz, align 4, !tbaa !5
  %.not19 = icmp eq i32 %7, 0
  br i1 %.not19, label %.critedge.preheader, label %.lr.ph

.critedge.preheader:                              ; preds = %.lr.ph, %4
  %.not16 = icmp eq i32 %0, 0
  br i1 %.not16, label %.loopexit, label %.critedge.preheader.split

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.01420 = phi i32 [ %8, %.lr.ph ], [ 18, %4 ]
  %8 = add nsw i32 %.01420, -1
  %9 = load ptr, ptr @in, align 8, !tbaa !9
  %10 = tail call i64 @readw(ptr noundef %9) #2
  %11 = load i32, ptr @blocksz, align 4, !tbaa !5
  %12 = add i32 %11, 1
  store i32 %12, ptr @blocksz, align 4, !tbaa !5
  %13 = zext i32 %11 to i64
  %14 = getelementptr inbounds [18 x i64], ptr @block, i64 0, i64 %13
  store i64 %10, ptr %14, align 8, !tbaa !11
  %15 = load i32, ptr @itemsz, align 4, !tbaa !5
  %16 = add i32 %15, -1
  store i32 %16, ptr @itemsz, align 4, !tbaa !5
  %.not = icmp eq i32 %16, 0
  %.not15 = icmp eq i32 %8, 0
  %or.cond = select i1 %.not, i1 true, i1 %.not15
  br i1 %or.cond, label %.critedge.preheader, label %.lr.ph, !llvm.loop !13

.critedge.preheader.split:                        ; preds = %.critedge.preheader, %.critedge
  %indvars.iv = phi i64 [ %indvars.iv.next, %.critedge ], [ 0, %.critedge.preheader ]
  %.022 = phi i64 [ %19, %.critedge ], [ %6, %.critedge.preheader ]
  %17 = lshr i64 %.022, 34
  %18 = trunc nuw nsw i64 %17 to i32
  %19 = shl i64 %.022, 2
  %20 = and i32 %18, 1
  %.not17 = icmp eq i32 %20, 0
  br i1 %.not17, label %30, label %21

21:                                               ; preds = %.critedge.preheader.split
  %22 = getelementptr inbounds [18 x i64], ptr @block, i64 0, i64 %indvars.iv
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = tail call i32 @left(i64 noundef %23) #2
  %25 = load i64, ptr %22, align 8, !tbaa !11
  %26 = tail call i32 @right(i64 noundef %25) #2
  %27 = load i32, ptr @rel, align 4, !tbaa !5
  %28 = add i32 %27, %26
  %29 = tail call i64 @fw(i32 noundef %24, i32 noundef %28) #2
  store i64 %29, ptr %22, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %21, %.critedge.preheader.split
  %31 = and i32 %18, 2
  %.not18 = icmp eq i32 %31, 0
  br i1 %.not18, label %.critedge, label %32

32:                                               ; preds = %30
  %33 = getelementptr inbounds [18 x i64], ptr @block, i64 0, i64 %indvars.iv
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = tail call i32 @left(i64 noundef %34) #2
  %36 = load i32, ptr @rel, align 4, !tbaa !5
  %37 = add i32 %36, %35
  %38 = load i64, ptr %33, align 8, !tbaa !11
  %39 = tail call i32 @right(i64 noundef %38) #2
  %40 = tail call i64 @fw(i32 noundef %37, i32 noundef %39) #2
  store i64 %40, ptr %33, align 8, !tbaa !11
  br label %.critedge

.critedge:                                        ; preds = %32, %30
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 18
  br i1 %exitcond.not, label %.loopexit, label %.critedge.preheader.split, !llvm.loop !15

.loopexit:                                        ; preds = %.critedge, %.critedge.preheader, %1
  ret void
}

declare i64 @readw(ptr noundef) local_unnamed_addr #0

attributes #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 #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 = !{!"int", !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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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