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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@a = external dso_local global [131072 x i32], align 16
@ans = 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 [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11sparseTablev() #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3rmqii(i32 noundef, i32 noundef) #0

; 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
  %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 @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %18, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp slt 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 %21

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [131072 x i32], ptr @a, i64 0, i64 %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %16)
  br label %18

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

21:                                               ; preds = %12
  call void @_Z11sparseTablev()
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @m, ptr noundef @x, ptr noundef @y)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1
  store i32 %24, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %25 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %25, ptr %4, align 4, !tbaa !5
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = icmp sge i32 %26, 11
  br i1 %27, label %28, label %77

28:                                               ; preds = %21
  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 = %73, %28
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = load i32, ptr @m, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %29
  %35 = load i32, ptr @x, align 4, !tbaa !5
  %36 = load i32, ptr @y, align 4, !tbaa !5
  %37 = icmp sle i32 %35, %36
  br i1 %37, label %38, label %45

38:                                               ; preds = %34
  %39 = load i32, ptr @x, align 4, !tbaa !5
  %40 = load i32, ptr @y, align 4, !tbaa !5
  %41 = call noundef i32 @_Z3rmqii(i32 noundef %39, i32 noundef %40)
  %42 = sext i32 %41 to i64
  %43 = load i64, ptr @ans, align 8, !tbaa !11
  %44 = add nsw i64 %43, %42
  store i64 %44, ptr @ans, align 8, !tbaa !11
  br label %52

45:                                               ; preds = %34
  %46 = load i32, ptr @y, align 4, !tbaa !5
  %47 = load i32, ptr @x, align 4, !tbaa !5
  %48 = call noundef i32 @_Z3rmqii(i32 noundef %46, i32 noundef %47)
  %49 = sext i32 %48 to i64
  %50 = load i64, ptr @ans, align 8, !tbaa !11
  %51 = add nsw i64 %50, %49
  store i64 %51, ptr @ans, align 8, !tbaa !11
  br label %52

52:                                               ; preds = %45, %38
  %53 = load i32, ptr @x, align 4, !tbaa !5
  %54 = add nsw i32 %53, 7
  store i32 %54, ptr @x, align 4, !tbaa !5
  %55 = load i32, ptr @y, align 4, !tbaa !5
  %56 = add nsw i32 %55, 11
  store i32 %56, ptr @y, align 4, !tbaa !5
  %57 = load i32, ptr @x, align 4, !tbaa !5
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = icmp sge i32 %57, %58
  br i1 %59, label %60, label %64

60:                                               ; preds = %52
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = load i32, ptr @x, align 4, !tbaa !5
  %63 = sub nsw i32 %62, %61
  store i32 %63, ptr @x, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %60, %52
  %65 = load i32, ptr @y, align 4, !tbaa !5
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = icmp sge i32 %65, %66
  br i1 %67, label %68, label %72

68:                                               ; preds = %64
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = load i32, ptr @y, align 4, !tbaa !5
  %71 = sub nsw i32 %70, %69
  store i32 %71, ptr @y, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %68, %64
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %5, align 4, !tbaa !5
  br label %29, !llvm.loop !13

76:                                               ; preds = %33
  br label %114

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

78:                                               ; preds = %110, %77
  %79 = load i32, ptr %6, align 4, !tbaa !5
  %80 = load i32, ptr @m, align 4, !tbaa !5
  %81 = icmp slt i32 %79, %80
  br i1 %81, label %83, label %82

82:                                               ; preds = %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %113

83:                                               ; preds = %78
  %84 = load i32, ptr @x, align 4, !tbaa !5
  %85 = load i32, ptr @y, align 4, !tbaa !5
  %86 = icmp sle i32 %84, %85
  br i1 %86, label %87, label %94

87:                                               ; preds = %83
  %88 = load i32, ptr @x, align 4, !tbaa !5
  %89 = load i32, ptr @y, align 4, !tbaa !5
  %90 = call noundef i32 @_Z3rmqii(i32 noundef %88, i32 noundef %89)
  %91 = sext i32 %90 to i64
  %92 = load i64, ptr @ans, align 8, !tbaa !11
  %93 = add nsw i64 %92, %91
  store i64 %93, ptr @ans, align 8, !tbaa !11
  br label %101

94:                                               ; preds = %83
  %95 = load i32, ptr @y, align 4, !tbaa !5
  %96 = load i32, ptr @x, align 4, !tbaa !5
  %97 = call noundef i32 @_Z3rmqii(i32 noundef %95, i32 noundef %96)
  %98 = sext i32 %97 to i64
  %99 = load i64, ptr @ans, align 8, !tbaa !11
  %100 = add nsw i64 %99, %98
  store i64 %100, ptr @ans, align 8, !tbaa !11
  br label %101

101:                                              ; preds = %94, %87
  %102 = load i32, ptr @x, align 4, !tbaa !5
  %103 = add nsw i32 %102, 7
  %104 = load i32, ptr %3, align 4, !tbaa !5
  %105 = srem i32 %103, %104
  store i32 %105, ptr @x, align 4, !tbaa !5
  %106 = load i32, ptr @y, align 4, !tbaa !5
  %107 = add nsw i32 %106, 11
  %108 = load i32, ptr %4, align 4, !tbaa !5
  %109 = srem i32 %107, %108
  store i32 %109, ptr @y, align 4, !tbaa !5
  br label %110

110:                                              ; preds = %101
  %111 = load i32, ptr %6, align 4, !tbaa !5
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %6, align 4, !tbaa !5
  br label %78, !llvm.loop !14

113:                                              ; preds = %82
  br label %114

114:                                              ; preds = %113, %76
  %115 = load i64, ptr @ans, align 8, !tbaa !11
  %116 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %115)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 0
}

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

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

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


