; 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: 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 @cff_build_IL(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = call ptr (...) @bufnew()
  store ptr %5, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #3
  store i16 0, ptr %4, align 2, !tbaa !9
  br label %6

6:                                                ; preds = %56, %1
  %7 = load i16, ptr %4, align 2, !tbaa !9
  %8 = zext i16 %7 to i32
  %9 = load ptr, ptr %2, 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 %4) #3
  br label %59

14:                                               ; preds = %6
  %15 = load ptr, ptr %2, 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 %4, 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 %54 [
    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 %2, 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 %4, 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 @cff_mergeCS2Operand(ptr noundef %24, double noundef %32)
  br label %55

33:                                               ; preds = %14
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load ptr, ptr %2, 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 %4, 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 @cff_mergeCS2Operator(ptr noundef %34, i32 noundef %42)
  br label %55

43:                                               ; preds = %14
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %2, 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 %4, 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
  %53 = trunc i32 %52 to i8
  call void @cff_mergeCS2Special(ptr noundef %44, i8 noundef zeroext %53)
  br label %55

54:                                               ; preds = %14
  br label %55

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

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

59:                                               ; preds = %13
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %60
}

declare ptr @bufnew(...) #2

declare void @cff_mergeCS2Operand(ptr noundef, double noundef) #2

declare void @cff_mergeCS2Operator(ptr noundef, i32 noundef) #2

declare void @cff_mergeCS2Special(ptr noundef, i8 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, !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
define dso_local ptr @cff_build_IL(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = tail call ptr (...) @bufnew() #2
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

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

._crit_edge:                                      ; preds = %20, %1
  ret ptr %2

5:                                                ; preds = %.lr.ph, %20
  %.014 = phi i16 [ 0, %.lr.ph ], [ %21, %20 ]
  %6 = load ptr, ptr %4, align 8, !tbaa !11
  %7 = zext i16 %.014 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 %20 [
    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 @cff_mergeCS2Operand(ptr noundef %2, double noundef %12) #2
  br label %20

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

16:                                               ; preds = %5
  %17 = getelementptr inbounds i8, ptr %8, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = trunc i32 %18 to i8
  tail call void @cff_mergeCS2Special(ptr noundef %2, i8 noundef zeroext %19) #2
  br label %20

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

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

declare void @cff_mergeCS2Operand(ptr noundef, double noundef) local_unnamed_addr #1

declare void @cff_mergeCS2Operator(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @cff_mergeCS2Special(ptr noundef, i8 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 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