; LLVM IR from chirag-singhal/Coding-Interview-101 :: Miscellaneous/Codechef/oclong (2)

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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local 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 i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca [100000 x i64], align 16
  %14 = alloca [100000 x i64], align 16
  %15 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %87, %0
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store i64 0, ptr %12, align 8, !tbaa !9
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5)
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %6)
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %7)
  call void @llvm.lifetime.start.p0(i64 800000, ptr %13) #4
  call void @llvm.memset.p0.i64(ptr align 16 %13, i8 0, i64 800000, i1 false)
  call void @llvm.lifetime.start.p0(i64 800000, ptr %14) #4
  call void @llvm.memset.p0.i64(ptr align 16 %14, i8 0, i64 800000, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store i64 0, ptr %15, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %70, %22
  %27 = load i64, ptr %15, align 8, !tbaa !11
  %28 = load i64, ptr %7, align 8, !tbaa !11
  %29 = icmp slt i64 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %73

31:                                               ; preds = %26
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %8)
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %9)
  %34 = load i64, ptr %8, align 8, !tbaa !11
  %35 = sub nsw i64 %34, 1
  %36 = getelementptr inbounds [100000 x i64], ptr %13, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !11
  %38 = srem i64 %37, 2
  %39 = icmp ne i64 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %31
  %41 = load i64, ptr %11, align 8, !tbaa !9
  %42 = add nsw i64 %41, -1
  store i64 %42, ptr %11, align 8, !tbaa !9
  br label %46

43:                                               ; preds = %31
  %44 = load i64, ptr %11, align 8, !tbaa !9
  %45 = add nsw i64 %44, 1
  store i64 %45, ptr %11, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %43, %40
  %47 = load i64, ptr %9, align 8, !tbaa !11
  %48 = sub nsw i64 %47, 1
  %49 = getelementptr inbounds [100000 x i64], ptr %14, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !11
  %51 = srem i64 %50, 2
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %46
  %54 = load i64, ptr %12, align 8, !tbaa !9
  %55 = add nsw i64 %54, -1
  store i64 %55, ptr %12, align 8, !tbaa !9
  br label %59

56:                                               ; preds = %46
  %57 = load i64, ptr %12, align 8, !tbaa !9
  %58 = add nsw i64 %57, 1
  store i64 %58, ptr %12, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %56, %53
  %60 = load i64, ptr %8, align 8, !tbaa !11
  %61 = sub nsw i64 %60, 1
  %62 = getelementptr inbounds [100000 x i64], ptr %13, i64 0, i64 %61
  %63 = load i64, ptr %62, align 8, !tbaa !11
  %64 = add nsw i64 %63, 1
  store i64 %64, ptr %62, align 8, !tbaa !11
  %65 = load i64, ptr %9, align 8, !tbaa !11
  %66 = sub nsw i64 %65, 1
  %67 = getelementptr inbounds [100000 x i64], ptr %14, i64 0, i64 %66
  %68 = load i64, ptr %67, align 8, !tbaa !11
  %69 = add nsw i64 %68, 1
  store i64 %69, ptr %67, align 8, !tbaa !11
  br label %70

70:                                               ; preds = %59
  %71 = load i64, ptr %15, align 8, !tbaa !11
  %72 = add nsw i64 %71, 1
  store i64 %72, ptr %15, align 8, !tbaa !11
  br label %26, !llvm.loop !13

73:                                               ; preds = %30
  %74 = load i64, ptr %11, align 8, !tbaa !9
  %75 = load i64, ptr %6, align 8, !tbaa !11
  %76 = load i64, ptr %12, align 8, !tbaa !9
  %77 = sub nsw i64 %75, %76
  %78 = mul nsw i64 %74, %77
  %79 = load i64, ptr %12, align 8, !tbaa !9
  %80 = load i64, ptr %5, align 8, !tbaa !11
  %81 = load i64, ptr %11, align 8, !tbaa !9
  %82 = sub nsw i64 %80, %81
  %83 = mul nsw i64 %79, %82
  %84 = add nsw i64 %78, %83
  store i64 %84, ptr %10, align 8, !tbaa !9
  %85 = load i64, ptr %10, align 8, !tbaa !9
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %85)
  call void @llvm.lifetime.end.p0(i64 800000, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 800000, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %87

87:                                               ; preds = %73
  %88 = load i32, ptr %3, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %3, align 4, !tbaa !5
  br label %17, !llvm.loop !15

90:                                               ; preds = %21
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %91 = load i32, ptr %1, align 4
  ret i32 %91
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; 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 = { 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca [100000 x i64], align 16
  %8 = alloca [100000 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph25, label %._crit_edge26

._crit_edge26:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0

.lr.ph25:                                         ; preds = %0, %._crit_edge
  %.01723 = phi i32 [ %25, %._crit_edge ], [ 0, %0 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %4)
  call void @llvm.lifetime.start.p0(i64 800000, ptr nonnull %7) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800000) %7, i8 0, i64 800000, i1 false)
  call void @llvm.lifetime.start.p0(i64 800000, ptr nonnull %8) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800000) %8, i8 0, i64 800000, i1 false)
  %15 = load i64, ptr %4, align 8, !tbaa !9
  %16 = icmp sgt i64 %15, 0
  br i1 %16, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph25
  %.015.lcssa = phi i64 [ 0, %.lr.ph25 ], [ %.116, %.lr.ph ]
  %.014.lcssa = phi i64 [ 0, %.lr.ph25 ], [ %.1, %.lr.ph ]
  %17 = load i64, ptr %3, align 8, !tbaa !9
  %18 = sub nsw i64 %17, %.014.lcssa
  %19 = mul nsw i64 %18, %.015.lcssa
  %20 = load i64, ptr %2, align 8, !tbaa !9
  %21 = sub nsw i64 %20, %.015.lcssa
  %22 = mul nsw i64 %21, %.014.lcssa
  %23 = add nsw i64 %22, %19
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %23)
  call void @llvm.lifetime.end.p0(i64 800000, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 800000, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %25 = add nuw nsw i32 %.01723, 1
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %.lr.ph25, label %._crit_edge26, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph25, %.lr.ph
  %.021 = phi i64 [ %42, %.lr.ph ], [ 0, %.lr.ph25 ]
  %.01420 = phi i64 [ %.1, %.lr.ph ], [ 0, %.lr.ph25 ]
  %.01519 = phi i64 [ %.116, %.lr.ph ], [ 0, %.lr.ph25 ]
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %5)
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %6)
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = add nsw i64 %30, -1
  %32 = getelementptr inbounds [100000 x i64], ptr %7, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = and i64 %33, 1
  %.not = icmp eq i64 %34, 0
  %.116.v = select i1 %.not, i64 1, i64 -1
  %.116 = add nsw i64 %.116.v, %.01519
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = add nsw i64 %35, -1
  %37 = getelementptr inbounds [100000 x i64], ptr %8, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = and i64 %38, 1
  %.not18 = icmp eq i64 %39, 0
  %.1.v = select i1 %.not18, i64 1, i64 -1
  %.1 = add nsw i64 %.1.v, %.01420
  %40 = add nsw i64 %33, 1
  store i64 %40, ptr %32, align 8, !tbaa !9
  %41 = add nsw i64 %38, 1
  store i64 %41, ptr %37, align 8, !tbaa !9
  %42 = add nuw nsw i64 %.021, 1
  %43 = load i64, ptr %4, align 8, !tbaa !9
  %44 = icmp slt i64 %42, %43
  br i1 %44, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

attributes #0 = { nofree 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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