; LLVM IR from tangjz/acm-icpc :: self_training/2015-02-09 (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"

@n = external dso_local global i32, align 4
@k = 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 [7 x i8], align 1

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

4:                                                ; preds = %64, %0
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @k)
  %6 = icmp eq i32 %5, 2
  br i1 %6, label %7, label %67

7:                                                ; preds = %4
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = load i32, ptr @k, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = mul nsw i64 %9, %11
  store i64 %12, ptr @ans, align 8, !tbaa !9
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = load i32, ptr @k, align 4, !tbaa !5
  %15 = icmp sgt i32 %13, %14
  br i1 %15, label %16, label %18

16:                                               ; preds = %7
  %17 = load i32, ptr @k, align 4, !tbaa !5
  store i32 %17, ptr @n, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %16, %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  br label %19

19:                                               ; preds = %61, %18
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = icmp sle i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %64

24:                                               ; preds = %19
  %25 = load i32, ptr @k, align 4, !tbaa !5
  %26 = load i32, ptr @k, align 4, !tbaa !5
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sdiv i32 %26, %27
  %29 = sdiv i32 %25, %28
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %32, label %38

32:                                               ; preds = %24
  %33 = load i32, ptr @k, align 4, !tbaa !5
  %34 = load i32, ptr @k, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sdiv i32 %34, %35
  %37 = sdiv i32 %33, %36
  br label %40

38:                                               ; preds = %24
  %39 = load i32, ptr @n, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %38, %32
  %41 = phi i32 [ %37, %32 ], [ %39, %38 ]
  store i32 %41, ptr %3, align 4, !tbaa !5
  %42 = load i32, ptr @k, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = sdiv i64 %43, %45
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = add nsw i32 %47, %48
  %50 = sext i32 %49 to i64
  %51 = mul nsw i64 %46, %50
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = sub nsw i32 %52, %53
  %55 = add nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = mul nsw i64 %51, %56
  %58 = ashr i64 %57, 1
  %59 = load i64, ptr @ans, align 8, !tbaa !9
  %60 = sub nsw i64 %59, %58
  store i64 %60, ptr @ans, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %40
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %2, align 4, !tbaa !5
  br label %19, !llvm.loop !11

64:                                               ; preds = %23
  %65 = load i64, ptr @ans, align 8, !tbaa !9
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %65)
  br label %4, !llvm.loop !13

67:                                               ; 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}


; 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
@k = external dso_local 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 [7 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, ptr noundef nonnull @k)
  %2 = icmp eq i32 %1, 2
  br i1 %2, label %.lr.ph16, label %._crit_edge17

.lr.ph16:                                         ; preds = %0, %12
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = load i32, ptr @k, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = mul nsw i64 %6, %4
  store i64 %7, ptr @ans, align 8, !tbaa !9
  %8 = icmp sgt i32 %3, %5
  br i1 %8, label %9, label %10

9:                                                ; preds = %.lr.ph16
  store i32 %5, ptr @n, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %9, %.lr.ph16
  %11 = phi i32 [ %5, %9 ], [ %3, %.lr.ph16 ]
  %.not13 = icmp slt i32 %11, 1
  br i1 %.not13, label %12, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  store i64 %29, ptr @ans, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %._crit_edge, %10
  %13 = phi i64 [ %29, %._crit_edge ], [ %7, %10 ]
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %13)
  %15 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %16 = icmp eq i32 %15, 2
  br i1 %16, label %.lr.ph16, label %._crit_edge17, !llvm.loop !11

.lr.ph:                                           ; preds = %10, %.lr.ph
  %.014 = phi i32 [ %30, %.lr.ph ], [ 1, %10 ]
  %17 = phi i64 [ %29, %.lr.ph ], [ %7, %10 ]
  %18 = sdiv i32 %5, %.014
  %19 = sdiv i32 %5, %18
  %. = tail call i32 @llvm.smin.i32(i32 %19, i32 %11)
  %20 = sext i32 %.014 to i64
  %21 = sdiv i64 %6, %20
  %22 = add nsw i32 %., %.014
  %23 = sext i32 %22 to i64
  %24 = mul nsw i64 %21, %23
  %reass.sub = sub i32 %., %.014
  %25 = add i32 %reass.sub, 1
  %26 = sext i32 %25 to i64
  %27 = mul nsw i64 %24, %26
  %28 = ashr i64 %27, 1
  %29 = sub nsw i64 %17, %28
  %30 = add nsw i32 %., 1
  %.not.not = icmp slt i32 %19, %11
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge17:                                    ; preds = %12, %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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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}


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