; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 199A. Hexadecimal's theorem (main)

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

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

8:                                                ; preds = %26, %0
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 46
  br i1 %10, label %11, label %29

11:                                               ; preds = %8
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sub nsw i32 %12, 1
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [46 x i32], ptr @arr, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sub nsw i32 %17, 2
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [46 x i32], ptr @arr, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %16, %21
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [46 x i32], ptr @arr, i64 0, i64 %24
  store i32 %22, ptr %25, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %11
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %3, align 4, !tbaa !5
  br label %8, !llvm.loop !9

29:                                               ; preds = %8
  br label %30

30:                                               ; preds = %66, %29
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %32 = icmp ne i32 %31, -1
  br i1 %32, label %33, label %68

33:                                               ; preds = %30
  store i32 0, ptr %6, align 4, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %58, %33
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [46 x i32], ptr @arr, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = mul nsw i32 2, %38
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %42, label %61

42:                                               ; preds = %34
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [46 x i32], ptr @arr, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  store i32 %46, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sub nsw i32 %47, %48
  store i32 %49, ptr %7, align 4, !tbaa !5
  %50 = call noundef zeroext i1 @_ZSt13binary_searchIPiiEbT_S1_RKT0_(ptr noundef @arr, ptr noundef getelementptr inbounds (i32, ptr @arr, i64 46), ptr noundef nonnull align 4 dereferenceable(4) %7)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br i1 %50, label %51, label %57

51:                                               ; preds = %42
  store i32 1, ptr %6, align 4, !tbaa !5
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sub nsw i32 %53, %54
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %52, i32 noundef %55)
  br label %61

57:                                               ; preds = %42
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %3, align 4, !tbaa !5
  br label %34, !llvm.loop !11

61:                                               ; preds = %51, %34
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %66

64:                                               ; preds = %61
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %66

66:                                               ; preds = %64, %61
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %30, !llvm.loop !12

68:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

; 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: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZSt13binary_searchIPiiEbT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #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 = { 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 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !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"

