; LLVM IR from tangjz/acm-icpc :: lydsy (1442)

; 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
@a = external dso_local global [51 x i32], align 16
@f = external dso_local global [3 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 [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 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
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [2 x i64], align 16
  store i32 0, ptr %1, align 4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %21, %0
  %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 %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %24

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

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

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

25:                                               ; preds = %121, %24
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = icmp sge i32 %26, 0
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 5, ptr %4, align 4
  br label %124

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = shl i32 1, %30
  %32 = sub i32 %31, 1
  store i32 %32, ptr %6, align 4, !tbaa !5
  store i64 1, ptr @f, align 16, !tbaa !11
  store i64 0, ptr getelementptr inbounds ([3 x i64], ptr @f, i64 0, i64 2), align 16, !tbaa !11
  store i64 0, ptr getelementptr inbounds ([3 x i64], ptr @f, i64 0, i64 1), align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %100, %29
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %103

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [51 x i32], ptr @a, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = and i32 %42, %43
  %45 = add i32 %44, 1
  store i32 %45, ptr %8, align 4, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [51 x i32], ptr @a, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = lshr i32 %49, %50
  %52 = and i32 %51, 1
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %86

54:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #3
  %55 = load i64, ptr @f, align 16, !tbaa !11
  %56 = load i64, ptr getelementptr inbounds ([3 x i64], ptr @f, i64 0, i64 2), align 16, !tbaa !11
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = zext i32 %57 to i64
  %59 = shl i64 %56, %58
  %60 = add i64 %55, %59
  store i64 %60, ptr %9, align 8, !tbaa !11
  %61 = getelementptr inbounds i64, ptr %9, i64 1
  %62 = load i64, ptr getelementptr inbounds ([3 x i64], ptr @f, i64 0, i64 1), align 8, !tbaa !11
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = zext i32 %63 to i64
  %65 = shl i64 %62, %64
  store i64 %65, ptr %61, align 8, !tbaa !11
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = xor i32 %66, 1
  store i32 %67, ptr %5, align 4, !tbaa !5
  %68 = load i32, ptr %8, align 4, !tbaa !5
  %69 = zext i32 %68 to i64
  %70 = load i64, ptr @f, align 16, !tbaa !11
  %71 = mul i64 %70, %69
  store i64 %71, ptr @f, align 16, !tbaa !11
  %72 = load i64, ptr getelementptr inbounds ([3 x i64], ptr @f, i64 0, i64 1), align 8, !tbaa !11
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = zext i32 %73 to i64
  %75 = mul i64 %72, %74
  %76 = getelementptr inbounds [2 x i64], ptr %9, i64 0, i64 0
  %77 = load i64, ptr %76, align 16, !tbaa !11
  %78 = add i64 %75, %77
  store i64 %78, ptr getelementptr inbounds ([3 x i64], ptr @f, i64 0, i64 1), align 8, !tbaa !11
  %79 = load i64, ptr getelementptr inbounds ([3 x i64], ptr @f, i64 0, i64 2), align 16, !tbaa !11
  %80 = load i32, ptr %8, align 4, !tbaa !5
  %81 = zext i32 %80 to i64
  %82 = mul i64 %79, %81
  %83 = getelementptr inbounds [2 x i64], ptr %9, i64 0, i64 1
  %84 = load i64, ptr %83, align 8, !tbaa !11
  %85 = add i64 %82, %84
  store i64 %85, ptr getelementptr inbounds ([3 x i64], ptr @f, i64 0, i64 2), align 16, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #3
  br label %99

86:                                               ; preds = %38
  %87 = load i32, ptr %8, align 4, !tbaa !5
  %88 = zext i32 %87 to i64
  %89 = load i64, ptr @f, align 16, !tbaa !11
  %90 = mul i64 %89, %88
  store i64 %90, ptr @f, align 16, !tbaa !11
  %91 = load i32, ptr %8, align 4, !tbaa !5
  %92 = zext i32 %91 to i64
  %93 = load i64, ptr getelementptr inbounds ([3 x i64], ptr @f, i64 0, i64 1), align 8, !tbaa !11
  %94 = mul i64 %93, %92
  store i64 %94, ptr getelementptr inbounds ([3 x i64], ptr @f, i64 0, i64 1), align 8, !tbaa !11
  %95 = load i32, ptr %8, align 4, !tbaa !5
  %96 = zext i32 %95 to i64
  %97 = load i64, ptr getelementptr inbounds ([3 x i64], ptr @f, i64 0, i64 2), align 16, !tbaa !11
  %98 = mul i64 %97, %96
  store i64 %98, ptr getelementptr inbounds ([3 x i64], ptr @f, i64 0, i64 2), align 16, !tbaa !11
  br label %99

99:                                               ; preds = %86, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %7, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %7, align 4, !tbaa !5
  br label %33, !llvm.loop !13

103:                                              ; preds = %37
  %104 = load i32, ptr %5, align 4, !tbaa !5
  %105 = xor i32 %104, 1
  %106 = add nsw i32 1, %105
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [3 x i64], ptr @f, i64 0, i64 %107
  %109 = load i64, ptr %108, align 8, !tbaa !11
  %110 = load i64, ptr @ans, align 8, !tbaa !11
  %111 = add i64 %110, %109
  store i64 %111, ptr @ans, align 8, !tbaa !11
  %112 = load i32, ptr %5, align 4, !tbaa !5
  %113 = icmp ne i32 %112, 0
  br i1 %113, label %114, label %117

114:                                              ; preds = %103
  %115 = load i64, ptr @ans, align 8, !tbaa !11
  %116 = add i64 %115, -1
  store i64 %116, ptr @ans, align 8, !tbaa !11
  store i32 5, ptr %4, align 4
  br label %118

117:                                              ; preds = %103
  store i32 0, ptr %4, align 4
  br label %118

118:                                              ; preds = %117, %114
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %119 = load i32, ptr %4, align 4
  switch i32 %119, label %124 [
    i32 0, label %120
  ]

120:                                              ; preds = %118
  br label %121

121:                                              ; preds = %120
  %122 = load i32, ptr %3, align 4, !tbaa !5
  %123 = add nsw i32 %122, -1
  store i32 %123, ptr %3, align 4, !tbaa !5
  br label %25, !llvm.loop !14

124:                                              ; preds = %118, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %125

125:                                              ; preds = %124
  %126 = load i64, ptr @ans, align 8, !tbaa !11
  %127 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %126)
  ret i32 0
}

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

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

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

