; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Random/Xoring-Ninja (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
@cnt = external dso_local global [31 x i32], align 16
@ans = external dso_local global i64, align 8
@MOD = external dso_local global i64, align 8
@p = external dso_local global [100100 x i64], align 16
@.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)
  store i64 1, ptr @p, 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 = %24, %0
  %9 = load i32, ptr %2, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 100100
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %8
  %13 = load i32, ptr %2, align 4, !tbaa !9
  %14 = sub nsw i32 %13, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100100 x i64], ptr @p, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = shl i64 %17, 1
  %19 = load i64, ptr @MOD, align 8, !tbaa !5
  %20 = srem i64 %18, %19
  %21 = load i32, ptr %2, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100100 x i64], ptr @p, i64 0, i64 %22
  store i64 %20, ptr %23, align 8, !tbaa !5
  br label %24

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

27:                                               ; preds = %11
  br label %28

28:                                               ; preds = %108, %27
  %29 = load i32, ptr @t, align 4, !tbaa !9
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr @t, align 4, !tbaa !9
  %31 = icmp ne i32 %29, 0
  br i1 %31, label %32, label %111

32:                                               ; preds = %28
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.memset.p0.i64(ptr align 16 @cnt, i8 0, i64 124, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %68, %32
  %35 = load i32, ptr %3, align 4, !tbaa !9
  %36 = load i32, ptr @n, align 4, !tbaa !9
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %39, label %38

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

39:                                               ; preds = %34
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %41
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %42)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %64, %39
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = icmp sle i32 %45, 30
  br i1 %46, label %48, label %47

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

48:                                               ; preds = %44
  %49 = load i32, ptr %3, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = shl i32 1, %53
  %55 = and i32 %52, %54
  %56 = icmp sgt i32 %55, 0
  br i1 %56, label %57, label %63

57:                                               ; preds = %48
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [31 x i32], ptr @cnt, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %60, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %57, %48
  br label %64

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

67:                                               ; preds = %47
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %3, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %3, align 4, !tbaa !9
  br label %34, !llvm.loop !14

71:                                               ; preds = %38
  store i64 0, ptr @ans, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %105, %71
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = icmp sle i32 %73, 30
  br i1 %74, label %76, label %75

75:                                               ; preds = %72
  store i32 13, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %108

76:                                               ; preds = %72
  %77 = load i32, ptr %6, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [31 x i32], ptr @cnt, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !9
  %81 = icmp sgt i32 %80, 0
  br i1 %81, label %82, label %104

82:                                               ; preds = %76
  %83 = load i32, ptr @n, align 4, !tbaa !9
  %84 = sub nsw i32 %83, 1
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [100100 x i64], ptr @p, i64 0, i64 %85
  %87 = load i64, ptr %86, align 8, !tbaa !5
  %88 = load i32, ptr %6, align 4, !tbaa !9
  %89 = shl i32 1, %88
  %90 = sext i32 %89 to i64
  %91 = mul nsw i64 %87, %90
  %92 = load i64, ptr @MOD, align 8, !tbaa !5
  %93 = srem i64 %91, %92
  %94 = load i64, ptr @ans, align 8, !tbaa !5
  %95 = add nsw i64 %94, %93
  store i64 %95, ptr @ans, align 8, !tbaa !5
  %96 = load i64, ptr @ans, align 8, !tbaa !5
  %97 = load i64, ptr @MOD, align 8, !tbaa !5
  %98 = icmp sge i64 %96, %97
  br i1 %98, label %99, label %103

99:                                               ; preds = %82
  %100 = load i64, ptr @MOD, align 8, !tbaa !5
  %101 = load i64, ptr @ans, align 8, !tbaa !5
  %102 = sub nsw i64 %101, %100
  store i64 %102, ptr @ans, align 8, !tbaa !5
  br label %103

103:                                              ; preds = %99, %82
  br label %104

104:                                              ; preds = %103, %76
  br label %105

105:                                              ; preds = %104
  %106 = load i32, ptr %6, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %6, align 4, !tbaa !9
  br label %72, !llvm.loop !15

108:                                              ; preds = %75
  %109 = load i64, ptr @ans, align 8, !tbaa !5
  %110 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %109)
  br label %28, !llvm.loop !16

111:                                              ; preds = %28
  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

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !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"

@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
@cnt = external dso_local local_unnamed_addr global [31 x i32], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@MOD = external dso_local local_unnamed_addr global i64, align 8
@p = external dso_local local_unnamed_addr global [100100 x i64], align 16
@.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)
  store i64 1, ptr @p, align 16, !tbaa !5
  %2 = load i64, ptr @MOD, align 8, !tbaa !5
  br label %5

.preheader:                                       ; preds = %5
  %3 = load i32, ptr @t, align 4, !tbaa !9
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr @t, align 4, !tbaa !9
  %.not27 = icmp eq i32 %3, 0
  br i1 %.not27, label %._crit_edge29, label %.lr.ph28

5:                                                ; preds = %10, %0
  %6 = phi i64 [ 1, %0 ], [ %12, %10 ]
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next.1, %10 ]
  %7 = shl i64 %6, 1
  %8 = srem i64 %7, %2
  %9 = getelementptr inbounds [100100 x i64], ptr @p, i64 0, i64 %indvars.iv
  store i64 %8, ptr %9, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100100
  br i1 %exitcond.not, label %.preheader, label %10, !llvm.loop !11

10:                                               ; preds = %5
  %11 = shl i64 %8, 1
  %12 = srem i64 %11, %2
  %13 = getelementptr inbounds [100100 x i64], ptr @p, i64 0, i64 %indvars.iv.next
  store i64 %12, ptr %13, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  br label %5

.lr.ph28:                                         ; preds = %.preheader, %46
  %14 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(124) @cnt, i8 0, i64 124, i1 false)
  %15 = load i32, ptr @n, align 4, !tbaa !9
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %24, %.lr.ph28
  %.lcssa = phi i32 [ %15, %.lr.ph28 ], [ %25, %24 ]
  store i64 0, ptr @ans, align 8, !tbaa !5
  %17 = add nsw i32 %.lcssa, -1
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100100 x i64], ptr @p, i64 0, i64 %18
  %20 = load i64, ptr @MOD, align 8
  br label %50

.lr.ph:                                           ; preds = %.lr.ph28, %24
  %indvars.iv36 = phi i64 [ %indvars.iv.next37, %24 ], [ 0, %.lr.ph28 ]
  %21 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %indvars.iv36
  %22 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %21)
  %23 = load i32, ptr %21, align 4, !tbaa !9
  br label %28

24:                                               ; preds = %36
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %25 = load i32, ptr @n, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = icmp slt i64 %indvars.iv.next37, %26
  br i1 %27, label %.lr.ph, label %._crit_edge, !llvm.loop !13

28:                                               ; preds = %45, %.lr.ph
  %indvars.iv32 = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next33.1, %45 ]
  %29 = trunc nuw nsw i64 %indvars.iv32 to i32
  %30 = shl nuw nsw i32 1, %29
  %31 = and i32 %23, %30
  %.not22 = icmp eq i32 %31, 0
  br i1 %.not22, label %36, label %32

32:                                               ; preds = %28
  %33 = getelementptr inbounds [31 x i32], ptr @cnt, i64 0, i64 %indvars.iv32
  %34 = load i32, ptr %33, align 8, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %33, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %28, %32
  %indvars.iv.next33 = or disjoint i64 %indvars.iv32, 1
  %exitcond35.not = icmp eq i64 %indvars.iv32, 30
  br i1 %exitcond35.not, label %24, label %37, !llvm.loop !14

37:                                               ; preds = %36
  %38 = trunc nuw nsw i64 %indvars.iv.next33 to i32
  %39 = shl nuw nsw i32 1, %38
  %40 = and i32 %23, %39
  %.not22.1 = icmp eq i32 %40, 0
  br i1 %.not22.1, label %45, label %41

41:                                               ; preds = %37
  %42 = getelementptr inbounds [31 x i32], ptr @cnt, i64 0, i64 %indvars.iv.next33
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %42, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %41, %37
  %indvars.iv.next33.1 = add nuw nsw i64 %indvars.iv32, 2
  br label %28

46:                                               ; preds = %62
  %47 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %63)
  %48 = load i32, ptr @t, align 4, !tbaa !9
  %49 = add nsw i32 %48, -1
  store i32 %49, ptr @t, align 4, !tbaa !9
  %.not = icmp eq i32 %48, 0
  br i1 %.not, label %._crit_edge29, label %.lr.ph28, !llvm.loop !15

50:                                               ; preds = %._crit_edge, %62
  %indvars.iv39 = phi i64 [ 0, %._crit_edge ], [ %indvars.iv.next40, %62 ]
  %51 = phi i64 [ 0, %._crit_edge ], [ %63, %62 ]
  %52 = getelementptr inbounds [31 x i32], ptr @cnt, i64 0, i64 %indvars.iv39
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = icmp sgt i32 %53, 0
  br i1 %54, label %55, label %62

55:                                               ; preds = %50
  %56 = load i64, ptr %19, align 8, !tbaa !5
  %57 = shl i64 %56, %indvars.iv39
  %58 = srem i64 %57, %20
  %59 = add nsw i64 %51, %58
  store i64 %59, ptr @ans, align 8, !tbaa !5
  %.not21 = icmp slt i64 %59, %20
  br i1 %.not21, label %62, label %60

60:                                               ; preds = %55
  %61 = sub nsw i64 %59, %20
  store i64 %61, ptr @ans, align 8, !tbaa !5
  br label %62

62:                                               ; preds = %50, %60, %55
  %63 = phi i64 [ %51, %50 ], [ %61, %60 ], [ %59, %55 ]
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %exitcond42.not = icmp eq i64 %indvars.iv.next40, 31
  br i1 %exitcond42.not, label %46, label %50, !llvm.loop !16

._crit_edge29:                                    ; preds = %46, %.preheader
  ret i32 0
}

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

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

; 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" }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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