; LLVM IR from DionysiosB/CodeForces :: 0100-0199/148D-BagOfMice-OLD.ll (Z7getProbbii)

; 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 [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z7getProbbii(i1 noundef zeroext %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca double, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = zext i1 %0 to i8
  store i8 %15, ptr %5, align 1, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %16 = load i8, ptr %5, align 1, !tbaa !5, !range !11, !noundef !12
  %17 = trunc i8 %16 to i1
  %18 = zext i1 %17 to i64
  %19 = select i1 %17, ptr @.str.2, ptr @.str.3
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %19, i32 noundef %20, i32 noundef %21)
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = icmp sle i32 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %3
  %26 = call i32 @puts(ptr noundef @.str.4)
  store double 1.000000e+00, ptr %4, align 8
  br label %120

27:                                               ; preds = %3
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp sle i32 %28, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %27
  %31 = call i32 @puts(ptr noundef @.str.5)
  store double 0.000000e+00, ptr %4, align 8
  br label %120

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = sitofp i32 %33 to double
  %35 = fmul double 1.000000e+00, %34
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = add nsw i32 %36, %37
  %39 = sitofp i32 %38 to double
  %40 = fdiv double %35, %39
  store double %40, ptr %8, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %41 = load double, ptr %8, align 8, !tbaa !13
  %42 = fsub double 1.000000e+00, %41
  store double %42, ptr %9, align 8, !tbaa !13
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = add nsw i32 %44, %45
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = add nsw i32 %48, %49
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %43, i32 noundef %46, i32 noundef %47, i32 noundef %50)
  %52 = load i8, ptr %5, align 1, !tbaa !5, !range !11, !noundef !12
  %53 = trunc i8 %52 to i1
  br i1 %53, label %54, label %72

54:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %55 = load double, ptr %8, align 8, !tbaa !13
  %56 = load double, ptr %9, align 8, !tbaa !13
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = sub nsw i32 %58, 1
  %60 = call noundef double @_Z7getProbbii(i1 noundef zeroext false, i32 noundef %57, i32 noundef %59)
  %61 = fsub double 1.000000e+00, %60
  %62 = call double @llvm.fmuladd.f64(double %56, double %61, double %55)
  store double %62, ptr %10, align 8, !tbaa !13
  %63 = load i8, ptr %5, align 1, !tbaa !5, !range !11, !noundef !12
  %64 = trunc i8 %63 to i1
  %65 = zext i1 %64 to i64
  %66 = select i1 %64, ptr @.str.2, ptr @.str.3
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = load double, ptr %10, align 8, !tbaa !13
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, ptr noundef %66, i32 noundef %67, i32 noundef %68, double noundef %69)
  %71 = load double, ptr %10, align 8, !tbaa !13
  store double %71, ptr %4, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %119

72:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %73 = load i32, ptr %7, align 4, !tbaa !9
  %74 = icmp sge i32 %73, 2
  br i1 %74, label %75, label %85

75:                                               ; preds = %72
  %76 = load i32, ptr %6, align 4, !tbaa !9
  %77 = sitofp i32 %76 to double
  %78 = fmul double 1.000000e+00, %77
  %79 = load i32, ptr %6, align 4, !tbaa !9
  %80 = load i32, ptr %7, align 4, !tbaa !9
  %81 = add nsw i32 %79, %80
  %82 = sub nsw i32 %81, 1
  %83 = sitofp i32 %82 to double
  %84 = fdiv double %78, %83
  br label %86

85:                                               ; preds = %72
  br label %86

