; LLVM IR from tangjz/acm-icpc :: codechef/OCT13 (ARRGAME2)

; 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
@n = external dso_local global i32, align 4
@a = external dso_local global [100001 x i32], align 16
@b = external dso_local global [100001 x i32], 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 [8 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %5

5:                                                ; preds = %117, %0
  %6 = load i32, ptr @t, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @t, align 4, !tbaa !5
  %8 = icmp ne i32 %6, 0
  br i1 %8, label %9, label %124

9:                                                ; preds = %5
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %40, %9
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %15, label %43

15:                                               ; preds = %11
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %17
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %18)
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %25, label %29

25:                                               ; preds = %15
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %27
  store i32 1000000001, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %25, %15
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 2
  br i1 %34, label %35, label %39

35:                                               ; preds = %29
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %37
  store i32 4, ptr %38, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %35, %29
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !9

43:                                               ; preds = %11
  %44 = load i32, ptr @n, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr @a, i64 %45
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @a, ptr noundef %46)
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %76, %43
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = load i32, ptr @n, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %79

51:                                               ; preds = %47
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100001 x i32], ptr @b, i64 0, i64 %53
  %55 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %54)
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [100001 x i32], ptr @b, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = icmp eq i32 %59, 1
  br i1 %60, label %61, label %65

61:                                               ; preds = %51
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [100001 x i32], ptr @b, i64 0, i64 %63
  store i32 1000000001, ptr %64, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %61, %51
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100001 x i32], ptr @b, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = icmp eq i32 %69, 2
  br i1 %70, label %71, label %75

71:                                               ; preds = %65
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [100001 x i32], ptr @b, i64 0, i64 %73
  store i32 4, ptr %74, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %71, %65
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %2, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %2, align 4, !tbaa !5
  br label %47, !llvm.loop !11

79:                                               ; preds = %47
  %80 = load i32, ptr @n, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i32, ptr @b, i64 %81
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @b, ptr noundef %82)
  store i32 0, ptr %3, align 4, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !5
  store i64 0, ptr @ans, align 8, !tbaa !12
  br label %83

83:                                               ; preds = %114, %79
  %84 = load i32, ptr %2, align 4, !tbaa !5
  %85 = load i32, ptr @n, align 4, !tbaa !5
  %86 = icmp slt i32 %84, %85
  br i1 %86, label %87, label %117

87:                                               ; preds = %83
  br label %88

88:                                               ; preds = %104, %87
  %89 = load i32, ptr %2, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = load i32, ptr %3, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [100001 x i32], ptr @b, i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !5
  %97 = icmp sge i32 %92, %96
  br i1 %97, label %98, label %102

98:                                               ; preds = %88
  %99 = load i32, ptr %3, align 4, !tbaa !5
  %100 = load i32, ptr @n, align 4, !tbaa !5
  %101 = icmp slt i32 %99, %100
  br label %102

102:                                              ; preds = %98, %88
  %103 = phi i1 [ false, %88 ], [ %101, %98 ]
  br i1 %103, label %104, label %107

104:                                              ; preds = %102
  %105 = load i32, ptr %3, align 4, !tbaa !5
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %3, align 4, !tbaa !5
  br label %88, !llvm.loop !14

107:                                              ; preds = %102
  %108 = load i32, ptr @n, align 4, !tbaa !5
  %109 = load i32, ptr %3, align 4, !tbaa !5
  %110 = sub nsw i32 %108, %109
  %111 = sext i32 %110 to i64
  %112 = load i64, ptr @ans, align 8, !tbaa !12
  %113 = add nsw i64 %112, %111
  store i64 %113, ptr @ans, align 8, !tbaa !12
  br label %114

114:                                              ; preds = %107
  %115 = load i32, ptr %2, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %2, align 4, !tbaa !5
  br label %83, !llvm.loop !15

117:                                              ; preds = %83
  %118 = load i64, ptr @ans, align 8, !tbaa !12
  %119 = sitofp i64 %118 to double
  %120 = load i32, ptr @n, align 4, !tbaa !5
  %121 = sitofp i32 %120 to double
  %122 = fdiv double %119, %121
  %123 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %122)
  br label %5, !llvm.loop !16

124:                                              ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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" }
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 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !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
@n = external dso_local global i32, align 4
@a = external dso_local global [100001 x i32], align 16
@b = external dso_local global [100001 x i32], 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 [8 x i8], align 1

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

.lr.ph42:                                         ; preds = %0, %45
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %.lr.ph42.._crit_edge_crit_edge

