; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-11-01 (B - Sum of divisors - lzy)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@b = external dso_local global [109 x i32], align 16
@p = external dso_local global i32, align 4
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3sqrx(i64 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %7

7:                                                ; preds = %101, %0
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %9 = icmp eq i32 %8, 2
  br i1 %9, label %10, label %103

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

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

17:                                               ; preds = %11
  store i32 4, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %73

18:                                               ; preds = %11
  %19 = load i32, ptr @n, align 4, !tbaa !9
  %20 = load i32, ptr %2, align 4, !tbaa !9
  %21 = srem i32 %19, %20
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %69

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %24 = load i32, ptr %2, align 4, !tbaa !9
  store i32 %24, ptr %5, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %37, %23
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 7, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %41

29:                                               ; preds = %25
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = load i32, ptr @m, align 4, !tbaa !9
  %32 = srem i32 %30, %31
  %33 = sext i32 %32 to i64
  %34 = call noundef i64 @_Z3sqrx(i64 noundef %33)
  %35 = load i64, ptr @ans, align 8, !tbaa !5
  %36 = add nsw i64 %35, %34
  store i64 %36, ptr @ans, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %29
  %38 = load i32, ptr @m, align 4, !tbaa !9
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = sdiv i32 %39, %38
  store i32 %40, ptr %5, align 4, !tbaa !9
  br label %25, !llvm.loop !11

41:                                               ; preds = %28
  %42 = load i32, ptr %2, align 4, !tbaa !9
  %43 = load i32, ptr %2, align 4, !tbaa !9
  %44 = mul nsw i32 %42, %43
  %45 = load i32, ptr @n, align 4, !tbaa !9
  %46 = icmp ne i32 %44, %45
  br i1 %46, label %47, label %68

47:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %48 = load i32, ptr @n, align 4, !tbaa !9
  %49 = load i32, ptr %2, align 4, !tbaa !9
  %50 = sdiv i32 %48, %49
  store i32 %50, ptr %6, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %63, %47
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %55, label %54

54:                                               ; preds = %51
  store i32 10, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %67

55:                                               ; preds = %51
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = load i32, ptr @m, align 4, !tbaa !9
  %58 = srem i32 %56, %57
  %59 = sext i32 %58 to i64
  %60 = call noundef i64 @_Z3sqrx(i64 noundef %59)
  %61 = load i64, ptr @ans, align 8, !tbaa !5
  %62 = add nsw i64 %61, %60
  store i64 %62, ptr @ans, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %55
  %64 = load i32, ptr @m, align 4, !tbaa !9
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = sdiv i32 %65, %64
  store i32 %66, ptr %6, align 4, !tbaa !9
  br label %51, !llvm.loop !13

67:                                               ; preds = %54
  br label %68

68:                                               ; preds = %67, %41
  br label %69

69:                                               ; preds = %68, %18
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %2, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %2, align 4, !tbaa !9
  br label %11, !llvm.loop !14

73:                                               ; preds = %17
  store i32 0, ptr @p, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %84, %73
  %75 = load i64, ptr @ans, align 8, !tbaa !5
  %76 = load i32, ptr @m, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = srem i64 %75, %77
  %79 = trunc i64 %78 to i32
  %80 = load i32, ptr @p, align 4, !tbaa !9
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr @p, align 4, !tbaa !9
  %82 = sext i32 %80 to i64
  %83 = getelementptr inbounds [109 x i32], ptr @b, i64 0, i64 %82
  store i32 %79, ptr %83, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %74
  %85 = load i32, ptr @m, align 4, !tbaa !9
  %86 = sext i32 %85 to i64
  %87 = load i64, ptr @ans, align 8, !tbaa !5
  %88 = sdiv i64 %87, %86
  store i64 %88, ptr @ans, align 8, !tbaa !5
  %89 = icmp ne i64 %88, 0
  br i1 %89, label %74, label %90, !llvm.loop !15

90:                                               ; preds = %84
  br label %91

91:                                               ; preds = %95, %90
  %92 = load i32, ptr @p, align 4, !tbaa !9
  %93 = add nsw i32 %92, -1
  store i32 %93, ptr @p, align 4, !tbaa !9
  %94 = icmp ne i32 %92, 0
  br i1 %94, label %95, label %101

95:                                               ; preds = %91
  %96 = load i32, ptr @p, align 4, !tbaa !9
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [109 x i32], ptr @b, i64 0, i64 %97
  %99 = load i32, ptr %98, align 4, !tbaa !9
  %100 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %99)
  br label %91, !llvm.loop !16

101:                                              ; preds = %91
  %102 = call i32 @putchar(i32 noundef 10)
  br label %7, !llvm.loop !17

103:                                              ; preds = %7
  ret i32 0
}

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

; 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 memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

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

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(i32 noundef) #4

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@b = external dso_local local_unnamed_addr global [109 x i32], align 16
@p = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3sqrx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %2 = icmp eq i32 %1, 2
  br i1 %2, label %.lr.ph36, label %._crit_edge37

.lr.ph36:                                         ; preds = %0, %._crit_edge34
  store i64 0, ptr @ans, align 8, !tbaa !5
  %3 = load i32, ptr @n, align 4, !tbaa !9
  %.not28 = icmp slt i32 %3, 1
  br i1 %.not28, label %._crit_edge, label %.lr.ph30

._crit_edge:                                      ; preds = %.loopexit, %.lr.ph36
  %ans.promoted = phi i64 [ 0, %.lr.ph36 ], [ %ans.promoted41, %.loopexit ]
  %4 = load i32, ptr @m, align 4, !tbaa !9
  %5 = sext i32 %4 to i64
  br label %33

