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

; 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.caryll_Buffer = type { i64, i64, i64, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @shrinkFlags(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call i64 @buflen(ptr noundef %7)
  %9 = icmp ne i64 %8, 0
  br i1 %9, label %12, label %10

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %11, ptr %2, align 8
  br label %108

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %13 = call ptr (...) @bufnew()
  store ptr %13, ptr %4, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.caryll_Buffer, ptr %15, i32 0, i32 3
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %17, i64 0
  %19 = load i8, ptr %18, align 1, !tbaa !12
  call void @bufwrite8(ptr noundef %14, i8 noundef zeroext %19)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 1, ptr %6, align 8, !tbaa !15
  br label %20

20:                                               ; preds = %102, %12
  %21 = load i64, ptr %6, align 8, !tbaa !15
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = call i64 @buflen(ptr noundef %22)
  %24 = icmp ult i64 %21, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %105

26:                                               ; preds = %20
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.caryll_Buffer, ptr %27, i32 0, i32 3
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = load i64, ptr %6, align 8, !tbaa !15
  %31 = getelementptr inbounds i8, ptr %29, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !12
  %33 = zext i8 %32 to i32
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.caryll_Buffer, ptr %34, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = load i64, ptr %6, align 8, !tbaa !15
  %38 = sub i64 %37, 1
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !12
  %41 = zext i8 %40 to i32
  %42 = icmp eq i32 %33, %41
  br i1 %42, label %43, label %93

43:                                               ; preds = %26
  %44 = load i32, ptr %5, align 4, !tbaa !13
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %64

46:                                               ; preds = %43
  %47 = load i32, ptr %5, align 4, !tbaa !13
  %48 = icmp slt i32 %47, 254
  br i1 %48, label %49, label %64

49:                                               ; preds = %46
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.caryll_Buffer, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.caryll_Buffer, ptr %53, i32 0, i32 0
  %55 = load i64, ptr %54, align 8, !tbaa !16
  %56 = sub i64 %55, 1
  %57 = getelementptr inbounds i8, ptr %52, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !12
  %59 = zext i8 %58 to i32
  %60 = add nsw i32 %59, 1
  %61 = trunc i32 %60 to i8
  store i8 %61, ptr %57, align 1, !tbaa !12
  %62 = load i32, ptr %5, align 4, !tbaa !13
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %5, align 4, !tbaa !13
  br label %92

64:                                               ; preds = %46, %43
  %65 = load i32, ptr %5, align 4, !tbaa !13
  %66 = icmp eq i32 %65, 0
  br i1 %66, label %67, label %83

67:                                               ; preds = %64
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.caryll_Buffer, ptr %68, i32 0, i32 3
  %70 = load ptr, ptr %69, align 8, !tbaa !9
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.caryll_Buffer, ptr %71, i32 0, i32 0
  %73 = load i64, ptr %72, align 8, !tbaa !16
  %74 = sub i64 %73, 1
  %75 = getelementptr inbounds i8, ptr %70, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !12
  %77 = zext i8 %76 to i32
  %78 = or i32 %77, 8
  %79 = trunc i32 %78 to i8
  store i8 %79, ptr %75, align 1, !tbaa !12
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  call void @bufwrite8(ptr noundef %80, i8 noundef zeroext 1)
  %81 = load i32, ptr %5, align 4, !tbaa !13
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %5, align 4, !tbaa !13
  br label %91

83:                                               ; preds = %64
  store i32 0, ptr %5, align 4, !tbaa !13
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.caryll_Buffer, ptr %85, i32 0, i32 3
  %87 = load ptr, ptr %86, align 8, !tbaa !9
  %88 = load i64, ptr %6, align 8, !tbaa !15
  %89 = getelementptr inbounds i8, ptr %87, i64 %88
  %90 = load i8, ptr %89, align 1, !tbaa !12
  call void @bufwrite8(ptr noundef %84, i8 noundef zeroext %90)
  br label %91

91:                                               ; preds = %83, %67
  br label %92

92:                                               ; preds = %91, %49
  br label %101

93:                                               ; preds = %26
  store i32 0, ptr %5, align 4, !tbaa !13
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.caryll_Buffer, ptr %95, i32 0, i32 3
  %97 = load ptr, ptr %96, align 8, !tbaa !9
  %98 = load i64, ptr %6, align 8, !tbaa !15
  %99 = getelementptr inbounds i8, ptr %97, i64 %98
  %100 = load i8, ptr %99, align 1, !tbaa !12
  call void @bufwrite8(ptr noundef %94, i8 noundef zeroext %100)
  br label %101

101:                                              ; preds = %93, %92
  br label %102

102:                                              ; preds = %101
  %103 = load i64, ptr %6, align 8, !tbaa !15
  %104 = add i64 %103, 1
  store i64 %104, ptr %6, align 8, !tbaa !15
  br label %20, !llvm.loop !17

105:                                              ; preds = %25
  %106 = load ptr, ptr %3, align 8, !tbaa !5
  call void @buffree(ptr noundef %106)
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %107, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %108

108:                                              ; preds = %105, %10
  %109 = load ptr, ptr %2, align 8
  ret ptr %109
}

declare i64 @buflen(ptr noundef) #1

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

declare ptr @bufnew(...) #1

declare void @bufwrite8(ptr noundef, i8 noundef zeroext) #1

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

declare void @buffree(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 24}
!10 = !{!"caryll_Buffer", !11, i64 0, !11, i64 8, !11, i64 16, !6, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @shrinkFlags(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i64 @buflen(ptr noundef %0) #2
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %44, label %3

3:                                                ; preds = %1
  %4 = tail call ptr (...) @bufnew() #2
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load i8, ptr %6, align 1, !tbaa !11
  tail call void @bufwrite8(ptr noundef %4, i8 noundef zeroext %7) #2
  %8 = tail call i64 @buflen(ptr noundef nonnull %0) #2
  %9 = icmp ugt i64 %8, 1
  br i1 %9, label %.lr.ph, label %._crit_edge

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

._crit_edge:                                      ; preds = %40, %3
  tail call void @buffree(ptr noundef nonnull %0) #2
  br label %44

11:                                               ; preds = %.lr.ph, %40
  %.033 = phi i64 [ 1, %.lr.ph ], [ %41, %40 ]
  %.03032 = phi i32 [ 0, %.lr.ph ], [ %.1, %40 ]
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 %.033
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = getelementptr i8, ptr %13, i64 -1
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = icmp eq i8 %14, %16
  br i1 %17, label %18, label %39

18:                                               ; preds = %11
  %19 = icmp ne i32 %.03032, 0
  %20 = icmp slt i32 %.03032, 254
  %or.cond = and i1 %19, %20
  br i1 %or.cond, label %21, label %29

21:                                               ; preds = %18
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = load i64, ptr %4, align 8, !tbaa !12
  %24 = getelementptr i8, ptr %22, i64 %23
  %25 = getelementptr i8, ptr %24, i64 -1
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = add i8 %26, 1
  store i8 %27, ptr %25, align 1, !tbaa !11
  %28 = add nsw i32 %.03032, 1
  br label %40

29:                                               ; preds = %18
  %30 = icmp eq i32 %.03032, 0
  br i1 %30, label %31, label %38

31:                                               ; preds = %29
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = load i64, ptr %4, align 8, !tbaa !12
  %34 = getelementptr i8, ptr %32, i64 %33
  %35 = getelementptr i8, ptr %34, i64 -1
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = or i8 %36, 8
  store i8 %37, ptr %35, align 1, !tbaa !11
  tail call void @bufwrite8(ptr noundef nonnull %4, i8 noundef zeroext 1) #2
  br label %40

38:                                               ; preds = %29
  tail call void @bufwrite8(ptr noundef %4, i8 noundef zeroext %14) #2
  br label %40

39:                                               ; preds = %11
  tail call void @bufwrite8(ptr noundef %4, i8 noundef zeroext %14) #2
  br label %40

40:                                               ; preds = %39, %31, %38, %21
  %.1 = phi i32 [ %28, %21 ], [ 1, %31 ], [ 0, %38 ], [ 0, %39 ]
  %41 = add nuw i64 %.033, 1
  %42 = tail call i64 @buflen(ptr noundef nonnull %0) #2
  %43 = icmp ult i64 %41, %42
  br i1 %43, label %11, label %._crit_edge, !llvm.loop !13

44:                                               ; preds = %1, %._crit_edge
  %.031 = phi ptr [ %4, %._crit_edge ], [ %0, %1 ]
  ret ptr %.031
}

declare i64 @buflen(ptr noundef) local_unnamed_addr #1

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

declare void @bufwrite8(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

declare void @buffree(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 = { "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 24}
!6 = !{!"caryll_Buffer", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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