; LLVM IR from tangjz/acm-icpc :: hdu (6748)

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

@sz = external dso_local global [5 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z6getCntx(i64 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z6getSumx(i64 noundef) #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 i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %12

12:                                               ; preds = %75, %73, %0
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = add nsw i32 %13, -1
  store i32 %14, ptr %2, align 4, !tbaa !5
  %15 = icmp ne i32 %13, 0
  br i1 %15, label %16, label %76

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

17:                                               ; preds = %26, %16
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 5
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %29

21:                                               ; preds = %17
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr @sz, i64 %23
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %24)
  br label %26

26:                                               ; preds = %21
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %3, align 4, !tbaa !5
  br label %17, !llvm.loop !9

29:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %30 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4)
  %31 = load i64, ptr %4, align 8, !tbaa !11
  %32 = icmp sle i64 %31, 1
  br i1 %32, label %33, label %35

33:                                               ; preds = %29
  %34 = call i32 @puts(ptr noundef @.str.2)
  store i32 2, ptr %5, align 4
  br label %73, !llvm.loop !13

35:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %36 = load i32, ptr getelementptr inbounds ([5 x i32], ptr @sz, i64 0, i64 4), align 16, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = mul nsw i64 %37, 8
  store i64 %38, ptr %7, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %57, %35
  %40 = load i64, ptr %6, align 8, !tbaa !11
  %41 = load i64, ptr %7, align 8, !tbaa !11
  %42 = icmp slt i64 %40, %41
  br i1 %42, label %43, label %58

43:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %44 = load i64, ptr %6, align 8, !tbaa !11
  %45 = load i64, ptr %7, align 8, !tbaa !11
  %46 = add nsw i64 %44, %45
  %47 = ashr i64 %46, 1
  store i64 %47, ptr %8, align 8, !tbaa !11
  %48 = load i64, ptr %8, align 8, !tbaa !11
  %49 = call noundef i64 @_Z6getCntx(i64 noundef %48)
  %50 = load i64, ptr %4, align 8, !tbaa !11
  %51 = icmp slt i64 %49, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %43
  %53 = load i64, ptr %8, align 8, !tbaa !11
  %54 = add nsw i64 %53, 1
  store i64 %54, ptr %6, align 8, !tbaa !11
  br label %57

55:                                               ; preds = %43
  %56 = load i64, ptr %8, align 8, !tbaa !11
  store i64 %56, ptr %7, align 8, !tbaa !11
  br label %57

57:                                               ; preds = %55, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %39, !llvm.loop !14

58:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %59 = load i64, ptr %4, align 8, !tbaa !11
  %60 = load i64, ptr %6, align 8, !tbaa !11
  %61 = sub nsw i64 %60, 1
  %62 = call noundef i64 @_Z6getCntx(i64 noundef %61)
  %63 = sub nsw i64 %59, %62
  store i64 %63, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %64 = load i64, ptr %6, align 8, !tbaa !11
  %65 = sub nsw i64 %64, 1
  %66 = call noundef i64 @_Z6getSumx(i64 noundef %65)
  %67 = load i64, ptr %9, align 8, !tbaa !11
  %68 = load i64, ptr %6, align 8, !tbaa !11
  %69 = mul nsw i64 %67, %68
  %70 = add nsw i64 %66, %69
  store i64 %70, ptr %10, align 8, !tbaa !11
  %71 = load i64, ptr %10, align 8, !tbaa !11
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %71)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  store i32 0, ptr %5, align 4
  br label %73

73:                                               ; preds = %58, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %74 = load i32, ptr %5, align 4
  switch i32 %74, label %78 [
    i32 0, label %75
    i32 2, label %12
  ]

75:                                               ; preds = %73
  br label %12, !llvm.loop !13

76:                                               ; preds = %12
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %77 = load i32, ptr %1, align 4
  ret i32 %77

78:                                               ; preds = %73
  unreachable
}

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

declare i32 @puts(ptr noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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"

@sz = external dso_local global [5 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z6getCntx(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z6getSumx(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr %1, align 4, !tbaa !5
  %.not22 = icmp eq i32 %4, 0
  br i1 %.not22, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %0, %35
  store i32 -1, ptr @sz, align 16, !tbaa !5
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @sz, i64 4))
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @sz, i64 8))
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @sz, i64 12))
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @sz, i64 16))
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %11 = load i64, ptr %2, align 8, !tbaa !9
  %12 = icmp slt i64 %11, 2
  br i1 %12, label %13, label %15

13:                                               ; preds = %.lr.ph24
  %14 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %35, !llvm.loop !11

15:                                               ; preds = %.lr.ph24
  %16 = load i32, ptr getelementptr inbounds (i8, ptr @sz, i64 16), align 16, !tbaa !5
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %15
  %18 = zext nneg i32 %16 to i64
  %19 = shl nuw nsw i64 %18, 3
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.01621 = phi i64 [ %.1, %.lr.ph ], [ %19, %.lr.ph.preheader ]
  %.01720 = phi i64 [ %.118, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %20 = add nsw i64 %.01621, %.01720
  %21 = ashr i64 %20, 1
  %22 = call noundef i64 @_Z6getCntx(i64 noundef %21)
  %23 = load i64, ptr %2, align 8, !tbaa !9
  %24 = icmp slt i64 %22, %23
  %25 = add nsw i64 %21, 1
  %.118 = select i1 %24, i64 %25, i64 %.01720
  %.1 = select i1 %24, i64 %.01621, i64 %21
  %26 = icmp slt i64 %.118, %.1
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %15
  %27 = phi i64 [ %11, %15 ], [ %23, %.lr.ph ]
  %.017.lcssa = phi i64 [ 0, %15 ], [ %.118, %.lr.ph ]
  %28 = add nsw i64 %.017.lcssa, -1
  %29 = call noundef i64 @_Z6getCntx(i64 noundef %28)
  %30 = sub nsw i64 %27, %29
  %31 = call noundef i64 @_Z6getSumx(i64 noundef %28)
  %32 = mul nsw i64 %30, %.017.lcssa
  %33 = add nsw i64 %32, %31
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %33)
  br label %35

35:                                               ; preds = %._crit_edge, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %36 = load i32, ptr %1, align 4, !tbaa !5
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %36, 0
  br i1 %.not, label %._crit_edge25, label %.lr.ph24

._crit_edge25:                                    ; preds = %35, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #3

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #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 = !{!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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass