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

; 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] }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @ptou(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call ptr @pparmq(ptr noundef %5)
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.precisionType, ptr %7, i32 0, i32 3
  %9 = load i8, ptr %8, align 2, !tbaa !9
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %11, label %15

11:                                               ; preds = %1
  %12 = call ptr @errorp(i32 noundef 4, ptr noundef @.str, ptr noundef @.str.1)
  %13 = ptrtoint ptr %12 to i64
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %4, align 4, !tbaa !12
  br label %53

15:                                               ; preds = %1
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.precisionType, ptr %16, i32 0, i32 4
  %18 = getelementptr inbounds [1 x i16], ptr %17, i64 0, i64 0
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.precisionType, ptr %19, i32 0, i32 2
  %21 = load i16, ptr %20, align 2, !tbaa !14
  %22 = zext i16 %21 to i32
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i16, ptr %18, i64 %23
  store ptr %24, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !12
  br label %25

25:                                               ; preds = %46, %15
  %26 = load i32, ptr %4, align 4, !tbaa !12
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds i16, ptr %27, i32 -1
  store ptr %28, ptr %3, align 8, !tbaa !5
  %29 = load i16, ptr %28, align 2, !tbaa !15
  %30 = zext i16 %29 to i32
  %31 = sub i32 -1, %30
  %32 = lshr i32 %31, 16
  %33 = icmp ugt i32 %26, %32
  br i1 %33, label %34, label %38

34:                                               ; preds = %25
  %35 = call ptr @errorp(i32 noundef 5, ptr noundef @.str, ptr noundef @.str.2)
  %36 = ptrtoint ptr %35 to i64
  %37 = trunc i64 %36 to i32
  store i32 %37, ptr %4, align 4, !tbaa !12
  br label %52

38:                                               ; preds = %25
  %39 = load i32, ptr %4, align 4, !tbaa !12
  %40 = shl i32 %39, 16
  store i32 %40, ptr %4, align 4, !tbaa !12
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i16, ptr %41, align 2, !tbaa !15
  %43 = zext i16 %42 to i32
  %44 = load i32, ptr %4, align 4, !tbaa !12
  %45 = add i32 %44, %43
  store i32 %45, ptr %4, align 4, !tbaa !12
  br label %46

46:                                               ; preds = %38
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.precisionType, ptr %48, i32 0, i32 4
  %50 = getelementptr inbounds [1 x i16], ptr %49, i64 0, i64 0
  %51 = icmp ugt ptr %47, %50
  br i1 %51, label %25, label %52, !llvm.loop !16

52:                                               ; preds = %46, %34
  br label %53

53:                                               ; preds = %52, %11
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  call void @pdestroy(ptr noundef %54)
  %55 = load i32, ptr %4, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret i32 %55
}

; 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

declare ptr @errorp(i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @pdestroy(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"}
!9 = !{!10, !7, i64 6}
!10 = !{!"", !11, i64 0, !11, i64 2, !11, i64 4, !7, i64 6, !7, i64 8}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !11, i64 4}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @ptou(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @pparmq(ptr noundef %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 6
  %4 = load i8, ptr %3, align 2, !tbaa !5
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %9, label %5

5:                                                ; preds = %1
  %6 = tail call ptr @errorp(i32 noundef 4, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1) #3
  %7 = ptrtoint ptr %6 to i64
  %8 = trunc i64 %7 to i32
  br label %.loopexit

9:                                                ; preds = %1
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = load i16, ptr %10, align 2, !tbaa !10
  %12 = zext i16 %11 to i64
  %.idx = shl nuw nsw i64 %12, 1
  %.add = add nuw nsw i64 %.idx, 8
  br label %13

13:                                               ; preds = %19, %9
  %.012.idx = phi i64 [ %.add, %9 ], [ %.012.add, %19 ]
  %.0 = phi i32 [ 0, %9 ], [ %23, %19 ]
  %14 = icmp ugt i32 %.0, 65535
  br i1 %14, label %15, label %19

15:                                               ; preds = %13
  %16 = tail call ptr @errorp(i32 noundef 5, ptr noundef nonnull @.str, ptr noundef nonnull @.str.2) #3
  %17 = ptrtoint ptr %16 to i64
  %18 = trunc i64 %17 to i32
  br label %.loopexit

19:                                               ; preds = %13
  %.012.add = add nsw i64 %.012.idx, -2
  %.ptr = getelementptr inbounds i8, ptr %0, i64 %.012.add
  %20 = load i16, ptr %.ptr, align 2, !tbaa !11
  %21 = zext i16 %20 to i32
  %22 = shl nuw i32 %.0, 16
  %23 = or disjoint i32 %22, %21
  %24 = icmp sgt i64 %.012.idx, 10
  br i1 %24, label %13, label %.loopexit, !llvm.loop !12

.loopexit:                                        ; preds = %19, %15, %5
  %.1 = phi i32 [ %8, %5 ], [ %18, %15 ], [ %23, %19 ]
  tail call void @pdestroy(ptr noundef nonnull %0)
  ret i32 %.1
}

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

declare ptr @errorp(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @pdestroy(ptr noundef) local_unnamed_addr #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 = { 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 #2 = { "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 = { 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, !8, i64 6}
!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 = !{!6, !7, i64 4}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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