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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4readRi(ptr noundef nonnull align 4 dereferenceable(4)) #0

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

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(i32 noundef) #1

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

3:                                                ; preds = %55, %0
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %5 = icmp ne i32 %4, -1
  br i1 %5, label %6, label %57

6:                                                ; preds = %3
  br label %7

7:                                                ; preds = %11, %6
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @n, align 4, !tbaa !5
  %10 = icmp ne i32 %8, 0
  br i1 %10, label %11, label %17

11:                                               ; preds = %7
  call void @_Z4readRi(ptr noundef nonnull align 4 dereferenceable(4) @x)
  %12 = load i32, ptr @x, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [101 x i32], ptr @val, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %14, align 4, !tbaa !5
  br label %7, !llvm.loop !9

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

18:                                               ; preds = %52, %17
  %19 = load i32, ptr @x, align 4, !tbaa !5
  %20 = icmp sle i32 %19, 100
  br i1 %20, label %21, label %55

21:                                               ; preds = %18
  %22 = load i32, ptr @x, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [101 x i32], ptr @val, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %51

27:                                               ; preds = %21
  br label %28

28:                                               ; preds = %42, %27
  %29 = load i32, ptr @x, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [101 x i32], ptr @val, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %50

34:                                               ; preds = %28
  %35 = load i8, ptr %2, align 1, !tbaa !11, !range !13, !noundef !14
  %36 = trunc i8 %35 to i1
  %37 = zext i1 %36 to i32
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %34
  store i8 1, ptr %2, align 1, !tbaa !11
  br label %42

40:                                               ; preds = %34
  %41 = call i32 @putchar(i32 noundef 32)
  br label %42

42:                                               ; preds = %40, %39
  %43 = phi i32 [ 1, %39 ], [ %41, %40 ]
  %44 = load i32, ptr @x, align 4, !tbaa !5
  call void @_Z5writei(i32 noundef %44)
  %45 = load i32, ptr @x, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [101 x i32], ptr @val, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = add nsw i32 %48, -1
  store i32 %49, ptr %47, align 4, !tbaa !5
  br label %28, !llvm.loop !15

50:                                               ; preds = %28
  br label %51

51:                                               ; preds = %50, %21
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr @x, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr @x, align 4, !tbaa !5
  br label %18, !llvm.loop !16

55:                                               ; preds = %18
  %56 = call i32 @putchar(i32 noundef 10)
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #5
  br label %3, !llvm.loop !17

57:                                               ; preds = %3
  ret i32 0
}

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

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

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

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 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = 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}
!17 = distinct !{!17, !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
@val = external dso_local local_unnamed_addr global [101 x i32], align 16
@x = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4readRi(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %.not13 = icmp eq i32 %1, -1
  br i1 %.not13, label %._crit_edge, label %.preheader6

.preheader6:                                      ; preds = %0, %31
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @n, align 4, !tbaa !5
  %.not27 = icmp eq i32 %2, 0
  br i1 %.not27, label %.preheader5, label %.lr.ph

.preheader5:                                      ; preds = %.lr.ph, %.preheader6
  store i32 1, ptr @x, align 4, !tbaa !5
  br label %11

.lr.ph:                                           ; preds = %.preheader6, %.lr.ph
  tail call void @_Z4readRi(ptr noundef nonnull align 4 dereferenceable(4) @x)
  %4 = load i32, ptr @x, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [101 x i32], ptr @val, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr @n, align 4, !tbaa !5
  %.not2 = icmp eq i32 %9, 0
  br i1 %.not2, label %.preheader5, label %.lr.ph, !llvm.loop !9

11:                                               ; preds = %.preheader5, %.loopexit
  %.012 = phi i8 [ 0, %.preheader5 ], [ %.3, %.loopexit ]
  %12 = phi i32 [ 1, %.preheader5 ], [ %29, %.loopexit ]
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [101 x i32], ptr @val, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %.not3 = icmp eq i32 %15, 0
  br i1 %.not3, label %.loopexit, label %.lr.ph10

.lr.ph10:                                         ; preds = %11, %21
  %16 = phi i32 [ %23, %21 ], [ %12, %11 ]
  %.19 = phi i8 [ %.2, %21 ], [ %.012, %11 ]
  %17 = and i8 %.19, 1
  %18 = icmp eq i8 %17, 0
  br i1 %18, label %21, label %19

19:                                               ; preds = %.lr.ph10
  %20 = tail call i32 @putchar(i32 noundef 32)
  %.pre = load i32, ptr @x, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %.lr.ph10, %19
  %22 = phi i32 [ %.pre, %19 ], [ %16, %.lr.ph10 ]
  %.2 = phi i8 [ %.19, %19 ], [ 1, %.lr.ph10 ]
  tail call void @_Z5writei(i32 noundef %22)
  %23 = load i32, ptr @x, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [101 x i32], ptr @val, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %25, align 4, !tbaa !5
  %.not4 = icmp eq i32 %27, 0
  br i1 %.not4, label %.loopexit, label %.lr.ph10, !llvm.loop !11

.loopexit:                                        ; preds = %21, %11
  %28 = phi i32 [ %12, %11 ], [ %23, %21 ]
  %.3 = phi i8 [ %.012, %11 ], [ %.2, %21 ]
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @x, align 4, !tbaa !5
  %30 = icmp slt i32 %28, 100
  br i1 %30, label %11, label %31, !llvm.loop !12

31:                                               ; preds = %.loopexit
  %32 = tail call i32 @putchar(i32 noundef 10)
  %33 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %.not = icmp eq i32 %33, -1
  br i1 %.not, label %._crit_edge, label %.preheader6, !llvm.loop !13

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

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 #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 = { 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}
!13 = distinct !{!13, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass