; LLVM IR from daanx/mimalloc-bench :: bench/cfrac (ppowmod)

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

@pone = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @ppowmod(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store ptr null, ptr %9, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = call ptr @pparmq(ptr noundef %10)
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call ptr @pparmq(ptr noundef %12)
  %14 = call ptr @psetq(ptr noundef %8, ptr noundef %13)
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call ptr @pparmq(ptr noundef %15)
  %17 = call ptr @psetq(ptr noundef %9, ptr noundef %16)
  %18 = load ptr, ptr @pone, align 8, !tbaa !5
  %19 = call ptr @psetq(ptr noundef %7, ptr noundef %18)
  br label %20

20:                                               ; preds = %46, %3
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = call i32 @podd(ptr noundef %21)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %31

24:                                               ; preds = %20
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call ptr @pmul(ptr noundef %25, ptr noundef %26)
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = call ptr @pdivmod(ptr noundef %27, ptr noundef %28, ptr noundef null, ptr noundef inttoptr (i64 -1 to ptr))
  %30 = call ptr @psetq(ptr noundef %7, ptr noundef %29)
  br label %31

31:                                               ; preds = %24, %20
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = call ptr @phalf(ptr noundef %32)
  %34 = call ptr @psetq(ptr noundef %9, ptr noundef %33)
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = call i32 @pcmpz(ptr noundef %35)
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %31
  br label %47

39:                                               ; preds = %31
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = call ptr @pmul(ptr noundef %40, ptr noundef %41)
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = call ptr @pdivmod(ptr noundef %42, ptr noundef %43, ptr noundef null, ptr noundef inttoptr (i64 -1 to ptr))
  %45 = call ptr @psetq(ptr noundef %8, ptr noundef %44)
  br label %46

46:                                               ; preds = %39
  br i1 true, label %20, label %47

47:                                               ; preds = %46, %38
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  call void @pdestroy(ptr noundef %48)
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  call void @pdestroy(ptr noundef %49)
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  call void @pdestroy(ptr noundef %50)
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  call void @pdestroy(ptr noundef %51)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  call void @pdestroy(ptr noundef %52)
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = call ptr @presult(ptr noundef %53)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret ptr %54
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @pparmq(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @psetq(ptr noundef, ptr noundef) #2

declare i32 @podd(ptr noundef) #3

declare ptr @pdivmod(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

declare ptr @pmul(ptr noundef, ptr noundef) #3

declare ptr @phalf(ptr noundef) #3

declare i32 @pcmpz(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @pdestroy(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @presult(ptr noundef) #2

; 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 = { inlinehint 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 #3 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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

@pone = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @ppowmod(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  store ptr null, ptr %6, align 8, !tbaa !5
  %7 = tail call ptr @pparmq(ptr noundef %2)
  %8 = tail call ptr @pparmq(ptr noundef %0)
  %9 = call ptr @psetq(ptr noundef nonnull %5, ptr noundef %8)
  %10 = call ptr @pparmq(ptr noundef %1)
  %11 = call ptr @psetq(ptr noundef nonnull %6, ptr noundef %10)
  %12 = load ptr, ptr @pone, align 8, !tbaa !5
  %13 = call ptr @psetq(ptr noundef nonnull %4, ptr noundef %12)
  br label %14

14:                                               ; preds = %31, %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = call i32 @podd(ptr noundef %15) #4
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %23, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call ptr @pmul(ptr noundef %18, ptr noundef %19) #4
  %21 = call ptr @pdivmod(ptr noundef %20, ptr noundef %2, ptr noundef null, ptr noundef nonnull inttoptr (i64 -1 to ptr)) #4
  %22 = call ptr @psetq(ptr noundef nonnull %4, ptr noundef %21)
  br label %23

23:                                               ; preds = %17, %14
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = call ptr @phalf(ptr noundef %24) #4
  %26 = call ptr @psetq(ptr noundef nonnull %6, ptr noundef %25)
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = call i32 @pcmpz(ptr noundef %27) #4
  %29 = icmp eq i32 %28, 0
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  br i1 %29, label %35, label %31

31:                                               ; preds = %23
  %32 = call ptr @pmul(ptr noundef %30, ptr noundef %30) #4
  %33 = call ptr @pdivmod(ptr noundef %32, ptr noundef %2, ptr noundef null, ptr noundef nonnull inttoptr (i64 -1 to ptr)) #4
  %34 = call ptr @psetq(ptr noundef nonnull %5, ptr noundef %33)
  br label %14

35:                                               ; preds = %23
  call void @pdestroy(ptr noundef %30)
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  call void @pdestroy(ptr noundef %36)
  call void @pdestroy(ptr noundef %0)
  call void @pdestroy(ptr noundef %1)
  call void @pdestroy(ptr noundef %2)
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = call ptr @presult(ptr noundef %37)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret ptr %38
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @pparmq(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @psetq(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @podd(ptr noundef) local_unnamed_addr #3

declare ptr @pdivmod(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare ptr @pmul(ptr noundef, ptr noundef) local_unnamed_addr #3

declare ptr @phalf(ptr noundef) local_unnamed_addr #3

declare i32 @pcmpz(ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @pdestroy(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @presult(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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