; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 36. C Programs (Calculator)

; 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 [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca i8, align 1
  %9 = alloca float, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  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 1, 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 %6, ptr noundef %8, ptr noundef %7)
  %12 = load i8, ptr %8, align 1, !tbaa !11
  %13 = sext i8 %12 to i32
  switch i32 %13, label %42 [
    i32 47, label %14
    i32 42, label %18
    i32 43, label %22
    i32 45, label %26
    i32 94, label %30
    i32 32, label %37
  ]

14:                                               ; preds = %2
  %15 = load float, ptr %6, align 4, !tbaa !12
  %16 = load float, ptr %7, align 4, !tbaa !12
  %17 = fdiv float %15, %16
  store float %17, ptr %9, align 4, !tbaa !12
  br label %43

18:                                               ; preds = %2
  %19 = load float, ptr %6, align 4, !tbaa !12
  %20 = load float, ptr %7, align 4, !tbaa !12
  %21 = fmul float %19, %20
  store float %21, ptr %9, align 4, !tbaa !12
  br label %43

22:                                               ; preds = %2
  %23 = load float, ptr %6, align 4, !tbaa !12
  %24 = load float, ptr %7, align 4, !tbaa !12
  %25 = fadd float %23, %24
  store float %25, ptr %9, align 4, !tbaa !12
  br label %43

26:                                               ; preds = %2
  %27 = load float, ptr %6, align 4, !tbaa !12
  %28 = load float, ptr %7, align 4, !tbaa !12
  %29 = fsub float %27, %28
  store float %29, ptr %9, align 4, !tbaa !12
  br label %43

30:                                               ; preds = %2
  %31 = load float, ptr %6, align 4, !tbaa !12
  %32 = fpext float %31 to double
  %33 = load float, ptr %7, align 4, !tbaa !12
  %34 = fpext float %33 to double
  %35 = call double @pow(double noundef %32, double noundef %34) #4
  %36 = fptrunc double %35 to float
  store float %36, ptr %9, align 4, !tbaa !12
  br label %43

37:                                               ; preds = %2
  %38 = load float, ptr %7, align 4, !tbaa !12
  %39 = fpext float %38 to double
  %40 = call double @sqrt(double noundef %39) #4
  %41 = fptrunc double %40 to float
  store float %41, ptr %9, align 4, !tbaa !12
  br label %43

42:                                               ; preds = %2
  br label %53

43:                                               ; preds = %37, %30, %26, %22, %18, %14
  %44 = load float, ptr %6, align 4, !tbaa !12
  %45 = fpext float %44 to double
  %46 = load i8, ptr %8, align 1, !tbaa !11
  %47 = sext i8 %46 to i32
  %48 = load float, ptr %7, align 4, !tbaa !12
  %49 = fpext float %48 to double
  %50 = load float, ptr %9, align 4, !tbaa !12
  %51 = fpext float %50 to double
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %45, i32 noundef %47, double noundef %49, double noundef %51)
  br label %55

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

55:                                               ; preds = %53, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, 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
  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: nounwind
declare double @pow(double noundef, double noundef) #3

; Function Attrs: nounwind
declare double @sqrt(double noundef) #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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !7, i64 0}


; 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 [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca i8, align 1
  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 1, 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, ptr noundef nonnull %5, ptr noundef nonnull %4)
  %8 = load i8, ptr %5, align 1, !tbaa !5
  switch i8 %8, label %43 [
    i8 47, label %9
    i8 42, label %13
    i8 43, label %17
    i8 45, label %21
    i8 94, label %25
    i8 32, label %32
  ]

9:                                                ; preds = %2
  %10 = load float, ptr %3, align 4, !tbaa !8
  %11 = load float, ptr %4, align 4, !tbaa !8
  %12 = fdiv float %10, %11
  br label %34

13:                                               ; preds = %2
  %14 = load float, ptr %3, align 4, !tbaa !8
  %15 = load float, ptr %4, align 4, !tbaa !8
  %16 = fmul float %14, %15
  br label %34

17:                                               ; preds = %2
  %18 = load float, ptr %3, align 4, !tbaa !8
  %19 = load float, ptr %4, align 4, !tbaa !8
  %20 = fadd float %18, %19
  br label %34

21:                                               ; preds = %2
  %22 = load float, ptr %3, align 4, !tbaa !8
  %23 = load float, ptr %4, align 4, !tbaa !8
  %24 = fsub float %22, %23
  br label %34

25:                                               ; preds = %2
  %26 = load float, ptr %3, align 4, !tbaa !8
  %27 = fpext float %26 to double
  %28 = load float, ptr %4, align 4, !tbaa !8
  %29 = fpext float %28 to double
  %30 = call double @pow(double noundef %27, double noundef %29) #4
  %31 = fptrunc double %30 to float
  br label %34

32:                                               ; preds = %2
  %33 = load float, ptr %4, align 4, !tbaa !8
  %sqrtf = call float @sqrtf(float noundef %33) #3
  br label %34

34:                                               ; preds = %32, %25, %21, %17, %13, %9
  %.0 = phi float [ %sqrtf, %32 ], [ %31, %25 ], [ %24, %21 ], [ %20, %17 ], [ %16, %13 ], [ %12, %9 ]
  %35 = load float, ptr %3, align 4, !tbaa !8
  %36 = fpext float %35 to double
  %37 = load i8, ptr %5, align 1, !tbaa !5
  %38 = sext i8 %37 to i32
  %39 = load float, ptr %4, align 4, !tbaa !8
  %40 = fpext float %39 to double
  %41 = fpext float %.0 to double
  %42 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %36, i32 noundef %38, double noundef %40, double noundef %41)
  br label %45

43:                                               ; preds = %2
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %45

45:                                               ; preds = %43, %34
  call void @llvm.lifetime.end.p0(i64 1, 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
  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 nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) 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

declare float @sqrtf(float) local_unnamed_addr

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 nofree nounwind willreturn memory(write) "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"float", !6, i64 0}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass