; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Company Contests/Cisco iCode/iCode/Problem A (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"

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

@n = external dso_local global i32, align 4
@a = external dso_local global [100100 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z1fx(i64 noundef) #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 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 i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %14

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

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %27

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %21
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %22)
  br label %24

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

27:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 10000, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %69, %27
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = icmp slt i32 %29, 100
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %72

32:                                               ; preds = %28
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sub nsw i32 %34, %35
  %37 = sdiv i32 %36, 3
  %38 = add nsw i32 %33, %37
  store i32 %38, ptr %5, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sub nsw i32 %40, %41
  %43 = sdiv i32 %42, 3
  %44 = sub nsw i32 %39, %43
  store i32 %44, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = call noundef i64 @_Z1fx(i64 noundef %46)
  store i64 %47, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = call noundef i64 @_Z1fx(i64 noundef %49)
  store i64 %50, ptr %9, align 8, !tbaa !11
  %51 = load i64, ptr %8, align 8, !tbaa !11
  %52 = load i64, ptr %9, align 8, !tbaa !11
  %53 = icmp slt i64 %51, %52
  br i1 %53, label %54, label %57

54:                                               ; preds = %32
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = sub nsw i32 %55, 1
  store i32 %56, ptr %4, align 4, !tbaa !5
  br label %68

57:                                               ; preds = %32
  %58 = load i64, ptr %8, align 8, !tbaa !11
  %59 = load i64, ptr %9, align 8, !tbaa !11
  %60 = icmp sgt i64 %58, %59
  br i1 %60, label %61, label %64

61:                                               ; preds = %57
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %3, align 4, !tbaa !5
  br label %67

64:                                               ; preds = %57
  %65 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %65, ptr %3, align 4, !tbaa !5
  %66 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %66, ptr %4, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %64, %61
  br label %68

68:                                               ; preds = %67, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %7, align 4, !tbaa !5
  br label %28, !llvm.loop !13

72:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 1000000000000000000, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 -1, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %73 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %73, ptr %12, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %91, %72
  %75 = load i32, ptr %12, align 4, !tbaa !5
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = icmp sle i32 %75, %76
  br i1 %77, label %79, label %78

78:                                               ; preds = %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %94

79:                                               ; preds = %74
  %80 = load i32, ptr %12, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = call noundef i64 @_Z1fx(i64 noundef %81)
  %83 = load i64, ptr %10, align 8, !tbaa !11
  %84 = icmp slt i64 %82, %83
  br i1 %84, label %85, label %90

85:                                               ; preds = %79
  %86 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %86, ptr %11, align 4, !tbaa !5
  %87 = load i32, ptr %12, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = call noundef i64 @_Z1fx(i64 noundef %88)
  store i64 %89, ptr %10, align 8, !tbaa !11
  br label %90

90:                                               ; preds = %85, %79
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %12, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %12, align 4, !tbaa !5
  br label %74, !llvm.loop !14

94:                                               ; preds = %78
  %95 = load i32, ptr %11, align 4, !tbaa !5
  %96 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %95)
  %97 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %96, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret i32 0
}

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

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #0 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 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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!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"

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

@n = external dso_local global i32, align 4
@a = external dso_local global [100100 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z1fx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.preheader42.preheader

.preheader42.preheader:                           ; preds = %.lr.ph, %0
  br label %.preheader42

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %4 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %indvars.iv
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %4)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = icmp slt i64 %indvars.iv.next, %7
  br i1 %8, label %.lr.ph, label %.preheader42.preheader, !llvm.loop !9

.preheader:                                       ; preds = %25
  %.not47 = icmp sgt i32 %.135, %.138
  br i1 %.not47, label %._crit_edge, label %.lr.ph51.preheader

.lr.ph51.preheader:                               ; preds = %.preheader
  %9 = sext i32 %.135 to i64
  %10 = add i32 %.138, 1
  br label %.lr.ph51

.preheader42:                                     ; preds = %.preheader42.preheader, %25
  %.03446 = phi i32 [ %.135, %25 ], [ 0, %.preheader42.preheader ]
  %.03645 = phi i32 [ %26, %25 ], [ 0, %.preheader42.preheader ]
  %.03744 = phi i32 [ %.138, %25 ], [ 10000, %.preheader42.preheader ]
  %11 = sub nsw i32 %.03744, %.03446
  %12 = sdiv i32 %11, 3
  %13 = add nsw i32 %12, %.03446
  %14 = sub nsw i32 %.03744, %12
  %15 = sext i32 %13 to i64
  %16 = tail call noundef i64 @_Z1fx(i64 noundef %15)
  %17 = sext i32 %14 to i64
  %18 = tail call noundef i64 @_Z1fx(i64 noundef %17)
  %19 = icmp slt i64 %16, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %.preheader42
  %21 = add nsw i32 %14, -1
  br label %25

22:                                               ; preds = %.preheader42
  %23 = icmp sgt i64 %16, %18
  %spec.select = select i1 %23, i32 %.03744, i32 %14
  %24 = zext i1 %23 to i32
  %spec.select41 = add nsw i32 %13, %24
  br label %25

25:                                               ; preds = %22, %20
  %.138 = phi i32 [ %21, %20 ], [ %spec.select, %22 ]
  %.135 = phi i32 [ %.03446, %20 ], [ %spec.select41, %22 ]
  %26 = add nuw nsw i32 %.03645, 1
  %exitcond.not = icmp eq i32 %26, 100
  br i1 %exitcond.not, label %.preheader, label %.preheader42, !llvm.loop !11

._crit_edge:                                      ; preds = %34, %.preheader
  %.030.lcssa = phi i32 [ -1, %.preheader ], [ %.1, %34 ]
  %27 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %.030.lcssa)
  %28 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %27, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

.lr.ph51:                                         ; preds = %.lr.ph51.preheader, %34
  %indvars.iv53 = phi i64 [ %9, %.lr.ph51.preheader ], [ %indvars.iv.next54, %34 ]
  %.03049 = phi i32 [ -1, %.lr.ph51.preheader ], [ %.1, %34 ]
  %.03148 = phi i64 [ 1000000000000000000, %.lr.ph51.preheader ], [ %.132, %34 ]
  %29 = tail call noundef i64 @_Z1fx(i64 noundef %indvars.iv53)
  %30 = icmp slt i64 %29, %.03148
  br i1 %30, label %31, label %34

31:                                               ; preds = %.lr.ph51
  %32 = tail call noundef i64 @_Z1fx(i64 noundef %indvars.iv53)
  %33 = trunc nsw i64 %indvars.iv53 to i32
  br label %34

34:                                               ; preds = %.lr.ph51, %31
  %.132 = phi i64 [ %32, %31 ], [ %.03148, %.lr.ph51 ]
  %.1 = phi i32 [ %33, %31 ], [ %.03049, %.lr.ph51 ]
  %indvars.iv.next54 = add nsw i64 %indvars.iv53, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next54 to i32
  %exitcond56.not = icmp eq i32 %10, %lftr.wideiv
  br i1 %exitcond56.not, label %._crit_edge, label %.lr.ph51, !llvm.loop !12
}

; 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 #0 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 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 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 #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 = { 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" }

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


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