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

; 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
@a = external dso_local global [100001 x i32], align 16
@c = external dso_local global [3 x i32], align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6updateii(i32 noundef, i32 noundef) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

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

11:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %24

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr @a, i64 %14
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %15)
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  call void @_Z6updateii(i32 noundef %20, i32 noundef 1)
  br label %21

21:                                               ; preds = %12
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

24:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #4
  store i8 0, ptr %3, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %71, %24
  %26 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %27 = trunc i8 %26 to i1
  br i1 %27, label %32, label %28

28:                                               ; preds = %25
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = icmp slt i32 %29, %30
  br label %32

32:                                               ; preds = %28, %25
  %33 = phi i1 [ false, %25 ], [ %31, %28 ]
  br i1 %33, label %35, label %34

34:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %74

35:                                               ; preds = %32
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %70

41:                                               ; preds = %35
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  call void @_Z6updateii(i32 noundef %45, i32 noundef -1)
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = sub nsw i32 %49, 1
  call void @_Z6updateii(i32 noundef %50, i32 noundef 1)
  %51 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @c, i64 0, i64 2), align 4, !tbaa !5
  %52 = icmp ne i32 %51, 0
  %53 = xor i1 %52, true
  %54 = zext i1 %53 to i32
  %55 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %56 = trunc i8 %55 to i1
  %57 = zext i1 %56 to i32
  %58 = or i32 %57, %54
  %59 = icmp ne i32 %58, 0
  %60 = zext i1 %59 to i8
  store i8 %60, ptr %3, align 1, !tbaa !11
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = sub nsw i32 %64, 1
  call void @_Z6updateii(i32 noundef %65, i32 noundef -1)
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  call void @_Z6updateii(i32 noundef %69, i32 noundef 1)
  br label %70

70:                                               ; preds = %41, %35
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %4, align 4, !tbaa !5
  br label %25, !llvm.loop !15

74:                                               ; preds = %34
  %75 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %76 = trunc i8 %75 to i1
  br i1 %76, label %77, label %101

77:                                               ; preds = %74
  store i8 0, ptr %3, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %97, %77
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = load i32, ptr @n, align 4, !tbaa !5
  %81 = icmp slt i32 %79, %80
  br i1 %81, label %83, label %82

82:                                               ; preds = %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %100

83:                                               ; preds = %78
  %84 = load i32, ptr %5, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = load i32, ptr %5, align 4, !tbaa !5
  %89 = add nsw i32 %87, %88
  %90 = and i32 %89, 1
  %91 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %92 = trunc i8 %91 to i1
  %93 = zext i1 %92 to i32
  %94 = xor i32 %93, %90
  %95 = icmp ne i32 %94, 0
  %96 = zext i1 %95 to i8
  store i8 %96, ptr %3, align 1, !tbaa !11
  br label %97

97:                                               ; preds = %83
  %98 = load i32, ptr %5, align 4, !tbaa !5
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %5, align 4, !tbaa !5
  br label %78, !llvm.loop !16

100:                                              ; preds = %82
  br label %101

101:                                              ; preds = %100, %74
  %102 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %103 = trunc i8 %102 to i1
  br i1 %103, label %104, label %105

104:                                              ; preds = %101
  br label %106

105:                                              ; preds = %101
  br label %106

106:                                              ; preds = %105, %104
  %107 = phi ptr [ @.str.1, %104 ], [ @.str.2, %105 ]
  %108 = getelementptr inbounds [6 x i8], ptr %107, i64 0, i64 0
  %109 = call i32 @puts(ptr noundef %108)
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #4
  ret i32 0
}

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

declare i32 @puts(ptr noundef) #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


; 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
@a = external dso_local global [100001 x i32], align 16
@c = external dso_local local_unnamed_addr global [3 x i32], align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6updateii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse 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 @n)
  %2 = load i32, ptr @n, align 4
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.loopexit

.preheader26:                                     ; preds = %.lr.ph
  %4 = icmp slt i32 %8, 1
  br i1 %4, label %.loopexit, label %.lr.ph31

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %5 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %5)
  %7 = load i32, ptr %5, align 4, !tbaa !5
  tail call void @_Z6updateii(i32 noundef %7, i32 noundef 1)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = load i32, ptr @n, align 4
  %9 = sext i32 %8 to i64
  %10 = icmp slt i64 %indvars.iv.next, %9
  br i1 %10, label %.lr.ph, label %.preheader26, !llvm.loop !9

._crit_edge:                                      ; preds = %25
  br i1 %27, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %._crit_edge
  %11 = icmp sgt i32 %26, 0
  br i1 %11, label %.lr.ph36.preheader, label %.loopexit

.lr.ph36.preheader:                               ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %26 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %12 = icmp eq i32 %26, 1
  br i1 %12, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph36.preheader.new

.lr.ph36.preheader.new:                           ; preds = %.lr.ph36.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.lr.ph36

.lr.ph31:                                         ; preds = %.preheader26, %25
  %13 = phi i32 [ %26, %25 ], [ %8, %.preheader26 ]
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %25 ], [ 0, %.preheader26 ]
  %.02129 = phi i8 [ %.1, %25 ], [ 0, %.preheader26 ]
  %14 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv42
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %25, label %16

16:                                               ; preds = %.lr.ph31
  tail call void @_Z6updateii(i32 noundef %15, i32 noundef -1)
  %17 = load i32, ptr %14, align 4, !tbaa !5
  %18 = add nsw i32 %17, -1
  tail call void @_Z6updateii(i32 noundef %18, i32 noundef 1)
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @c, i64 8), align 4, !tbaa !5
  %.not25 = icmp eq i32 %19, 0
  %20 = zext i1 %.not25 to i8
  %21 = or i8 %.02129, %20
  %22 = load i32, ptr %14, align 4, !tbaa !5
  %23 = add nsw i32 %22, -1
  tail call void @_Z6updateii(i32 noundef %23, i32 noundef -1)
  %24 = load i32, ptr %14, align 4, !tbaa !5
  tail call void @_Z6updateii(i32 noundef %24, i32 noundef 1)
  %.pre = load i32, ptr @n, align 4
  br label %25

25:                                               ; preds = %.lr.ph31, %16
  %26 = phi i32 [ %.pre, %16 ], [ %13, %.lr.ph31 ]
  %.1 = phi i8 [ %21, %16 ], [ %.02129, %.lr.ph31 ]
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %27 = trunc i8 %.1 to i1
  %28 = sext i32 %26 to i64
  %29 = icmp sge i64 %indvars.iv.next43, %28
  %.not24 = select i1 %27, i1 true, i1 %29
  br i1 %.not24, label %._crit_edge, label %.lr.ph31, !llvm.loop !11

.lr.ph36:                                         ; preds = %.lr.ph36, %.lr.ph36.preheader.new
  %indvars.iv44 = phi i64 [ 0, %.lr.ph36.preheader.new ], [ %indvars.iv.next45.1, %.lr.ph36 ]
  %.234 = phi i8 [ 0, %.lr.ph36.preheader.new ], [ %39, %.lr.ph36 ]
  %niter = phi i64 [ 0, %.lr.ph36.preheader.new ], [ %niter.next.1, %.lr.ph36 ]
  %30 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv44
  %31 = load i32, ptr %30, align 8, !tbaa !5
  %32 = and i32 %31, 1
  %33 = zext nneg i8 %.234 to i32
  %indvars.iv.next45 = or disjoint i64 %indvars.iv44, 1
  %34 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv.next45
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = trunc i32 %35 to i1
  %37 = icmp eq i32 %32, %33
  %38 = xor i1 %37, %36
  %39 = zext i1 %38 to i8
  %indvars.iv.next45.1 = add nuw nsw i64 %indvars.iv44, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa.loopexit, label %.lr.ph36, !llvm.loop !12

.loopexit.loopexit.unr-lcssa.loopexit:            ; preds = %.lr.ph36
  %40 = zext i1 %38 to i32
  br label %.loopexit.loopexit.unr-lcssa

.loopexit.loopexit.unr-lcssa:                     ; preds = %.loopexit.loopexit.unr-lcssa.loopexit, %.lr.ph36.preheader
  %.lcssa.ph = phi i8 [ poison, %.lr.ph36.preheader ], [ %39, %.loopexit.loopexit.unr-lcssa.loopexit ]
  %indvars.iv44.unr = phi i64 [ 0, %.lr.ph36.preheader ], [ %indvars.iv.next45.1, %.loopexit.loopexit.unr-lcssa.loopexit ]
  %.234.unr = phi i32 [ 0, %.lr.ph36.preheader ], [ %40, %.loopexit.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph36.epil

.lr.ph36.epil:                                    ; preds = %.loopexit.loopexit.unr-lcssa
  %41 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv44.unr
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = trunc nuw nsw i64 %indvars.iv44.unr to i32
  %44 = add nsw i32 %42, %43
  %45 = and i32 %44, 1
  %46 = icmp ne i32 %45, %.234.unr
  %47 = zext i1 %46 to i8
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph36.epil, %.loopexit.loopexit.unr-lcssa, %0, %.preheader26, %.preheader, %._crit_edge
  %.3 = phi i8 [ %.1, %._crit_edge ], [ 0, %.preheader ], [ 0, %.preheader26 ], [ 0, %0 ], [ %.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %47, %.lr.ph36.epil ]
  %48 = trunc i8 %.3 to i1
  %.str.1..str.2 = select i1 %48, ptr @.str.1, ptr @.str.2
  %49 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.1..str.2)
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(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 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 = { 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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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