; LLVM IR from tangjz/acm-icpc :: hackerrank (manipulative-numbers)

; 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 [101 x i32], align 16
@b = external dso_local global [101 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 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
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %9 = 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 %10

10:                                               ; preds = %20, %0
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %23

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr @a, i64 %17
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %18)
  br label %20

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

23:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 29, ptr %3, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %99, %23
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = icmp sge i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  store i32 5, ptr %4, align 4
  br label %102

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

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

33:                                               ; preds = %29
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %47

34:                                               ; preds = %29
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = ashr i32 %38, %39
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [101 x i32], ptr @b, i64 0, i64 %42
  store i32 %40, ptr %43, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %34
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %5, align 4, !tbaa !5
  br label %29, !llvm.loop !11

47:                                               ; preds = %33
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr @b, i64 %49
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @b, ptr noundef %50)
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  store i8 1, ptr %6, align 1, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %86, %47
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = load i32, ptr @n, align 4, !tbaa !5
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  store i32 11, ptr %4, align 4
  br label %88

56:                                               ; preds = %51
  br label %57

57:                                               ; preds = %74, %56
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = load i32, ptr @n, align 4, !tbaa !5
  %60 = icmp slt i32 %58, %59
  br i1 %60, label %61, label %71

61:                                               ; preds = %57
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [101 x i32], ptr @b, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [101 x i32], ptr @b, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = icmp eq i32 %65, %69
  br label %71

71:                                               ; preds = %61, %57
  %72 = phi i1 [ false, %57 ], [ %70, %61 ]
  br i1 %72, label %73, label %77

73:                                               ; preds = %71
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %8, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %8, align 4, !tbaa !5
  br label %57, !llvm.loop !14

77:                                               ; preds = %71
  %78 = load i32, ptr %8, align 4, !tbaa !5
  %79 = load i32, ptr %7, align 4, !tbaa !5
  %80 = sub nsw i32 %78, %79
  %81 = load i32, ptr @n, align 4, !tbaa !5
  %82 = ashr i32 %81, 1
  %83 = icmp sgt i32 %80, %82
  br i1 %83, label %84, label %85

84:                                               ; preds = %77
  store i8 0, ptr %6, align 1, !tbaa !12
  store i32 11, ptr %4, align 4
  br label %88

85:                                               ; preds = %77
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %87, ptr %7, align 4, !tbaa !5
  br label %51, !llvm.loop !15

88:                                               ; preds = %84, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %89

89:                                               ; preds = %88
  %90 = load i8, ptr %6, align 1, !tbaa !12, !range !16, !noundef !17
  %91 = trunc i8 %90 to i1
  br i1 %91, label %92, label %95

92:                                               ; preds = %89
  %93 = load i32, ptr %3, align 4, !tbaa !5
  %94 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %93)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %96

95:                                               ; preds = %89
  store i32 0, ptr %4, align 4
  br label %96

96:                                               ; preds = %95, %92
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  %97 = load i32, ptr %4, align 4
  switch i32 %97, label %102 [
    i32 0, label %98
  ]

98:                                               ; preds = %96
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr %3, align 4, !tbaa !5
  %101 = add nsw i32 %100, -1
  store i32 %101, ptr %3, align 4, !tbaa !5
  br label %24, !llvm.loop !18

102:                                              ; preds = %96, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  %103 = load i32, ptr %4, align 4
  switch i32 %103, label %108 [
    i32 5, label %104
    i32 1, label %106
  ]

104:                                              ; preds = %102
  %105 = call i32 @puts(ptr noundef @.str.2)
  store i32 0, ptr %1, align 4
  br label %106

106:                                              ; preds = %104, %102
  %107 = load i32, ptr %1, align 4
  ret i32 %107

108:                                              ; preds = %102
  unreachable
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #3

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

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 = { 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 }

