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

; 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_gasp = type { i16, %struct.gasp_RecordList }
%struct.gasp_RecordList = type { i64, i64, ptr }
%struct.gasp_Record = type { i16, i8, i8, i8, i8 }

; 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_buildGasp(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
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  br label %76

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

21:                                               ; preds = %71, %12
  %22 = load i16, ptr %7, align 2, !tbaa !14
  %23 = zext i16 %22 to i64
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.table_gasp, ptr %24, i32 0, i32 1
  %26 = getelementptr inbounds %struct.gasp_RecordList, ptr %25, i32 0, i32 0
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = icmp ult i64 %23, %27
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.table_gasp, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.gasp_RecordList, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = load i16, ptr %7, align 2, !tbaa !14
  %36 = zext i16 %35 to i64
  %37 = getelementptr inbounds %struct.gasp_Record, ptr %34, i64 %36
  store ptr %37, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.gasp_Record, ptr %39, i32 0, i32 0
  %41 = load i16, ptr %40, align 2, !tbaa !16
  call void @bufwrite16b(ptr noundef %38, i16 noundef zeroext %41)
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.gasp_Record, ptr %43, i32 0, i32 1
  %45 = load i8, ptr %44, align 2, !tbaa !19, !range !20, !noundef !21
  %46 = trunc i8 %45 to i1
  %47 = zext i1 %46 to i64
  %48 = select i1 %46, i32 2, i32 0
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.gasp_Record, ptr %49, i32 0, i32 2
  %51 = load i8, ptr %50, align 1, !tbaa !22, !range !20, !noundef !21
  %52 = trunc i8 %51 to i1
  %53 = zext i1 %52 to i64
  %54 = select i1 %52, i32 1, i32 0
  %55 = or i32 %48, %54
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.gasp_Record, ptr %56, i32 0, i32 4
  %58 = load i8, ptr %57, align 1, !tbaa !23, !range !20, !noundef !21
  %59 = trunc i8 %58 to i1
  %60 = zext i1 %59 to i64
  %61 = select i1 %59, i32 4, i32 0
  %62 = or i32 %55, %61
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.gasp_Record, ptr %63, i32 0, i32 3
  %65 = load i8, ptr %64, align 2, !tbaa !24, !range !20, !noundef !21
  %66 = trunc i8 %65 to i1
  %67 = zext i1 %66 to i64
  %68 = select i1 %66, i32 8, i32 0
  %69 = or i32 %62, %68
  %70 = trunc i32 %69 to i16
  call void @bufwrite16b(ptr noundef %42, i16 noundef zeroext %70)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %71

71:                                               ; preds = %30
  %72 = load i16, ptr %7, align 2, !tbaa !14
  %73 = add i16 %72, 1
  store i16 %73, ptr %7, align 2, !tbaa !14
  br label %21, !llvm.loop !25

74:                                               ; preds = %29
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %75, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %76

76:                                               ; preds = %74, %11
  %77 = load ptr, ptr %3, align 8
  ret ptr %77
}

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, !13, i64 8}
!10 = !{!"", !11, i64 0, !12, i64 8}
!11 = !{!"short", !7, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8, !6, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !6, i64 24}
!16 = !{!17, !11, i64 0}
!17 = !{!"", !11, i64 0, !18, i64 2, !18, i64 3, !18, i64 4, !18, i64 5}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!17, !18, i64 2}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!17, !18, i64 3}
!23 = !{!17, !18, i64 5}
!24 = !{!17, !18, i64 4}
!25 = distinct !{!25, !26}
!26 = !{!"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.gasp_Record = type { i16, i8, i8, i8, i8 }

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @otfcc_buildGasp(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
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = trunc i64 %6 to i16
  tail call void @bufwrite16b(ptr noundef %4, i16 noundef zeroext %7) #2
  %8 = load i64, ptr %5, align 8, !tbaa !5
  %.not21 = icmp eq i64 %8, 0
  br i1 %.not21, label %.loopexit, label %.lr.ph

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

10:                                               ; preds = %.lr.ph, %10
  %11 = phi i64 [ 0, %.lr.ph ], [ %34, %10 ]
  %.01720 = phi i16 [ 0, %.lr.ph ], [ %33, %10 ]
  %12 = load ptr, ptr %9, align 8, !tbaa !13
  %13 = getelementptr inbounds %struct.gasp_Record, ptr %12, i64 %11
  %14 = load i16, ptr %13, align 2, !tbaa !14
  tail call void @bufwrite16b(ptr noundef %4, i16 noundef zeroext %14) #2
  %15 = getelementptr inbounds i8, ptr %13, i64 2
  %16 = load i8, ptr %15, align 2, !tbaa !17, !range !18, !noundef !19
  %17 = trunc nuw i8 %16 to i1
  %18 = select i1 %17, i16 2, i16 0
  %19 = getelementptr inbounds i8, ptr %13, i64 3
  %20 = load i8, ptr %19, align 1, !tbaa !20, !range !18, !noundef !19
  %21 = zext nneg i8 %20 to i16
  %22 = or disjoint i16 %18, %21
  %23 = getelementptr inbounds i8, ptr %13, i64 5
  %24 = load i8, ptr %23, align 1, !tbaa !21, !range !18, !noundef !19
  %25 = trunc nuw i8 %24 to i1
  %26 = select i1 %25, i16 4, i16 0
  %27 = or disjoint i16 %22, %26
  %28 = getelementptr inbounds i8, ptr %13, i64 4
  %29 = load i8, ptr %28, align 2, !tbaa !22, !range !18, !noundef !19
  %30 = trunc nuw i8 %29 to i1
  %31 = select i1 %30, i16 8, i16 0
  %32 = or disjoint i16 %27, %31
  tail call void @bufwrite16b(ptr noundef %4, i16 noundef zeroext %32) #2
  %33 = add i16 %.01720, 1
  %34 = zext i16 %33 to i64
  %35 = load i64, ptr %5, align 8, !tbaa !5
  %36 = icmp ugt i64 %35, %34
  br i1 %36, label %10, label %.loopexit, !llvm.loop !23

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

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, !11, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !12, i64 24}
!14 = !{!15, !7, i64 0}
!15 = !{!"", !7, i64 0, !16, i64 2, !16, i64 3, !16, i64 4, !16, i64 5}
!16 = !{!"_Bool", !8, i64 0}
!17 = !{!15, !16, i64 2}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!15, !16, i64 3}
!21 = !{!15, !16, i64 5}
!22 = !{!15, !16, i64 4}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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