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

; 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 [6 x i8], align 1
@cmpError = external hidden global [28 x i8], align 16

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

12:                                               ; preds = %2
  store i32 -1, ptr %5, align 4, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %15, label %37

15:                                               ; preds = %12
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = sub nsw i32 0, %16
  %18 = icmp sge i32 %17, 65536
  br i1 %18, label %19, label %21

19:                                               ; preds = %15
  %20 = call ptr @errorp(i32 noundef 4, ptr noundef @.str, ptr noundef @cmpError)
  br label %21

21:                                               ; preds = %19, %15
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.precisionType, ptr %22, i32 0, i32 2
  %24 = load i16, ptr %23, align 2, !tbaa !14
  %25 = zext i16 %24 to i32
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %36

27:                                               ; preds = %21
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.precisionType, ptr %28, i32 0, i32 4
  %30 = getelementptr inbounds [1 x i16], ptr %29, i64 0, i64 0
  %31 = load i16, ptr %30, align 2, !tbaa !15
  %32 = zext i16 %31 to i32
  %33 = sub nsw i32 0, %32
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = sub nsw i32 %33, %34
  store i32 %35, ptr %5, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %27, %21
  br label %37

37:                                               ; preds = %36, %12
  br label %62

38:                                               ; preds = %2
  store i32 1, ptr %5, align 4, !tbaa !9
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = icmp sge i32 %39, 0
  br i1 %40, label %41, label %61

41:                                               ; preds = %38
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = icmp sge i32 %42, 65536
  br i1 %43, label %44, label %46

44:                                               ; preds = %41
  %45 = call ptr @errorp(i32 noundef 4, ptr noundef @.str, ptr noundef @cmpError)
  br label %46

46:                                               ; preds = %44, %41
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.precisionType, ptr %47, i32 0, i32 2
  %49 = load i16, ptr %48, align 2, !tbaa !14
  %50 = zext i16 %49 to i32
  %51 = icmp eq i32 %50, 1
  br i1 %51, label %52, label %60

52:                                               ; preds = %46
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.precisionType, ptr %53, i32 0, i32 4
  %55 = getelementptr inbounds [1 x i16], ptr %54, i64 0, i64 0
  %56 = load i16, ptr %55, align 2, !tbaa !15
  %57 = zext i16 %56 to i32
  %58 = load i32, ptr %4, align 4, !tbaa !9
  %59 = sub nsw i32 %57, %58
  store i32 %59, ptr %5, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %52, %46
  br label %61

61:                                               ; preds = %60, %38
  br label %62

62:                                               ; preds = %61, %37
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  call void @pdestroy(ptr noundef %63)
  %64 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %64
}

; 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 6}
!12 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !7, i64 6, !7, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 4}
!15 = !{!13, !13, 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"

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@cmpError = external hidden global [28 x i8], align 16

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

6:                                                ; preds = %2
  %7 = icmp slt i32 %1, 0
  br i1 %7, label %8, label %37

8:                                                ; preds = %6
  %9 = icmp ult i32 %1, -65535
  br i1 %9, label %10, label %12

10:                                               ; preds = %8
  %11 = tail call ptr @errorp(i32 noundef 4, ptr noundef nonnull @.str, ptr noundef nonnull @cmpError) #3
  br label %12

12:                                               ; preds = %10, %8
  %13 = getelementptr inbounds i8, ptr %0, i64 4
  %14 = load i16, ptr %13, align 2, !tbaa !10
  %15 = icmp eq i16 %14, 1
  br i1 %15, label %16, label %37

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load i16, ptr %17, align 2, !tbaa !11
  %19 = zext i16 %18 to i32
  %20 = add nsw i32 %19, %1
  %21 = sub i32 0, %20
  br label %37

22:                                               ; preds = %2
  %23 = icmp sgt i32 %1, -1
  br i1 %23, label %24, label %37

24:                                               ; preds = %22
  %25 = icmp ugt i32 %1, 65535
  br i1 %25, label %26, label %28

26:                                               ; preds = %24
  %27 = tail call ptr @errorp(i32 noundef 4, ptr noundef nonnull @.str, ptr noundef nonnull @cmpError) #3
  br label %28

28:                                               ; preds = %26, %24
  %29 = getelementptr inbounds i8, ptr %0, i64 4
  %30 = load i16, ptr %29, align 2, !tbaa !10
  %31 = icmp eq i16 %30, 1
  br i1 %31, label %32, label %37

32:                                               ; preds = %28
  %33 = getelementptr inbounds i8, ptr %0, i64 8
  %34 = load i16, ptr %33, align 2, !tbaa !11
  %35 = zext i16 %34 to i32
  %36 = sub nsw i32 %35, %1
  br label %37

37:                                               ; preds = %22, %32, %28, %6, %16, %12
  %.0 = phi i32 [ %21, %16 ], [ -1, %12 ], [ -1, %6 ], [ %36, %32 ], [ 1, %28 ], [ 1, %22 ]
  tail call void @pdestroy(ptr noundef nonnull %0)
  ret i32 %.0
}

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


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