@arr = external dso_local global [46 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.preheader14:
  %0 = alloca i32, align 4
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %0) #4
  store i32 0, ptr @arr, align 16, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @arr, i64 4), align 4, !tbaa !5
  %2 = load i32, ptr @arr, align 16, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr getelementptr inbounds (i8, ptr @arr, i64 8), align 8, !tbaa !5
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @arr, i64 4), align 4, !tbaa !5
  %5 = add nsw i32 %4, %3
  store i32 %5, ptr getelementptr inbounds (i8, ptr @arr, i64 12), align 4, !tbaa !5
  %6 = add nsw i32 %3, %5
  store i32 %6, ptr getelementptr inbounds (i8, ptr @arr, i64 16), align 16, !tbaa !5
  %7 = add nsw i32 %5, %6
  store i32 %7, ptr getelementptr inbounds (i8, ptr @arr, i64 20), align 4, !tbaa !5
  %8 = add nsw i32 %6, %7
  store i32 %8, ptr getelementptr inbounds (i8, ptr @arr, i64 24), align 8, !tbaa !5
  %9 = add nsw i32 %7, %8
  store i32 %9, ptr getelementptr inbounds (i8, ptr @arr, i64 28), align 4, !tbaa !5
  %10 = add nsw i32 %8, %9
  store i32 %10, ptr getelementptr inbounds (i8, ptr @arr, i64 32), align 16, !tbaa !5
  %11 = add nsw i32 %9, %10
  store i32 %11, ptr getelementptr inbounds (i8, ptr @arr, i64 36), align 4, !tbaa !5
  %12 = add nsw i32 %10, %11
  store i32 %12, ptr getelementptr inbounds (i8, ptr @arr, i64 40), align 8, !tbaa !5
  %13 = add nsw i32 %11, %12
  store i32 %13, ptr getelementptr inbounds (i8, ptr @arr, i64 44), align 4, !tbaa !5
  %14 = add nsw i32 %12, %13
  store i32 %14, ptr getelementptr inbounds (i8, ptr @arr, i64 48), align 16, !tbaa !5
  %15 = add nsw i32 %13, %14
  store i32 %15, ptr getelementptr inbounds (i8, ptr @arr, i64 52), align 4, !tbaa !5
  %16 = add nsw i32 %14, %15
  store i32 %16, ptr getelementptr inbounds (i8, ptr @arr, i64 56), align 8, !tbaa !5
  %17 = add nsw i32 %15, %16
  store i32 %17, ptr getelementptr inbounds (i8, ptr @arr, i64 60), align 4, !tbaa !5
  %18 = add nsw i32 %16, %17
  store i32 %18, ptr getelementptr inbounds (i8, ptr @arr, i64 64), align 16, !tbaa !5
  %19 = add nsw i32 %17, %18
  store i32 %19, ptr getelementptr inbounds (i8, ptr @arr, i64 68), align 4, !tbaa !5
  %20 = add nsw i32 %18, %19
  store i32 %20, ptr getelementptr inbounds (i8, ptr @arr, i64 72), align 8, !tbaa !5
  %21 = add nsw i32 %19, %20
  store i32 %21, ptr getelementptr inbounds (i8, ptr @arr, i64 76), align 4, !tbaa !5
  %22 = add nsw i32 %20, %21
  store i32 %22, ptr getelementptr inbounds (i8, ptr @arr, i64 80), align 16, !tbaa !5
  %23 = add nsw i32 %21, %22
  store i32 %23, ptr getelementptr inbounds (i8, ptr @arr, i64 84), align 4, !tbaa !5
  %24 = add nsw i32 %22, %23
  store i32 %24, ptr getelementptr inbounds (i8, ptr @arr, i64 88), align 8, !tbaa !5
  %25 = add nsw i32 %23, %24
  store i32 %25, ptr getelementptr inbounds (i8, ptr @arr, i64 92), align 4, !tbaa !5
  %26 = add nsw i32 %24, %25
  store i32 %26, ptr getelementptr inbounds (i8, ptr @arr, i64 96), align 16, !tbaa !5
  %27 = add nsw i32 %25, %26
  store i32 %27, ptr getelementptr inbounds (i8, ptr @arr, i64 100), align 4, !tbaa !5
  %28 = add nsw i32 %26, %27
  store i32 %28, ptr getelementptr inbounds (i8, ptr @arr, i64 104), align 8, !tbaa !5
  %29 = add nsw i32 %27, %28
  store i32 %29, ptr getelementptr inbounds (i8, ptr @arr, i64 108), align 4, !tbaa !5
  %30 = add nsw i32 %28, %29
  store i32 %30, ptr getelementptr inbounds (i8, ptr @arr, i64 112), align 16, !tbaa !5
  %31 = add nsw i32 %29, %30
  store i32 %31, ptr getelementptr inbounds (i8, ptr @arr, i64 116), align 4, !tbaa !5
  %32 = add nsw i32 %30, %31
  store i32 %32, ptr getelementptr inbounds (i8, ptr @arr, i64 120), align 8, !tbaa !5
  %33 = add nsw i32 %31, %32
  store i32 %33, ptr getelementptr inbounds (i8, ptr @arr, i64 124), align 4, !tbaa !5
  %34 = add nsw i32 %32, %33
  store i32 %34, ptr getelementptr inbounds (i8, ptr @arr, i64 128), align 16, !tbaa !5
  %35 = add nsw i32 %33, %34
  store i32 %35, ptr getelementptr inbounds (i8, ptr @arr, i64 132), align 4, !tbaa !5
  %36 = add nsw i32 %34, %35
  store i32 %36, ptr getelementptr inbounds (i8, ptr @arr, i64 136), align 8, !tbaa !5
  %37 = add nsw i32 %35, %36
  store i32 %37, ptr getelementptr inbounds (i8, ptr @arr, i64 140), align 4, !tbaa !5
  %38 = add nsw i32 %36, %37
  store i32 %38, ptr getelementptr inbounds (i8, ptr @arr, i64 144), align 16, !tbaa !5
  %39 = add nsw i32 %37, %38
  store i32 %39, ptr getelementptr inbounds (i8, ptr @arr, i64 148), align 4, !tbaa !5
  %40 = add nsw i32 %38, %39
  store i32 %40, ptr getelementptr inbounds (i8, ptr @arr, i64 152), align 8, !tbaa !5
  %41 = add nsw i32 %39, %40
  store i32 %41, ptr getelementptr inbounds (i8, ptr @arr, i64 156), align 4, !tbaa !5
  %42 = add nsw i32 %40, %41
  store i32 %42, ptr getelementptr inbounds (i8, ptr @arr, i64 160), align 16, !tbaa !5
  %43 = add nsw i32 %41, %42
  store i32 %43, ptr getelementptr inbounds (i8, ptr @arr, i64 164), align 4, !tbaa !5
  %44 = add nsw i32 %42, %43
  store i32 %44, ptr getelementptr inbounds (i8, ptr @arr, i64 168), align 8, !tbaa !5
  %45 = add nsw i32 %43, %44
  store i32 %45, ptr getelementptr inbounds (i8, ptr @arr, i64 172), align 4, !tbaa !5
  %46 = add nsw i32 %44, %45
  store i32 %46, ptr getelementptr inbounds (i8, ptr @arr, i64 176), align 16, !tbaa !5
  %47 = add nsw i32 %45, %46
  store i32 %47, ptr getelementptr inbounds (i8, ptr @arr, i64 180), align 4, !tbaa !5
  %48 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %.not19 = icmp eq i32 %48, -1
  br i1 %.not19, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %.preheader14, %66
  %49 = load i32, ptr @arr, align 16, !tbaa !5
  %50 = shl nsw i32 %49, 1
  %51 = load i32, ptr %0, align 4, !tbaa !5
  %.not1317 = icmp sgt i32 %50, %51
  br i1 %.not1317, label %.critedge, label %.lr.ph

52:                                               ; preds = %.lr.ph
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %53 = getelementptr inbounds [46 x i32], ptr @arr, i64 0, i64 %indvars.iv.next23
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = shl nsw i32 %54, 1
  %56 = load i32, ptr %0, align 4, !tbaa !5
  %.not13 = icmp sgt i32 %55, %56
  br i1 %.not13, label %.critedge, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader, %52
  %indvars.iv22 = phi i64 [ %indvars.iv.next23, %52 ], [ 0, %.preheader ]
  %57 = phi i32 [ %56, %52 ], [ %51, %.preheader ]
  %58 = phi i32 [ %54, %52 ], [ %49, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %59 = sub nsw i32 %57, %58
  store i32 %59, ptr %1, align 4, !tbaa !5
  %60 = call noundef zeroext i1 @_ZSt13binary_searchIPiiEbT_S1_RKT0_(ptr noundef nonnull @arr, ptr noundef nonnull getelementptr inbounds (i8, ptr @arr, i64 184), ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  br i1 %60, label %61, label %52

61:                                               ; preds = %.lr.ph
  %62 = load i32, ptr %0, align 4, !tbaa !5
  %63 = sub nsw i32 %62, %58
  %64 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %58, i32 noundef %63)
  br label %66

.critedge:                                        ; preds = %52, %.preheader
  %65 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %66

66:                                               ; preds = %61, %.critedge
  %67 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %68 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %.not = icmp eq i32 %68, -1
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !11

._crit_edge:                                      ; preds = %66, %.preheader14
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %0) #4
  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: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZSt13binary_searchIPiiEbT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #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 = { 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 = { 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 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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