; LLVM IR from int32bit/leetcode :: algorithms/Pow (pow)

; 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"

; Function Attrs: nounwind uwtable
declare dso_local i32 @doubleEQ(double noundef, double noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local double @myPow(double noundef %0, i32 noundef %1) #0 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  store double %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store double 1.000000e+00, ptr %3, align 8
  br label %73

12:                                               ; preds = %2
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %17

15:                                               ; preds = %12
  %16 = load double, ptr %4, align 8, !tbaa !5
  store double %16, ptr %3, align 8
  br label %73

17:                                               ; preds = %12
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %29

20:                                               ; preds = %17
  %21 = load double, ptr %4, align 8, !tbaa !5
  %22 = fsub double %21, 0.000000e+00
  %23 = call double @llvm.fabs.f64(double %22)
  %24 = fcmp olt double %23, 1.000000e-08
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  store double 0x41DFFFFFFFC00000, ptr %3, align 8
  br label %73

26:                                               ; preds = %20
  %27 = load double, ptr %4, align 8, !tbaa !5
  %28 = fdiv double 1.000000e+00, %27
  store double %28, ptr %3, align 8
  br label %73

29:                                               ; preds = %17
  %30 = load double, ptr %4, align 8, !tbaa !5
  %31 = call i32 @doubleEQ(double noundef %30, double noundef 0.000000e+00)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %29
  store double 0.000000e+00, ptr %3, align 8
  br label %73

34:                                               ; preds = %29
  %35 = load double, ptr %4, align 8, !tbaa !5
  %36 = call i32 @doubleEQ(double noundef %35, double noundef 1.000000e+00)
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  store double 1.000000e+00, ptr %3, align 8
  br label %73

39:                                               ; preds = %34
  %40 = load double, ptr %4, align 8, !tbaa !5
  %41 = call i32 @doubleEQ(double noundef %40, double noundef -1.000000e+00)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %49

43:                                               ; preds = %39
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = and i32 %44, 1
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %43
  store double -1.000000e+00, ptr %3, align 8
  br label %73

48:                                               ; preds = %43
  store double 1.000000e+00, ptr %3, align 8
  br label %73

49:                                               ; preds = %39
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = and i32 %50, 1
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %65

53:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = sub nsw i32 %54, 1
  %56 = sdiv i32 %55, 2
  store i32 %56, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %57 = load double, ptr %4, align 8, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = call double @myPow(double noundef %57, i32 noundef %58)
  store double %59, ptr %7, align 8, !tbaa !5
  %60 = load double, ptr %7, align 8, !tbaa !5
  %61 = load double, ptr %7, align 8, !tbaa !5
  %62 = fmul double %60, %61
  %63 = load double, ptr %4, align 8, !tbaa !5
  %64 = fmul double %62, %63
  store double %64, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %73

65:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %66 = load double, ptr %4, align 8, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = sdiv i32 %67, 2
  %69 = call double @myPow(double noundef %66, i32 noundef %68)
  store double %69, ptr %8, align 8, !tbaa !5
  %70 = load double, ptr %8, align 8, !tbaa !5
  %71 = load double, ptr %8, align 8, !tbaa !5
  %72 = fmul double %70, %71
  store double %72, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %73

73:                                               ; preds = %65, %53, %48, %47, %38, %33, %26, %25, %15, %11
  %74 = load double, ptr %3, align 8
  ret double %74
}

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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 speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

; Function Attrs: nounwind uwtable
declare dso_local i32 @doubleEQ(double noundef, double noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local double @myPow(double noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  switch i32 %1, label %9 [
    i32 0, label %common.ret26
    i32 1, label %3
    i32 -1, label %4
  ]

3:                                                ; preds = %2
  br label %common.ret26

4:                                                ; preds = %2
  %5 = tail call double @llvm.fabs.f64(double %0)
  %6 = fcmp olt double %5, 1.000000e-08
  br i1 %6, label %common.ret26, label %7

7:                                                ; preds = %4
  %8 = fdiv double 1.000000e+00, %0
  br label %common.ret26

9:                                                ; preds = %2
  %10 = tail call i32 @doubleEQ(double noundef %0, double noundef 0.000000e+00)
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %11, label %common.ret26

11:                                               ; preds = %9
  %12 = tail call i32 @doubleEQ(double noundef %0, double noundef 1.000000e+00)
  %.not22 = icmp eq i32 %12, 0
  br i1 %.not22, label %13, label %common.ret26

13:                                               ; preds = %11
  %14 = tail call i32 @doubleEQ(double noundef %0, double noundef -1.000000e+00)
  %.not23 = icmp eq i32 %14, 0
  %15 = and i32 %1, 1
  %.not24 = icmp eq i32 %15, 0
  br i1 %.not23, label %17, label %16

16:                                               ; preds = %13
  %. = select i1 %.not24, double 1.000000e+00, double -1.000000e+00
  br label %common.ret26

17:                                               ; preds = %13
  br i1 %.not24, label %24, label %18

common.ret26:                                     ; preds = %16, %11, %9, %4, %2, %7, %3, %24, %18
  %common.ret26.op = phi double [ %23, %18 ], [ %27, %24 ], [ %0, %3 ], [ %8, %7 ], [ 1.000000e+00, %2 ], [ 0x41DFFFFFFFC00000, %4 ], [ 0.000000e+00, %9 ], [ 1.000000e+00, %11 ], [ %., %16 ]
  ret double %common.ret26.op

18:                                               ; preds = %17
  %19 = add nsw i32 %1, -1
  %20 = ashr exact i32 %19, 1
  %21 = tail call double @myPow(double noundef %0, i32 noundef %20)
  %22 = fmul double %21, %21
  %23 = fmul double %22, %0
  br label %common.ret26

24:                                               ; preds = %17
  %25 = ashr exact i32 %1, 1
  %26 = tail call double @myPow(double noundef %0, i32 noundef %25)
  %27 = fmul double %26, %26
  br label %common.ret26
}

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 = { 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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass