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

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

@t = external dso_local global i32, align 4
@top = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@ch = external dso_local global i8, align 1
@str = external dso_local global [101 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.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 void @_Z6inserti(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z4findi(i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %3

3:                                                ; preds = %76, %0
  %4 = load i32, ptr @t, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @t, align 4, !tbaa !5
  %6 = icmp ne i32 %4, 0
  br i1 %6, label %7, label %77

7:                                                ; preds = %3
  store i32 0, ptr @tot, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %13, %7
  %9 = call i32 @getchar()
  %10 = trunc i32 %9 to i8
  store i8 %10, ptr @ch, align 1, !tbaa !9
  %11 = sext i8 %10 to i32
  %12 = icmp ne i32 %11, 10
  br i1 %12, label %13, label %14

13:                                               ; preds = %8
  br label %8, !llvm.loop !10

14:                                               ; preds = %8
  store i32 0, ptr @n, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %53, %27, %14
  %16 = call i32 @getchar()
  %17 = trunc i32 %16 to i8
  store i8 %17, ptr @ch, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = icmp ne i32 %18, 10
  br i1 %19, label %20, label %54

20:                                               ; preds = %15
  %21 = load i8, ptr @ch, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = icmp eq i32 %22, 32
  br i1 %23, label %24, label %34

24:                                               ; preds = %20
  %25 = load i32, ptr @top, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  br label %15, !llvm.loop !12

28:                                               ; preds = %24
  %29 = load i32, ptr @top, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %30
  store i8 0, ptr %31, align 1, !tbaa !9
  %32 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef @str, ptr noundef @.str, ptr noundef @x) #5
  %33 = load i32, ptr @x, align 4, !tbaa !5
  call void @_Z6inserti(i32 noundef %33)
  store i32 0, ptr @top, align 4, !tbaa !5
  br label %53

34:                                               ; preds = %20
  %35 = load i8, ptr @ch, align 1, !tbaa !9
  %36 = sext i8 %35 to i32
  %37 = icmp sge i32 %36, 48
  br i1 %37, label %38, label %42

38:                                               ; preds = %34
  %39 = load i8, ptr @ch, align 1, !tbaa !9
  %40 = sext i8 %39 to i32
  %41 = icmp sle i32 %40, 57
  br i1 %41, label %46, label %42

42:                                               ; preds = %38, %34
  %43 = load i8, ptr @ch, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = icmp eq i32 %44, 45
  br i1 %45, label %46, label %52

46:                                               ; preds = %42, %38
  %47 = load i8, ptr @ch, align 1, !tbaa !9
  %48 = load i32, ptr @top, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr @top, align 4, !tbaa !5
  %50 = sext i32 %48 to i64
  %51 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %50
  store i8 %47, ptr %51, align 1, !tbaa !9
  br label %52

52:                                               ; preds = %46, %42
  br label %53

53:                                               ; preds = %52, %28
  br label %15, !llvm.loop !12

54:                                               ; preds = %15
  %55 = load i32, ptr @top, align 4, !tbaa !5
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %63

57:                                               ; preds = %54
  %58 = load i32, ptr @top, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %59
  store i8 0, ptr %60, align 1, !tbaa !9
  %61 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef @str, ptr noundef @.str, ptr noundef @x) #5
  %62 = load i32, ptr @x, align 4, !tbaa !5
  call void @_Z6inserti(i32 noundef %62)
  store i32 0, ptr @top, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %57, %54
  %64 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @m)
  br label %65

65:                                               ; preds = %69, %63
  %66 = load i32, ptr @m, align 4, !tbaa !5
  %67 = add nsw i32 %66, -1
  store i32 %67, ptr @m, align 4, !tbaa !5
  %68 = icmp ne i32 %66, 0
  br i1 %68, label %69, label %76

69:                                               ; preds = %65
  %70 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  %71 = load i32, ptr @x, align 4, !tbaa !5
  %72 = call noundef zeroext i1 @_Z4findi(i32 noundef %71)
  %73 = zext i1 %72 to i64
  %74 = select i1 %72, ptr @.str.1, ptr @.str.2
  %75 = call i32 @puts(ptr noundef %74)
  br label %65, !llvm.loop !13

76:                                               ; preds = %65
  br label %3, !llvm.loop !14

77:                                               ; preds = %3
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @getchar() #3

; Function Attrs: nounwind
declare i32 @__isoc99_sscanf(ptr noundef, ptr noundef, ...) #4

declare i32 @puts(ptr noundef) #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 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 = { "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 = { inlinehint mustprogress 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 #4 = { 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 #5 = { 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}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}


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

