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

@mem = external dso_local global [262144 x i64], align 16

declare i32 @left(i64 noundef) #0

declare i32 @right(i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @extendreq(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %12, %2
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = zext i32 %6 to i64
  %8 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %7
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = call i32 @right(i64 noundef %9)
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %18

12:                                               ; preds = %5
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = call i32 @right(i64 noundef %16)
  store i32 %17, ptr %3, align 4, !tbaa !5
  br label %5, !llvm.loop !11

18:                                               ; preds = %5
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = call i32 @left(i64 noundef %22)
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = call i64 @fw(i32 noundef %23, i32 noundef %24)
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %27
  store i64 %25, ptr %28, align 8, !tbaa !9
  ret void
}

declare i64 @fw(i32 noundef, i32 noundef) #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" }

!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}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@mem = external dso_local local_unnamed_addr global [262144 x i64], align 16

declare i32 @left(i64 noundef) local_unnamed_addr #0

declare i32 @right(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @extendreq(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = zext i32 %0 to i64
  %4 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %3
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = tail call i32 @right(i64 noundef %5) #2
  %.not5 = icmp eq i32 %6, 0
  br i1 %.not5, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %7 = phi ptr [ %11, %.lr.ph ], [ %4, %2 ]
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = tail call i32 @right(i64 noundef %8) #2
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds [262144 x i64], ptr @mem, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = tail call i32 @right(i64 noundef %12) #2
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.lcssa = phi ptr [ %4, %2 ], [ %11, %.lr.ph ]
  %14 = load i64, ptr %.lcssa, align 8, !tbaa !5
  %15 = tail call i32 @left(i64 noundef %14) #2
  %16 = tail call i64 @fw(i32 noundef %15, i32 noundef %1) #2
  store i64 %16, ptr %.lcssa, align 8, !tbaa !5
  ret void
}

declare i64 @fw(i32 noundef, i32 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 = !{!"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,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass