; LLVM IR from tangjz/acm-icpc :: codeforces (521A)

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

@code = external dso_local global ptr, align 8
@n = external dso_local global i32, align 4
@cnt = external dso_local global [100002 x i32], align 16
@pos = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@str = external dso_local global [100002 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

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

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %38, %13
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp slt i32 %15, 4
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %14
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100002 x i8], ptr @str, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = load ptr, ptr @code, align 8, !tbaa !10
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %24, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = sext i8 %28 to i32
  %30 = icmp eq i32 %23, %29
  br i1 %30, label %31, label %37

31:                                               ; preds = %18
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [100002 x i32], ptr @cnt, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %34, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %31, %18
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %4, align 4, !tbaa !5
  br label %14, !llvm.loop !12

41:                                               ; preds = %17
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !14

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

46:                                               ; preds = %63, %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = icmp slt i32 %47, 4
  br i1 %48, label %50, label %49

49:                                               ; preds = %46
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %66

50:                                               ; preds = %46
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100002 x i32], ptr @cnt, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = load i32, ptr @pos, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100002 x i32], ptr @cnt, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = icmp sgt i32 %54, %58
  br i1 %59, label %60, label %62

60:                                               ; preds = %50
  %61 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %61, ptr @pos, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %60, %50
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %5, align 4, !tbaa !5
  br label %46, !llvm.loop !15

66:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %85, %66
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = icmp slt i32 %68, 4
  br i1 %69, label %71, label %70

70:                                               ; preds = %67
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %88

71:                                               ; preds = %67
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [100002 x i32], ptr @cnt, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = load i32, ptr @pos, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [100002 x i32], ptr @cnt, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = icmp eq i32 %75, %79
  br i1 %80, label %81, label %84

81:                                               ; preds = %71
  %82 = load i32, ptr @ans, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr @ans, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %81, %71
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %6, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %6, align 4, !tbaa !5
  br label %67, !llvm.loop !16

88:                                               ; preds = %70
  %89 = load i32, ptr @ans, align 4, !tbaa !5
  %90 = load i32, ptr @n, align 4, !tbaa !5
  %91 = call noundef i32 @_Z3powii(i32 noundef %89, i32 noundef %90)
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %91)
  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 = !{!"any pointer", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !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"

@code = external dso_local local_unnamed_addr global ptr, align 8
@n = external dso_local global i32, align 4
@cnt = external dso_local local_unnamed_addr global [100002 x i32], align 16
@pos = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@str = external dso_local global [100002 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3powii(i32 noundef, i32 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.1, ptr noundef nonnull @n, ptr noundef nonnull @str)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.preheader18.lr.ph, label %.preheader17

.preheader18.lr.ph:                               ; preds = %0
  %4 = load ptr, ptr @code, align 8, !tbaa !9
  %wide.trip.count = zext nneg i32 %2 to i64
  %5 = getelementptr inbounds i8, ptr %4, i64 1
  %6 = getelementptr inbounds i8, ptr %4, i64 2
  %7 = getelementptr inbounds i8, ptr %4, i64 3
  br label %.preheader18

.preheader18:                                     ; preds = %.preheader18.lr.ph, %38
  %indvars.iv = phi i64 [ 0, %.preheader18.lr.ph ], [ %indvars.iv.next, %38 ]
  %8 = getelementptr inbounds [100002 x i8], ptr @str, i64 0, i64 %indvars.iv
  %9 = load i8, ptr %8, align 1, !tbaa !11
  %10 = load i8, ptr %4, align 1, !tbaa !11
  %11 = icmp eq i8 %9, %10
  br i1 %11, label %17, label %20

.preheader17:                                     ; preds = %38, %0
  %pos.promoted = load i32, ptr @pos, align 4, !tbaa !5
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @cnt, i64 4), align 4, !tbaa !5
  %13 = sext i32 %pos.promoted to i64
  %14 = getelementptr inbounds [100002 x i32], ptr @cnt, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp sgt i32 %12, %15
  br i1 %16, label %39, label %40

17:                                               ; preds = %.preheader18
  %18 = load i32, ptr @cnt, align 16, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @cnt, align 16, !tbaa !5
  br label %20

20:                                               ; preds = %.preheader18, %17
  %21 = load i8, ptr %5, align 1, !tbaa !11
  %22 = icmp eq i8 %9, %21
  br i1 %22, label %23, label %26

23:                                               ; preds = %20
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @cnt, i64 4), align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr getelementptr inbounds (i8, ptr @cnt, i64 4), align 4, !tbaa !5
  br label %26

26:                                               ; preds = %23, %20
  %27 = load i8, ptr %6, align 1, !tbaa !11
  %28 = icmp eq i8 %9, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %26
  %30 = load i32, ptr getelementptr inbounds (i8, ptr @cnt, i64 8), align 8, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr getelementptr inbounds (i8, ptr @cnt, i64 8), align 8, !tbaa !5
  br label %32

32:                                               ; preds = %29, %26
  %33 = load i8, ptr %7, align 1, !tbaa !11
  %34 = icmp eq i8 %9, %33
  br i1 %34, label %35, label %38

35:                                               ; preds = %32
  %36 = load i32, ptr getelementptr inbounds (i8, ptr @cnt, i64 12), align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr getelementptr inbounds (i8, ptr @cnt, i64 12), align 4, !tbaa !5
  br label %38

38:                                               ; preds = %35, %32
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader17, label %.preheader18, !llvm.loop !12

39:                                               ; preds = %.preheader17
  store i32 1, ptr @pos, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %.preheader17, %39
  %41 = phi i32 [ %15, %.preheader17 ], [ %12, %39 ]
  %42 = load i32, ptr getelementptr inbounds (i8, ptr @cnt, i64 8), align 8, !tbaa !5
  %43 = icmp sgt i32 %42, %41
  br i1 %43, label %44, label %45

44:                                               ; preds = %40
  store i32 2, ptr @pos, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %44, %40
  %46 = phi i32 [ %41, %40 ], [ %42, %44 ]
  %47 = load i32, ptr getelementptr inbounds (i8, ptr @cnt, i64 12), align 4, !tbaa !5
  %48 = icmp sgt i32 %47, %46
  br i1 %48, label %49, label %.preheader

49:                                               ; preds = %45
  store i32 3, ptr @pos, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %49, %45
  %50 = phi i32 [ %47, %49 ], [ %46, %45 ]
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  %51 = load i32, ptr @cnt, align 16, !tbaa !5
  %52 = icmp eq i32 %51, %50
  %53 = zext i1 %52 to i32
  %54 = add nsw i32 %ans.promoted, %53
  %55 = icmp eq i32 %12, %50
  %56 = zext i1 %55 to i32
  %57 = add nsw i32 %54, %56
  %58 = or i1 %52, %55
  %59 = icmp eq i32 %42, %50
  %60 = zext i1 %59 to i32
  %spec.select = add nsw i32 %57, %60
  %61 = or i1 %58, %59
  %62 = icmp eq i32 %47, %50
  %63 = zext i1 %62 to i32
  %spec.select38 = add nsw i32 %spec.select, %63
  %64 = or i1 %61, %62
  br i1 %64, label %65, label %66

65:                                               ; preds = %.preheader
  store i32 %spec.select38, ptr @ans, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %.preheader, %65
  %67 = tail call noundef i32 @_Z3powii(i32 noundef %spec.select38, i32 noundef %2)
  %68 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %67)
  ret i32 0
}

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass