; LLVM IR from ravireddy07/cpp-book :: src/Code-Chef (CHEFFED)

; 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 [5 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z9sumDigitsl(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 i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = sub nsw i64 %6, 200
  store i64 %7, ptr %4, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %34, %0
  %9 = load i64, ptr %4, align 8, !tbaa !5
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = icmp sle i64 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %37

13:                                               ; preds = %8
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = icmp sle i64 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  br label %34

17:                                               ; preds = %13
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = call noundef i32 @_Z9sumDigitsl(i64 noundef %19)
  %21 = sext i32 %20 to i64
  %22 = add nsw i64 %18, %21
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = call noundef i32 @_Z9sumDigitsl(i64 noundef %23)
  %25 = sext i32 %24 to i64
  %26 = call noundef i32 @_Z9sumDigitsl(i64 noundef %25)
  %27 = sext i32 %26 to i64
  %28 = add nsw i64 %22, %27
  %29 = load i64, ptr %2, align 8, !tbaa !5
  %30 = icmp eq i64 %28, %29
  %31 = zext i1 %30 to i64
  %32 = load i64, ptr %3, align 8, !tbaa !5
  %33 = add nsw i64 %32, %31
  store i64 %33, ptr %3, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %17, %16
  %35 = load i64, ptr %4, align 8, !tbaa !5
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %4, align 8, !tbaa !5
  br label %8, !llvm.loop !9

37:                                               ; preds = %12
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %38)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  ret i32 0
}

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

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

attributes #0 = { mustprogress 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 = { 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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; 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 [5 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z9sumDigitsl(i64 noundef) local_unnamed_addr #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: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
.lr.ph.preheader:
  %0 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %0) #4
  %1 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %2 = load i64, ptr %0, align 8, !tbaa !5
  %3 = add nsw i64 %2, -200
  br label %.lr.ph

._crit_edge:                                      ; preds = %20
  %4 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %.1)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %0) #4
  ret i32 0

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %5 = phi i64 [ %21, %20 ], [ %2, %.lr.ph.preheader ]
  %.011 = phi i64 [ %22, %20 ], [ %3, %.lr.ph.preheader ]
  %.0810 = phi i64 [ %.1, %20 ], [ 0, %.lr.ph.preheader ]
  %6 = icmp slt i64 %.011, 1
  br i1 %6, label %20, label %7

7:                                                ; preds = %.lr.ph
  %8 = call noundef i32 @_Z9sumDigitsl(i64 noundef %.011)
  %9 = sext i32 %8 to i64
  %10 = add nsw i64 %.011, %9
  %11 = call noundef i32 @_Z9sumDigitsl(i64 noundef %.011)
  %12 = sext i32 %11 to i64
  %13 = call noundef i32 @_Z9sumDigitsl(i64 noundef %12)
  %14 = sext i32 %13 to i64
  %15 = add nsw i64 %10, %14
  %16 = load i64, ptr %0, align 8, !tbaa !5
  %17 = icmp eq i64 %15, %16
  %18 = zext i1 %17 to i64
  %19 = add nsw i64 %.0810, %18
  br label %20

20:                                               ; preds = %.lr.ph, %7
  %21 = phi i64 [ %5, %.lr.ph ], [ %16, %7 ]
  %.1 = phi i64 [ %.0810, %.lr.ph ], [ %19, %7 ]
  %22 = add nsw i64 %.011, 1
  %.not.not = icmp slt i64 %.011, %21
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

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

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

attributes #0 = { mustprogress 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 = { mustprogress 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 #3 = { 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 #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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