; LLVM IR from tangjz/acm-icpc :: leetcode/extra (meituan_006-小团的神秘暗号)

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

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

10:                                               ; preds = %31, %0
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %27

14:                                               ; preds = %10
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100001 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = sext i8 %18 to i32
  %20 = icmp ne i32 %19, 84
  br i1 %20, label %25, label %21

21:                                               ; preds = %14
  %22 = load i8, ptr %5, align 1, !tbaa !9, !range !12, !noundef !13
  %23 = trunc i8 %22 to i1
  %24 = xor i1 %23, true
  br label %25

25:                                               ; preds = %21, %14
  %26 = phi i1 [ true, %14 ], [ %24, %21 ]
  br label %27

27:                                               ; preds = %25, %10
  %28 = phi i1 [ false, %10 ], [ %26, %25 ]
  br i1 %28, label %30, label %29

29:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  br label %46

30:                                               ; preds = %27
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %32 to i64
  %35 = getelementptr inbounds [100001 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 77
  %39 = zext i1 %38 to i32
  %40 = load i8, ptr %5, align 1, !tbaa !9, !range !12, !noundef !13
  %41 = trunc i8 %40 to i1
  %42 = zext i1 %41 to i32
  %43 = or i32 %42, %39
  %44 = icmp ne i32 %43, 0
  %45 = zext i1 %44 to i8
  store i8 %45, ptr %5, align 1, !tbaa !9
  br label %10, !llvm.loop !14

46:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  store i8 0, ptr %6, align 1, !tbaa !9
  br label %47

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

51:                                               ; preds = %47
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100001 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !11
  %56 = sext i8 %55 to i32
  %57 = icmp ne i32 %56, 77
  br i1 %57, label %62, label %58

58:                                               ; preds = %51
  %59 = load i8, ptr %6, align 1, !tbaa !9, !range !12, !noundef !13
  %60 = trunc i8 %59 to i1
  %61 = xor i1 %60, true
  br label %62

62:                                               ; preds = %58, %51
  %63 = phi i1 [ true, %51 ], [ %61, %58 ]
  br label %64

64:                                               ; preds = %62, %47
  %65 = phi i1 [ false, %47 ], [ %63, %62 ]
  br i1 %65, label %67, label %66

66:                                               ; preds = %64
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  br label %83

67:                                               ; preds = %64
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = add nsw i32 %69, -1
  store i32 %70, ptr %4, align 4, !tbaa !5
  %71 = sext i32 %69 to i64
  %72 = getelementptr inbounds [100001 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !11
  %74 = sext i8 %73 to i32
  %75 = icmp eq i32 %74, 84
  %76 = zext i1 %75 to i32
  %77 = load i8, ptr %6, align 1, !tbaa !9, !range !12, !noundef !13
  %78 = trunc i8 %77 to i1
  %79 = zext i1 %78 to i32
  %80 = or i32 %79, %76
  %81 = icmp ne i32 %80, 0
  %82 = zext i1 %81 to i8
  store i8 %82, ptr %6, align 1, !tbaa !9
  br label %47, !llvm.loop !16

83:                                               ; preds = %66
  %84 = load i32, ptr %3, align 4, !tbaa !5
  %85 = add nsw i32 %84, 1
  %86 = load i32, ptr %4, align 4, !tbaa !5
  %87 = icmp slt i32 %85, %86
  br i1 %87, label %88, label %97

88:                                               ; preds = %83
  %89 = load i32, ptr %4, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [100001 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %90
  store i8 0, ptr %91, align 1, !tbaa !11
  %92 = load i32, ptr %3, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds i8, ptr @_ZZ4mainE3buf, i64 %93
  %95 = getelementptr inbounds i8, ptr %94, i64 1
  %96 = call i32 @puts(ptr noundef %95)
  br label %97

97:                                               ; preds = %88, %83
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare i32 @puts(ptr noundef) #2

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


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

@_ZZ4mainE3buf = external hidden global [100001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull @_ZZ4mainE3buf)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %12
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %12 ]
  %.01723 = phi i1 [ false, %.lr.ph.preheader ], [ %14, %12 ]
  %5 = getelementptr inbounds [100001 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %indvars.iv
  %6 = load i8, ptr %5, align 1, !tbaa !9
  %7 = icmp eq i8 %6, 84
  %.not20 = select i1 %7, i1 %.01723, i1 false
  br i1 %.not20, label %.critedge.loopexit, label %12

.critedge.loopexit:                               ; preds = %.lr.ph
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %0
  %.019.lcssa = phi i32 [ 0, %0 ], [ %8, %.critedge.loopexit ]
  %.01826 = add nsw i32 %3, -1
  %9 = icmp slt i32 %.019.lcssa, %.01826
  br i1 %9, label %.lr.ph29.preheader, label %.critedge2

.lr.ph29.preheader:                               ; preds = %.critedge
  %10 = sext i32 %.01826 to i64
  %11 = sext i32 %.019.lcssa to i64
  br label %.lr.ph29

12:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = icmp eq i8 %6, 77
  %14 = or i1 %.01723, %13
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge.thread, label %.lr.ph, !llvm.loop !10

.critedge.thread:                                 ; preds = %12
  %.0182636 = add nsw i32 %3, -1
  br label %.critedge2

.lr.ph29:                                         ; preds = %.lr.ph29.preheader, %21
  %indvars.iv33 = phi i64 [ %10, %.lr.ph29.preheader ], [ %indvars.iv.next34, %21 ]
  %.027 = phi i1 [ false, %.lr.ph29.preheader ], [ %23, %21 ]
  %15 = getelementptr inbounds [100001 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %indvars.iv33
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = icmp eq i8 %16, 77
  %.not21 = select i1 %17, i1 %.027, i1 false
  br i1 %.not21, label %.critedge2.loopexit.split.loop.exit39, label %21

.critedge2.loopexit.split.loop.exit39:            ; preds = %.lr.ph29
  %18 = trunc nsw i64 %indvars.iv33 to i32
  br label %.critedge2

.critedge2:                                       ; preds = %21, %.critedge2.loopexit.split.loop.exit39, %.critedge.thread, %.critedge
  %.019.lcssa37 = phi i32 [ %.019.lcssa, %.critedge ], [ %3, %.critedge.thread ], [ %.019.lcssa, %.critedge2.loopexit.split.loop.exit39 ], [ %.019.lcssa, %21 ]
  %.018.lcssa = phi i32 [ %.01826, %.critedge ], [ %.0182636, %.critedge.thread ], [ %18, %.critedge2.loopexit.split.loop.exit39 ], [ %.019.lcssa, %21 ]
  %19 = add nuw nsw i32 %.019.lcssa37, 1
  %20 = icmp slt i32 %19, %.018.lcssa
  br i1 %20, label %25, label %32

21:                                               ; preds = %.lr.ph29
  %22 = icmp eq i8 %16, 84
  %23 = or i1 %.027, %22
  %indvars.iv.next34 = add nsw i64 %indvars.iv33, -1
  %24 = icmp sgt i64 %indvars.iv.next34, %11
  br i1 %24, label %.lr.ph29, label %.critedge2, !llvm.loop !12

25:                                               ; preds = %.critedge2
  %26 = sext i32 %.018.lcssa to i64
  %27 = getelementptr inbounds [100001 x i8], ptr @_ZZ4mainE3buf, i64 0, i64 %26
  store i8 0, ptr %27, align 1, !tbaa !9
  %28 = zext nneg i32 %.019.lcssa37 to i64
  %29 = getelementptr inbounds i8, ptr @_ZZ4mainE3buf, i64 %28
  %30 = getelementptr inbounds i8, ptr %29, i64 1
  %31 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %30)
  br label %32

32:                                               ; preds = %25, %.critedge2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 0
}

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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