; LLVM IR from tangjz/acm-icpc :: 51nod (1150)

; 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
@Log10 = external dso_local global [61 x i32], align 16
@a = external dso_local global [50001 x i64], align 16
@pw10 = external dso_local global [20 x i64], align 16
@ans = 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 [5 x i8], align 1
@.str.2 = 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 void @_Z7solve_1iii(i32 noundef, i32 noundef, i32 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 i32, align 4
  store i32 0, ptr %1, align 4
  store i64 1, ptr @pw10, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %19, %0
  %6 = load i32, ptr %2, align 4, !tbaa !9
  %7 = icmp slt i32 %6, 20
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %5
  %10 = load i32, ptr %2, align 4, !tbaa !9
  %11 = sub nsw i32 %10, 1
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [20 x i64], ptr @pw10, i64 0, i64 %12
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = mul nsw i64 %14, 10
  %16 = load i32, ptr %2, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [20 x i64], ptr @pw10, i64 0, i64 %17
  store i64 %15, ptr %18, align 8, !tbaa !5
  br label %19

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

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

23:                                               ; preds = %78, %22
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 61
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %23
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = sub nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %34
  store i32 %32, ptr %35, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %49, %27
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [20 x i64], ptr @pw10, i64 0, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = shl i64 1, %45
  %47 = icmp slt i64 %43, %46
  br i1 %47, label %48, label %55

48:                                               ; preds = %36
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %3, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %52, align 4, !tbaa !9
  br label %36, !llvm.loop !13

55:                                               ; preds = %36
  %56 = load i32, ptr %3, align 4, !tbaa !9
  %57 = sub nsw i32 %56, 1
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = load i32, ptr %3, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = icmp slt i32 %60, %64
  br i1 %65, label %66, label %77

66:                                               ; preds = %55
  %67 = load i32, ptr %3, align 4, !tbaa !9
  %68 = sub nsw i32 %67, 1
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = sub nsw i32 0, %71
  %73 = load i32, ptr %3, align 4, !tbaa !9
  %74 = sub nsw i32 %73, 1
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %75
  store i32 %72, ptr %76, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %66, %55
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %3, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %3, align 4, !tbaa !9
  br label %23, !llvm.loop !14

81:                                               ; preds = %26
  %82 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %83

83:                                               ; preds = %93, %81
  %84 = load i32, ptr %4, align 4, !tbaa !9
  %85 = load i32, ptr @n, align 4, !tbaa !9
  %86 = icmp slt i32 %84, %85
  br i1 %86, label %88, label %87

87:                                               ; preds = %83
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %96

88:                                               ; preds = %83
  %89 = load i32, ptr %4, align 4, !tbaa !9
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i64, ptr @a, i64 %90
  %92 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %91)
  br label %93

93:                                               ; preds = %88
  %94 = load i32, ptr %4, align 4, !tbaa !9
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %4, align 4, !tbaa !9
  br label %83, !llvm.loop !15

