; LLVM IR from tangjz/acm-icpc :: codeforces (725B)

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

@ord = external dso_local global ptr, align 8
@n = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@ch = external dso_local global i8, align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 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
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @ch)
  %5 = load i64, ptr @n, align 8, !tbaa !5
  %6 = sub nsw i64 %5, 1
  %7 = load i64, ptr @n, align 8, !tbaa !5
  %8 = sub nsw i64 %7, 1
  %9 = and i64 %8, 3
  %10 = icmp sle i64 %9, 1
  %11 = zext i1 %10 to i64
  %12 = select i1 %10, i32 0, i32 2
  %13 = sext i32 %12 to i64
  %14 = sub nsw i64 %6, %13
  store i64 %14, ptr @ans, align 8, !tbaa !5
  %15 = load i64, ptr @n, align 8, !tbaa !5
  %16 = sub nsw i64 %15, 1
  %17 = ashr i64 %16, 2
  %18 = mul nsw i64 %17, 12
  %19 = load i64, ptr @ans, align 8, !tbaa !5
  %20 = add nsw i64 %19, %18
  store i64 %20, ptr @ans, align 8, !tbaa !5
  %21 = load i64, ptr @n, align 8, !tbaa !5
  %22 = sub nsw i64 %21, 1
  %23 = and i64 %22, 3
  %24 = and i64 %23, 1
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %0
  %27 = load i64, ptr @ans, align 8, !tbaa !5
  %28 = add nsw i64 %27, 6
  store i64 %28, ptr @ans, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %26, %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %52, %29
  %31 = load ptr, ptr @ord, align 8, !tbaa !11
  %32 = load i32, ptr %2, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !13
  %36 = icmp ne i8 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %30
  store i32 2, ptr %3, align 4
  br label %55

38:                                               ; preds = %30
  %39 = load i64, ptr @ans, align 8, !tbaa !5
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr @ans, align 8, !tbaa !5
  %41 = load ptr, ptr @ord, align 8, !tbaa !11
  %42 = load i32, ptr %2, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !13
  %46 = sext i8 %45 to i32
  %47 = load i8, ptr @ch, align 1, !tbaa !13
  %48 = sext i8 %47 to i32
  %49 = icmp eq i32 %46, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %38
  store i32 2, ptr %3, align 4
  br label %55

51:                                               ; preds = %38
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %2, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %2, align 4, !tbaa !9
  br label %30, !llvm.loop !14

55:                                               ; preds = %50, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %56

56:                                               ; preds = %55
  %57 = load i64, ptr @ans, align 8, !tbaa !5
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %57)
  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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

@ord = external dso_local local_unnamed_addr global ptr, align 8
@n = external dso_local global i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@ch = external dso_local global i8, align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 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.1, ptr noundef nonnull @n, ptr noundef nonnull @ch)
  %2 = load i64, ptr @n, align 8, !tbaa !5
  %3 = add nsw i64 %2, -1
  %4 = and i64 %3, -3
  %5 = ashr i64 %3, 2
  %6 = mul nsw i64 %5, 12
  %7 = add nsw i64 %6, %4
  %8 = and i64 %2, 1
  %.not.not = icmp eq i64 %8, 0
  %9 = add nsw i64 %7, 6
  %spec.select = select i1 %.not.not, i64 %9, i64 %7
  store i64 %spec.select, ptr @ans, align 8, !tbaa !5
  %10 = load ptr, ptr @ord, align 8, !tbaa !9
  %11 = load i8, ptr %10, align 1, !tbaa !11
  %.not3 = icmp eq i8 %11, 0
  br i1 %.not3, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %12 = load i8, ptr @ch, align 1, !tbaa !11
  br label %16

13:                                               ; preds = %16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = getelementptr inbounds i8, ptr %10, i64 %indvars.iv.next
  %15 = load i8, ptr %14, align 1, !tbaa !11
  %.not = icmp eq i8 %15, 0
  br i1 %.not, label %._crit_edge, label %16, !llvm.loop !12

16:                                               ; preds = %.lr.ph, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %13 ]
  %17 = phi i64 [ %spec.select, %.lr.ph ], [ %19, %13 ]
  %18 = getelementptr inbounds i8, ptr %10, i64 %indvars.iv
  %19 = add nsw i64 %17, 1
  store i64 %19, ptr @ans, align 8, !tbaa !5
  %20 = load i8, ptr %18, align 1, !tbaa !11
  %21 = icmp eq i8 %20, %12
  br i1 %21, label %._crit_edge, label %13

._crit_edge:                                      ; preds = %13, %16, %0
  %22 = phi i64 [ %spec.select, %0 ], [ %19, %16 ], [ %19, %13 ]
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %22)
  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

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

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


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