; LLVM IR from tangjz/acm-icpc :: self_training/2015-02-01 (E)

; 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
@k = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@a = external dso_local global [12 x i64], align 16
@L = external dso_local global i64, align 8
@R = external dso_local global i64, align 8
@M = external dso_local global i64, align 8
@ret = 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 [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsii(i32 noundef, i32 noundef) #0

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

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

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

4:                                                ; preds = %42, %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 %45

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

10:                                               ; preds = %20, %8
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @k, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i64, ptr @a, i64 %17
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %18)
  br label %20

20:                                               ; preds = %15
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !9

23:                                               ; preds = %14
  store i64 1, ptr @L, align 8, !tbaa !11
  store i64 1000000000000000, ptr @R, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %41, %23
  %25 = load i64, ptr @L, align 8, !tbaa !11
  %26 = load i64, ptr @R, align 8, !tbaa !11
  %27 = icmp slt i64 %25, %26
  br i1 %27, label %28, label %42

28:                                               ; preds = %24
  %29 = load i64, ptr @L, align 8, !tbaa !11
  %30 = load i64, ptr @R, align 8, !tbaa !11
  %31 = add nsw i64 %29, %30
  %32 = ashr i64 %31, 1
  store i64 %32, ptr @M, align 8, !tbaa !11
  store i64 0, ptr @ret, align 8, !tbaa !11
  call void @_Z3dfsii(i32 noundef 0, i32 noundef 0)
  %33 = load i64, ptr @ret, align 8, !tbaa !11
  %34 = load i64, ptr @n, align 8, !tbaa !11
  %35 = icmp slt i64 %33, %34
  br i1 %35, label %36, label %39

36:                                               ; preds = %28
  %37 = load i64, ptr @M, align 8, !tbaa !11
  %38 = add nsw i64 %37, 1
  store i64 %38, ptr @L, align 8, !tbaa !11
  br label %41

39:                                               ; preds = %28
  %40 = load i64, ptr @M, align 8, !tbaa !11
  store i64 %40, ptr @R, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %39, %36
  br label %24, !llvm.loop !13

42:                                               ; preds = %24
  %43 = load i64, ptr @L, align 8, !tbaa !11
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %43)
  br label %4, !llvm.loop !14

45:                                               ; preds = %4
  ret i32 0
}

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

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

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

@t = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@a = external dso_local global [12 x i64], align 16
@L = external dso_local local_unnamed_addr global i64, align 8
@R = external dso_local local_unnamed_addr global i64, align 8
@M = external dso_local local_unnamed_addr global i64, align 8
@ret = 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 [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse 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 @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
  %.not9 = icmp eq i32 %2, 0
  br i1 %.not9, label %._crit_edge12, label %.lr.ph11

.lr.ph11:                                         ; preds = %0, %._crit_edge8
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @k, ptr noundef nonnull @n)
  %5 = load i32, ptr @k, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %.lr.ph7.preheader

.lr.ph7.preheader:                                ; preds = %.lr.ph, %.lr.ph11
  store i64 1, ptr @L, align 8, !tbaa !9
  store i64 1000000000000000, ptr @R, align 8, !tbaa !9
  br label %.lr.ph7

.lr.ph:                                           ; preds = %.lr.ph11, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph11 ]
  %7 = getelementptr inbounds i64, ptr @a, i64 %indvars.iv
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %7)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = load i32, ptr @k, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = icmp slt i64 %indvars.iv.next, %10
  br i1 %11, label %.lr.ph, label %.lr.ph7.preheader, !llvm.loop !11

.lr.ph7:                                          ; preds = %.lr.ph7.preheader, %23
  %12 = phi i64 [ %24, %23 ], [ 1000000000000000, %.lr.ph7.preheader ]
  %13 = phi i64 [ %25, %23 ], [ 1, %.lr.ph7.preheader ]
  %14 = add nsw i64 %12, %13
  %15 = ashr i64 %14, 1
  store i64 %15, ptr @M, align 8, !tbaa !9
  store i64 0, ptr @ret, align 8, !tbaa !9
  tail call void @_Z3dfsii(i32 noundef 0, i32 noundef 0)
  %16 = load i64, ptr @ret, align 8, !tbaa !9
  %17 = load i64, ptr @n, align 8, !tbaa !9
  %18 = icmp slt i64 %16, %17
  %19 = load i64, ptr @M, align 8, !tbaa !9
  br i1 %18, label %20, label %22

20:                                               ; preds = %.lr.ph7
  %21 = add nsw i64 %19, 1
  store i64 %21, ptr @L, align 8, !tbaa !9
  %.pre15 = load i64, ptr @R, align 8, !tbaa !9
  br label %23

22:                                               ; preds = %.lr.ph7
  store i64 %19, ptr @R, align 8, !tbaa !9
  %.pre = load i64, ptr @L, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %22, %20
  %24 = phi i64 [ %19, %22 ], [ %.pre15, %20 ]
  %25 = phi i64 [ %.pre, %22 ], [ %21, %20 ]
  %26 = icmp slt i64 %25, %24
  br i1 %26, label %.lr.ph7, label %._crit_edge8, !llvm.loop !13

._crit_edge8:                                     ; preds = %23
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %25)
  %28 = load i32, ptr @t, align 4, !tbaa !5
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %28, 0
  br i1 %.not, label %._crit_edge12, label %.lr.ph11, !llvm.loop !14

._crit_edge12:                                    ; preds = %._crit_edge8, %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

attributes #0 = { 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 #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 = { 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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass