; LLVM IR from bytecodealliance/sightglass :: benchmarks/shootout/src (sieve)

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

@main.flags = external hidden global [8193 x i8], align 16
@.str = external hidden unnamed_addr constant [35 x i8], align 1
@black_box = external hidden global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 17000, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i64 0, ptr %2, align 8, !tbaa !9
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %7)
  call void (...) @bench_start()
  br label %9

9:                                                ; preds = %53, %0
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr %3, align 4, !tbaa !5
  %12 = icmp ne i32 %10, 0
  br i1 %12, label %13, label %58

13:                                               ; preds = %9
  store i32 0, ptr %6, align 4, !tbaa !5
  store i64 2, ptr %4, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %20, %13
  %15 = load i64, ptr %4, align 8, !tbaa !9
  %16 = icmp sle i64 %15, 8192
  br i1 %16, label %17, label %23

17:                                               ; preds = %14
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = getelementptr inbounds [8193 x i8], ptr @main.flags, i64 0, i64 %18
  store i8 1, ptr %19, align 1, !tbaa !11
  br label %20

20:                                               ; preds = %17
  %21 = load i64, ptr %4, align 8, !tbaa !9
  %22 = add nsw i64 %21, 1
  store i64 %22, ptr %4, align 8, !tbaa !9
  br label %14, !llvm.loop !12

23:                                               ; preds = %14
  store i64 2, ptr %4, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %50, %23
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = icmp sle i64 %25, 8192
  br i1 %26, label %27, label %53

27:                                               ; preds = %24
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = getelementptr inbounds [8193 x i8], ptr @main.flags, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = icmp ne i8 %30, 0
  br i1 %31, label %32, label %49

32:                                               ; preds = %27
  %33 = load i64, ptr %4, align 8, !tbaa !9
  %34 = load i64, ptr %4, align 8, !tbaa !9
  %35 = add nsw i64 %33, %34
  store i64 %35, ptr %5, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %42, %32
  %37 = load i64, ptr %5, align 8, !tbaa !9
  %38 = icmp sle i64 %37, 8192
  br i1 %38, label %39, label %46

39:                                               ; preds = %36
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds [8193 x i8], ptr @main.flags, i64 0, i64 %40
  store i8 0, ptr %41, align 1, !tbaa !11
  br label %42

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

46:                                               ; preds = %36
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %6, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %46, %27
  br label %50

50:                                               ; preds = %49
  %51 = load i64, ptr %4, align 8, !tbaa !9
  %52 = add nsw i64 %51, 1
  store i64 %52, ptr %4, align 8, !tbaa !9
  br label %24, !llvm.loop !15

53:                                               ; preds = %24
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = load i64, ptr %2, align 8, !tbaa !9
  %57 = add i64 %56, %55
  store i64 %57, ptr %2, align 8, !tbaa !9
  br label %9, !llvm.loop !16

58:                                               ; preds = %9
  call void (...) @bench_end()
  %59 = load volatile ptr, ptr @black_box, align 8, !tbaa !17
  call void %59(ptr noundef %2)
  %60 = load i64, ptr %2, align 8, !tbaa !9
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %60)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %62 = load i32, ptr %1, align 4
  ret i32 %62
}

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

declare i32 @printf(ptr noundef, ...) #2

declare void @bench_start(...) #2

declare void @bench_end(...) #2

; 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 = { "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 #3 = { 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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !13}
!17 = !{!18, !18, i64 0}
!18 = !{!"any pointer", !7, i64 0}


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

@main.flags = external hidden local_unnamed_addr global [8193 x i8], align 16
@.str = external hidden unnamed_addr constant [35 x i8], align 1
@black_box = external hidden global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 17000)
  tail call void (...) @bench_start() #5
  br label %.preheader22

.preheader22:                                     ; preds = %0, %16
  %3 = phi i32 [ 16999, %0 ], [ %19, %16 ]
  %4 = phi i64 [ 0, %0 ], [ %18, %16 ]
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(8191) getelementptr inbounds (i8, ptr @main.flags, i64 2), i8 1, i64 8191, i1 false), !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader22, %14
  %.027 = phi i32 [ %.1, %14 ], [ 0, %.preheader22 ]
  %.11925 = phi i64 [ %15, %14 ], [ 2, %.preheader22 ]
  %5 = getelementptr inbounds [8193 x i8], ptr @main.flags, i64 0, i64 %.11925
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %.not21 = icmp eq i8 %6, 0
  br i1 %.not21, label %14, label %7

7:                                                ; preds = %.preheader
  %8 = icmp ult i64 %.11925, 4097
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %7
  %9 = shl nuw nsw i64 %.11925, 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.01724 = phi i64 [ %11, %.lr.ph ], [ %9, %.lr.ph.preheader ]
  %10 = getelementptr inbounds [8193 x i8], ptr @main.flags, i64 0, i64 %.01724
  store i8 0, ptr %10, align 1, !tbaa !5
  %11 = add nuw nsw i64 %.01724, %.11925
  %12 = icmp ult i64 %11, 8193
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %7
  %13 = add nsw i32 %.027, 1
  br label %14

14:                                               ; preds = %.preheader, %._crit_edge
  %.1 = phi i32 [ %13, %._crit_edge ], [ %.027, %.preheader ]
  %15 = add nuw nsw i64 %.11925, 1
  %exitcond.not = icmp eq i64 %15, 8193
  br i1 %exitcond.not, label %16, label %.preheader, !llvm.loop !10

16:                                               ; preds = %14
  %17 = sext i32 %.1 to i64
  %18 = add i64 %4, %17
  %19 = add nsw i32 %3, -1
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %20, label %.preheader22, !llvm.loop !11

20:                                               ; preds = %16
  store i64 %18, ptr %1, align 8, !tbaa !12
  tail call void (...) @bench_end() #5
  %21 = load volatile ptr, ptr @black_box, align 8, !tbaa !14
  call void %21(ptr noundef nonnull %1) #5
  %22 = load i64, ptr %1, align 8, !tbaa !12
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %22)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare void @bench_start(...) local_unnamed_addr #3

declare void @bench_end(...) local_unnamed_addr #3

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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 #3 = { "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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = distinct !{!11, !9}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !6, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !6, i64 0}


; Effective O3 passes: DSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass