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

@d = external dso_local global [1000001 x i32], align 16
@ok = external dso_local global [1000001 x i32], align 16
@.str = external hidden unnamed_addr constant [4 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
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %39, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 1000001
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %42

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %14 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %14, ptr %4, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %25, %13
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 1000001
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %29

19:                                               ; preds = %15
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %22, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %19
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add nsw i32 %27, %26
  store i32 %28, ptr %4, align 4, !tbaa !5
  br label %15, !llvm.loop !9

29:                                               ; preds = %18
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp sgt i32 %33, 3
  %35 = zext i1 %34 to i32
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1000001 x i32], ptr @ok, i64 0, i64 %37
  store i32 %35, ptr %38, align 4, !tbaa !5
  br label %39

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

42:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %74, %42
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = icmp slt i32 %44, 1000001
  br i1 %45, label %47, label %46

46:                                               ; preds = %43
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %77

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %48 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %48, ptr %6, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %69, %47
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = icmp slt i32 %50, 1000001
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %73

53:                                               ; preds = %49
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = srem i32 %57, %61
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %68

64:                                               ; preds = %53
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [1000001 x i32], ptr @ok, i64 0, i64 %66
  store i32 0, ptr %67, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %64, %53
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = add nsw i32 %71, %70
  store i32 %72, ptr %6, align 4, !tbaa !5
  br label %49, !llvm.loop !12

73:                                               ; preds = %52
  br label %74

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

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

78:                                               ; preds = %96, %77
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = icmp slt i32 %79, 1000001
  br i1 %80, label %82, label %81

81:                                               ; preds = %78
  store i32 14, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %99

82:                                               ; preds = %78
  %83 = load i32, ptr %8, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [1000001 x i32], ptr @ok, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %95

88:                                               ; preds = %82
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %7, align 4, !tbaa !5
  %91 = icmp eq i32 %90, 108
  br i1 %91, label %92, label %95

92:                                               ; preds = %88
  %93 = load i32, ptr %8, align 4, !tbaa !5
  %94 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %93)
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %95

95:                                               ; preds = %92, %88, %82
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %8, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %8, align 4, !tbaa !5
  br label %78, !llvm.loop !14

99:                                               ; preds = %81
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %100 = load i32, ptr %1, align 4
  ret i32 %100
}

; 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 @printf(ptr noundef, ...) #2

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 = { 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}
!12 = distinct !{!12, !10}
!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"

@d = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@ok = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@.str = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  br label %.preheader33

.preheader33:                                     ; preds = %0, %1
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next, %1 ]
  br label %7

1:                                                ; preds = %7
  %2 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %indvars.iv
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 3
  %5 = zext i1 %4 to i32
  %6 = getelementptr inbounds [1000001 x i32], ptr @ok, i64 0, i64 %indvars.iv
  store i32 %5, ptr %6, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1000001
  br i1 %exitcond.not, label %.preheader31, label %.preheader33, !llvm.loop !9

7:                                                ; preds = %.preheader33, %7
  %indvars.iv40 = phi i64 [ %indvars.iv, %.preheader33 ], [ %indvars.iv.next41, %7 ]
  %8 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %indvars.iv40
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %8, align 4, !tbaa !5
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, %indvars.iv
  %11 = icmp ult i64 %indvars.iv.next41, 1000001
  br i1 %11, label %7, label %1, !llvm.loop !11

.preheader31:                                     ; preds = %1, %14
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %14 ], [ 1, %1 ]
  %12 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %indvars.iv44
  %13 = load i32, ptr %12, align 4, !tbaa !5
  br label %15

14:                                               ; preds = %21
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %exitcond50.not = icmp eq i64 %indvars.iv.next45, 1000001
  br i1 %exitcond50.not, label %.preheader, label %.preheader31, !llvm.loop !12

15:                                               ; preds = %.preheader31, %21
  %indvars.iv46 = phi i64 [ %indvars.iv44, %.preheader31 ], [ %indvars.iv.next47, %21 ]
  %16 = getelementptr inbounds [1000001 x i32], ptr @d, i64 0, i64 %indvars.iv46
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = srem i32 %17, %13
  %.not30 = icmp eq i32 %18, 0
  br i1 %.not30, label %21, label %19

19:                                               ; preds = %15
  %20 = getelementptr inbounds [1000001 x i32], ptr @ok, i64 0, i64 %indvars.iv46
  store i32 0, ptr %20, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %15, %19
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, %indvars.iv44
  %22 = icmp ult i64 %indvars.iv.next47, 1000001
  br i1 %22, label %15, label %14, !llvm.loop !13

23:                                               ; preds = %32
  ret i32 0

.preheader:                                       ; preds = %14, %32
  %indvars.iv51 = phi i64 [ %indvars.iv.next52, %32 ], [ 2, %14 ]
  %.02438 = phi i32 [ %.1, %32 ], [ 0, %14 ]
  %24 = getelementptr inbounds [1000001 x i32], ptr @ok, i64 0, i64 %indvars.iv51
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %32, label %26

26:                                               ; preds = %.preheader
  %27 = add nsw i32 %.02438, 1
  %28 = icmp eq i32 %27, 108
  br i1 %28, label %29, label %32

29:                                               ; preds = %26
  %30 = trunc nuw nsw i64 %indvars.iv51 to i32
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %30)
  br label %32

32:                                               ; preds = %.preheader, %26, %29
  %.1 = phi i32 [ 0, %29 ], [ %27, %26 ], [ %.02438, %.preheader ]
  %indvars.iv.next52 = add nuw nsw i64 %indvars.iv51, 1
  %exitcond54.not = icmp eq i64 %indvars.iv.next52, 1000001
  br i1 %exitcond54.not, label %23, label %.preheader, !llvm.loop !14
}

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

!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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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