; LLVM IR from freddiev4/dailyprogrammerchallenges :: Easy Challenges/Challenge 0002 Easy/solutions (solution1)

; 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 [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [49 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca float, align 4
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  %9 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %7)
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3)
  %14 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef %9)
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef %8)
  %18 = load i32, ptr %8, align 4, !tbaa !5
  %19 = load i32, ptr %9, align 4, !tbaa !5
  %20 = sdiv i32 %18, %19
  %21 = sitofp i32 %20 to float
  store float %21, ptr %4, align 4, !tbaa !9
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2)
  %24 = load float, ptr %2, align 4, !tbaa !9
  %25 = fcmp oeq float %24, 1.000000e+00
  br i1 %25, label %26, label %34

26:                                               ; preds = %0
  %27 = load float, ptr %7, align 4, !tbaa !9
  %28 = load float, ptr %3, align 4, !tbaa !9
  %29 = fdiv float %28, 1.000000e+02
  %30 = load float, ptr %7, align 4, !tbaa !9
  %31 = fmul float %29, %30
  %32 = load float, ptr %4, align 4, !tbaa !9
  %33 = call float @llvm.fmuladd.f32(float %31, float %32, float %27)
  store float %33, ptr %6, align 4, !tbaa !9
  br label %56

34:                                               ; preds = %0
  %35 = load float, ptr %2, align 4, !tbaa !9
  %36 = fcmp oeq float %35, 2.000000e+00
  br i1 %36, label %37, label %53

37:                                               ; preds = %34
  %38 = load float, ptr %7, align 4, !tbaa !9
  store float %38, ptr %6, align 4, !tbaa !9
  store float 1.000000e+00, ptr %5, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %49, %37
  %40 = load float, ptr %5, align 4, !tbaa !9
  %41 = load float, ptr %4, align 4, !tbaa !9
  %42 = fcmp ole float %40, %41
  br i1 %42, label %43, label %52

43:                                               ; preds = %39
  %44 = load float, ptr %6, align 4, !tbaa !9
  %45 = load float, ptr %6, align 4, !tbaa !9
  %46 = load float, ptr %3, align 4, !tbaa !9
  %47 = fdiv float %46, 1.000000e+02
  %48 = call float @llvm.fmuladd.f32(float %45, float %47, float %44)
  store float %48, ptr %6, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %43
  %50 = load float, ptr %5, align 4, !tbaa !9
  %51 = fadd float %50, 1.000000e+00
  store float %51, ptr %5, align 4, !tbaa !9
  br label %39, !llvm.loop !11

52:                                               ; preds = %39
  br label %55

53:                                               ; preds = %34
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %55

55:                                               ; preds = %53, %52
  br label %56

56:                                               ; preds = %55, %26
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = load float, ptr %6, align 4, !tbaa !9
  %59 = fpext float %58 to double
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i32 noundef %57, double noundef %59)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  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 @printf(ptr noundef, ...) #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

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

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 nosync nounwind speculatable willreturn memory(none) }
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 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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 [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [49 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca float, align 4
  %2 = alloca float, align 4
  %3 = alloca float, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %8 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %10 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull %5)
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull %4)
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sdiv i32 %14, %15
  %17 = sitofp i32 %16 to float
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %20 = load float, ptr %1, align 4, !tbaa !9
  %21 = fcmp oeq float %20, 1.000000e+00
  br i1 %21, label %22, label %28

22:                                               ; preds = %0
  %23 = load float, ptr %3, align 4, !tbaa !9
  %24 = load float, ptr %2, align 4, !tbaa !9
  %25 = fdiv float %24, 1.000000e+02
  %26 = fmul float %23, %25
  %27 = call float @llvm.fmuladd.f32(float %26, float %17, float %23)
  br label %.loopexit

28:                                               ; preds = %0
  %29 = fcmp oeq float %20, 2.000000e+00
  br i1 %29, label %30, label %39

30:                                               ; preds = %28
  %31 = load float, ptr %3, align 4, !tbaa !9
  %32 = icmp slt i32 %16, 1
  br i1 %32, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %30
  %33 = load float, ptr %2, align 4, !tbaa !9
  %34 = fdiv float %33, 1.000000e+02
  br label %35

35:                                               ; preds = %.lr.ph, %35
  %.010 = phi float [ %31, %.lr.ph ], [ %36, %35 ]
  %.079 = phi float [ 1.000000e+00, %.lr.ph ], [ %37, %35 ]
  %36 = call float @llvm.fmuladd.f32(float %.010, float %34, float %.010)
  %37 = fadd float %.079, 1.000000e+00
  %38 = fcmp ugt float %37, %17
  br i1 %38, label %.loopexit, label %35, !llvm.loop !11

39:                                               ; preds = %28
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %.loopexit

.loopexit:                                        ; preds = %35, %30, %39, %22
  %.1 = phi float [ %27, %22 ], [ undef, %39 ], [ %31, %30 ], [ %36, %35 ]
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = fpext float %.1 to double
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, i32 noundef %41, double noundef %42)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #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 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

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

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 nosync nounwind speculatable willreturn memory(none) }
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 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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