; LLVM IR from caryll/otfcc :: lib/libcff (charstring-il)

; 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.cff_CharstringIL = type { i32, i32, ptr }
%struct.cff_CharstringInstruction = type { i32, i32, %union.anon }
%union.anon = type { double }

; Function Attrs: nounwind uwtable
declare dso_local void @il_push_operand(ptr noundef, double noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @il_push_special(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @il_push_op(ptr noundef, i32 noundef) #0

; 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

; Function Attrs: nounwind uwtable
define dso_local void @cff_ILmergeIL(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  store i16 0, ptr %5, align 2, !tbaa !9
  br label %6

6:                                                ; preds = %55, %2
  %7 = load i16, ptr %5, align 2, !tbaa !9
  %8 = zext i16 %7 to i32
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.cff_CharstringIL, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = icmp ult i32 %8, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  br label %58

14:                                               ; preds = %6
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.cff_CharstringIL, ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = load i16, ptr %5, align 2, !tbaa !9
  %19 = zext i16 %18 to i64
  %20 = getelementptr inbounds %struct.cff_CharstringInstruction, ptr %17, i64 %19
  %21 = getelementptr inbounds %struct.cff_CharstringInstruction, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !15
  switch i32 %22, label %53 [
    i32 0, label %23
    i32 1, label %33
    i32 2, label %43
  ]

23:                                               ; preds = %14
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.cff_CharstringIL, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = load i16, ptr %5, align 2, !tbaa !9
  %29 = zext i16 %28 to i64
  %30 = getelementptr inbounds %struct.cff_CharstringInstruction, ptr %27, i64 %29
  %31 = getelementptr inbounds %struct.cff_CharstringInstruction, ptr %30, i32 0, i32 2
  %32 = load double, ptr %31, align 8, !tbaa !17
  call void @il_push_operand(ptr noundef %24, double noundef %32)
  br label %54

33:                                               ; preds = %14
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.cff_CharstringIL, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = load i16, ptr %5, align 2, !tbaa !9
  %39 = zext i16 %38 to i64
  %40 = getelementptr inbounds %struct.cff_CharstringInstruction, ptr %37, i64 %39
  %41 = getelementptr inbounds %struct.cff_CharstringInstruction, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !17
  call void @il_push_op(ptr noundef %34, i32 noundef %42)
  br label %54

43:                                               ; preds = %14
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.cff_CharstringIL, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !14
  %48 = load i16, ptr %5, align 2, !tbaa !9
  %49 = zext i16 %48 to i64
  %50 = getelementptr inbounds %struct.cff_CharstringInstruction, ptr %47, i64 %49
  %51 = getelementptr inbounds %struct.cff_CharstringInstruction, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 8, !tbaa !17
  call void @il_push_special(ptr noundef %44, i32 noundef %52)
  br label %54

53:                                               ; preds = %14
  br label %54

54:                                               ; preds = %53, %43, %33, %23
  br label %55

55:                                               ; preds = %54
  %56 = load i16, ptr %5, align 2, !tbaa !9
  %57 = add i16 %56, 1
  store i16 %57, ptr %5, align 2, !tbaa !9
  br label %6, !llvm.loop !18

58:                                               ; preds = %13
  ret void
}

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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 4, !6, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !13, i64 0}
!16 = !{!"", !13, i64 0, !13, i64 4, !7, i64 8}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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.cff_CharstringInstruction = type { i32, i32, %union.anon }
%union.anon = type { double }

; Function Attrs: nounwind uwtable
declare dso_local void @il_push_operand(ptr noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @il_push_special(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @il_push_op(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @cff_ILmergeIL(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  br label %5

._crit_edge:                                      ; preds = %19, %2
  ret void

5:                                                ; preds = %.lr.ph, %19
  %.013 = phi i16 [ 0, %.lr.ph ], [ %20, %19 ]
  %6 = load ptr, ptr %4, align 8, !tbaa !11
  %7 = zext i16 %.013 to i64
  %8 = getelementptr inbounds %struct.cff_CharstringInstruction, ptr %6, i64 %7
  %9 = load i32, ptr %8, align 8, !tbaa !12
  switch i32 %9, label %19 [
    i32 0, label %10
    i32 1, label %13
    i32 2, label %16
  ]

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %8, i64 8
  %12 = load double, ptr %11, align 8, !tbaa !14
  tail call void @il_push_operand(ptr noundef %0, double noundef %12)
  br label %19

13:                                               ; preds = %5
  %14 = getelementptr inbounds i8, ptr %8, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !14
  tail call void @il_push_op(ptr noundef %0, i32 noundef %15)
  br label %19

16:                                               ; preds = %5
  %17 = getelementptr inbounds i8, ptr %8, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !14
  tail call void @il_push_special(ptr noundef %0, i32 noundef %18)
  br label %19

19:                                               ; preds = %10, %13, %16, %5
  %20 = add i16 %.013, 1
  %21 = zext i16 %20 to i32
  %22 = load i32, ptr %1, align 8, !tbaa !5
  %23 = icmp ugt i32 %22, %21
  br i1 %23, label %5, label %._crit_edge, !llvm.loop !15
}

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

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


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