; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Game Theory/Problem H (H)

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

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

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

14:                                               ; preds = %10
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1001000 x i32], ptr @g, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %53, label %20

20:                                               ; preds = %14
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1001000 x i32], ptr @g, i64 0, i64 %22
  store i32 1, ptr %23, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = add nsw i32 %24, %25
  store i32 %26, ptr %4, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %48, %20
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp slt i32 %28, 1001000
  br i1 %29, label %31, label %30

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

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %32 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %32, ptr %5, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %38, %31
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = srem i32 %34, %35
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %47

38:                                               ; preds = %33
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [1001000 x i32], ptr @g, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %41, align 4, !tbaa !5
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sdiv i32 %45, %44
  store i32 %46, ptr %5, align 4, !tbaa !5
  br label %33, !llvm.loop !9

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

48:                                               ; preds = %47
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = add nsw i32 %50, %49
  store i32 %51, ptr %4, align 4, !tbaa !5
  br label %27, !llvm.loop !11

52:                                               ; preds = %30
  br label %53

53:                                               ; preds = %52, %14
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !12

57:                                               ; preds = %13
  %58 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %59

59:                                               ; preds = %88, %57
  %60 = load i32, ptr @t, align 4, !tbaa !5
  %61 = add nsw i32 %60, -1
  store i32 %61, ptr @t, align 4, !tbaa !5
  %62 = icmp ne i32 %60, 0
  br i1 %62, label %63, label %89

63:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %64 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6)
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %78, %63
  %66 = load i32, ptr %9, align 4, !tbaa !5
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %70, label %69

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

70:                                               ; preds = %65
  %71 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %8)
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [1001000 x i32], ptr @g, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = xor i32 %76, %75
  store i32 %77, ptr %7, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %70
  %79 = load i32, ptr %9, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %9, align 4, !tbaa !5
  br label %65, !llvm.loop !13

81:                                               ; preds = %69
  %82 = load i32, ptr %7, align 4, !tbaa !5
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %86

84:                                               ; preds = %81
  %85 = call i32 @puts(ptr noundef @.str.1)
  br label %88

86:                                               ; preds = %81
  %87 = call i32 @puts(ptr noundef @.str.2)
  br label %88

88:                                               ; preds = %86, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %59, !llvm.loop !14

89:                                               ; preds = %59
  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 i32 @puts(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"

@t = external dso_local global i32, align 4
@g = external dso_local local_unnamed_addr global [1001000 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  br label %7

3:                                                ; preds = %.loopexit
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %5 = load i32, ptr @t, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !5
  %.not34 = icmp eq i32 %5, 0
  br i1 %.not34, label %._crit_edge37, label %.lr.ph36

7:                                                ; preds = %0, %.loopexit
  %indvars.iv39 = phi i64 [ 2, %0 ], [ %indvars.iv.next40, %.loopexit ]
  %indvars.iv = phi i64 [ 4, %0 ], [ %indvars.iv.next, %.loopexit ]
  %8 = getelementptr inbounds [1001000 x i32], ptr @g, i64 0, i64 %indvars.iv39
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not24 = icmp eq i32 %9, 0
  br i1 %.not24, label %10, label %.loopexit

10:                                               ; preds = %7
  store i32 1, ptr %8, align 4, !tbaa !5
  %11 = icmp ult i64 %indvars.iv39, 500500
  br i1 %11, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %10
  %12 = trunc nuw nsw i64 %indvars.iv39 to i32
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %23
  %indvars.iv41 = phi i64 [ %indvars.iv, %.preheader.preheader ], [ %indvars.iv.next42, %23 ]
  %13 = trunc nuw nsw i64 %indvars.iv41 to i32
  %14 = urem i32 %13, %12
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %.lr.ph, label %23

.lr.ph:                                           ; preds = %.preheader
  %16 = getelementptr inbounds [1001000 x i32], ptr @g, i64 0, i64 %indvars.iv41
  %.promoted = load i32, ptr %16, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %.lr.ph, %17
  %18 = phi i32 [ %.promoted, %.lr.ph ], [ %19, %17 ]
  %.02025 = phi i32 [ %13, %.lr.ph ], [ %20, %17 ]
  %19 = add nsw i32 %18, 1
  %20 = sdiv i32 %.02025, %12
  %21 = srem i32 %20, %12
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %17, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %17
  store i32 %19, ptr %16, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %._crit_edge, %.preheader
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, %indvars.iv39
  %24 = icmp ult i64 %indvars.iv.next42, 1001000
  br i1 %24, label %.preheader, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %23, %10, %7
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not = icmp eq i64 %indvars.iv.next40, 1001000
  br i1 %exitcond.not, label %3, label %7, !llvm.loop !12

.lr.ph36:                                         ; preds = %3, %37
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %.lr.ph32, label %._crit_edge33.thread

._crit_edge33:                                    ; preds = %.lr.ph32
  %.not23 = icmp eq i32 %32, %.01929
  br i1 %.not23, label %._crit_edge33.thread, label %37

.lr.ph32:                                         ; preds = %.lr.ph36, %.lr.ph32
  %.030 = phi i32 [ %34, %.lr.ph32 ], [ 0, %.lr.ph36 ]
  %.01929 = phi i32 [ %33, %.lr.ph32 ], [ 0, %.lr.ph36 ]
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1001000 x i32], ptr @g, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = xor i32 %32, %.01929
  %34 = add nuw nsw i32 %.030, 1
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %.lr.ph32, label %._crit_edge33, !llvm.loop !13

._crit_edge33.thread:                             ; preds = %.lr.ph36, %._crit_edge33
  br label %37

37:                                               ; preds = %._crit_edge33, %._crit_edge33.thread
  %.str.2.sink = phi ptr [ @.str.2, %._crit_edge33.thread ], [ @.str.1, %._crit_edge33 ]
  %38 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.2.sink)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  %39 = load i32, ptr @t, align 4, !tbaa !5
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %39, 0
  br i1 %.not, label %._crit_edge37, label %.lr.ph36, !llvm.loop !14

._crit_edge37:                                    ; preds = %37, %3
  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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

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


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