; LLVM IR from chirag-singhal/Coding-Interview-101 :: Miscellaneous/Codechef/novlong (2)

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

@.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: nounwind uwtable
define dso_local 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 [10 x i32], align 16
  %7 = alloca i32, align 4
  %8 = alloca [10 x i8], align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %76, %0
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %79

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 40, ptr %6) #5
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 40, i1 false)
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %51, %18
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %54

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 10, ptr %8) #5
  %26 = call i32 @getchar()
  %27 = getelementptr inbounds [10 x i8], ptr %8, i64 0, i64 0
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %27)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %47, %25
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = icmp slt i32 %30, 10
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %29
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [10 x i8], ptr %8, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = sext i8 %37 to i32
  %39 = icmp eq i32 %38, 49
  br i1 %39, label %40, label %46

40:                                               ; preds = %33
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %43, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %40, %33
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %9, align 4, !tbaa !5
  br label %29, !llvm.loop !10

50:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 10, ptr %8) #5
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !5
  br label %20, !llvm.loop !12

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

55:                                               ; preds = %70, %54
  %56 = load i32, ptr %11, align 4, !tbaa !5
  %57 = icmp slt i32 %56, 10
  br i1 %57, label %59, label %58

58:                                               ; preds = %55
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %73

59:                                               ; preds = %55
  %60 = load i32, ptr %11, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [10 x i32], ptr %6, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = srem i32 %63, 2
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %69

66:                                               ; preds = %59
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %10, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %66, %59
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %11, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %11, align 4, !tbaa !5
  br label %55, !llvm.loop !13

73:                                               ; preds = %58
  %74 = load i32, ptr %10, align 4, !tbaa !5
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %74)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %76

76:                                               ; preds = %73
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !14

79:                                               ; preds = %17
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %80 = load i32, ptr %1, align 4
  ret i32 %80
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: inlinehint nounwind uwtable
declare i32 @getchar() #4

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

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { inlinehint 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 #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/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"

@.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: nofree nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [10 x i8], align 2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph23.preheader, label %._crit_edge

.lr.ph23.preheader:                               ; preds = %0
  %7 = getelementptr inbounds i8, ptr %3, i64 2
  br label %.lr.ph23

._crit_edge:                                      ; preds = %.preheader, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 0

.lr.ph23:                                         ; preds = %.lr.ph23.preheader, %.preheader
  %.01722 = phi i32 [ %23, %.preheader ], [ 0, %.lr.ph23.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %.lr.ph23
  %11 = phi <8 x i32> [ zeroinitializer, %.lr.ph23 ], [ %38, %.lr.ph ]
  %12 = phi <2 x i32> [ zeroinitializer, %.lr.ph23 ], [ %34, %.lr.ph ]
  %13 = shufflevector <8 x i32> %11, <8 x i32> poison, <8 x i32> <i32 poison, i32 poison, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5>
  %14 = shufflevector <2 x i32> %12, <2 x i32> poison, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
  %15 = shufflevector <8 x i32> %14, <8 x i32> %13, <8 x i32> <i32 0, i32 1, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
  %16 = and <8 x i32> %15, <i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1>
  %17 = shufflevector <8 x i32> %11, <8 x i32> poison, <2 x i32> <i32 6, i32 7>
  %18 = and <2 x i32> %17, <i32 1, i32 1>
  %19 = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %16)
  %20 = extractelement <2 x i32> %18, i64 0
  %op.rdx = add i32 %19, %20
  %21 = extractelement <2 x i32> %18, i64 1
  %op.rdx45 = add i32 %op.rdx, %21
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %op.rdx45)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  %23 = add nuw nsw i32 %.01722, 1
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %.lr.ph23, label %._crit_edge, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph23, %.lr.ph
  %.01619 = phi i32 [ %39, %.lr.ph ], [ 0, %.lr.ph23 ]
  %26 = phi <8 x i32> [ %38, %.lr.ph ], [ zeroinitializer, %.lr.ph23 ]
  %27 = phi <2 x i32> [ %34, %.lr.ph ], [ zeroinitializer, %.lr.ph23 ]
  call void @llvm.lifetime.start.p0(i64 10, ptr nonnull %3) #5
  %28 = call i32 @getchar()
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %30 = load <2 x i8>, ptr %3, align 2, !tbaa !11
  %31 = icmp eq <2 x i8> %30, <i8 49, i8 49>
  %32 = zext <2 x i1> %31 to <2 x i32>
  %33 = shufflevector <2 x i32> %32, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
  %34 = add nuw nsw <2 x i32> %27, %33
  %35 = load <8 x i8>, ptr %7, align 2, !tbaa !11
  %36 = icmp eq <8 x i8> %35, <i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49>
  %37 = zext <8 x i1> %36 to <8 x i32>
  %38 = add nuw nsw <8 x i32> %26, %37
  call void @llvm.lifetime.end.p0(i64 10, ptr nonnull %3) #5
  %39 = add nuw nsw i32 %.01619, 1
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %.lr.ph, label %.preheader, !llvm.loop !12
}

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

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v8i32(<8 x i32>) #4

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass