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

; 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_VORG = type { i16, double, ptr }
%struct.VORG_entry = type { i16, i16 }

; 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_buildVORG(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  br label %57

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %12 = call ptr (...) @bufnew()
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  call void @bufwrite16b(ptr noundef %13, i16 noundef zeroext 1)
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  call void @bufwrite16b(ptr noundef %14, i16 noundef zeroext 0)
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.table_VORG, ptr %16, i32 0, i32 1
  %18 = load double, ptr %17, align 8, !tbaa !9
  %19 = fptoui double %18 to i16
  call void @bufwrite16b(ptr noundef %15, i16 noundef zeroext %19)
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.table_VORG, ptr %21, i32 0, i32 0
  %23 = load i16, ptr %22, align 8, !tbaa !13
  call void @bufwrite16b(ptr noundef %20, i16 noundef zeroext %23)
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  store i16 0, ptr %7, align 2, !tbaa !14
  br label %24

24:                                               ; preds = %52, %11
  %25 = load i16, ptr %7, align 2, !tbaa !14
  %26 = zext i16 %25 to i32
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.table_VORG, ptr %27, i32 0, i32 0
  %29 = load i16, ptr %28, align 8, !tbaa !13
  %30 = zext i16 %29 to i32
  %31 = icmp slt i32 %26, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  br label %55

33:                                               ; preds = %24
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.table_VORG, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = load i16, ptr %7, align 2, !tbaa !14
  %39 = zext i16 %38 to i64
  %40 = getelementptr inbounds %struct.VORG_entry, ptr %37, i64 %39
  %41 = getelementptr inbounds %struct.VORG_entry, ptr %40, i32 0, i32 0
  %42 = load i16, ptr %41, align 2, !tbaa !16
  call void @bufwrite16b(ptr noundef %34, i16 noundef zeroext %42)
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.table_VORG, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load i16, ptr %7, align 2, !tbaa !14
  %48 = zext i16 %47 to i64
  %49 = getelementptr inbounds %struct.VORG_entry, ptr %46, i64 %48
  %50 = getelementptr inbounds %struct.VORG_entry, ptr %49, i32 0, i32 1
  %51 = load i16, ptr %50, align 2, !tbaa !18
  call void @bufwrite16b(ptr noundef %43, i16 noundef zeroext %51)
  br label %52

52:                                               ; preds = %33
  %53 = load i16, ptr %7, align 2, !tbaa !14
  %54 = add i16 %53, 1
  store i16 %54, ptr %7, align 2, !tbaa !14
  br label %24, !llvm.loop !19

55:                                               ; preds = %32
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %56, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %57

57:                                               ; preds = %55, %10
  %58 = load ptr, ptr %3, align 8
  ret ptr %58
}

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, !12, i64 8}
!10 = !{!"", !11, i64 0, !12, i64 8, !6, i64 16}
!11 = !{!"short", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !6, i64 16}
!16 = !{!17, !11, i64 0}
!17 = !{!"", !11, i64 0, !11, i64 2}
!18 = !{!17, !11, i64 2}
!19 = distinct !{!19, !20}
!20 = !{!"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"

%struct.VORG_entry = type { i16, i16 }

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

3:                                                ; preds = %2
  %4 = tail call ptr (...) @bufnew() #2
  tail call void @bufwrite16b(ptr noundef %4, i16 noundef zeroext 1) #2
  tail call void @bufwrite16b(ptr noundef %4, i16 noundef zeroext 0) #2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = fptoui double %6 to i16
  tail call void @bufwrite16b(ptr noundef %4, i16 noundef zeroext %7) #2
  %8 = load i16, ptr %0, align 8, !tbaa !12
  tail call void @bufwrite16b(ptr noundef %4, i16 noundef zeroext %8) #2
  %9 = load i16, ptr %0, align 8, !tbaa !12
  %.not20 = icmp eq i16 %9, 0
  br i1 %.not20, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  br label %11

11:                                               ; preds = %.lr.ph, %11
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %11 ]
  %12 = load ptr, ptr %10, align 8, !tbaa !13
  %13 = getelementptr inbounds %struct.VORG_entry, ptr %12, i64 %indvars.iv
  %14 = load i16, ptr %13, align 2, !tbaa !14
  tail call void @bufwrite16b(ptr noundef %4, i16 noundef zeroext %14) #2
  %15 = load ptr, ptr %10, align 8, !tbaa !13
  %16 = getelementptr inbounds %struct.VORG_entry, ptr %15, i64 %indvars.iv, i32 1
  %17 = load i16, ptr %16, align 2, !tbaa !16
  tail call void @bufwrite16b(ptr noundef %4, i16 noundef zeroext %17) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i16, ptr %0, align 8, !tbaa !12
  %19 = zext i16 %18 to i64
  %20 = icmp ult i64 %indvars.iv.next, %19
  br i1 %20, label %11, label %.loopexit, !llvm.loop !17

.loopexit:                                        ; preds = %11, %3, %2
  %.017 = phi ptr [ null, %2 ], [ %4, %3 ], [ %4, %11 ]
  ret ptr %.017
}

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


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