@t = external dso_local global i32, align 4
@top = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@ch = external dso_local local_unnamed_addr global i8, align 1
@str = external dso_local global [101 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.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 void @_Z6inserti(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z4findi(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, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not14 = icmp eq i32 %2, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph15

.loopexit:                                        ; preds = %.lr.ph, %35
  %4 = load i32, ptr @t, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph15, !llvm.loop !9

.lr.ph15:                                         ; preds = %0, %.loopexit
  store i32 0, ptr @tot, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %6, %.lr.ph15
  %7 = tail call i32 @getchar()
  %8 = trunc i32 %7 to i8
  store i8 %8, ptr @ch, align 1, !tbaa !11
  %sext.mask = and i32 %7, 255
  %.not8 = icmp eq i32 %sext.mask, 10
  br i1 %.not8, label %9, label %6, !llvm.loop !12

9:                                                ; preds = %6
  store i32 0, ptr @n, align 4, !tbaa !5
  br label %.backedge

.backedge:                                        ; preds = %.backedge.backedge, %9
  %10 = tail call i32 @getchar()
  %11 = trunc i32 %10 to i8
  store i8 %11, ptr @ch, align 1, !tbaa !11
  %sext = shl i32 %10, 24
  switch i32 %sext, label %19 [
    i32 167772160, label %28
    i32 536870912, label %12
  ]

12:                                               ; preds = %.backedge
  %13 = load i32, ptr @top, align 4, !tbaa !5
  %.not12 = icmp eq i32 %13, 0
  br i1 %.not12, label %.backedge.backedge, label %14

14:                                               ; preds = %12
  %15 = sext i32 %13 to i64
  %16 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %15
  store i8 0, ptr %16, align 1, !tbaa !11
  %17 = tail call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef nonnull @str, ptr noundef nonnull @.str, ptr noundef nonnull @x) #4
  %18 = load i32, ptr @x, align 4, !tbaa !5
  tail call void @_Z6inserti(i32 noundef %18)
  store i32 0, ptr @top, align 4, !tbaa !5
  br label %.backedge.backedge

.backedge.backedge:                               ; preds = %14, %19, %23, %12
  br label %.backedge, !llvm.loop !13

19:                                               ; preds = %.backedge
  %20 = ashr exact i32 %sext, 24
  %21 = add nsw i32 %20, -48
  %or.cond = icmp ult i32 %21, 10
  %22 = icmp eq i32 %sext, 754974720
  %or.cond5 = or i1 %22, %or.cond
  br i1 %or.cond5, label %23, label %.backedge.backedge

23:                                               ; preds = %19
  %24 = load i32, ptr @top, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @top, align 4, !tbaa !5
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %26
  store i8 %11, ptr %27, align 1, !tbaa !11
  br label %.backedge.backedge

28:                                               ; preds = %.backedge
  %29 = load i32, ptr @top, align 4, !tbaa !5
  %.not10 = icmp eq i32 %29, 0
  br i1 %.not10, label %35, label %30

30:                                               ; preds = %28
  %31 = sext i32 %29 to i64
  %32 = getelementptr inbounds [101 x i8], ptr @str, i64 0, i64 %31
  store i8 0, ptr %32, align 1, !tbaa !11
  %33 = tail call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef nonnull @str, ptr noundef nonnull @.str, ptr noundef nonnull @x) #4
  %34 = load i32, ptr @x, align 4, !tbaa !5
  tail call void @_Z6inserti(i32 noundef %34)
  store i32 0, ptr @top, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %30, %28
  %36 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @m)
  %37 = load i32, ptr @m, align 4, !tbaa !5
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr @m, align 4, !tbaa !5
  %.not1113 = icmp eq i32 %37, 0
  br i1 %.not1113, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %35, %.lr.ph
  %39 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %40 = load i32, ptr @x, align 4, !tbaa !5
  %41 = tail call noundef zeroext i1 @_Z4findi(i32 noundef %40)
  %42 = select i1 %41, ptr @.str.1, ptr @.str.2
  %43 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %42)
  %44 = load i32, ptr @m, align 4, !tbaa !5
  %45 = add nsw i32 %44, -1
  store i32 %45, ptr @m, align 4, !tbaa !5
  %.not11 = icmp eq i32 %44, 0
  br i1 %.not11, label %.loopexit, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.loopexit, %0
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @getchar() local_unnamed_addr #3

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(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" }
attributes #3 = { inlinehint mustprogress nofree 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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