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

; 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
@now = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@str = external dso_local global [300002 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6insertx(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 nounwind uwtable
declare dso_local noundef i32 @_Z4findx(i64 noundef) #0

; 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
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @str)
  call void @_Z6insertx(i64 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %66, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %69

11:                                               ; preds = %6
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [300002 x i8], ptr @str, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = icmp sle i32 %16, 90
  br i1 %17, label %18, label %29

18:                                               ; preds = %11
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [300002 x i8], ptr @str, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = sub nsw i32 %23, 65
  %25 = zext i32 %24 to i64
  %26 = shl i64 1, %25
  %27 = load i64, ptr @now, align 8, !tbaa !10
  %28 = xor i64 %27, %26
  store i64 %28, ptr @now, align 8, !tbaa !10
  br label %41

29:                                               ; preds = %11
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [300002 x i8], ptr @str, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !9
  %34 = sext i8 %33 to i32
  %35 = sub nsw i32 %34, 97
  %36 = add nsw i32 %35, 26
  %37 = zext i32 %36 to i64
  %38 = shl i64 1, %37
  %39 = load i64, ptr @now, align 8, !tbaa !10
  %40 = xor i64 %39, %38
  store i64 %40, ptr @now, align 8, !tbaa !10
  br label %41

41:                                               ; preds = %29, %18
  %42 = load i64, ptr @now, align 8, !tbaa !10
  %43 = call noundef i32 @_Z4findx(i64 noundef %42)
  %44 = sext i32 %43 to i64
  %45 = load i64, ptr @ans, align 8, !tbaa !10
  %46 = add nsw i64 %45, %44
  store i64 %46, ptr @ans, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %61, %41
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = icmp slt i32 %48, 52
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %64

51:                                               ; preds = %47
  %52 = load i64, ptr @now, align 8, !tbaa !10
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = zext i32 %53 to i64
  %55 = shl i64 1, %54
  %56 = xor i64 %52, %55
  %57 = call noundef i32 @_Z4findx(i64 noundef %56)
  %58 = sext i32 %57 to i64
  %59 = load i64, ptr @ans, align 8, !tbaa !10
  %60 = add nsw i64 %59, %58
  store i64 %60, ptr @ans, align 8, !tbaa !10
  br label %61

61:                                               ; preds = %51
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %4, align 4, !tbaa !5
  br label %47, !llvm.loop !12

64:                                               ; preds = %50
  %65 = load i64, ptr @now, align 8, !tbaa !10
  call void @_Z6insertx(i64 noundef %65)
  br label %66

66:                                               ; preds = %64
  %67 = load i32, ptr %2, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !14

69:                                               ; preds = %10
  %70 = load i64, ptr @ans, align 8, !tbaa !10
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %70)
  ret i32 0
}

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

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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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
@now = external dso_local local_unnamed_addr global i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@str = external dso_local global [300002 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6insertx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4findx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind 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 @str)
  tail call void @_Z6insertx(i64 noundef 0)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %19, %0
  %4 = load i64, ptr @ans, align 8, !tbaa !9
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %4)
  ret i32 0

.lr.ph:                                           ; preds = %0, %19
  %indvars.iv13 = phi i64 [ %indvars.iv.next14, %19 ], [ 0, %0 ]
  %6 = getelementptr inbounds [300002 x i8], ptr @str, i64 0, i64 %indvars.iv13
  %7 = load i8, ptr %6, align 1, !tbaa !11
  %8 = sext i8 %7 to i64
  %9 = icmp slt i8 %7, 91
  %10 = load i64, ptr @now, align 8, !tbaa !9
  %. = select i1 %9, i64 4294967231, i64 4294967225
  %11 = add nsw i64 %., %8
  %12 = and i64 %11, 4294967295
  %13 = shl nuw i64 1, %12
  %14 = xor i64 %10, %13
  store i64 %14, ptr @now, align 8, !tbaa !9
  %15 = tail call noundef i32 @_Z4findx(i64 noundef %14)
  %16 = sext i32 %15 to i64
  %17 = load i64, ptr @ans, align 8, !tbaa !9
  %18 = add nsw i64 %17, %16
  store i64 %18, ptr @ans, align 8, !tbaa !9
  br label %24

19:                                               ; preds = %24
  %20 = load i64, ptr @now, align 8, !tbaa !9
  tail call void @_Z6insertx(i64 noundef %20)
  %indvars.iv.next14 = add nuw nsw i64 %indvars.iv13, 1
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next14, %22
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !12

24:                                               ; preds = %.lr.ph, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %24 ]
  %25 = load i64, ptr @now, align 8, !tbaa !9
  %26 = shl nuw nsw i64 1, %indvars.iv
  %27 = xor i64 %25, %26
  %28 = tail call noundef i32 @_Z4findx(i64 noundef %27)
  %29 = sext i32 %28 to i64
  %30 = load i64, ptr @ans, align 8, !tbaa !9
  %31 = add nsw i64 %30, %29
  store i64 %31, ptr @ans, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 52
  br i1 %exitcond.not, label %19, label %24, !llvm.loop !14
}

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

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

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass