; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/LATGACH3 (lag)

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

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [31 x i32], align 16
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 124, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %5 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 0
  store i32 1, ptr %5, align 16, !tbaa !5
  %6 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 1
  store i32 0, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 2
  store i32 3, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 3
  store i32 0, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 4
  store i32 11, ptr %9, align 16, !tbaa !5
  %10 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 5
  store i32 0, ptr %10, align 4, !tbaa !5
  %11 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 6
  store i32 41, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 7
  store i32 0, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 8
  store i32 153, ptr %13, align 16, !tbaa !5
  %14 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 9
  store i32 0, ptr %14, align 4, !tbaa !5
  %15 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 10
  store i32 571, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 11
  store i32 0, ptr %16, align 4, !tbaa !5
  %17 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 12
  store i32 2131, ptr %17, align 16, !tbaa !5
  %18 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 13
  store i32 0, ptr %18, align 4, !tbaa !5
  %19 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 14
  store i32 7953, ptr %19, align 8, !tbaa !5
  %20 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 15
  store i32 0, ptr %20, align 4, !tbaa !5
  %21 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 16
  store i32 29681, ptr %21, align 16, !tbaa !5
  %22 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 17
  store i32 0, ptr %22, align 4, !tbaa !5
  %23 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 18
  store i32 110771, ptr %23, align 8, !tbaa !5
  %24 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 19
  store i32 0, ptr %24, align 4, !tbaa !5
  %25 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 20
  store i32 413403, ptr %25, align 16, !tbaa !5
  %26 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 21
  store i32 0, ptr %26, align 4, !tbaa !5
  %27 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 22
  store i32 1542841, ptr %27, align 8, !tbaa !5
  %28 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 23
  store i32 0, ptr %28, align 4, !tbaa !5
  %29 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 24
  store i32 5757961, ptr %29, align 16, !tbaa !5
  %30 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 25
  store i32 0, ptr %30, align 4, !tbaa !5
  %31 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 26
  store i32 21489003, ptr %31, align 8, !tbaa !5
  %32 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 27
  store i32 0, ptr %32, align 4, !tbaa !5
  %33 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 28
  store i32 80198051, ptr %33, align 16, !tbaa !5
  %34 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 29
  store i32 0, ptr %34, align 4, !tbaa !5
  %35 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 30
  store i32 299303201, ptr %35, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 4, ptr %4, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %56, %0
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = icmp slt i32 %37, 31
  br i1 %38, label %40, label %39

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

40:                                               ; preds = %36
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sub nsw i32 %41, 2
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = mul nsw i32 %45, 4
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sub nsw i32 %47, 4
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = sub nsw i32 %46, %51
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 %54
  store i32 %52, ptr %55, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %40
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %4, align 4, !tbaa !5
  br label %36, !llvm.loop !9

59:                                               ; preds = %39
  %60 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  br label %61

61:                                               ; preds = %64, %59
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = icmp ne i32 %62, -1
  br i1 %63, label %64, label %72

64:                                               ; preds = %61
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [31 x i32], ptr %2, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %68)
  %70 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %69, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  %71 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  br label %61, !llvm.loop !11

72:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 124, ptr %2) #5
  ret i32 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

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

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #4

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 = { 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 = { 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 #4 = { inlinehint 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 #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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !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"

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [31 x i32], align 16
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 124, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  store <4 x i32> <i32 1, i32 0, i32 3, i32 0>, ptr %1, align 16, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %1, i64 16
  %4 = getelementptr inbounds i8, ptr %1, i64 32
  %5 = getelementptr inbounds i8, ptr %1, i64 48
  %6 = getelementptr inbounds i8, ptr %1, i64 64
  %7 = getelementptr inbounds i8, ptr %1, i64 80
  %8 = getelementptr inbounds i8, ptr %1, i64 96
  %9 = getelementptr inbounds i8, ptr %1, i64 112
  %10 = getelementptr inbounds i8, ptr %1, i64 116
  %11 = getelementptr inbounds i8, ptr %1, i64 120
  store <4 x i32> <i32 11, i32 0, i32 41, i32 0>, ptr %3, align 16, !tbaa !5
  store <4 x i32> <i32 153, i32 0, i32 571, i32 0>, ptr %4, align 16, !tbaa !5
  store <4 x i32> <i32 2131, i32 0, i32 7953, i32 0>, ptr %5, align 16, !tbaa !5
  store <4 x i32> <i32 29681, i32 0, i32 110771, i32 0>, ptr %6, align 16, !tbaa !5
  store <4 x i32> <i32 413403, i32 0, i32 1542841, i32 0>, ptr %7, align 16, !tbaa !5
  store <4 x i32> <i32 5757961, i32 0, i32 21489003, i32 0>, ptr %8, align 16, !tbaa !5
  store i32 80198051, ptr %9, align 16, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !5
  store i32 299303201, ptr %11, align 8, !tbaa !5
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %.not7 = icmp eq i32 %13, -1
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %14 = phi i32 [ %21, %.lr.ph ], [ %13, %0 ]
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [31 x i32], ptr %1, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %17)
  %19 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i32 %21, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 124, ptr nonnull %1) #6
  ret i32 0
}

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

; 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 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #5

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 = { 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 = { "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 = { 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 #5 = { inlinehint 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 #6 = { 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"}


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