86:                                               ; preds = %85, %75
  %87 = phi double [ %84, %75 ], [ 1.000000e+00, %85 ]
  store double %87, ptr %12, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %88 = load double, ptr %12, align 8, !tbaa !13
  %89 = fsub double 1.000000e+00, %88
  store double %89, ptr %13, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %90 = load double, ptr %8, align 8, !tbaa !13
  %91 = load double, ptr %9, align 8, !tbaa !13
  %92 = load double, ptr %12, align 8, !tbaa !13
  %93 = load i32, ptr %6, align 4, !tbaa !9
  %94 = sub nsw i32 %93, 1
  %95 = load i32, ptr %7, align 4, !tbaa !9
  %96 = sub nsw i32 %95, 1
  %97 = call noundef double @_Z7getProbbii(i1 noundef zeroext true, i32 noundef %94, i32 noundef %96)
  %98 = fsub double 1.000000e+00, %97
  %99 = load double, ptr %13, align 8, !tbaa !13
  %100 = load i32, ptr %6, align 4, !tbaa !9
  %101 = load i32, ptr %7, align 4, !tbaa !9
  %102 = sub nsw i32 %101, 2
  %103 = call noundef double @_Z7getProbbii(i1 noundef zeroext true, i32 noundef %100, i32 noundef %102)
  %104 = fsub double 1.000000e+00, %103
  %105 = fmul double %99, %104
  %106 = call double @llvm.fmuladd.f64(double %92, double %98, double %105)
  %107 = call double @llvm.fmuladd.f64(double %91, double %106, double %90)
  store double %107, ptr %14, align 8, !tbaa !13
  %108 = load i8, ptr %5, align 1, !tbaa !5, !range !11, !noundef !12
  %109 = trunc i8 %108 to i1
  %110 = zext i1 %109 to i64
  %111 = select i1 %109, ptr @.str.2, ptr @.str.3
  %112 = load i32, ptr %6, align 4, !tbaa !9
  %113 = load i32, ptr %7, align 4, !tbaa !9
  %114 = load double, ptr %12, align 8, !tbaa !13
  %115 = load double, ptr %13, align 8, !tbaa !13
  %116 = load double, ptr %14, align 8, !tbaa !13
  %117 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, ptr noundef %111, i32 noundef %112, i32 noundef %113, double noundef %114, double noundef %115, double noundef %116)
  %118 = load double, ptr %14, align 8, !tbaa !13
  store double %118, ptr %4, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %119

119:                                              ; preds = %86, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %120

120:                                              ; preds = %119, %30, %25
  %121 = load double, ptr %4, align 8
  ret double %121
}

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

declare i32 @puts(ptr noundef) #1

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

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

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

attributes #0 = { 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 #1 = { "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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !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 [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noundef double @_Z7getProbbii(i1 noundef zeroext %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = select i1 %0, ptr @.str.2, ptr @.str.3
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull %4, i32 noundef %1, i32 noundef %2)
  %6 = icmp slt i32 %2, 1
  br i1 %6, label %7, label %9

7:                                                ; preds = %3
  %8 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %common.ret47

9:                                                ; preds = %3
  %10 = icmp slt i32 %1, 1
  br i1 %10, label %11, label %13

11:                                               ; preds = %9
  %12 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %common.ret47

13:                                               ; preds = %9
  %14 = uitofp nneg i32 %1 to double
  %15 = add nuw nsw i32 %2, %1
  %16 = uitofp nneg i32 %15 to double
  %17 = fdiv double %14, %16
  %18 = fsub double 1.000000e+00, %17
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %1, i32 noundef %15, i32 noundef %2, i32 noundef %15)
  br i1 %0, label %20, label %26

common.ret47:                                     ; preds = %11, %7, %26, %20
  %common.ret47.op = phi double [ %24, %20 ], [ %41, %26 ], [ 1.000000e+00, %7 ], [ 0.000000e+00, %11 ]
  ret double %common.ret47.op

20:                                               ; preds = %13
  %21 = add nsw i32 %2, -1
  %22 = tail call noundef double @_Z7getProbbii(i1 noundef zeroext false, i32 noundef %1, i32 noundef %21)
  %23 = fsub double 1.000000e+00, %22
  %24 = tail call double @llvm.fmuladd.f64(double %18, double %23, double %17)
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull @.str.2, i32 noundef %1, i32 noundef %2, double noundef %24)
  br label %common.ret47

26:                                               ; preds = %13
  %.not = icmp eq i32 %2, 1
  %27 = add nsw i32 %15, -1
  %28 = uitofp nneg i32 %27 to double
  %29 = fdiv double %14, %28
  %30 = select i1 %.not, double 1.000000e+00, double %29
  %31 = fsub double 1.000000e+00, %30
  %32 = add nsw i32 %1, -1
  %33 = add nsw i32 %2, -1
  %34 = tail call noundef double @_Z7getProbbii(i1 noundef zeroext true, i32 noundef %32, i32 noundef %33)
  %35 = fsub double 1.000000e+00, %34
  %36 = add nsw i32 %2, -2
  %37 = tail call noundef double @_Z7getProbbii(i1 noundef zeroext true, i32 noundef %1, i32 noundef %36)
  %38 = fsub double 1.000000e+00, %37
  %39 = fmul double %31, %38
  %40 = tail call double @llvm.fmuladd.f64(double %30, double %35, double %39)
  %41 = tail call double @llvm.fmuladd.f64(double %18, double %40, double %17)
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef nonnull @.str.3, i32 noundef %1, i32 noundef %2, double noundef %30, double noundef %31, double noundef %41)
  br label %common.ret47
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

attributes #0 = { mustprogress 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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass