; LLVM IR from xuxping/codelife :: foroffer (question16)

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

@g_InvalidInput = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local double @powerWithUnsignedExponent(double noundef, i32 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: 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
  store double %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 0, ptr @g_InvalidInput, align 4, !tbaa !9
  %8 = load double, ptr %4, align 8, !tbaa !5
  %9 = fcmp oeq double %8, 0.000000e+00
  br i1 %9, label %10, label %14

10:                                               ; preds = %2
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  store i32 1, ptr @g_InvalidInput, align 4, !tbaa !9
  store double 0.000000e+00, ptr %3, align 8
  br label %32

14:                                               ; preds = %10, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %15 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %15, ptr %6, align 4, !tbaa !9
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %14
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sub nsw i32 0, %19
  store i32 %20, ptr %6, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %18, %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %22 = load double, ptr %4, align 8, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = call double @powerWithUnsignedExponent(double noundef %22, i32 noundef %23)
  store double %24, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %21
  %28 = load double, ptr %7, align 8, !tbaa !5
  %29 = fdiv double 1.000000e+00, %28
  store double %29, ptr %7, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %27, %21
  %31 = load double, ptr %7, align 8, !tbaa !5
  store double %31, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %32

32:                                               ; preds = %30, %13
  %33 = load double, ptr %3, align 8
  ret double %33
}

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 = { 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"

@g_InvalidInput = external dso_local local_unnamed_addr global i32, align 4

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

; Function Attrs: nounwind uwtable
define dso_local double @myPow(double noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  store i32 0, ptr @g_InvalidInput, align 4, !tbaa !5
  %3 = fcmp oeq double %0, 0.000000e+00
  %4 = icmp slt i32 %1, 0
  %or.cond = and i1 %3, %4
  br i1 %or.cond, label %5, label %6

5:                                                ; preds = %2
  store i32 1, ptr @g_InvalidInput, align 4, !tbaa !5
  br label %9

6:                                                ; preds = %2
  %spec.select = tail call i32 @llvm.abs.i32(i32 %1, i1 true)
  %7 = tail call double @powerWithUnsignedExponent(double noundef %0, i32 noundef %spec.select)
  %8 = fdiv double 1.000000e+00, %7
  %.0 = select i1 %4, double %8, double %7
  br label %9

9:                                                ; preds = %6, %5
  %.012 = phi double [ 0.000000e+00, %5 ], [ %.0, %6 ]
  ret double %.012
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #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 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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