declare i32 @printf(ptr noundef, ...) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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"

@n = external dso_local global i32, align 4
@a = external dso_local global [51 x i32], align 16
@f = external dso_local local_unnamed_addr global [3 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 [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind 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 @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.preheader.thread

.preheader.thread:                                ; preds = %0
  %ans.promoted62 = load i64, ptr @ans, align 8, !tbaa !9
  br label %.critedge.preheader

.preheader:                                       ; preds = %.lr.ph
  %4 = icmp sgt i32 %42, 0
  %ans.promoted = load i64, ptr @ans, align 8, !tbaa !9
  br i1 %4, label %.lr.ph36.us.preheader, label %.critedge.preheader

.critedge.preheader:                              ; preds = %.preheader.thread, %.preheader
  %ans.promoted63 = phi i64 [ %ans.promoted62, %.preheader.thread ], [ %ans.promoted, %.preheader ]
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) getelementptr inbounds (i8, ptr @f, i64 8), i8 0, i64 16, i1 false)
  br label %.loopexit

.lr.ph36.us.preheader:                            ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %42 to i64
  br label %.lr.ph36.us

.lr.ph36.us:                                      ; preds = %.lr.ph36.us.preheader, %9
  %indvars.iv58 = phi i64 [ 31, %.lr.ph36.us.preheader ], [ %indvars.iv.next59, %9 ]
  %5 = phi i64 [ %ans.promoted, %.lr.ph36.us.preheader ], [ %39, %9 ]
  %6 = trunc nuw nsw i64 %indvars.iv58 to i32
  %notmask.us = shl nsw i32 -1, %6
  %7 = xor i32 %notmask.us, -1
  %8 = shl nuw i32 1, %6
  br label %10

