; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/Random/PPXOR (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"

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [100100 x i32], align 16
@ans = external dso_local global i64, align 8
@last = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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 i32, align 4
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %8

8:                                                ; preds = %67, %0
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr @t, align 4, !tbaa !5
  %11 = icmp ne i32 %9, 0
  br i1 %11, label %12, label %70

12:                                               ; preds = %8
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %24, %12
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp sle i32 %15, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %21
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %22)
  br label %24

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

27:                                               ; preds = %18
  store i64 0, ptr @ans, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %64, %27
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = icmp slt i32 %29, 30
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  store i32 7, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %67

32:                                               ; preds = %28
  store i64 0, ptr @last, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = shl i32 1, %33
  store i32 %34, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %60, %32
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = icmp sle i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  store i32 10, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %63

40:                                               ; preds = %35
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = and i32 %44, %45
  %47 = icmp sgt i32 %46, 0
  br i1 %47, label %48, label %53

48:                                               ; preds = %40
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = load i64, ptr @last, align 8, !tbaa !11
  %52 = sub nsw i64 %50, %51
  store i64 %52, ptr @last, align 8, !tbaa !11
  br label %53

53:                                               ; preds = %48, %40
  %54 = load i64, ptr @last, align 8, !tbaa !11
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = mul nsw i64 %54, %56
  %58 = load i64, ptr @ans, align 8, !tbaa !11
  %59 = add nsw i64 %58, %57
  store i64 %59, ptr @ans, align 8, !tbaa !11
  br label %60

60:                                               ; preds = %53
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %6, align 4, !tbaa !5
  br label %35, !llvm.loop !13

63:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %3, align 4, !tbaa !5
  br label %28, !llvm.loop !14

67:                                               ; preds = %31
  %68 = load i64, ptr @ans, align 8, !tbaa !11
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %68)
  br label %8, !llvm.loop !15

70:                                               ; preds = %8
  ret i32 0
}

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 @printf(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"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !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"

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [100100 x i32], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@last = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not36 = icmp eq i32 %2, 0
  br i1 %.not36, label %._crit_edge39, label %.lr.ph38

.lr.ph38:                                         ; preds = %0, %.split35.us
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %.not1417 = icmp slt i32 %5, 1
  br i1 %.not1417, label %.split35.us.sink.split, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  store i64 0, ptr @ans, align 8, !tbaa !9
  %.not1519 = icmp slt i32 %10, 1
  br i1 %.not1519, label %.split35.us, label %.lr.ph22.preheader

.lr.ph22.preheader:                               ; preds = %._crit_edge
  %6 = zext nneg i32 %10 to i64
  %xtraiter = and i64 %6, 1
  %7 = icmp eq i32 %10, 1
  %unroll_iter = and i64 %6, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph22

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

.split35.us.sink.split:                           ; preds = %._crit_edge23, %.lr.ph38
  %.sink = phi i64 [ 0, %.lr.ph38 ], [ %.lcssa54, %._crit_edge23 ]
  %.us-phi.ph = phi i64 [ 0, %.lr.ph38 ], [ %spec.select.lcssa, %._crit_edge23 ]
  store i64 %.sink, ptr @ans, align 8, !tbaa !9
  br label %.split35.us

.split35.us:                                      ; preds = %.split35.us.sink.split, %._crit_edge
  %12 = phi i64 [ 0, %._crit_edge ], [ %.sink, %.split35.us.sink.split ]
  %.us-phi = phi i64 [ 0, %._crit_edge ], [ %.us-phi.ph, %.split35.us.sink.split ]
  store i64 %.us-phi, ptr @last, align 8, !tbaa !9
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %12)
  %14 = load i32, ptr @t, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %._crit_edge39, label %.lr.ph38, !llvm.loop !13

.lr.ph22:                                         ; preds = %.lr.ph22.preheader, %._crit_edge23
  %indvars.iv46 = phi i64 [ 0, %.lr.ph22.preheader ], [ %indvars.iv.next47, %._crit_edge23 ]
  %.lcssa243032 = phi i64 [ 0, %.lr.ph22.preheader ], [ %.lcssa54, %._crit_edge23 ]
  %16 = trunc nuw nsw i64 %indvars.iv46 to i32
  %17 = shl nuw nsw i32 1, %16
  br i1 %7, label %._crit_edge23.unr-lcssa, label %.lr.ph22.new

._crit_edge23.unr-lcssa:                          ; preds = %.lr.ph22.new, %.lr.ph22
  %spec.select.lcssa.ph = phi i64 [ poison, %.lr.ph22 ], [ %spec.select.1, %.lr.ph22.new ]
  %.lcssa54.ph = phi i64 [ poison, %.lr.ph22 ], [ %37, %.lr.ph22.new ]
  %indvars.iv43.unr = phi i64 [ 1, %.lr.ph22 ], [ %indvars.iv.next44.1, %.lr.ph22.new ]
  %.unr = phi i64 [ 0, %.lr.ph22 ], [ %spec.select.1, %.lr.ph22.new ]
  %.unr55 = phi i64 [ %.lcssa243032, %.lr.ph22 ], [ %37, %.lr.ph22.new ]
  br i1 %lcmp.mod.not, label %._crit_edge23, label %._crit_edge23.epilog-lcssa

._crit_edge23.epilog-lcssa:                       ; preds = %._crit_edge23.unr-lcssa
  %18 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %indvars.iv43.unr
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = and i32 %19, %17
  %.not16.epil = icmp eq i32 %20, 0
  %21 = sub nsw i64 %indvars.iv43.unr, %.unr
  %spec.select.epil = select i1 %.not16.epil, i64 %.unr, i64 %21
  %22 = shl i64 %spec.select.epil, %indvars.iv46
  %23 = add nsw i64 %.unr55, %22
  br label %._crit_edge23

._crit_edge23:                                    ; preds = %._crit_edge23.unr-lcssa, %._crit_edge23.epilog-lcssa
  %spec.select.lcssa = phi i64 [ %spec.select.lcssa.ph, %._crit_edge23.unr-lcssa ], [ %spec.select.epil, %._crit_edge23.epilog-lcssa ]
  %.lcssa54 = phi i64 [ %.lcssa54.ph, %._crit_edge23.unr-lcssa ], [ %23, %._crit_edge23.epilog-lcssa ]
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %exitcond49.not = icmp eq i64 %indvars.iv.next47, 30
  br i1 %exitcond49.not, label %.split35.us.sink.split, label %.lr.ph22, !llvm.loop !14

.lr.ph22.new:                                     ; preds = %.lr.ph22, %.lr.ph22.new
  %indvars.iv43 = phi i64 [ %indvars.iv.next44.1, %.lr.ph22.new ], [ 1, %.lr.ph22 ]
  %24 = phi i64 [ %spec.select.1, %.lr.ph22.new ], [ 0, %.lr.ph22 ]
  %25 = phi i64 [ %37, %.lr.ph22.new ], [ %.lcssa243032, %.lr.ph22 ]
  %niter = phi i64 [ %niter.next.1, %.lr.ph22.new ], [ 0, %.lr.ph22 ]
  %26 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %indvars.iv43
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = and i32 %27, %17
  %.not16 = icmp eq i32 %28, 0
  %29 = sub nsw i64 %indvars.iv43, %24
  %spec.select = select i1 %.not16, i64 %24, i64 %29
  %30 = shl i64 %spec.select, %indvars.iv46
  %31 = add nsw i64 %25, %30
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %32 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %indvars.iv.next44
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = and i32 %33, %17
  %.not16.1 = icmp eq i32 %34, 0
  %35 = sub nsw i64 %indvars.iv.next44, %spec.select
  %spec.select.1 = select i1 %.not16.1, i64 %spec.select, i64 %35
  %36 = shl i64 %spec.select.1, %indvars.iv46
  %37 = add nsw i64 %31, %36
  %indvars.iv.next44.1 = add nuw nsw i64 %indvars.iv43, 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 %._crit_edge23.unr-lcssa, label %.lr.ph22.new, !llvm.loop !15

._crit_edge39:                                    ; preds = %.split35.us, %0
  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 @printf(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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


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