; LLVM IR from caryll/otfcc :: lib/table (vmtx)

; 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.table_vmtx = type { ptr, ptr }
%struct.vertical_metric = type { double, double }

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @otfcc_buildVmtx(ptr noundef %0, i16 noundef zeroext %1, i16 noundef zeroext %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca i16, align 2
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i16, align 2
  %12 = alloca i16, align 2
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i16 %1, ptr %7, align 2, !tbaa !9
  store i16 %2, ptr %8, align 2, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  br label %84

16:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %17 = call ptr (...) @bufnew()
  store ptr %17, ptr %10, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.table_vmtx, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %55

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  store i16 0, ptr %11, align 2, !tbaa !9
  br label %23

23:                                               ; preds = %51, %22
  %24 = load i16, ptr %11, align 2, !tbaa !9
  %25 = zext i16 %24 to i32
  %26 = load i16, ptr %7, align 2, !tbaa !9
  %27 = zext i16 %26 to i32
  %28 = icmp slt i32 %25, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  br label %54

30:                                               ; preds = %23
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.table_vmtx, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = load i16, ptr %11, align 2, !tbaa !9
  %36 = zext i16 %35 to i64
  %37 = getelementptr inbounds %struct.vertical_metric, ptr %34, i64 %36
  %38 = getelementptr inbounds %struct.vertical_metric, ptr %37, i32 0, i32 0
  %39 = load double, ptr %38, align 8, !tbaa !13
  %40 = fptoui double %39 to i16
  call void @bufwrite16b(ptr noundef %31, i16 noundef zeroext %40)
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.table_vmtx, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  %45 = load i16, ptr %11, align 2, !tbaa !9
  %46 = zext i16 %45 to i64
  %47 = getelementptr inbounds %struct.vertical_metric, ptr %44, i64 %46
  %48 = getelementptr inbounds %struct.vertical_metric, ptr %47, i32 0, i32 1
  %49 = load double, ptr %48, align 8, !tbaa !16
  %50 = fptoui double %49 to i16
  call void @bufwrite16b(ptr noundef %41, i16 noundef zeroext %50)
  br label %51

51:                                               ; preds = %30
  %52 = load i16, ptr %11, align 2, !tbaa !9
  %53 = add i16 %52, 1
  store i16 %53, ptr %11, align 2, !tbaa !9
  br label %23, !llvm.loop !17

54:                                               ; preds = %29
  br label %55

55:                                               ; preds = %54, %16
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.table_vmtx, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !19
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %82

60:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #3
  store i16 0, ptr %12, align 2, !tbaa !9
  br label %61

61:                                               ; preds = %78, %60
  %62 = load i16, ptr %12, align 2, !tbaa !9
  %63 = zext i16 %62 to i32
  %64 = load i16, ptr %8, align 2, !tbaa !9
  %65 = zext i16 %64 to i32
  %66 = icmp slt i32 %63, %65
  br i1 %66, label %68, label %67

67:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #3
  br label %81

68:                                               ; preds = %61
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.table_vmtx, ptr %70, i32 0, i32 1
  %72 = load ptr, ptr %71, align 8, !tbaa !19
  %73 = load i16, ptr %12, align 2, !tbaa !9
  %74 = zext i16 %73 to i64
  %75 = getelementptr inbounds double, ptr %72, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !20
  %77 = fptoui double %76 to i16
  call void @bufwrite16b(ptr noundef %69, i16 noundef zeroext %77)
  br label %78

78:                                               ; preds = %68
  %79 = load i16, ptr %12, align 2, !tbaa !9
  %80 = add i16 %79, 1
  store i16 %80, ptr %12, align 2, !tbaa !9
  br label %61, !llvm.loop !21

81:                                               ; preds = %67
  br label %82

82:                                               ; preds = %81, %55
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %83, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %84

84:                                               ; preds = %82, %15
  %85 = load ptr, ptr %5, align 8
  ret ptr %85
}

declare ptr @bufnew(...) #2

declare void @bufwrite16b(ptr noundef, i16 noundef zeroext) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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, !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 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8}
!13 = !{!14, !15, i64 0}
!14 = !{!"", !15, i64 0, !15, i64 8}
!15 = !{!"double", !7, i64 0}
!16 = !{!14, !15, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !6, i64 8}
!20 = !{!15, !15, i64 0}
!21 = distinct !{!21, !18}


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

%struct.vertical_metric = type { double, double }

; Function Attrs: nounwind uwtable
define dso_local ptr @otfcc_buildVmtx(ptr noundef readonly %0, i16 noundef zeroext %1, i16 noundef zeroext %2, ptr nocapture noundef readnone %3) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %5

5:                                                ; preds = %4
  %6 = tail call ptr (...) @bufnew() #2
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %.not22 = icmp ne ptr %7, null
  %8 = icmp ne i16 %1, 0
  %or.cond = and i1 %.not22, %8
  br i1 %or.cond, label %.lr.ph.preheader, label %.loopexit25

.lr.ph.preheader:                                 ; preds = %5
  %wide.trip.count = zext i16 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %9 = load ptr, ptr %0, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.vertical_metric, ptr %9, i64 %indvars.iv
  %11 = load double, ptr %10, align 8, !tbaa !10
  %12 = fptoui double %11 to i16
  tail call void @bufwrite16b(ptr noundef %6, i16 noundef zeroext %12) #2
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.vertical_metric, ptr %13, i64 %indvars.iv, i32 1
  %15 = load double, ptr %14, align 8, !tbaa !13
  %16 = fptoui double %15 to i16
  tail call void @bufwrite16b(ptr noundef %6, i16 noundef zeroext %16) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit25, label %.lr.ph, !llvm.loop !14

.loopexit25:                                      ; preds = %.lr.ph, %5
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %.not23 = icmp ne ptr %18, null
  %19 = icmp ne i16 %2, 0
  %or.cond29 = and i1 %.not23, %19
  br i1 %or.cond29, label %.lr.ph28.preheader, label %.loopexit

.lr.ph28.preheader:                               ; preds = %.loopexit25
  %wide.trip.count34 = zext i16 %2 to i64
  br label %.lr.ph28

.lr.ph28:                                         ; preds = %.lr.ph28.preheader, %.lr.ph28
  %indvars.iv31 = phi i64 [ 0, %.lr.ph28.preheader ], [ %indvars.iv.next32, %.lr.ph28 ]
  %20 = load ptr, ptr %17, align 8, !tbaa !16
  %21 = getelementptr inbounds double, ptr %20, i64 %indvars.iv31
  %22 = load double, ptr %21, align 8, !tbaa !17
  %23 = fptoui double %22 to i16
  tail call void @bufwrite16b(ptr noundef %6, i16 noundef zeroext %23) #2
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %exitcond35.not = icmp eq i64 %indvars.iv.next32, %wide.trip.count34
  br i1 %exitcond35.not, label %.loopexit, label %.lr.ph28, !llvm.loop !18

.loopexit:                                        ; preds = %.lr.ph28, %.loopexit25, %4
  %.020 = phi ptr [ null, %4 ], [ %6, %.loopexit25 ], [ %6, %.lr.ph28 ]
  ret ptr %.020
}

declare ptr @bufnew(...) local_unnamed_addr #1

declare void @bufwrite16b(ptr noundef, i16 noundef zeroext) 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 = { "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 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"", !12, i64 0, !12, i64 8}
!12 = !{!"double", !8, i64 0}
!13 = !{!11, !12, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !7, i64 8}
!17 = !{!12, !12, i64 0}
!18 = distinct !{!18, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass