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

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

%struct.precisionType = type { i16, i16, i16, i8, [1 x i16] }

; Function Attrs: nounwind uwtable
define dso_local void @pnorm(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.precisionType, ptr %4, i32 0, i32 4
  %6 = getelementptr inbounds [1 x i16], ptr %5, i64 0, i64 0
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.precisionType, ptr %7, i32 0, i32 2
  %9 = load i16, ptr %8, align 2, !tbaa !9
  %10 = zext i16 %9 to i32
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i16, ptr %6, i64 %11
  store ptr %12, ptr %3, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %21, %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds i16, ptr %14, i32 -1
  store ptr %15, ptr %3, align 8, !tbaa !5
  %16 = load i16, ptr %15, align 2, !tbaa !12
  %17 = zext i16 %16 to i32
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %13
  br label %27

20:                                               ; preds = %13
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.precisionType, ptr %23, i32 0, i32 4
  %25 = getelementptr inbounds [1 x i16], ptr %24, i64 0, i64 0
  %26 = icmp ugt ptr %22, %25
  br i1 %26, label %13, label %27, !llvm.loop !13

27:                                               ; preds = %21, %19
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.precisionType, ptr %29, i32 0, i32 4
  %31 = getelementptr inbounds [1 x i16], ptr %30, i64 0, i64 0
  %32 = icmp eq ptr %28, %31
  br i1 %32, label %33, label %41

33:                                               ; preds = %27
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i16, ptr %34, align 2, !tbaa !12
  %36 = zext i16 %35 to i32
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %33
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.precisionType, ptr %39, i32 0, i32 3
  store i8 0, ptr %40, align 2, !tbaa !15
  br label %41

41:                                               ; preds = %38, %33, %27
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.precisionType, ptr %43, i32 0, i32 4
  %45 = getelementptr inbounds [1 x i16], ptr %44, i64 0, i64 0
  %46 = ptrtoint ptr %42 to i64
  %47 = ptrtoint ptr %45 to i64
  %48 = sub i64 %46, %47
  %49 = sdiv exact i64 %48, 2
  %50 = add nsw i64 %49, 1
  %51 = trunc i64 %50 to i16
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.precisionType, ptr %52, i32 0, i32 2
  store i16 %51, ptr %53, align 2, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

; 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

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"", !11, i64 0, !11, i64 2, !11, i64 4, !7, i64 6, !7, i64 8}
!11 = !{!"short", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !7, i64 6}


; 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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @pnorm(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i16, ptr %2, align 2, !tbaa !5
  %4 = zext i16 %3 to i64
  %.idx = shl nuw nsw i64 %4, 1
  %.add = add nuw nsw i64 %.idx, 8
  br label %5

5:                                                ; preds = %5, %1
  %.0.idx = phi i64 [ %.add, %1 ], [ %.0.add, %5 ]
  %.0.add = add nsw i64 %.0.idx, -2
  %.ptr = getelementptr inbounds i8, ptr %0, i64 %.0.add
  %6 = load i16, ptr %.ptr, align 2, !tbaa !10
  %.not = icmp eq i16 %6, 0
  %7 = icmp ugt i64 %.0.idx, 10
  %or.cond = and i1 %7, %.not
  br i1 %or.cond, label %5, label %8, !llvm.loop !11

8:                                                ; preds = %5
  %9 = icmp eq i64 %.0.add, 8
  %brmerge.not = and i1 %9, %.not
  br i1 %brmerge.not, label %10, label %12

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %0, i64 6
  store i8 0, ptr %11, align 2, !tbaa !13
  br label %12

12:                                               ; preds = %8, %10
  %gepdiff = add nuw i64 %.0.idx, 131062
  %13 = lshr exact i64 %gepdiff, 1
  %14 = trunc i64 %13 to i16
  %15 = add i16 %14, 1
  store i16 %15, ptr %2, align 2, !tbaa !5
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

!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, !7, i64 4}
!6 = !{!"", !7, i64 0, !7, i64 2, !7, i64 4, !8, i64 6, !8, i64 8}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !8, i64 6}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass