; LLVM IR from tangjz/acm-icpc :: hackerrank (xor-subsequence)

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3FWTPxii(ptr noundef, i32 noundef, i32 noundef) #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 i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %6 = load i64, ptr @f, align 16, !tbaa !5
  %7 = add nsw i64 %6, 1
  store i64 %7, ptr @f, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %32, %0
  %9 = load i32, ptr %2, align 4, !tbaa !9
  %10 = load i32, ptr @n, align 4, !tbaa !9
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %35

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i32, ptr @a, i64 %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %16)
  %18 = load i32, ptr %2, align 4, !tbaa !9
  %19 = sub nsw i32 %18, 1
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = load i32, ptr %2, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = xor i32 %26, %22
  store i32 %27, ptr %25, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = add nsw i64 %30, 1
  store i64 %31, ptr %29, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %13
  %33 = load i32, ptr %2, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %2, align 4, !tbaa !9
  br label %8, !llvm.loop !11

35:                                               ; preds = %12
  call void @_Z3FWTPxii(ptr noundef @f, i32 noundef 65536, i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %50, %35
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = icmp slt i32 %37, 65536
  br i1 %38, label %40, label %39

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

40:                                               ; preds = %36
  %41 = load i32, ptr %3, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !5
  %45 = load i32, ptr %3, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = mul nsw i64 %48, %44
  store i64 %49, ptr %47, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %40
  %51 = load i32, ptr %3, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %3, align 4, !tbaa !9
  br label %36, !llvm.loop !13

53:                                               ; preds = %39
  call void @_Z3FWTPxii(ptr noundef @f, i32 noundef 65536, i32 noundef -1)
  %54 = load i32, ptr @n, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = load i64, ptr @f, align 16, !tbaa !5
  %58 = sub nsw i64 %57, %56
  store i64 %58, ptr @f, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %76, %53
  %60 = load i32, ptr %4, align 4, !tbaa !9
  %61 = icmp slt i32 %60, 65536
  br i1 %61, label %63, label %62

62:                                               ; preds = %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %79

63:                                               ; preds = %59
  %64 = load i32, ptr @id, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !5
  %68 = load i32, ptr %4, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %69
  %71 = load i64, ptr %70, align 8, !tbaa !5
  %72 = icmp slt i64 %67, %71
  br i1 %72, label %73, label %75

73:                                               ; preds = %63
  %74 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %74, ptr @id, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %73, %63
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %4, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %4, align 4, !tbaa !9
  br label %59, !llvm.loop !14

79:                                               ; preds = %62
  %80 = load i32, ptr @id, align 4, !tbaa !9
  %81 = load i32, ptr @id, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %82
  %84 = load i64, ptr %83, align 8, !tbaa !5
  %85 = ashr i64 %84, 1
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %80, i64 noundef %85)
  ret i32 0
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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

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

; Function Attrs: mustprogress norecurse nounwind 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 i64, ptr @f, align 16, !tbaa !5
  %3 = add nsw i64 %2, 1
  store i64 %3, ptr @f, align 16, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !9
  %.not15 = icmp slt i32 %4, 1
  br i1 %.not15, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  tail call void @_Z3FWTPxii(ptr noundef nonnull @f, i32 noundef 65536, i32 noundef 1)
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %._crit_edge
  %index = phi i64 [ 0, %._crit_edge ], [ %index.next, %vector.body ]
  %5 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %index
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %wide.load = load <2 x i64>, ptr %5, align 16, !tbaa !5
  %wide.load30 = load <2 x i64>, ptr %6, align 16, !tbaa !5
  %7 = mul nsw <2 x i64> %wide.load, %wide.load
  %8 = mul nsw <2 x i64> %wide.load30, %wide.load30
  store <2 x i64> %7, ptr %5, align 16, !tbaa !5
  store <2 x i64> %8, ptr %6, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %9 = icmp eq i64 %index.next, 65536
  br i1 %9, label %middle.block, label %vector.body, !llvm.loop !11

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %10 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %11 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %10)
  %12 = add nsw i64 %indvars.iv, -1
  %13 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = load i32, ptr %10, align 4, !tbaa !9
  %16 = xor i32 %15, %14
  store i32 %16, ptr %10, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = add nsw i64 %19, 1
  store i64 %20, ptr %18, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i32, ptr @n, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %.not.not = icmp slt i64 %indvars.iv, %22
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  tail call void @_Z3FWTPxii(ptr noundef nonnull @f, i32 noundef 65536, i32 noundef -1)
  %23 = load i32, ptr @n, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = load i64, ptr @f, align 16, !tbaa !5
  %27 = sub nsw i64 %26, %25
  store i64 %27, ptr @f, align 16, !tbaa !5
  %id.promoted = load i32, ptr @id, align 4, !tbaa !9
  br label %34

28:                                               ; preds = %63
  %29 = sext i32 %64 to i64
  %30 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = ashr i64 %31, 1
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %64, i64 noundef %32)
  ret i32 0

34:                                               ; preds = %63, %middle.block
  %indvars.iv26 = phi i64 [ 1, %middle.block ], [ %indvars.iv.next27.2, %63 ]
  %.01920 = phi i32 [ %id.promoted, %middle.block ], [ %64, %63 ]
  %35 = sext i32 %.01920 to i64
  %36 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %indvars.iv26
  %39 = load i64, ptr %38, align 8, !tbaa !5
  %40 = icmp slt i64 %37, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %34
  %42 = trunc nuw nsw i64 %indvars.iv26 to i32
  store i32 %42, ptr @id, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %34, %41
  %44 = phi i32 [ %.01920, %34 ], [ %42, %41 ]
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %indvars.iv.next27
  %49 = load i64, ptr %48, align 8, !tbaa !5
  %50 = icmp slt i64 %47, %49
  br i1 %50, label %51, label %53

51:                                               ; preds = %43
  %52 = trunc nuw nsw i64 %indvars.iv.next27 to i32
  store i32 %52, ptr @id, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %51, %43
  %54 = phi i32 [ %44, %43 ], [ %52, %51 ]
  %indvars.iv.next27.1 = add nuw nsw i64 %indvars.iv26, 2
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !5
  %58 = getelementptr inbounds [100001 x i64], ptr @f, i64 0, i64 %indvars.iv.next27.1
  %59 = load i64, ptr %58, align 8, !tbaa !5
  %60 = icmp slt i64 %57, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %53
  %62 = trunc nuw nsw i64 %indvars.iv.next27.1 to i32
  store i32 %62, ptr @id, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %61, %53
  %64 = phi i32 [ %54, %53 ], [ %62, %61 ]
  %indvars.iv.next27.2 = add nuw nsw i64 %indvars.iv26, 3
  %exitcond29.not.2 = icmp eq i64 %indvars.iv.next27.2, 65536
  br i1 %exitcond29.not.2, label %28, label %34, !llvm.loop !16
}

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

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

attributes #0 = { mustprogress 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 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 #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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