; LLVM IR from MinaFaried3/Assiut-University-Training---Newcomers :: j-sheet7_recursion/V-CreatingExpression1.ll (Z5checkxl)

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

@size_ = external dso_local global i64, align 8
@result = external dso_local global i64, align 8
@arr = external dso_local global [21 x i64], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5checkxl(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %8 = load i64, ptr %5, align 8, !tbaa !9
  %9 = load i64, ptr @size_, align 8, !tbaa !5
  %10 = icmp eq i64 %8, %9
  br i1 %10, label %11, label %15

11:                                               ; preds = %2
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = load i64, ptr @result, align 8, !tbaa !5
  %14 = icmp eq i64 %12, %13
  store i1 %14, ptr %3, align 1
  br label %41

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = getelementptr inbounds [21 x i64], ptr @arr, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = add nsw i64 %16, %19
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = add nsw i64 %21, 1
  %23 = call noundef zeroext i1 @_Z5checkxl(i64 noundef %20, i64 noundef %22)
  %24 = zext i1 %23 to i8
  store i8 %24, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds [21 x i64], ptr @arr, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = sub nsw i64 %25, %28
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = add nsw i64 %30, 1
  %32 = call noundef zeroext i1 @_Z5checkxl(i64 noundef %29, i64 noundef %31)
  %33 = zext i1 %32 to i8
  store i8 %33, ptr %7, align 1, !tbaa !11
  %34 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %35 = trunc i8 %34 to i1
  br i1 %35, label %39, label %36

36:                                               ; preds = %15
  %37 = load i8, ptr %7, align 1, !tbaa !11, !range !13, !noundef !14
  %38 = trunc i8 %37 to i1
  br label %39

39:                                               ; preds = %36, %15
  %40 = phi i1 [ true, %15 ], [ %38, %36 ]
  store i1 %40, ptr %3, align 1
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  br label %41

41:                                               ; preds = %39, %11
  %42 = load i1, ptr %3, align 1
  ret i1 %42
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!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"

@size_ = external dso_local local_unnamed_addr global i64, align 8
@result = external dso_local local_unnamed_addr global i64, align 8
@arr = external dso_local local_unnamed_addr global [21 x i64], align 16

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z5checkxl(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = load i64, ptr @size_, align 8, !tbaa !5
  %4 = icmp eq i64 %3, %1
  br i1 %4, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  %accumulator.tr.lcssa = phi i1 [ false, %2 ], [ %13, %tailrecurse ]
  %.tr.lcssa = phi i64 [ %0, %2 ], [ %12, %tailrecurse ]
  %5 = load i64, ptr @result, align 8, !tbaa !5
  %6 = icmp eq i64 %5, %.tr.lcssa
  %accumulator.ret.tr = or i1 %accumulator.tr.lcssa, %6
  ret i1 %accumulator.ret.tr

tailrecurse:                                      ; preds = %2, %tailrecurse
  %.tr1114 = phi i64 [ %10, %tailrecurse ], [ %1, %2 ]
  %.tr13 = phi i64 [ %12, %tailrecurse ], [ %0, %2 ]
  %accumulator.tr12 = phi i1 [ %13, %tailrecurse ], [ false, %2 ]
  %7 = getelementptr inbounds [21 x i64], ptr @arr, i64 0, i64 %.tr1114
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = add nsw i64 %8, %.tr13
  %10 = add nsw i64 %.tr1114, 1
  %11 = tail call noundef zeroext i1 @_Z5checkxl(i64 noundef %9, i64 noundef %10)
  %12 = sub nsw i64 %.tr13, %8
  %13 = or i1 %accumulator.tr12, %11
  %14 = icmp eq i64 %3, %10
  br i1 %14, label %tailrecurse._crit_edge, label %tailrecurse
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn 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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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