; LLVM IR from AllAlgorithms/c :: algorithms/strings/reverse (reverse)

; 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: nounwind uwtable
define dso_local i32 @is_prime(i64 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  %6 = load i64, ptr %3, align 8, !tbaa !5
  switch i64 %6, label %9 [
    i64 0, label %7
    i64 1, label %7
    i64 2, label %8
  ]

7:                                                ; preds = %1, %1
  store i32 0, ptr %2, align 4
  br label %35

8:                                                ; preds = %1
  store i32 1, ptr %2, align 4
  br label %35

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = urem i64 %10, 2
  %12 = icmp eq i64 0, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %9
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %34

14:                                               ; preds = %9
  store i32 3, ptr %4, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %30, %14
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = mul i32 %16, %17
  %19 = zext i32 %18 to i64
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = icmp ule i64 %19, %20
  br i1 %21, label %22, label %33

22:                                               ; preds = %15
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = urem i64 %23, %25
  %27 = icmp eq i64 0, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %22
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %34

29:                                               ; preds = %22
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = add i32 %31, 2
  store i32 %32, ptr %4, align 4, !tbaa !9
  br label %15, !llvm.loop !11

33:                                               ; preds = %15
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %34

34:                                               ; preds = %33, %28, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %35

35:                                               ; preds = %34, %8, %7
  %36 = load i32, ptr %2, align 4
  ret i32 %36
}

; 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 = { 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

@switch.table.is_prime = private unnamed_addr constant [3 x i32] [i32 0, i32 0, i32 1], align 4

; Function Attrs: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local range(i32 0, 2) i32 @is_prime(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp ult i64 %0, 3
  br i1 %2, label %switch.lookup, label %3

3:                                                ; preds = %1
  %4 = and i64 %0, 1
  %5 = icmp eq i64 %4, 0
  br i1 %5, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %3
  %.not11 = icmp ult i64 %0, 9
  br i1 %.not11, label %.loopexit, label %.lr.ph

6:                                                ; preds = %.lr.ph
  %7 = add i32 %.012, 2
  %8 = mul i32 %7, %7
  %9 = zext i32 %8 to i64
  %.not = icmp ugt i64 %9, %0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %6
  %.012 = phi i32 [ %7, %6 ], [ 3, %.preheader ]
  %10 = zext i32 %.012 to i64
  %11 = urem i64 %0, %10
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %.loopexit, label %6

switch.lookup:                                    ; preds = %1
  %switch.gep = getelementptr inbounds [3 x i32], ptr @switch.table.is_prime, i64 0, i64 %0
  %switch.load = load i32, ptr %switch.gep, align 4
  br label %.loopexit

.loopexit:                                        ; preds = %6, %.lr.ph, %switch.lookup, %.preheader, %3
  %.1 = phi i32 [ 0, %3 ], [ 1, %.preheader ], [ %switch.load, %switch.lookup ], [ 1, %6 ], [ 0, %.lr.ph ]
  ret i32 %.1
}

attributes #0 = { nofree norecurse nosync nounwind 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: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass