; LLVM IR from brpapa/algorithms :: solutions/uva (725)

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

11:                                               ; preds = %84, %0
  br label %12

12:                                               ; preds = %11
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  br label %85

17:                                               ; preds = %12
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %3, align 4, !tbaa !5
  %20 = icmp ne i32 %18, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %17
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %23

23:                                               ; preds = %21, %17
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  store i8 0, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1234, ptr %5, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %75, %23
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = mul nsw i32 %25, %26
  %28 = icmp sle i32 %27, 98765
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = mul nsw i32 %31, %32
  store i32 %33, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = icmp slt i32 %34, 10000
  %36 = zext i1 %35 to i32
  store i32 %36, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %37 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %37, ptr %9, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %48, %30
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = icmp sgt i32 %39, 0
  br i1 %40, label %42, label %41

41:                                               ; preds = %38
  store i32 7, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %51

42:                                               ; preds = %38
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = srem i32 %43, 10
  %45 = shl i32 1, %44
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = or i32 %46, %45
  store i32 %47, ptr %8, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %42
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = sdiv i32 %49, 10
  store i32 %50, ptr %9, align 4, !tbaa !5
  br label %38, !llvm.loop !11

51:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %52 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %52, ptr %10, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %63, %51
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = icmp sgt i32 %54, 0
  br i1 %55, label %57, label %56

56:                                               ; preds = %53
  store i32 10, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %66

57:                                               ; preds = %53
  %58 = load i32, ptr %10, align 4, !tbaa !5
  %59 = srem i32 %58, 10
  %60 = shl i32 1, %59
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = or i32 %61, %60
  store i32 %62, ptr %8, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %57
  %64 = load i32, ptr %10, align 4, !tbaa !5
  %65 = sdiv i32 %64, 10
  store i32 %65, ptr %10, align 4, !tbaa !5
  br label %53, !llvm.loop !13

66:                                               ; preds = %56
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = icmp eq i32 %67, 1023
  br i1 %68, label %69, label %74

69:                                               ; preds = %66
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %70, i32 noundef %71, i32 noundef %72)
  store i8 1, ptr %4, align 1, !tbaa !9
  br label %74

74:                                               ; preds = %69, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %75

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

78:                                               ; preds = %29
  %79 = load i8, ptr %4, align 1, !tbaa !9, !range !15, !noundef !16
  %80 = trunc i8 %79 to i1
  br i1 %80, label %84, label %81

81:                                               ; preds = %78
  %82 = load i32, ptr %2, align 4, !tbaa !5
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %82)
  br label %84

84:                                               ; preds = %81, %78
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  br label %11, !llvm.loop !17

85:                                               ; preds = %16
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %86 = load i32, ptr %1, align 4
  ret i32 %86
}

; 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

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

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

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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !12}


; 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 [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [32 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
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %._crit_edge40, label %.lr.ph39

.lr.ph39:                                         ; preds = %0, %36
  %5 = phi i32 [ %38, %36 ], [ %3, %0 ]
  %.02537 = phi i32 [ %6, %36 ], [ 0, %0 ]
  %6 = add nuw nsw i32 %.02537, 1
  %.not = icmp eq i32 %.02537, 0
  br i1 %.not, label %9, label %7

7:                                                ; preds = %.lr.ph39
  %8 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %7, %.lr.ph39
  %10 = phi i32 [ %.pre, %7 ], [ %5, %.lr.ph39 ]
  %11 = icmp slt i32 %10, 81
  br i1 %11, label %.lr.ph34.preheader, label %._crit_edge.thread

.lr.ph34.preheader:                               ; preds = %9
  %12 = mul nsw i32 %10, 1234
  br label %.lr.ph34

._crit_edge:                                      ; preds = %30
  br i1 %.124, label %36, label %._crit_edge.thread

.lr.ph34:                                         ; preds = %.lr.ph34.preheader, %30
  %13 = phi i32 [ %31, %30 ], [ %10, %.lr.ph34.preheader ]
  %14 = phi i32 [ %33, %30 ], [ %12, %.lr.ph34.preheader ]
  %.02233 = phi i32 [ %32, %30 ], [ 1234, %.lr.ph34.preheader ]
  %.02332 = phi i1 [ %.124, %30 ], [ false, %.lr.ph34.preheader ]
  %15 = icmp ult i32 %.02233, 10000
  %16 = zext i1 %15 to i32
  %17 = icmp sgt i32 %14, 0
  br i1 %17, label %.lr.ph, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.lr.ph, %.lr.ph34
  %.130.ph = phi i32 [ %16, %.lr.ph34 ], [ %20, %.lr.ph ]
  br label %.preheader

.lr.ph:                                           ; preds = %.lr.ph34, %.lr.ph
  %.02029 = phi i32 [ %21, %.lr.ph ], [ %14, %.lr.ph34 ]
  %.02128 = phi i32 [ %20, %.lr.ph ], [ %16, %.lr.ph34 ]
  %18 = urem i32 %.02029, 10
  %19 = shl nuw nsw i32 1, %18
  %20 = or i32 %19, %.02128
  %21 = udiv i32 %.02029, 10
  %.not41 = icmp ult i32 %.02029, 10
  br i1 %.not41, label %.preheader.preheader, label %.lr.ph, !llvm.loop !9

22:                                               ; preds = %.preheader
  %23 = icmp eq i32 %26, 1023
  br i1 %23, label %28, label %30

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %.031 = phi i32 [ %27, %.preheader ], [ %.02233, %.preheader.preheader ]
  %.130 = phi i32 [ %26, %.preheader ], [ %.130.ph, %.preheader.preheader ]
  %24 = urem i32 %.031, 10
  %25 = shl nuw nsw i32 1, %24
  %26 = or i32 %25, %.130
  %27 = udiv i32 %.031, 10
  %.not27 = icmp ult i32 %.031, 10
  br i1 %.not27, label %22, label %.preheader, !llvm.loop !11

28:                                               ; preds = %22
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %14, i32 noundef %.02233, i32 noundef %13)
  %.pre45 = load i32, ptr %1, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %28, %22
  %31 = phi i32 [ %.pre45, %28 ], [ %13, %22 ]
  %.124 = phi i1 [ true, %28 ], [ %.02332, %22 ]
  %32 = add nuw nsw i32 %.02233, 1
  %33 = mul nsw i32 %31, %32
  %34 = icmp slt i32 %33, 98766
  br i1 %34, label %.lr.ph34, label %._crit_edge, !llvm.loop !12

._crit_edge.thread:                               ; preds = %9, %._crit_edge
  %.lcssa48 = phi i32 [ %31, %._crit_edge ], [ %10, %9 ]
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %.lcssa48)
  br label %36

36:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %37 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %38 = load i32, ptr %1, align 4, !tbaa !5
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %._crit_edge40, label %.lr.ph39, !llvm.loop !13

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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}


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