; 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
@m = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@a = external dso_local global [131072 x i32], align 16
@ans = 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 [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11sparseTablev() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3rmqii(i32 noundef, i32 noundef) local_unnamed_addr #0

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

._crit_edge:                                      ; preds = %.lr.ph, %0
  tail call void @_Z11sparseTablev()
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @m, ptr noundef nonnull @x, ptr noundef nonnull @y)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  %7 = icmp sgt i32 %5, 10
  %8 = load i32, ptr @m, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %7, label %.preheader, label %.preheader30

.preheader30:                                     ; preds = %._crit_edge
  br i1 %9, label %.lr.ph34.preheader, label %.loopexit

.lr.ph34.preheader:                               ; preds = %.preheader30
  %.pre = load i32, ptr @x, align 4, !tbaa !5
  %.pre39 = load i32, ptr @y, align 4, !tbaa !5
  br label %.lr.ph34

.preheader:                                       ; preds = %._crit_edge
  br i1 %9, label %.lr.ph36.preheader, label %.loopexit

.lr.ph36.preheader:                               ; preds = %.preheader
  %.pre40 = load i32, ptr @x, align 4, !tbaa !5
  %.pre41 = load i32, ptr @y, align 4, !tbaa !5
  br label %.lr.ph36

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

.lr.ph36:                                         ; preds = %.lr.ph36.preheader, %35
  %15 = phi i32 [ %36, %35 ], [ %.pre41, %.lr.ph36.preheader ]
  %16 = phi i32 [ %32, %35 ], [ %.pre40, %.lr.ph36.preheader ]
  %.01335 = phi i32 [ %37, %35 ], [ 0, %.lr.ph36.preheader ]
  %.not26 = icmp sgt i32 %16, %15
  br i1 %.not26, label %19, label %17

17:                                               ; preds = %.lr.ph36
  %18 = tail call noundef i32 @_Z3rmqii(i32 noundef %16, i32 noundef %15)
  br label %21

19:                                               ; preds = %.lr.ph36
  %20 = tail call noundef i32 @_Z3rmqii(i32 noundef %15, i32 noundef %16)
  br label %21

21:                                               ; preds = %19, %17
  %.sink = phi i32 [ %20, %19 ], [ %18, %17 ]
  %22 = sext i32 %.sink to i64
  %23 = load i64, ptr @ans, align 8, !tbaa !11
  %24 = add nsw i64 %23, %22
  store i64 %24, ptr @ans, align 8, !tbaa !11
  %25 = load i32, ptr @x, align 4, !tbaa !5
  %26 = add nsw i32 %25, 7
  store i32 %26, ptr @x, align 4, !tbaa !5
  %27 = load i32, ptr @y, align 4, !tbaa !5
  %28 = add nsw i32 %27, 11
  store i32 %28, ptr @y, align 4, !tbaa !5
  %.not28 = icmp slt i32 %26, %6
  br i1 %.not28, label %31, label %29

29:                                               ; preds = %21
  %30 = sub nsw i32 %26, %6
  store i32 %30, ptr @x, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %29, %21
  %32 = phi i32 [ %30, %29 ], [ %26, %21 ]
  %.not29 = icmp slt i32 %28, %5
  br i1 %.not29, label %35, label %33

33:                                               ; preds = %31
  %34 = sub nsw i32 %28, %5
  store i32 %34, ptr @y, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %31, %33
  %36 = phi i32 [ %28, %31 ], [ %34, %33 ]
  %37 = add nuw nsw i32 %.01335, 1
  %38 = load i32, ptr @m, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %.lr.ph36, label %.loopexit, !llvm.loop !13

.lr.ph34:                                         ; preds = %.lr.ph34.preheader, %46
  %40 = phi i32 [ %55, %46 ], [ %.pre39, %.lr.ph34.preheader ]
  %41 = phi i32 [ %52, %46 ], [ %.pre, %.lr.ph34.preheader ]
  %.033 = phi i32 [ %56, %46 ], [ 0, %.lr.ph34.preheader ]
  %.not = icmp sgt i32 %41, %40
  br i1 %.not, label %44, label %42

42:                                               ; preds = %.lr.ph34
  %43 = tail call noundef i32 @_Z3rmqii(i32 noundef %41, i32 noundef %40)
  br label %46

44:                                               ; preds = %.lr.ph34
  %45 = tail call noundef i32 @_Z3rmqii(i32 noundef %40, i32 noundef %41)
  br label %46

46:                                               ; preds = %44, %42
  %.sink46 = phi i32 [ %45, %44 ], [ %43, %42 ]
  %47 = sext i32 %.sink46 to i64
  %48 = load i64, ptr @ans, align 8, !tbaa !11
  %49 = add nsw i64 %48, %47
  store i64 %49, ptr @ans, align 8, !tbaa !11
  %50 = load i32, ptr @x, align 4, !tbaa !5
  %51 = add nsw i32 %50, 7
  %52 = srem i32 %51, %6
  store i32 %52, ptr @x, align 4, !tbaa !5
  %53 = load i32, ptr @y, align 4, !tbaa !5
  %54 = add nsw i32 %53, 11
  %55 = srem i32 %54, %5
  store i32 %55, ptr @y, align 4, !tbaa !5
  %56 = add nuw nsw i32 %.033, 1
  %57 = load i32, ptr @m, align 4, !tbaa !5
  %58 = icmp slt i32 %56, %57
  br i1 %58, label %.lr.ph34, label %.loopexit, !llvm.loop !14

.loopexit:                                        ; preds = %46, %35, %.preheader30, %.preheader
  %59 = load i64, ptr @ans, align 8, !tbaa !11
  %60 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %59)
  ret i32 0
}

; 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 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 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 = !{!"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}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass