; LLVM IR from tangjz/acm-icpc :: self_training/2015-04-30 (I)

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

@Case = 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 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
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  br label %5

5:                                                ; preds = %65, %0
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %8, label %70

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

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

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

18:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %19 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %19, ptr %4, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %58, %18
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = mul nsw i64 %21, %22
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = mul nsw i64 %23, %24
  %26 = load i64, ptr @n, align 8, !tbaa !5
  %27 = icmp sle i64 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %20
  store i32 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %61

29:                                               ; preds = %20
  %30 = load i64, ptr %2, align 8, !tbaa !5
  %31 = load i64, ptr %4, align 8, !tbaa !5
  %32 = icmp eq i64 %30, %31
  br i1 %32, label %33, label %45

33:                                               ; preds = %29
  %34 = load i64, ptr @n, align 8, !tbaa !5
  %35 = load i64, ptr %2, align 8, !tbaa !5
  %36 = sdiv i64 %34, %35
  %37 = load i64, ptr %4, align 8, !tbaa !5
  %38 = sdiv i64 %36, %37
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = sub nsw i64 %38, %39
  %41 = mul nsw i64 3, %40
  %42 = add nsw i64 1, %41
  %43 = load i64, ptr @ans, align 8, !tbaa !5
  %44 = add nsw i64 %43, %42
  store i64 %44, ptr @ans, align 8, !tbaa !5
  br label %57

45:                                               ; preds = %29
  %46 = load i64, ptr @n, align 8, !tbaa !5
  %47 = load i64, ptr %2, align 8, !tbaa !5
  %48 = sdiv i64 %46, %47
  %49 = load i64, ptr %4, align 8, !tbaa !5
  %50 = sdiv i64 %48, %49
  %51 = load i64, ptr %4, align 8, !tbaa !5
  %52 = sub nsw i64 %50, %51
  %53 = mul nsw i64 6, %52
  %54 = add nsw i64 3, %53
  %55 = load i64, ptr @ans, align 8, !tbaa !5
  %56 = add nsw i64 %55, %54
  store i64 %56, ptr @ans, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %45, %33
  br label %58

58:                                               ; preds = %57
  %59 = load i64, ptr %4, align 8, !tbaa !5
  %60 = add nsw i64 %59, 1
  store i64 %60, ptr %4, align 8, !tbaa !5
  br label %20, !llvm.loop !9

61:                                               ; preds = %28
  br label %62

62:                                               ; preds = %61
  %63 = load i64, ptr %2, align 8, !tbaa !5
  %64 = add nsw i64 %63, 1
  store i64 %64, ptr %2, align 8, !tbaa !5
  br label %9, !llvm.loop !11

65:                                               ; preds = %17
  %66 = load i32, ptr @Case, align 4, !tbaa !12
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr @Case, align 4, !tbaa !12
  %68 = load i64, ptr @ans, align 8, !tbaa !5
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %67, i64 noundef %68)
  br label %5, !llvm.loop !14

70:                                               ; preds = %5
  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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !10}


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

@Case = external dso_local local_unnamed_addr 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 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 @n)
  %2 = icmp eq i32 %1, 1
  br i1 %2, label %.lr.ph32, label %._crit_edge33

.lr.ph32:                                         ; preds = %0, %._crit_edge30
  store i64 0, ptr @ans, align 8, !tbaa !5
  %3 = load i64, ptr @n, align 8, !tbaa !5
  %.not27 = icmp slt i64 %3, 1
  br i1 %.not27, label %._crit_edge30, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph32, %11
  %.01729 = phi i64 [ %12, %11 ], [ 1, %.lr.ph32 ]
  %storemerge.lcssa2628 = phi i64 [ %20, %11 ], [ 0, %.lr.ph32 ]
  %4 = udiv i64 %3, %.01729
  br label %.lr.ph

._crit_edge30.loopexit:                           ; preds = %11
  store i64 %20, ptr @ans, align 8, !tbaa !5
  br label %._crit_edge30

._crit_edge30:                                    ; preds = %._crit_edge30.loopexit, %.lr.ph32
  %5 = phi i64 [ 0, %.lr.ph32 ], [ %20, %._crit_edge30.loopexit ]
  %6 = load i32, ptr @Case, align 4, !tbaa !9
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @Case, align 4, !tbaa !9
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %7, i64 noundef %5)
  %9 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %.lr.ph32, label %._crit_edge33, !llvm.loop !11

11:                                               ; preds = %.lr.ph
  %12 = add nuw nsw i64 %.01729, 1
  %13 = mul nuw nsw i64 %12, %12
  %14 = mul nuw nsw i64 %13, %12
  %.not = icmp sgt i64 %14, %3
  br i1 %.not, label %._crit_edge30.loopexit, label %.lr.ph.preheader, !llvm.loop !13

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.023 = phi i64 [ %21, %.lr.ph ], [ %.01729, %.lr.ph.preheader ]
  %storemerge2022 = phi i64 [ %20, %.lr.ph ], [ %storemerge.lcssa2628, %.lr.ph.preheader ]
  %15 = icmp eq i64 %.01729, %.023
  %. = select i1 %15, i64 3, i64 6
  %.40 = select i1 %15, i64 1, i64 3
  %16 = udiv i64 %4, %.023
  %17 = sub nsw i64 %16, %.023
  %18 = mul nsw i64 %17, %.
  %19 = add i64 %storemerge2022, %.40
  %20 = add i64 %19, %18
  %21 = add nuw nsw i64 %.023, 1
  %22 = mul nuw nsw i64 %21, %.01729
  %23 = mul nuw nsw i64 %22, %21
  %.not19 = icmp sgt i64 %23, %3
  br i1 %.not19, label %11, label %.lr.ph, !llvm.loop !14

._crit_edge33:                                    ; preds = %._crit_edge30, %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 = !{!"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}


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