.lr.ph42.._crit_edge_crit_edge:                   ; preds = %.lr.ph42
  %.pre = sext i32 %5 to i64
  br label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph42, %11
  %indvars.iv = phi i64 [ %indvars.iv.next, %11 ], [ 0, %.lr.ph42 ]
  %7 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %7)
  %9 = load i32, ptr %7, align 4, !tbaa !5
  switch i32 %9, label %11 [
    i32 1, label %.sink.split
    i32 2, label %10
  ]

10:                                               ; preds = %.lr.ph
  br label %.sink.split

.sink.split:                                      ; preds = %.lr.ph, %10
  %.sink = phi i32 [ 4, %10 ], [ 1000000001, %.lr.ph ]
  store i32 %.sink, ptr %7, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %.sink.split, %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = icmp slt i64 %indvars.iv.next, %13
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %11, %.lr.ph42.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.lr.ph42.._crit_edge_crit_edge ], [ %13, %11 ]
  %15 = getelementptr inbounds i32, ptr @a, i64 %.pre-phi
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %15)
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph32, label %._crit_edge.._crit_edge33_crit_edge

._crit_edge.._crit_edge33_crit_edge:              ; preds = %._crit_edge
  %.pre57 = sext i32 %16 to i64
  br label %._crit_edge33

.lr.ph32:                                         ; preds = %._crit_edge, %22
  %indvars.iv48 = phi i64 [ %indvars.iv.next49, %22 ], [ 0, %._crit_edge ]
  %18 = getelementptr inbounds [100001 x i32], ptr @b, i64 0, i64 %indvars.iv48
  %19 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %18)
  %20 = load i32, ptr %18, align 4, !tbaa !5
  switch i32 %20, label %22 [
    i32 1, label %.sink.split61
    i32 2, label %21
  ]

21:                                               ; preds = %.lr.ph32
  br label %.sink.split61

.sink.split61:                                    ; preds = %.lr.ph32, %21
  %.sink62 = phi i32 [ 4, %21 ], [ 1000000001, %.lr.ph32 ]
  store i32 %.sink62, ptr %18, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %.sink.split61, %.lr.ph32
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %indvars.iv.next49, %24
  br i1 %25, label %.lr.ph32, label %._crit_edge33, !llvm.loop !11

._crit_edge33:                                    ; preds = %22, %._crit_edge.._crit_edge33_crit_edge
  %.pre-phi58 = phi i64 [ %.pre57, %._crit_edge.._crit_edge33_crit_edge ], [ %24, %22 ]
  %26 = getelementptr inbounds i32, ptr @b, i64 %.pre-phi58
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @b, ptr noundef nonnull %26)
  store i64 0, ptr @ans, align 8, !tbaa !12
  %27 = load i32, ptr @n, align 4
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.preheader.preheader, label %45

.preheader.preheader:                             ; preds = %._crit_edge33
  %29 = zext nneg i32 %27 to i64
  %wide.trip.count = zext nneg i32 %27 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %40
  %indvars.iv54 = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next55, %40 ]
  %.036 = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv51, %40 ]
  %30 = phi i64 [ 0, %.preheader.preheader ], [ %44, %40 ]
  %31 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv54
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %sext = shl i64 %.036, 32
  %33 = ashr exact i64 %sext, 32
  br label %34

34:                                               ; preds = %34, %.preheader
  %indvars.iv51 = phi i64 [ %indvars.iv.next52, %34 ], [ %33, %.preheader ]
  %35 = getelementptr inbounds [100001 x i32], ptr @b, i64 0, i64 %indvars.iv51
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp sge i32 %32, %36
  %38 = icmp slt i64 %indvars.iv51, %29
  %39 = and i1 %38, %37
  %indvars.iv.next52 = add nsw i64 %indvars.iv51, 1
  br i1 %39, label %34, label %40, !llvm.loop !14

40:                                               ; preds = %34
  %41 = trunc nsw i64 %indvars.iv51 to i32
  %42 = sub nsw i32 %27, %41
  %43 = sext i32 %42 to i64
  %44 = add nsw i64 %30, %43
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next55, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge37, label %.preheader, !llvm.loop !15

._crit_edge37:                                    ; preds = %40
  store i64 %44, ptr @ans, align 8, !tbaa !12
  br label %45

45:                                               ; preds = %._crit_edge37, %._crit_edge33
  %46 = phi i64 [ %44, %._crit_edge37 ], [ 0, %._crit_edge33 ]
  %47 = sitofp i64 %46 to double
  %48 = sitofp i32 %27 to double
  %49 = fdiv double %47, %48
  %50 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %49)
  %51 = load i32, ptr @t, align 4, !tbaa !5
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %51, 0
  br i1 %.not, label %._crit_edge43, label %.lr.ph42, !llvm.loop !16

._crit_edge43:                                    ; preds = %45, %0
  ret i32 0
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 = { 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}
!16 = distinct !{!16, !10}


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