9:                                                ; preds = %._crit_edge.us
  %indvars.iv.next59 = add nsw i64 %indvars.iv58, -1
  %.not = icmp eq i64 %indvars.iv58, 0
  br i1 %.not, label %.loopexit, label %.lr.ph36.us, !llvm.loop !11

10:                                               ; preds = %.lr.ph36.us, %32
  %indvars.iv55 = phi i64 [ 0, %.lr.ph36.us ], [ %indvars.iv.next56, %32 ]
  %.02734.us = phi i32 [ 0, %.lr.ph36.us ], [ %.1.us, %32 ]
  %11 = phi i64 [ 1, %.lr.ph36.us ], [ %33, %32 ]
  %storemerge3133.us = phi i64 [ 0, %.lr.ph36.us ], [ %storemerge.us, %32 ]
  %12 = phi i64 [ 0, %.lr.ph36.us ], [ %.sink, %32 ]
  %13 = getelementptr inbounds [51 x i32], ptr @a, i64 0, i64 %indvars.iv55
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = and i32 %14, %7
  %16 = add nuw i32 %15, 1
  %17 = and i32 %14, %8
  %.not28.us = icmp eq i32 %17, 0
  br i1 %.not28.us, label %28, label %18

18:                                               ; preds = %10
  %19 = shl i64 %storemerge3133.us, %indvars.iv58
  %20 = add i64 %19, %11
  %21 = shl i64 %12, %indvars.iv58
  %22 = xor i32 %.02734.us, 1
  %23 = zext i32 %16 to i64
  %24 = mul i64 %12, %23
  %25 = add i64 %20, %24
  %26 = mul i64 %storemerge3133.us, %23
  %27 = add i64 %21, %26
  br label %32

28:                                               ; preds = %10
  %29 = zext i32 %16 to i64
  %30 = mul i64 %12, %29
  %31 = mul i64 %storemerge3133.us, %29
  br label %32

32:                                               ; preds = %28, %18
  %.sink = phi i64 [ %30, %28 ], [ %25, %18 ]
  %.pn = phi i64 [ %29, %28 ], [ %23, %18 ]
  %storemerge.us = phi i64 [ %31, %28 ], [ %27, %18 ]
  %.1.us = phi i32 [ %.02734.us, %28 ], [ %22, %18 ]
  %33 = mul i64 %11, %.pn
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next56, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %10, !llvm.loop !13

._crit_edge.us:                                   ; preds = %32
  store i64 %.sink, ptr getelementptr inbounds (i8, ptr @f, i64 8), align 8
  store i64 %storemerge.us, ptr getelementptr inbounds (i8, ptr @f, i64 16), align 16, !tbaa !9
  %34 = xor i32 %.1.us, 1
  %35 = add nuw nsw i32 %34, 1
  %36 = zext nneg i32 %35 to i64
  %37 = getelementptr inbounds [3 x i64], ptr @f, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = add i64 %5, %38
  %.not.us = icmp eq i32 %.1.us, 0
  br i1 %.not.us, label %9, label %.split.us

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %40 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %41 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %40)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %42 = load i32, ptr @n, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = icmp slt i64 %indvars.iv.next, %43
  br i1 %44, label %.lr.ph, label %.preheader, !llvm.loop !14

.split.us:                                        ; preds = %._crit_edge.us
  store i64 %33, ptr @f, align 16, !tbaa !9
  %45 = add i64 %39, -1
  br label %46

.loopexit:                                        ; preds = %9, %.critedge.preheader
  %.us-phi = phi i64 [ %ans.promoted63, %.critedge.preheader ], [ %39, %9 ]
  %.us-phi46 = phi i64 [ 1, %.critedge.preheader ], [ %33, %9 ]
  store i64 %.us-phi46, ptr @f, align 16, !tbaa !9
  br label %46

46:                                               ; preds = %.loopexit, %.split.us
  %storemerge = phi i64 [ %45, %.split.us ], [ %.us-phi, %.loopexit ]
  store i64 %storemerge, ptr @ans, align 8, !tbaa !9
  %47 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %storemerge)
  ret i32 0
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { mustprogress nofree norecurse 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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass