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

; 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.otfcc_Options = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, ptr, ptr }
%struct.otfcc_ILogger = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.table_CPAL = type { i16, %struct.cpal_PaletteSet }
%struct.cpal_PaletteSet = type { i64, i64, ptr }
%struct.cpal_Palette = type { %struct.cpal_ColorSet, i32, i32 }
%struct.cpal_ColorSet = type { i64, i64, ptr }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1

; 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 void @otfcc_dumpCPAL(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i16, align 2
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %3
  br label %83

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.otfcc_Options, ptr %16, i32 0, i32 24
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.otfcc_ILogger, ptr %18, i32 0, i32 4
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.otfcc_Options, ptr %21, i32 0, i32 24
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = call ptr @sdsempty()
  %25 = call ptr (ptr, ptr, ...) @sdscatprintf(ptr noundef %24, ptr noundef @.str)
  call void %20(ptr noundef %23, ptr noundef %25)
  store i8 1, ptr %7, align 1, !tbaa !14
  br label %26

26:                                               ; preds = %74, %15
  %27 = load i8, ptr %7, align 1, !tbaa !14, !range !15, !noundef !16
  %28 = trunc i8 %27 to i1
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  br label %83

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %31 = call ptr @json_object_new(i64 noundef 2)
  store ptr %31, ptr %9, align 8, !tbaa !5
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.table_CPAL, ptr %33, i32 0, i32 0
  %35 = load i16, ptr %34, align 8, !tbaa !17
  %36 = zext i16 %35 to i64
  %37 = call ptr @json_integer_new(i64 noundef %36)
  %38 = call ptr @json_object_push(ptr noundef %32, ptr noundef @.str.1, ptr noundef %37)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.table_CPAL, ptr %39, i32 0, i32 1
  %41 = getelementptr inbounds %struct.cpal_PaletteSet, ptr %40, i32 0, i32 0
  %42 = load i64, ptr %41, align 8, !tbaa !22
  %43 = call ptr @json_array_new(i64 noundef %42)
  store ptr %43, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #4
  store i16 0, ptr %11, align 2, !tbaa !23
  br label %44

44:                                               ; preds = %64, %30
  %45 = load i16, ptr %11, align 2, !tbaa !23
  %46 = zext i16 %45 to i64
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.table_CPAL, ptr %47, i32 0, i32 1
  %49 = getelementptr inbounds %struct.cpal_PaletteSet, ptr %48, i32 0, i32 0
  %50 = load i64, ptr %49, align 8, !tbaa !22
  %51 = icmp ult i64 %46, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %44
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #4
  br label %67

53:                                               ; preds = %44
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.table_CPAL, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds %struct.cpal_PaletteSet, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !24
  %59 = load i16, ptr %11, align 2, !tbaa !23
  %60 = zext i16 %59 to i64
  %61 = getelementptr inbounds %struct.cpal_Palette, ptr %58, i64 %60
  %62 = call ptr @dumpPalette(ptr noundef %61)
  %63 = call ptr @json_array_push(ptr noundef %54, ptr noundef %62)
  br label %64

64:                                               ; preds = %53
  %65 = load i16, ptr %11, align 2, !tbaa !23
  %66 = add i16 %65, 1
  store i16 %66, ptr %11, align 2, !tbaa !23
  br label %44, !llvm.loop !25

67:                                               ; preds = %52
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = call ptr @json_object_push(ptr noundef %68, ptr noundef @.str.2, ptr noundef %69)
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = call ptr @json_object_push(ptr noundef %71, ptr noundef @.str, ptr noundef %72)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %74

74:                                               ; preds = %67
  store i8 0, ptr %7, align 1, !tbaa !14
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.otfcc_Options, ptr %75, i32 0, i32 24
  %77 = load ptr, ptr %76, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.otfcc_ILogger, ptr %77, i32 0, i32 8
  %79 = load ptr, ptr %78, align 8, !tbaa !27
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.otfcc_Options, ptr %80, i32 0, i32 24
  %82 = load ptr, ptr %81, align 8, !tbaa !9
  call void %79(ptr noundef %82)
  br label %26, !llvm.loop !28

83:                                               ; preds = %29, %14
  ret void
}

declare ptr @sdscatprintf(ptr noundef, ptr noundef, ...) #2

declare ptr @sdsempty() #2

declare ptr @json_object_new(i64 noundef) #2

declare ptr @json_object_push(ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @json_integer_new(i64 noundef) #2

declare ptr @json_array_new(i64 noundef) #2

declare ptr @json_array_push(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @dumpPalette(ptr noundef) #3

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 = { inlinehint 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 #4 = { 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 32}
!10 = !{!"", !11, i64 0, !11, i64 1, !11, i64 2, !11, i64 3, !11, i64 4, !11, i64 5, !11, i64 6, !11, i64 7, !11, i64 8, !11, i64 9, !11, i64 10, !11, i64 11, !11, i64 12, !11, i64 13, !11, i64 14, !11, i64 15, !11, i64 16, !11, i64 17, !11, i64 18, !11, i64 19, !11, i64 20, !11, i64 21, !11, i64 22, !6, i64 24, !6, i64 32}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!13, !6, i64 32}
!13 = !{!"otfcc_ILogger", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!14 = !{!11, !11, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !19, i64 0}
!18 = !{!"", !19, i64 0, !20, i64 8}
!19 = !{!"short", !7, i64 0}
!20 = !{!"", !21, i64 0, !21, i64 8, !6, i64 16}
!21 = !{!"long", !7, i64 0}
!22 = !{!18, !21, i64 8}
!23 = !{!19, !19, i64 0}
!24 = !{!18, !6, i64 24}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!13, !6, i64 64}
!28 = distinct !{!28, !26}


; 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.cpal_Palette = type { %struct.cpal_ColorSet, i32, i32 }
%struct.cpal_ColorSet = type { i64, i64, ptr }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @otfcc_dumpCPAL(ptr noundef readonly %0, ptr noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %35, label %.critedge

.critedge:                                        ; preds = %3
  %4 = getelementptr inbounds i8, ptr %2, i64 32
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 32
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = tail call ptr @sdsempty() #3
  %9 = tail call ptr (ptr, ptr, ...) @sdscatprintf(ptr noundef %8, ptr noundef nonnull @.str) #3
  tail call void %7(ptr noundef %5, ptr noundef %9) #3
  %10 = tail call ptr @json_object_new(i64 noundef 2) #3
  %11 = load i16, ptr %0, align 8, !tbaa !13
  %12 = zext i16 %11 to i64
  %13 = tail call ptr @json_integer_new(i64 noundef %12) #3
  %14 = tail call ptr @json_object_push(ptr noundef %10, ptr noundef nonnull @.str.1, ptr noundef %13) #3
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !18
  %17 = tail call ptr @json_array_new(i64 noundef %16) #3
  %18 = load i64, ptr %15, align 8, !tbaa !18
  %.not22 = icmp eq i64 %18, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.critedge
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  br label %25

._crit_edge:                                      ; preds = %25, %.critedge
  %20 = tail call ptr @json_object_push(ptr noundef %10, ptr noundef nonnull @.str.2, ptr noundef %17) #3
  %21 = tail call ptr @json_object_push(ptr noundef %1, ptr noundef nonnull @.str, ptr noundef %10) #3
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 64
  %24 = load ptr, ptr %23, align 8, !tbaa !19
  tail call void %24(ptr noundef %22) #3
  br label %35

25:                                               ; preds = %.lr.ph, %25
  %26 = phi i64 [ 0, %.lr.ph ], [ %32, %25 ]
  %.021 = phi i16 [ 0, %.lr.ph ], [ %31, %25 ]
  %27 = load ptr, ptr %19, align 8, !tbaa !20
  %28 = getelementptr inbounds %struct.cpal_Palette, ptr %27, i64 %26
  %29 = tail call ptr @dumpPalette(ptr noundef %28)
  %30 = tail call ptr @json_array_push(ptr noundef %17, ptr noundef %29) #3
  %31 = add i16 %.021, 1
  %32 = zext i16 %31 to i64
  %33 = load i64, ptr %15, align 8, !tbaa !18
  %34 = icmp ugt i64 %33, %32
  br i1 %34, label %25, label %._crit_edge, !llvm.loop !21

35:                                               ; preds = %3, %._crit_edge
  ret void
}

declare ptr @sdscatprintf(ptr noundef, ptr noundef, ...) local_unnamed_addr #1

declare ptr @sdsempty() local_unnamed_addr #1

declare ptr @json_object_new(i64 noundef) local_unnamed_addr #1

declare ptr @json_object_push(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @json_integer_new(i64 noundef) local_unnamed_addr #1

declare ptr @json_array_new(i64 noundef) local_unnamed_addr #1

declare ptr @json_array_push(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @dumpPalette(ptr noundef) local_unnamed_addr #2

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 = { inlinehint 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 #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, !10, i64 32}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19, !7, i64 20, !7, i64 21, !7, i64 22, !10, i64 24, !10, i64 32}
!7 = !{!"_Bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"otfcc_ILogger", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88}
!13 = !{!14, !15, i64 0}
!14 = !{!"", !15, i64 0, !16, i64 8}
!15 = !{!"short", !8, i64 0}
!16 = !{!"", !17, i64 0, !17, i64 8, !10, i64 16}
!17 = !{!"long", !8, i64 0}
!18 = !{!14, !17, i64 8}
!19 = !{!12, !10, i64 64}
!20 = !{!14, !10, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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