; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (806)

; 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
@cnt = external dso_local global i32, align 4
@str = external dso_local global [21 x i8], align 16
@r = external dso_local global [21 x i8], align 16
@c = external dso_local global [21 x i8], align 16
@u = external dso_local global [41 x i8], align 16
@d = external dso_local global [41 x i8], align 16
@ans = external dso_local global i8, align 1
@.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 [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 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
  store i32 0, ptr %1, align 4
  br label %5

5:                                                ; preds = %97, %0
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %8, label %113

8:                                                ; preds = %5
  store i8 1, ptr @ans, align 1, !tbaa !5
  store i32 0, ptr @cnt, align 4, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 16 @r, i8 0, i64 21, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @c, i8 0, i64 21, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @u, i8 0, i64 41, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @d, i8 0, i64 41, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %9

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

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

14:                                               ; preds = %9
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @str)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %90, %14
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = load i32, ptr @n, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %93

21:                                               ; preds = %16
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [21 x i8], ptr @str, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = sext i8 %25 to i32
  %27 = icmp eq i32 %26, 49
  br i1 %27, label %28, label %89

28:                                               ; preds = %21
  %29 = load i32, ptr @cnt, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @cnt, align 4, !tbaa !9
  %31 = load i32, ptr %2, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [21 x i8], ptr @r, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !5, !range !12, !noundef !13
  %35 = trunc i8 %34 to i1
  br i1 %35, label %36, label %37

36:                                               ; preds = %28
  store i8 0, ptr @ans, align 1, !tbaa !5
  br label %41

37:                                               ; preds = %28
  %38 = load i32, ptr %2, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [21 x i8], ptr @r, i64 0, i64 %39
  store i8 1, ptr %40, align 1, !tbaa !5
  br label %41

41:                                               ; preds = %37, %36
  %42 = phi ptr [ @ans, %36 ], [ %40, %37 ]
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [21 x i8], ptr @c, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !5, !range !12, !noundef !13
  %47 = trunc i8 %46 to i1
  br i1 %47, label %48, label %49

48:                                               ; preds = %41
  store i8 0, ptr @ans, align 1, !tbaa !5
  br label %53

49:                                               ; preds = %41
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [21 x i8], ptr @c, i64 0, i64 %51
  store i8 1, ptr %52, align 1, !tbaa !5
  br label %53

53:                                               ; preds = %49, %48
  %54 = phi ptr [ @ans, %48 ], [ %52, %49 ]
  %55 = load i32, ptr %2, align 4, !tbaa !9
  %56 = load i32, ptr %4, align 4, !tbaa !9
  %57 = add nsw i32 %55, %56
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [41 x i8], ptr @u, i64 0, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !5, !range !12, !noundef !13
  %61 = trunc i8 %60 to i1
  br i1 %61, label %62, label %63

62:                                               ; preds = %53
  store i8 0, ptr @ans, align 1, !tbaa !5
  br label %69

63:                                               ; preds = %53
  %64 = load i32, ptr %2, align 4, !tbaa !9
  %65 = load i32, ptr %4, align 4, !tbaa !9
  %66 = add nsw i32 %64, %65
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [41 x i8], ptr @u, i64 0, i64 %67
  store i8 1, ptr %68, align 1, !tbaa !5
  br label %69

69:                                               ; preds = %63, %62
  %70 = phi ptr [ @ans, %62 ], [ %68, %63 ]
  %71 = load i32, ptr %2, align 4, !tbaa !9
  %72 = load i32, ptr %4, align 4, !tbaa !9
  %73 = sub nsw i32 %71, %72
  %74 = add nsw i32 %73, 19
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [41 x i8], ptr @d, i64 0, i64 %75
  %77 = load i8, ptr %76, align 1, !tbaa !5, !range !12, !noundef !13
  %78 = trunc i8 %77 to i1
  br i1 %78, label %79, label %80

79:                                               ; preds = %69
  store i8 0, ptr @ans, align 1, !tbaa !5
  br label %87

80:                                               ; preds = %69
  %81 = load i32, ptr %2, align 4, !tbaa !9
  %82 = load i32, ptr %4, align 4, !tbaa !9
  %83 = sub nsw i32 %81, %82
  %84 = add nsw i32 %83, 19
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [41 x i8], ptr @d, i64 0, i64 %85
  store i8 1, ptr %86, align 1, !tbaa !5
  br label %87

87:                                               ; preds = %80, %79
  %88 = phi ptr [ @ans, %79 ], [ %86, %80 ]
  br label %89

89:                                               ; preds = %87, %21
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %4, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %4, align 4, !tbaa !9
  br label %16, !llvm.loop !14

93:                                               ; preds = %20
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %2, align 4, !tbaa !9
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %2, align 4, !tbaa !9
  br label %9, !llvm.loop !16

97:                                               ; preds = %13
  %98 = load i32, ptr @cnt, align 4, !tbaa !9
  %99 = load i32, ptr @n, align 4, !tbaa !9
  %100 = icmp eq i32 %98, %99
  %101 = zext i1 %100 to i32
  %102 = load i8, ptr @ans, align 1, !tbaa !5, !range !12, !noundef !13
  %103 = trunc i8 %102 to i1
  %104 = zext i1 %103 to i32
  %105 = and i32 %104, %101
  %106 = icmp ne i32 %105, 0
  %107 = zext i1 %106 to i8
  store i8 %107, ptr @ans, align 1, !tbaa !5
  %108 = load i8, ptr @ans, align 1, !tbaa !5, !range !12, !noundef !13
  %109 = trunc i8 %108 to i1
  %110 = zext i1 %109 to i64
  %111 = select i1 %109, ptr @.str.2, ptr @.str.3
  %112 = call i32 @puts(ptr noundef %111)
  br label %5, !llvm.loop !17

113:                                              ; preds = %5
  ret i32 0
}

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

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

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

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

declare i32 @puts(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 nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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}
!17 = distinct !{!17, !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"

@n = external dso_local global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@str = external dso_local global [21 x i8], align 16
@r = external dso_local local_unnamed_addr global [21 x i8], align 16
@c = external dso_local local_unnamed_addr global [21 x i8], align 16
@u = external dso_local local_unnamed_addr global [41 x i8], align 16
@d = external dso_local local_unnamed_addr global [41 x i8], align 16
@ans = external dso_local local_unnamed_addr global i8, align 1
@.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 [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 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 = icmp eq i32 %1, 1
  br i1 %2, label %.lr.ph25, label %._crit_edge26

.lr.ph25:                                         ; preds = %0, %._crit_edge23
  store i8 1, ptr @ans, align 1, !tbaa !5
  store i32 0, ptr @cnt, align 4, !tbaa !9
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(21) @r, i8 0, i64 21, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(21) @c, i8 0, i64 21, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(41) @u, i8 0, i64 41, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(41) @d, i8 0, i64 41, i1 false)
  %3 = load i32, ptr @n, align 4, !tbaa !9
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph22, label %._crit_edge23

._crit_edge23.loopexit:                           ; preds = %._crit_edge
  %.pre = load i32, ptr @cnt, align 4, !tbaa !9
  %.pre32 = load i8, ptr @ans, align 1, !tbaa !5, !range !11
  br label %._crit_edge23

._crit_edge23:                                    ; preds = %._crit_edge23.loopexit, %.lr.ph25
  %5 = phi i8 [ 1, %.lr.ph25 ], [ %.pre32, %._crit_edge23.loopexit ]
  %6 = phi i32 [ 0, %.lr.ph25 ], [ %.pre, %._crit_edge23.loopexit ]
  %.lcssa = phi i32 [ %3, %.lr.ph25 ], [ %16, %._crit_edge23.loopexit ]
  %7 = icmp eq i32 %6, %.lcssa
  %8 = icmp ne i8 %5, 0
  %9 = and i1 %7, %8
  %10 = zext i1 %9 to i8
  store i8 %10, ptr @ans, align 1, !tbaa !5
  %11 = select i1 %9, ptr @.str.2, ptr @.str.3
  %12 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %11)
  %13 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %.lr.ph25, label %._crit_edge26, !llvm.loop !12

.lr.ph22:                                         ; preds = %.lr.ph25, %._crit_edge
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %._crit_edge ], [ 0, %.lr.ph25 ]
  %15 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @str)
  %16 = load i32, ptr @n, align 4, !tbaa !9
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph22
  %cnt.promoted = load i32, ptr @cnt, align 4, !tbaa !9
  %18 = getelementptr inbounds [21 x i8], ptr @r, i64 0, i64 %indvars.iv29
  %wide.trip.count = zext nneg i32 %16 to i64
  %19 = add nuw i64 %indvars.iv29, 19
  br label %22

._crit_edge:                                      ; preds = %54, %.lr.ph22
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %20 = sext i32 %16 to i64
  %21 = icmp slt i64 %indvars.iv.next30, %20
  br i1 %21, label %.lr.ph22, label %._crit_edge23.loopexit, !llvm.loop !14

22:                                               ; preds = %.lr.ph, %54
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %54 ]
  %23 = phi i32 [ %cnt.promoted, %.lr.ph ], [ %55, %54 ]
  %24 = getelementptr inbounds [21 x i8], ptr @str, i64 0, i64 %indvars.iv
  %25 = load i8, ptr %24, align 1, !tbaa !15
  %26 = icmp eq i8 %25, 49
  br i1 %26, label %27, label %54

27:                                               ; preds = %22
  %28 = add nsw i32 %23, 1
  store i32 %28, ptr @cnt, align 4, !tbaa !9
  %29 = load i8, ptr %18, align 1, !tbaa !5, !range !11, !noundef !16
  %30 = trunc nuw i8 %29 to i1
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  store i8 0, ptr @ans, align 1, !tbaa !5
  br label %33

32:                                               ; preds = %27
  store i8 1, ptr %18, align 1, !tbaa !5
  br label %33

33:                                               ; preds = %32, %31
  %34 = getelementptr inbounds [21 x i8], ptr @c, i64 0, i64 %indvars.iv
  %35 = load i8, ptr %34, align 1, !tbaa !5, !range !11, !noundef !16
  %36 = trunc nuw i8 %35 to i1
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  store i8 0, ptr @ans, align 1, !tbaa !5
  br label %39

38:                                               ; preds = %33
  store i8 1, ptr %34, align 1, !tbaa !5
  br label %39

39:                                               ; preds = %38, %37
  %40 = add nuw nsw i64 %indvars.iv, %indvars.iv29
  %41 = getelementptr inbounds [41 x i8], ptr @u, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !5, !range !11, !noundef !16
  %43 = trunc nuw i8 %42 to i1
  br i1 %43, label %44, label %45

44:                                               ; preds = %39
  store i8 0, ptr @ans, align 1, !tbaa !5
  br label %46

45:                                               ; preds = %39
  store i8 1, ptr %41, align 1, !tbaa !5
  br label %46

46:                                               ; preds = %45, %44
  %47 = sub i64 %19, %indvars.iv
  %sext = shl i64 %47, 32
  %48 = ashr exact i64 %sext, 32
  %49 = getelementptr inbounds [41 x i8], ptr @d, i64 0, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !5, !range !11, !noundef !16
  %51 = trunc nuw i8 %50 to i1
  br i1 %51, label %52, label %53

52:                                               ; preds = %46
  store i8 0, ptr @ans, align 1, !tbaa !5
  br label %54

53:                                               ; preds = %46
  store i8 1, ptr %49, align 1, !tbaa !5
  br label %54

54:                                               ; preds = %22, %53, %52
  %55 = phi i32 [ %23, %22 ], [ %28, %53 ], [ %28, %52 ]
  %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 %._crit_edge, label %22, !llvm.loop !17

._crit_edge26:                                    ; preds = %._crit_edge23, %0
  ret i32 0
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(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" }
attributes #2 = { mustprogress 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!7, !7, i64 0}
!16 = !{}
!17 = distinct !{!17, !13}


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