; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/CURDPROD (curd)

; 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
@T = external dso_local global i32, align 4
@q = external dso_local global [10000 x i32], align 16
@m = external dso_local global i64, align 8
@total = 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5checkRx(ptr noundef nonnull align 8 dereferenceable(8)) #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 norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %7

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

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

13:                                               ; preds = %40, %11
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %43

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10000 x i32], ptr @q, i64 0, i64 %20
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %21)
  %23 = load i64, ptr @m, align 8, !tbaa !9
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10000 x i32], ptr @q, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = icmp sgt i64 %23, %28
  br i1 %29, label %30, label %32

30:                                               ; preds = %18
  %31 = load i64, ptr @m, align 8, !tbaa !9
  br label %38

32:                                               ; preds = %18
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [10000 x i32], ptr @q, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  br label %38

38:                                               ; preds = %32, %30
  %39 = phi i64 [ %31, %30 ], [ %37, %32 ]
  store i64 %39, ptr @m, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %38
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !11

43:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 1, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %44 = load i32, ptr @T, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = load i64, ptr @m, align 8, !tbaa !9
  %47 = mul nsw i64 %45, %46
  store i64 %47, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  br label %48

48:                                               ; preds = %66, %43
  %49 = load i64, ptr %3, align 8, !tbaa !9
  %50 = load i64, ptr %4, align 8, !tbaa !9
  %51 = icmp slt i64 %49, %50
  br i1 %51, label %52, label %67

52:                                               ; preds = %48
  %53 = load i64, ptr %3, align 8, !tbaa !9
  %54 = load i64, ptr %4, align 8, !tbaa !9
  %55 = add nsw i64 %53, %54
  %56 = sdiv i64 %55, 2
  store i64 %56, ptr %5, align 8, !tbaa !9
  call void @_Z5checkRx(ptr noundef nonnull align 8 dereferenceable(8) %5)
  %57 = load i64, ptr @total, align 8, !tbaa !9
  %58 = load i32, ptr @T, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = icmp sge i64 %57, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %52
  %62 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %62, ptr %4, align 8, !tbaa !9
  br label %66

63:                                               ; preds = %52
  %64 = load i64, ptr %5, align 8, !tbaa !9
  %65 = add nsw i64 %64, 1
  store i64 %65, ptr %3, align 8, !tbaa !9
  br label %66

66:                                               ; preds = %63, %61
  br label %48, !llvm.loop !13

67:                                               ; preds = %48
  %68 = load i64, ptr %4, align 8, !tbaa !9
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %68)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %7, !llvm.loop !14

70:                                               ; preds = %7
  ret i32 0
}

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

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

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


; 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
@T = external dso_local global i32, align 4
@q = external dso_local global [10000 x i32], align 16
@m = external dso_local local_unnamed_addr global i64, align 8
@total = 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5checkRx(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #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: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i64, align 8
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %3 = load i32, ptr @t, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr @t, align 4, !tbaa !5
  %.not22 = icmp eq i32 %3, 0
  br i1 %.not22, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %0, %._crit_edge21
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @T)
  store i64 0, ptr @m, align 8, !tbaa !9
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph24
  %8 = phi i64 [ 0, %.lr.ph24 ], [ %., %.lr.ph ]
  %9 = load i32, ptr @T, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = mul nsw i64 %8, %10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %12 = icmp sgt i64 %11, 1
  br i1 %12, label %.lr.ph20, label %._crit_edge21

.lr.ph:                                           ; preds = %.lr.ph24, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph24 ]
  %13 = getelementptr inbounds [10000 x i32], ptr @q, i64 0, i64 %indvars.iv
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %13)
  %15 = load i64, ptr @m, align 8, !tbaa !9
  %16 = load i32, ptr %13, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %. = call i64 @llvm.smax.i64(i64 %15, i64 %17)
  store i64 %., ptr @m, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !11

.lr.ph20:                                         ; preds = %._crit_edge, %.lr.ph20
  %.018 = phi i64 [ %.1, %.lr.ph20 ], [ %11, %._crit_edge ]
  %.01017 = phi i64 [ %.111, %.lr.ph20 ], [ 1, %._crit_edge ]
  %21 = add nsw i64 %.018, %.01017
  %22 = sdiv i64 %21, 2
  store i64 %22, ptr %1, align 8, !tbaa !9
  call void @_Z5checkRx(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %23 = load i64, ptr @total, align 8, !tbaa !9
  %24 = load i32, ptr @T, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %.not15 = icmp slt i64 %23, %25
  %26 = load i64, ptr %1, align 8
  %27 = add nsw i64 %26, 1
  %.111 = select i1 %.not15, i64 %27, i64 %.01017
  %.1 = select i1 %.not15, i64 %.018, i64 %26
  %28 = icmp slt i64 %.111, %.1
  br i1 %28, label %.lr.ph20, label %._crit_edge21, !llvm.loop !13

._crit_edge21:                                    ; preds = %.lr.ph20, %._crit_edge
  %.0.lcssa = phi i64 [ %11, %._crit_edge ], [ %.1, %.lr.ph20 ]
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.0.lcssa)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  %30 = load i32, ptr @t, align 4, !tbaa !5
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %._crit_edge25, label %.lr.ph24, !llvm.loop !14

._crit_edge25:                                    ; preds = %._crit_edge21, %0
  ret i32 0
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #4

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!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}


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