!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 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !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 [101 x i32], align 16
@b = external dso_local global [101 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse 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, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.preheader41.preheader

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

.preheader41.preheader:                           ; preds = %.lr.ph, %0
  %.ph = phi i32 [ %2, %0 ], [ %6, %.lr.ph ]
  br label %.preheader41

.preheader41:                                     ; preds = %.preheader41.preheader, %.critedge36
  %9 = phi i32 [ %20, %.critedge36 ], [ %.ph, %.preheader41.preheader ]
  %.02851 = phi i32 [ %39, %.critedge36 ], [ 29, %.preheader41.preheader ]
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph49.preheader, label %._crit_edge

.lr.ph49.preheader:                               ; preds = %.preheader41
  %wide.trip.count = zext nneg i32 %9 to i64
  %min.iters.check = icmp ult i32 %9, 8
  br i1 %min.iters.check, label %.lr.ph49.preheader68, label %vector.ph

.lr.ph49.preheader68:                             ; preds = %middle.block, %.lr.ph49.preheader
  %indvars.iv54.ph = phi i64 [ 0, %.lr.ph49.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph49

vector.ph:                                        ; preds = %.lr.ph49.preheader
  %n.vec = and i64 %wide.trip.count, 2147483640
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %.02851, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %11 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %wide.load = load <4 x i32>, ptr %11, align 16, !tbaa !5
  %wide.load67 = load <4 x i32>, ptr %12, align 16, !tbaa !5
  %13 = ashr <4 x i32> %wide.load, %broadcast.splat
  %14 = ashr <4 x i32> %wide.load67, %broadcast.splat
  %15 = getelementptr inbounds [101 x i32], ptr @b, i64 0, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store <4 x i32> %13, ptr %15, align 16, !tbaa !5
  store <4 x i32> %14, ptr %16, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %17 = icmp eq i64 %index.next, %n.vec
  br i1 %17, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph49.preheader68

._crit_edge:                                      ; preds = %.lr.ph49, %middle.block, %.preheader41
  %18 = sext i32 %9 to i64
  %19 = getelementptr inbounds i32, ptr @b, i64 %18
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @b, ptr noundef nonnull %19)
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = ashr i32 %20, 1
  %22 = sext i32 %20 to i64
  br label %27

.lr.ph49:                                         ; preds = %.lr.ph49.preheader68, %.lr.ph49
  %indvars.iv54 = phi i64 [ %indvars.iv.next55, %.lr.ph49 ], [ %indvars.iv54.ph, %.lr.ph49.preheader68 ]
  %23 = getelementptr inbounds [101 x i32], ptr @a, i64 0, i64 %indvars.iv54
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = ashr i32 %24, %.02851
  %26 = getelementptr inbounds [101 x i32], ptr @b, i64 0, i64 %indvars.iv54
  store i32 %25, ptr %26, align 4, !tbaa !5
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next55, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph49, !llvm.loop !14

27:                                               ; preds = %.critedge, %._crit_edge
  %.0 = phi i32 [ 0, %._crit_edge ], [ %.1.lcssa, %.critedge ]
  %.not = icmp slt i32 %.0, %20
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %27
  %28 = sext i32 %.0 to i64
  %29 = getelementptr inbounds [101 x i32], ptr @b, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %.preheader, %35
  %indvars.iv57 = phi i64 [ %28, %.preheader ], [ %indvars.iv.next58, %35 ]
  %32 = getelementptr inbounds [101 x i32], ptr @b, i64 0, i64 %indvars.iv57
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp eq i32 %30, %33
  br i1 %34, label %35, label %.critedge.split.loop.exit63

35:                                               ; preds = %31
  %indvars.iv.next58 = add nsw i64 %indvars.iv57, 1
  %exitcond60.not = icmp eq i64 %indvars.iv.next58, %22
  br i1 %exitcond60.not, label %.critedge, label %31, !llvm.loop !15

.critedge.split.loop.exit63:                      ; preds = %31
  %36 = trunc nsw i64 %indvars.iv57 to i32
  br label %.critedge

.critedge:                                        ; preds = %35, %.critedge.split.loop.exit63
  %.1.lcssa = phi i32 [ %36, %.critedge.split.loop.exit63 ], [ %20, %35 ]
  %37 = sub nsw i32 %.1.lcssa, %.0
  %38 = icmp sgt i32 %37, %21
  br i1 %38, label %.critedge36, label %27, !llvm.loop !16

.critedge36:                                      ; preds = %.critedge
  %39 = add nsw i32 %.02851, -1
  %.not61 = icmp eq i32 %.02851, 0
  br i1 %.not61, label %41, label %.preheader41, !llvm.loop !17

.loopexit:                                        ; preds = %27
  %40 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.02851)
  br label %43

41:                                               ; preds = %.critedge36
  %42 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %43

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(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 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 = { 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 = { 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" }

!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, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !10, !13, !12}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass