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

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

%"struct.std::greater" = type { i8 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [131072 x i32], align 16
@b = external dso_local global [131072 x i32], align 16
@k = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3cntx(i64 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
  %3 = alloca i32, align 4
  %4 = alloca %"struct.std::greater", align 1
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  br label %8

8:                                                ; preds = %64, %0
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @k)
  %10 = icmp eq i32 %9, 3
  br i1 %10, label %11, label %67

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

12:                                               ; preds = %22, %11
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %25

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

22:                                               ; preds = %17
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !9

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

26:                                               ; preds = %36, %25
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr @m, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %39

31:                                               ; preds = %26
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr @b, i64 %33
  %35 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %34)
  br label %36

36:                                               ; preds = %31
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %3, align 4, !tbaa !5
  br label %26, !llvm.loop !11

39:                                               ; preds = %30
  %40 = load i32, ptr @m, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr @b, i64 %41
  %43 = getelementptr inbounds i32, ptr %42, i64 1
  call void @_ZSt4sortIPiSt7greaterIiEEvT_S3_T0_(ptr noundef getelementptr inbounds (i32, ptr @b, i64 1), ptr noundef %43)
  store i32 131072, ptr @b, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 1, ptr %5, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 10000000000, ptr %6, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  br label %44

44:                                               ; preds = %63, %39
  %45 = load i64, ptr %5, align 8, !tbaa !12
  %46 = load i64, ptr %6, align 8, !tbaa !12
  %47 = icmp slt i64 %45, %46
  br i1 %47, label %48, label %64

48:                                               ; preds = %44
  %49 = load i64, ptr %5, align 8, !tbaa !12
  %50 = load i64, ptr %6, align 8, !tbaa !12
  %51 = add nsw i64 %49, %50
  %52 = add nsw i64 %51, 1
  %53 = ashr i64 %52, 1
  store i64 %53, ptr %7, align 8, !tbaa !12
  %54 = load i64, ptr %7, align 8, !tbaa !12
  %55 = call noundef i64 @_Z3cntx(i64 noundef %54)
  %56 = load i64, ptr @k, align 8, !tbaa !12
  %57 = icmp slt i64 %55, %56
  br i1 %57, label %58, label %61

58:                                               ; preds = %48
  %59 = load i64, ptr %7, align 8, !tbaa !12
  %60 = sub nsw i64 %59, 1
  store i64 %60, ptr %6, align 8, !tbaa !12
  br label %63

61:                                               ; preds = %48
  %62 = load i64, ptr %7, align 8, !tbaa !12
  store i64 %62, ptr %5, align 8, !tbaa !12
  br label %63

63:                                               ; preds = %61, %58
  br label %44, !llvm.loop !14

64:                                               ; preds = %44
  %65 = load i64, ptr %5, align 8, !tbaa !12
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %65)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %8, !llvm.loop !15

67:                                               ; preds = %8
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiSt7greaterIiEEvT_S3_T0_(ptr noundef, ptr noundef) #4

declare i32 @printf(ptr noundef, ...) #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 = { 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 = { 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 = !{!"int", !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 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !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"

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [131072 x i32], align 16
@b = external dso_local global [131072 x i32], align 16
@k = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3cntx(i64 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 @n, ptr noundef nonnull @m, ptr noundef nonnull @k)
  %2 = icmp eq i32 %1, 3
  br i1 %2, label %.preheader20, label %._crit_edge28

.preheader20:                                     ; preds = %0, %22
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %.not21 = icmp slt i32 %3, 1
  br i1 %.not21, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %.preheader20
  %4 = load i32, ptr @m, align 4, !tbaa !5
  %.not1923 = icmp slt i32 %4, 1
  br i1 %.not1923, label %.preheader.._crit_edge_crit_edge, label %.lr.ph25

.preheader.._crit_edge_crit_edge:                 ; preds = %.preheader
  %.pre = sext i32 %4 to i64
  br label %._crit_edge

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

._crit_edge:                                      ; preds = %.lr.ph25, %.preheader.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.preheader.._crit_edge_crit_edge ], [ %12, %.lr.ph25 ]
  %gep = getelementptr i32, ptr getelementptr inbounds (i8, ptr @b, i64 4), i64 %.pre-phi
  tail call void @_ZSt4sortIPiSt7greaterIiEEvT_S3_T0_(ptr noundef nonnull getelementptr inbounds (i8, ptr @b, i64 4), ptr noundef nonnull %gep)
  store i32 131072, ptr @b, align 16, !tbaa !5
  br label %13

.lr.ph25:                                         ; preds = %.preheader, %.lr.ph25
  %indvars.iv31 = phi i64 [ %indvars.iv.next32, %.lr.ph25 ], [ 1, %.preheader ]
  %9 = getelementptr inbounds i32, ptr @b, i64 %indvars.iv31
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %9)
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %11 = load i32, ptr @m, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %.not19.not = icmp slt i64 %indvars.iv31, %12
  br i1 %.not19.not, label %.lr.ph25, label %._crit_edge, !llvm.loop !11

13:                                               ; preds = %._crit_edge, %13
  %.01427 = phi i64 [ 10000000000, %._crit_edge ], [ %.1, %13 ]
  %.01526 = phi i64 [ 1, %._crit_edge ], [ %.116, %13 ]
  %14 = add nsw i64 %.01526, 1
  %15 = add i64 %14, %.01427
  %16 = ashr i64 %15, 1
  %17 = tail call noundef i64 @_Z3cntx(i64 noundef %16)
  %18 = load i64, ptr @k, align 8, !tbaa !12
  %19 = icmp slt i64 %17, %18
  %20 = add nsw i64 %16, -1
  %.116 = select i1 %19, i64 %.01526, i64 %16
  %.1 = select i1 %19, i64 %20, i64 %.01427
  %21 = icmp slt i64 %.116, %.1
  br i1 %21, label %13, label %22, !llvm.loop !14

22:                                               ; preds = %13
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.116)
  %24 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @k)
  %25 = icmp eq i32 %24, 3
  br i1 %25, label %.preheader20, label %._crit_edge28, !llvm.loop !15

._crit_edge28:                                    ; preds = %22, %0
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiSt7greaterIiEEvT_S3_T0_(ptr noundef, ptr noundef) local_unnamed_addr #3

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

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 = { 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 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 = !{!"int", !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 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


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