; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/308 Division 2/Problem C/C.ll (Z5recurx)

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

@w = external dso_local global i64, align 8

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

6:                                                ; preds = %1
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %6, %1
  store i1 true, ptr %2, align 1
  br label %48

10:                                               ; preds = %6
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = sub nsw i64 %11, 1
  %13 = load i64, ptr @w, align 8, !tbaa !5
  %14 = srem i64 %12, %13
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %22

16:                                               ; preds = %10
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = sub nsw i64 %17, 1
  %19 = load i64, ptr @w, align 8, !tbaa !5
  %20 = sdiv i64 %18, %19
  %21 = call noundef zeroext i1 @_Z5recurx(i64 noundef %20)
  store i1 %21, ptr %2, align 1
  br label %48

22:                                               ; preds = %10
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = add nsw i64 %23, 1
  %25 = load i64, ptr @w, align 8, !tbaa !5
  %26 = srem i64 %24, %25
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %34

28:                                               ; preds = %22
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = add nsw i64 %29, 1
  %31 = load i64, ptr @w, align 8, !tbaa !5
  %32 = sdiv i64 %30, %31
  %33 = call noundef zeroext i1 @_Z5recurx(i64 noundef %32)
  store i1 %33, ptr %2, align 1
  br label %48

34:                                               ; preds = %22
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = load i64, ptr @w, align 8, !tbaa !5
  %37 = srem i64 %35, %36
  %38 = icmp eq i64 %37, 0
  br i1 %38, label %39, label %44

39:                                               ; preds = %34
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = load i64, ptr @w, align 8, !tbaa !5
  %42 = sdiv i64 %40, %41
  %43 = call noundef zeroext i1 @_Z5recurx(i64 noundef %42)
  store i1 %43, ptr %2, align 1
  br label %48

44:                                               ; preds = %34
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  store i1 false, ptr %2, align 1
  br label %48

48:                                               ; preds = %47, %39, %28, %16, %9
  %49 = load i1, ptr %2, align 1
  ret i1 %49
}

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

!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"}


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

@w = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z5recurx(i64 noundef %0) local_unnamed_addr #0 {
  %or.cond10 = icmp ult i64 %0, 2
  br i1 %or.cond10, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %2 = load i64, ptr @w, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %.lr.ph, %tailrecurse.backedge
  %.tr11 = phi i64 [ %0, %.lr.ph ], [ %.tr.be, %tailrecurse.backedge ]
  %4 = add nsw i64 %.tr11, -1
  %5 = srem i64 %4, %2
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %tailrecurse.backedge, label %7

tailrecurse.backedge:                             ; preds = %11, %7, %3
  %.pn = phi i64 [ %4, %3 ], [ %8, %7 ], [ %.tr11, %11 ]
  %.tr.be = sdiv i64 %.pn, %2
  %or.cond = icmp ult i64 %.tr.be, 2
  br i1 %or.cond, label %._crit_edge, label %3

7:                                                ; preds = %3
  %8 = add nsw i64 %.tr11, 1
  %9 = srem i64 %8, %2
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %tailrecurse.backedge, label %11

11:                                               ; preds = %7
  %12 = srem i64 %.tr11, %2
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %tailrecurse.backedge, label %._crit_edge

._crit_edge:                                      ; preds = %tailrecurse.backedge, %11, %1
  %.0 = phi i1 [ true, %1 ], [ false, %11 ], [ true, %tailrecurse.backedge ]
  ret i1 %.0
}

attributes #0 = { mustprogress nofree norecurse 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,GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass