; LLVM IR from freddiev4/dailyprogrammerchallenges :: Easy Challenges/Challenge 0208 Easy - Culling Numbers/solutions (solution)

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

@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @error_msg() #0

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  call void @error_msg()
  br label %17

17:                                               ; preds = %16, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = zext i32 %18 to i64
  %20 = call ptr @llvm.stacksave.p0()
  store ptr %20, ptr %10, align 8
  %21 = alloca i64, i64 %19, align 16
  store i64 %19, ptr %11, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #6
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %81, %17
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %26, label %84

26:                                               ; preds = %22
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %27, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %31, i64 0
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %34, 45
  br i1 %35, label %36, label %37

36:                                               ; preds = %26
  call void @error_msg()
  br label %37

37:                                               ; preds = %36, %26
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds ptr, ptr %38, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = call i64 @strtoul(ptr noundef %42, ptr noundef %12, i32 noundef 10) #6
  store i64 %43, ptr %9, align 8, !tbaa !12
  %44 = load ptr, ptr %12, align 8, !tbaa !9
  %45 = load ptr, ptr %5, align 8, !tbaa !9
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds ptr, ptr %45, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = icmp eq ptr %44, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %37
  call void @error_msg()
  br label %52

52:                                               ; preds = %51, %37
  store i8 0, ptr %13, align 1, !tbaa !14
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %66, %52
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %57, label %69

57:                                               ; preds = %53
  %58 = load i64, ptr %9, align 8, !tbaa !12
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i64, ptr %21, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !12
  %63 = icmp eq i64 %58, %62
  br i1 %63, label %64, label %65

64:                                               ; preds = %57
  store i8 1, ptr %13, align 1, !tbaa !14
  br label %69

65:                                               ; preds = %57
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %7, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %7, align 4, !tbaa !5
  br label %53, !llvm.loop !16

69:                                               ; preds = %64, %53
  %70 = load i8, ptr %13, align 1, !tbaa !14, !range !18, !noundef !19
  %71 = trunc i8 %70 to i1
  %72 = zext i1 %71 to i32
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %80

74:                                               ; preds = %69
  %75 = load i64, ptr %9, align 8, !tbaa !12
  %76 = load i32, ptr %8, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %8, align 4, !tbaa !5
  %78 = sext i32 %76 to i64
  %79 = getelementptr inbounds i64, ptr %21, i64 %78
  store i64 %75, ptr %79, align 8, !tbaa !12
  br label %80

80:                                               ; preds = %74, %69
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %6, align 4, !tbaa !5
  br label %22, !llvm.loop !20

84:                                               ; preds = %22
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %96, %84
  %87 = load i32, ptr %6, align 4, !tbaa !5
  %88 = load i32, ptr %8, align 4, !tbaa !5
  %89 = icmp slt i32 %87, %88
  br i1 %89, label %90, label %99

90:                                               ; preds = %86
  %91 = load i32, ptr %6, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds i64, ptr %21, i64 %92
  %94 = load i64, ptr %93, align 8, !tbaa !12
  %95 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %94)
  br label %96

96:                                               ; preds = %90
  %97 = load i32, ptr %6, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %6, align 4, !tbaa !5
  br label %86, !llvm.loop !21

99:                                               ; preds = %86
  %100 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @exit(i32 noundef 0) #7
  unreachable
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #4

; Function Attrs: nounwind
declare i64 @strtoul(ptr noundef, ptr noundef, i32 noundef) #5

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 = { "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 #2 = { noreturn 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nosync nounwind willreturn }
attributes #5 = { 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 #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = distinct !{!20, !17}
!21 = distinct !{!21, !17}


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

@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @error_msg() local_unnamed_addr #0

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #3 {
  %3 = alloca ptr, align 8
  %4 = icmp eq i32 %0, 1
  br i1 %4, label %.thread, label %5

.thread:                                          ; preds = %2
  tail call void @error_msg()
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #6
  br label %._crit_edge.thread

5:                                                ; preds = %2
  %6 = zext i32 %0 to i64
  %7 = alloca i64, i64 %6, align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #6
  %8 = icmp sgt i32 %0, 1
  br i1 %8, label %.lr.ph30, label %._crit_edge.thread

.lr.ph30:                                         ; preds = %5, %.loopexit
  %indvars.iv36 = phi i64 [ %indvars.iv.next37, %.loopexit ], [ 1, %5 ]
  %.02428 = phi i32 [ %.125, %.loopexit ], [ 0, %5 ]
  %9 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv36
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = icmp eq i8 %11, 45
  br i1 %12, label %13, label %14

13:                                               ; preds = %.lr.ph30
  tail call void @error_msg()
  %.pre = load ptr, ptr %9, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %13, %.lr.ph30
  %15 = phi ptr [ %.pre, %13 ], [ %10, %.lr.ph30 ]
  %16 = call i64 @strtoul(ptr noundef %15, ptr noundef nonnull %3, i32 noundef 10) #6
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = icmp eq ptr %17, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %14
  tail call void @error_msg()
  br label %21

21:                                               ; preds = %20, %14
  %.not26 = icmp sgt i32 %.02428, 0
  br i1 %.not26, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %21
  %wide.trip.count = zext nneg i32 %.02428 to i64
  br label %.lr.ph

22:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !10

.lr.ph:                                           ; preds = %.lr.ph.preheader, %22
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %22 ]
  %23 = getelementptr inbounds i64, ptr %7, i64 %indvars.iv
  %24 = load i64, ptr %23, align 8, !tbaa !12
  %25 = icmp eq i64 %16, %24
  br i1 %25, label %.loopexit, label %22

.critedge:                                        ; preds = %22, %21
  %26 = add nsw i32 %.02428, 1
  %27 = sext i32 %.02428 to i64
  %28 = getelementptr inbounds i64, ptr %7, i64 %27
  store i64 %16, ptr %28, align 8, !tbaa !12
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.critedge
  %.125 = phi i32 [ %26, %.critedge ], [ %.02428, %.lr.ph ]
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond40.not = icmp eq i64 %indvars.iv.next37, %6
  br i1 %exitcond40.not, label %._crit_edge, label %.lr.ph30, !llvm.loop !14

._crit_edge.thread:                               ; preds = %5, %.thread
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %._crit_edge34

._crit_edge:                                      ; preds = %.loopexit
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %31 = icmp sgt i32 %.125, 0
  br i1 %31, label %.lr.ph33.preheader, label %._crit_edge34

.lr.ph33.preheader:                               ; preds = %._crit_edge
  %wide.trip.count44 = zext nneg i32 %.125 to i64
  br label %.lr.ph33

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %.lr.ph33
  %indvars.iv41 = phi i64 [ 0, %.lr.ph33.preheader ], [ %indvars.iv.next42, %.lr.ph33 ]
  %32 = getelementptr inbounds i64, ptr %7, i64 %indvars.iv41
  %33 = load i64, ptr %32, align 8, !tbaa !12
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %33)
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %exitcond45.not = icmp eq i64 %indvars.iv.next42, %wide.trip.count44
  br i1 %exitcond45.not, label %._crit_edge34, label %.lr.ph33, !llvm.loop !15

._crit_edge34:                                    ; preds = %.lr.ph33, %._crit_edge.thread, %._crit_edge
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  tail call void @exit(i32 noundef 0) #7
  unreachable
}

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

; Function Attrs: mustprogress nofree nounwind willreturn
declare i64 @strtoul(ptr noundef readonly, ptr nocapture noundef, i32 noundef) local_unnamed_addr #5

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


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