96:                                               ; preds = %87
  %97 = load i32, ptr @n, align 4, !tbaa !9
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds i64, ptr @a, i64 %98
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef @a, ptr noundef %99)
  %100 = load i32, ptr @n, align 4, !tbaa !9
  %101 = sub nsw i32 %100, 1
  call void @_Z7solve_1iii(i32 noundef 60, i32 noundef 0, i32 noundef %101)
  %102 = load i64, ptr @ans, align 8, !tbaa !5
  %103 = shl i64 %102, 1
  %104 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %103)
  ret i32 0
}

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

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

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 = { 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 = !{!"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}
!15 = distinct !{!15, !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
@Log10 = external dso_local local_unnamed_addr global [61 x i32], align 16
@a = external dso_local global [50001 x i64], align 16
@pw10 = external dso_local local_unnamed_addr global [20 x i64], align 16
@ans = 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
.preheader.preheader:
  store i64 1, ptr @pw10, align 16, !tbaa !5
  store i64 10, ptr getelementptr inbounds (i8, ptr @pw10, i64 8), align 8, !tbaa !5
  store i64 100, ptr getelementptr inbounds (i8, ptr @pw10, i64 16), align 16, !tbaa !5
  store i64 1000, ptr getelementptr inbounds (i8, ptr @pw10, i64 24), align 8, !tbaa !5
  store i64 10000, ptr getelementptr inbounds (i8, ptr @pw10, i64 32), align 16, !tbaa !5
  store i64 100000, ptr getelementptr inbounds (i8, ptr @pw10, i64 40), align 8, !tbaa !5
  store i64 1000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 48), align 16, !tbaa !5
  store i64 10000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 56), align 8, !tbaa !5
  store i64 100000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 64), align 16, !tbaa !5
  store i64 1000000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 72), align 8, !tbaa !5
  store i64 10000000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 80), align 16, !tbaa !5
  store i64 100000000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 88), align 8, !tbaa !5
  store i64 1000000000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 96), align 16, !tbaa !5
  store i64 10000000000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 104), align 8, !tbaa !5
  store i64 100000000000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 112), align 16, !tbaa !5
  store i64 1000000000000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 120), align 8, !tbaa !5
  store i64 10000000000000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 128), align 16, !tbaa !5
  store i64 100000000000000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 136), align 8, !tbaa !5
  store i64 1000000000000000000, ptr getelementptr inbounds (i8, ptr @pw10, i64 144), align 16, !tbaa !5
  store i64 -8446744073709551616, ptr getelementptr inbounds (i8, ptr @pw10, i64 152), align 8, !tbaa !5
  %.pre = load i32, ptr @Log10, align 16, !tbaa !9
  br label %.preheader

0:                                                ; preds = %19
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !9
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre35 = sext i32 %2 to i64
  br label %._crit_edge

.preheader:                                       ; preds = %.preheader.preheader, %19
  %4 = phi i32 [ %.pre, %.preheader.preheader ], [ %15, %19 ]
  %indvars.iv29 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next30, %19 ]
  %5 = add nsw i64 %indvars.iv29, -1
  %6 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %5
  %7 = shl nuw i64 1, %indvars.iv29
  %8 = sext i32 %4 to i64
  br label %9

9:                                                ; preds = %9, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next, %9 ], [ %8, %.preheader ]
  %10 = getelementptr inbounds [20 x i64], ptr @pw10, i64 0, i64 %indvars.iv
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = icmp slt i64 %11, %7
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  br i1 %12, label %9, label %13, !llvm.loop !11

13:                                               ; preds = %9
  %14 = getelementptr inbounds [61 x i32], ptr @Log10, i64 0, i64 %indvars.iv29
  %15 = trunc nsw i64 %indvars.iv to i32
  store i32 %15, ptr %14, align 4, !tbaa !9
  %16 = icmp slt i32 %4, %15
  br i1 %16, label %17, label %19

17:                                               ; preds = %13
  %18 = sub nsw i32 0, %4
  store i32 %18, ptr %6, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %13, %17
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next30, 61
  br i1 %exitcond.not, label %0, label %.preheader, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre35, %.._crit_edge_crit_edge ], [ %29, %.lr.ph ]
  %20 = getelementptr inbounds i64, ptr @a, i64 %.pre-phi
  tail call void @_ZSt4sortIPxEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %20)
  %21 = load i32, ptr @n, align 4, !tbaa !9
  %22 = add nsw i32 %21, -1
  tail call void @_Z7solve_1iii(i32 noundef 60, i32 noundef 0, i32 noundef %22)
  %23 = load i64, ptr @ans, align 8, !tbaa !5
  %24 = shl i64 %23, 1
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %24)
  ret i32 0

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %.lr.ph ], [ 0, %0 ]
  %26 = getelementptr inbounds i64, ptr @a, i64 %indvars.iv32
  %27 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %26)
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %28 = load i32, ptr @n, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = icmp slt i64 %indvars.iv.next33, %29
  br i1 %30, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

; 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 @_ZSt4sortIPxEvT_S1_(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 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 = !{!"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,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass