; LLVM IR from DionysiosB/CodeForces :: 1400-1499/1474B-DifferentDivisors.ll (Z7isPrimex)

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

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

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

11:                                               ; preds = %8
  %12 = load i64, ptr %3, align 8, !tbaa !5
  %13 = icmp eq i64 %12, 5
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %8, %1
  store i1 true, ptr %2, align 1
  br label %49

15:                                               ; preds = %11
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = srem i64 %16, 2
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %27, label %19

19:                                               ; preds = %15
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = srem i64 %20, 3
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %27, label %23

23:                                               ; preds = %19
  %24 = load i64, ptr %3, align 8, !tbaa !5
  %25 = srem i64 %24, 5
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %23, %19, %15
  store i1 false, ptr %2, align 1
  br label %49

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store i64 7, ptr %4, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %43, %28
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = load i64, ptr %4, align 8, !tbaa !5
  %32 = mul nsw i64 %30, %31
  %33 = load i64, ptr %3, align 8, !tbaa !5
  %34 = icmp sle i64 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %29
  store i32 2, ptr %5, align 4
  br label %46

36:                                               ; preds = %29
  %37 = load i64, ptr %3, align 8, !tbaa !5
  %38 = load i64, ptr %4, align 8, !tbaa !5
  %39 = srem i64 %37, %38
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %46

42:                                               ; preds = %36
  br label %43

43:                                               ; preds = %42
  %44 = load i64, ptr %4, align 8, !tbaa !5
  %45 = add nsw i64 %44, 2
  store i64 %45, ptr %4, align 8, !tbaa !5
  br label %29, !llvm.loop !9

46:                                               ; preds = %41, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %47 = load i32, ptr %5, align 4
  switch i32 %47, label %51 [
    i32 2, label %48
    i32 1, label %49
  ]

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

49:                                               ; preds = %48, %46, %27, %14
  %50 = load i1, ptr %2, align 1
  ret i1 %50

51:                                               ; preds = %46
  unreachable
}

; 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 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 #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 = distinct !{!9, !10}
!10 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef zeroext i1 @_Z7isPrimex(i64 noundef %0) local_unnamed_addr #0 {
  switch i64 %0, label %2 [
    i64 5, label %.loopexit
    i64 3, label %.loopexit
    i64 2, label %.loopexit
  ]

2:                                                ; preds = %1
  %3 = and i64 %0, 1
  %4 = icmp eq i64 %3, 0
  %5 = srem i64 %0, 3
  %6 = icmp eq i64 %5, 0
  %or.cond = or i1 %4, %6
  %7 = srem i64 %0, 5
  %8 = icmp eq i64 %7, 0
  %or.cond21 = or i1 %8, %or.cond
  br i1 %or.cond21, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2
  %.not22 = icmp slt i64 %0, 49
  br i1 %.not22, label %.loopexit, label %.lr.ph

9:                                                ; preds = %.lr.ph
  %10 = add nuw nsw i64 %.01623, 2
  %11 = mul nuw nsw i64 %10, %10
  %.not = icmp sgt i64 %11, %0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %9
  %.01623 = phi i64 [ %10, %9 ], [ 7, %.preheader ]
  %12 = urem i64 %0, %.01623
  %.not26 = icmp ne i64 %12, 0
  br i1 %.not26, label %9, label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %9, %.preheader, %2, %1, %1, %1
  %.1 = phi i1 [ true, %1 ], [ true, %1 ], [ true, %1 ], [ false, %2 ], [ true, %.preheader ], [ %.not26, %9 ], [ %.not26, %.lr.ph ]
  ret i1 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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