.lr.ph30:                                         ; preds = %.lr.ph36, %.loopexit
  %ans.promoted42 = phi i64 [ %ans.promoted41, %.loopexit ], [ 0, %.lr.ph36 ]
  %6 = phi i32 [ %30, %.loopexit ], [ %3, %.lr.ph36 ]
  %7 = phi i32 [ %32, %.loopexit ], [ 1, %.lr.ph36 ]
  %.01529 = phi i32 [ %31, %.loopexit ], [ 1, %.lr.ph36 ]
  %8 = srem i32 %6, %.01529
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %.lr.ph30
  %.pre = load i32, ptr @m, align 4, !tbaa !9
  br label %.preheader

10:                                               ; preds = %.preheader
  %11 = load i32, ptr @n, align 4, !tbaa !9
  %.not22 = icmp eq i32 %7, %11
  br i1 %.not22, label %.loopexit, label %20

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %12 = phi i32 [ %18, %.preheader ], [ %.pre, %.preheader.preheader ]
  %.01425 = phi i32 [ %19, %.preheader ], [ %.01529, %.preheader.preheader ]
  %13 = srem i32 %.01425, %12
  %14 = sext i32 %13 to i64
  %15 = tail call noundef i64 @_Z3sqrx(i64 noundef %14)
  %16 = load i64, ptr @ans, align 8, !tbaa !5
  %17 = add nsw i64 %16, %15
  store i64 %17, ptr @ans, align 8, !tbaa !5
  %18 = load i32, ptr @m, align 4, !tbaa !9
  %19 = sdiv i32 %.01425, %18
  %.not21 = icmp eq i32 %19, 0
  br i1 %.not21, label %10, label %.preheader, !llvm.loop !11

20:                                               ; preds = %10
  %21 = sdiv i32 %11, %.01529
  %.not2326 = icmp eq i32 %21, 0
  br i1 %.not2326, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %20, %.lr.ph
  %22 = phi i32 [ %28, %.lr.ph ], [ %18, %20 ]
  %.027 = phi i32 [ %29, %.lr.ph ], [ %21, %20 ]
  %23 = srem i32 %.027, %22
  %24 = sext i32 %23 to i64
  %25 = tail call noundef i64 @_Z3sqrx(i64 noundef %24)
  %26 = load i64, ptr @ans, align 8, !tbaa !5
  %27 = add nsw i64 %26, %25
  store i64 %27, ptr @ans, align 8, !tbaa !5
  %28 = load i32, ptr @m, align 4, !tbaa !9
  %29 = sdiv i32 %.027, %28
  %.not23 = icmp eq i32 %29, 0
  br i1 %.not23, label %.loopexit.loopexit, label %.lr.ph, !llvm.loop !13

.loopexit.loopexit:                               ; preds = %.lr.ph
  %.pre40 = load i32, ptr @n, align 4, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %20, %.lr.ph30, %10
  %ans.promoted41 = phi i64 [ %27, %.loopexit.loopexit ], [ %17, %20 ], [ %ans.promoted42, %.lr.ph30 ], [ %17, %10 ]
  %30 = phi i32 [ %.pre40, %.loopexit.loopexit ], [ %11, %20 ], [ %6, %.lr.ph30 ], [ %7, %10 ]
  %31 = add nuw nsw i32 %.01529, 1
  %32 = mul nuw nsw i32 %31, %31
  %.not = icmp sgt i32 %32, %30
  br i1 %.not, label %._crit_edge, label %.lr.ph30, !llvm.loop !14

33:                                               ; preds = %33, %._crit_edge
  %indvars.iv = phi i64 [ %indvars.iv.next, %33 ], [ 0, %._crit_edge ]
  %34 = phi i64 [ %38, %33 ], [ %ans.promoted, %._crit_edge ]
  %35 = srem i64 %34, %5
  %36 = trunc nsw i64 %35 to i32
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = getelementptr inbounds [109 x i32], ptr @b, i64 0, i64 %indvars.iv
  store i32 %36, ptr %37, align 4, !tbaa !9
  %38 = sdiv i64 %34, %5
  %.not19 = icmp eq i64 %38, 0
  br i1 %.not19, label %.lr.ph33.preheader, label %33, !llvm.loop !15

.lr.ph33.preheader:                               ; preds = %33
  %39 = trunc nuw nsw i64 %indvars.iv to i32
  store i64 0, ptr @ans, align 8, !tbaa !5
  store i32 %39, ptr @p, align 4, !tbaa !9
  br label %.lr.ph33

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %.lr.ph33
  %40 = phi i32 [ %46, %.lr.ph33 ], [ %39, %.lr.ph33.preheader ]
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [109 x i32], ptr @b, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %43)
  %45 = load i32, ptr @p, align 4, !tbaa !9
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr @p, align 4, !tbaa !9
  %.not20 = icmp eq i32 %45, 0
  br i1 %.not20, label %._crit_edge34, label %.lr.ph33, !llvm.loop !16

._crit_edge34:                                    ; preds = %.lr.ph33
  %47 = tail call i32 @putchar(i32 noundef 10)
  %48 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %49 = icmp eq i32 %48, 2
  br i1 %49, label %.lr.ph36, label %._crit_edge37, !llvm.loop !17

._crit_edge37:                                    ; preds = %._crit_edge34, %0
  ret i32 0
}

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

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

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #3

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 = { mustprogress 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 #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 = { inlinehint mustprogress nofree 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" }

!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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


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