; LLVM IR from tangjz/acm-icpc :: projecteuler (3)

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

@t = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %4

4:                                                ; preds = %47, %0
  %5 = load i32, ptr @t, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !5
  %7 = icmp ne i32 %5, 0
  br i1 %7, label %8, label %50

8:                                                ; preds = %4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n)
  store i64 1, ptr @ans, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 2, ptr %2, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %39, %8
  %11 = load i64, ptr %2, align 8, !tbaa !9
  %12 = load i64, ptr %2, align 8, !tbaa !9
  %13 = mul nsw i64 %11, %12
  %14 = load i64, ptr @n, align 8, !tbaa !9
  %15 = icmp sle i64 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %42

17:                                               ; preds = %10
  %18 = load i64, ptr @n, align 8, !tbaa !9
  %19 = load i64, ptr %2, align 8, !tbaa !9
  %20 = srem i64 %18, %19
  %21 = icmp eq i64 %20, 0
  br i1 %21, label %22, label %38

22:                                               ; preds = %17
  %23 = load i64, ptr %2, align 8, !tbaa !9
  store i64 %23, ptr @ans, align 8, !tbaa !9
  %24 = load i64, ptr %2, align 8, !tbaa !9
  %25 = load i64, ptr @n, align 8, !tbaa !9
  %26 = sdiv i64 %25, %24
  store i64 %26, ptr @n, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %33, %22
  %28 = load i64, ptr @n, align 8, !tbaa !9
  %29 = load i64, ptr %2, align 8, !tbaa !9
  %30 = srem i64 %28, %29
  %31 = icmp eq i64 %30, 0
  br i1 %31, label %32, label %37

32:                                               ; preds = %27
  br label %33

33:                                               ; preds = %32
  %34 = load i64, ptr %2, align 8, !tbaa !9
  %35 = load i64, ptr @n, align 8, !tbaa !9
  %36 = sdiv i64 %35, %34
  store i64 %36, ptr @n, align 8, !tbaa !9
  br label %27, !llvm.loop !11

37:                                               ; preds = %27
  br label %38

38:                                               ; preds = %37, %17
  br label %39

39:                                               ; preds = %38
  %40 = load i64, ptr %2, align 8, !tbaa !9
  %41 = add nsw i64 %40, 1
  store i64 %41, ptr %2, align 8, !tbaa !9
  br label %10, !llvm.loop !13

42:                                               ; preds = %16
  %43 = load i64, ptr @n, align 8, !tbaa !9
  %44 = icmp sgt i64 %43, 1
  br i1 %44, label %45, label %47

45:                                               ; preds = %42
  %46 = load i64, ptr @n, align 8, !tbaa !9
  store i64 %46, ptr @ans, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %45, %42
  %48 = load i64, ptr @ans, align 8, !tbaa !9
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %48)
  br label %4, !llvm.loop !14

50:                                               ; preds = %4
  ret i32 0
}

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

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

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

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

attributes #0 = { mustprogress norecurse 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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

@t = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not15 = icmp eq i32 %2, 0
  br i1 %.not15, label %._crit_edge18, label %.lr.ph17

.lr.ph17:                                         ; preds = %0, %19
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n)
  store i64 1, ptr @ans, align 8, !tbaa !9
  %n.promoted = load i64, ptr @n, align 8, !tbaa !9
  %.not912 = icmp slt i64 %n.promoted, 4
  br i1 %.not912, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %14, %.lr.ph17
  %5 = phi i64 [ 1, %.lr.ph17 ], [ %15, %14 ]
  %.lcssa = phi i64 [ %n.promoted, %.lr.ph17 ], [ %storemerge.lcssa10, %14 ]
  %6 = icmp sgt i64 %.lcssa, 1
  br i1 %6, label %18, label %19

.lr.ph:                                           ; preds = %.lr.ph17, %14
  %7 = phi i64 [ %15, %14 ], [ 1, %.lr.ph17 ]
  %.014 = phi i64 [ %16, %14 ], [ 2, %.lr.ph17 ]
  %storemerge.lcssa1113 = phi i64 [ %storemerge.lcssa10, %14 ], [ %n.promoted, %.lr.ph17 ]
  %8 = srem i64 %storemerge.lcssa1113, %.014
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %14

10:                                               ; preds = %.lr.ph
  store i64 %.014, ptr @ans, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %11, %10
  %.pn = phi i64 [ %storemerge.lcssa1113, %10 ], [ %storemerge, %11 ]
  %storemerge = sdiv i64 %.pn, %.014
  %12 = srem i64 %storemerge, %.014
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %11, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %11
  store i64 %storemerge, ptr @n, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %.loopexit, %.lr.ph
  %15 = phi i64 [ %.014, %.loopexit ], [ %7, %.lr.ph ]
  %storemerge.lcssa10 = phi i64 [ %storemerge, %.loopexit ], [ %storemerge.lcssa1113, %.lr.ph ]
  %16 = add nuw nsw i64 %.014, 1
  %17 = mul nuw nsw i64 %16, %16
  %.not9 = icmp sgt i64 %17, %storemerge.lcssa10
  br i1 %.not9, label %._crit_edge, label %.lr.ph, !llvm.loop !13

18:                                               ; preds = %._crit_edge
  store i64 %.lcssa, ptr @ans, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %18, %._crit_edge
  %20 = phi i64 [ %.lcssa, %18 ], [ %5, %._crit_edge ]
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %20)
  %22 = load i32, ptr @t, align 4, !tbaa !5
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %22, 0
  br i1 %.not, label %._crit_edge18, label %.lr.ph17, !llvm.loop !14

._crit_edge18:                                    ; preds = %19, %0
  ret i32 0
}

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

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

attributes #0 = { mustprogress nofree norecurse 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" }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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