; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/248 Division 2/Problem A (A)

; 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
@c1 = external dso_local global i32, align 4
@c2 = external dso_local global i32, align 4
@w = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@.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 [4 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
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %23, %0
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @w)
  %11 = load i32, ptr @w, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 100
  br i1 %12, label %13, label %16

13:                                               ; preds = %9
  %14 = load i32, ptr @c1, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr @c1, align 4, !tbaa !5
  br label %19

16:                                               ; preds = %9
  %17 = load i32, ptr @c2, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr @c2, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %16, %13
  %20 = load i32, ptr @w, align 4, !tbaa !5
  %21 = load i32, ptr @t, align 4, !tbaa !5
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr @t, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %19
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %2, align 4, !tbaa !5
  br label %4, !llvm.loop !9

26:                                               ; preds = %8
  %27 = load i32, ptr @t, align 4, !tbaa !5
  %28 = srem i32 %27, 2
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %37, label %30

30:                                               ; preds = %26
  %31 = load i32, ptr @c1, align 4, !tbaa !5
  %32 = srem i32 %31, 2
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %37, label %34

34:                                               ; preds = %30
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = icmp eq i32 %35, 1
  br i1 %36, label %37, label %39

37:                                               ; preds = %34, %30, %26
  %38 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  br label %66

39:                                               ; preds = %34
  %40 = load i32, ptr @c1, align 4, !tbaa !5
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %51

42:                                               ; preds = %39
  %43 = load i32, ptr @c2, align 4, !tbaa !5
  %44 = srem i32 %43, 2
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %48

46:                                               ; preds = %42
  %47 = call i32 @puts(ptr noundef @.str.2)
  br label %50

48:                                               ; preds = %42
  %49 = call i32 @puts(ptr noundef @.str.1)
  br label %50

50:                                               ; preds = %48, %46
  store i32 0, ptr %1, align 4
  br label %66

51:                                               ; preds = %39
  %52 = load i32, ptr @c2, align 4, !tbaa !5
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %63

54:                                               ; preds = %51
  %55 = load i32, ptr @c1, align 4, !tbaa !5
  %56 = srem i32 %55, 2
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %60

58:                                               ; preds = %54
  %59 = call i32 @puts(ptr noundef @.str.2)
  br label %62

60:                                               ; preds = %54
  %61 = call i32 @puts(ptr noundef @.str.1)
  br label %62

62:                                               ; preds = %60, %58
  store i32 0, ptr %1, align 4
  br label %66

63:                                               ; preds = %51
  br label %64

64:                                               ; preds = %63
  %65 = call i32 @puts(ptr noundef @.str.2)
  store i32 0, ptr %1, align 4
  br label %66

66:                                               ; preds = %64, %62, %50, %37
  %67 = load i32, ptr %1, align 4
  ret i32 %67
}

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 @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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@n = external dso_local global i32, align 4
@c1 = external dso_local local_unnamed_addr global i32, align 4
@c2 = external dso_local local_unnamed_addr global i32, align 4
@w = external dso_local global i32, align 4
@t = external dso_local local_unnamed_addr global i32, align 4
@.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 [4 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 = load i32, ptr @n, align 4
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = load i32, ptr @t, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %4 = icmp eq i32 %16, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %.._crit_edge_crit_edge, %._crit_edge.loopexit
  %5 = phi i32 [ %.pre, %.._crit_edge_crit_edge ], [ %14, %._crit_edge.loopexit ]
  %.lcssa = phi i1 [ false, %.._crit_edge_crit_edge ], [ %4, %._crit_edge.loopexit ]
  %6 = and i32 %5, -2147483647
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %32, label %18

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.07 = phi i32 [ %15, %.lr.ph ], [ 0, %0 ]
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @w)
  %9 = load i32, ptr @w, align 4, !tbaa !5
  %10 = icmp eq i32 %9, 100
  %c1.c2 = select i1 %10, ptr @c1, ptr @c2
  %11 = load i32, ptr %c1.c2, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %c1.c2, align 4, !tbaa !5
  %13 = load i32, ptr @t, align 4, !tbaa !5
  %14 = add nsw i32 %13, %9
  store i32 %14, ptr @t, align 4, !tbaa !5
  %15 = add nuw nsw i32 %.07, 1
  %16 = load i32, ptr @n, align 4
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9

18:                                               ; preds = %._crit_edge
  %19 = load i32, ptr @c1, align 4, !tbaa !5
  %20 = srem i32 %19, 2
  %21 = icmp eq i32 %20, 1
  %or.cond = or i1 %.lcssa, %21
  br i1 %or.cond, label %32, label %22

22:                                               ; preds = %18
  %23 = icmp eq i32 %19, 0
  %24 = load i32, ptr @c2, align 4, !tbaa !5
  br i1 %23, label %25, label %28

25:                                               ; preds = %22
  %26 = and i32 %24, 1
  %27 = icmp eq i32 %26, 0
  %.str.2..str.1 = select i1 %27, ptr @.str.2, ptr @.str.1
  br label %32

28:                                               ; preds = %22
  %29 = icmp eq i32 %24, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %28
  %31 = icmp eq i32 %20, 0
  %.str.2..str.113 = select i1 %31, ptr @.str.2, ptr @.str.1
  br label %32

32:                                               ; preds = %28, %30, %25, %._crit_edge, %18
  %.str.2.sink = phi ptr [ @.str.1, %18 ], [ @.str.1, %._crit_edge ], [ %.str.2..str.1, %25 ], [ %.str.2..str.113, %30 ], [ @.str.2, %28 ]
  %33 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.2.sink)
  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 @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" }

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


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