; LLVM IR from AngelJumbo/lavat :: lavat (tb_extend_cell)

; 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.tb_global_t = type { i32, i32, i32, i32, [2 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i64, [36 x ptr], %struct.cap_trie_t, %struct.bytebuf_t, %struct.bytebuf_t, %struct.cellbuf_t, %struct.cellbuf_t, %struct.termios, i32, i32, i32, ptr, ptr, [1024 x i8] }
%struct.cap_trie_t = type { i8, ptr, i64, i32, i16, i8 }
%struct.bytebuf_t = type { ptr, i64, i64 }
%struct.cellbuf_t = type { i32, i32, ptr }
%struct.termios = type { i32, i32, i32, i32, i8, [32 x i8], i32, i32 }
%struct.tb_cell = type { i32, i32, i32, ptr, i64, i64 }

@global = external hidden global %struct.tb_global_t, align 8

; 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
declare hidden i32 @cellbuf_get(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @tb_extend_cell(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr getelementptr inbounds (%struct.tb_global_t, ptr @global, i32 0, i32 28), align 4, !tbaa !9
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %3
  store i32 -8, ptr %4, align 4
  br label %76

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = call i32 @cellbuf_get(ptr noundef getelementptr inbounds (%struct.tb_global_t, ptr @global, i32 0, i32 23), i32 noundef %16, i32 noundef %17, ptr noundef %9)
  store i32 %18, ptr %8, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %15
  %21 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %21, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %75

22:                                               ; preds = %15
  %23 = load ptr, ptr %9, align 8, !tbaa !18
  %24 = getelementptr inbounds %struct.tb_cell, ptr %23, i32 0, i32 4
  %25 = load i64, ptr %24, align 8, !tbaa !19
  %26 = icmp ugt i64 %25, 0
  br i1 %26, label %27, label %46

27:                                               ; preds = %22
  %28 = load ptr, ptr %9, align 8, !tbaa !18
  %29 = getelementptr inbounds %struct.tb_cell, ptr %28, i32 0, i32 4
  %30 = load i64, ptr %29, align 8, !tbaa !19
  %31 = add i64 %30, 1
  store i64 %31, ptr %10, align 8, !tbaa !21
  %32 = load ptr, ptr %9, align 8, !tbaa !18
  %33 = load i64, ptr %10, align 8, !tbaa !21
  %34 = call i32 @cell_reserve_ech(ptr noundef %32, i64 noundef %33)
  store i32 %34, ptr %8, align 4, !tbaa !5
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %27
  %37 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %37, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %75

38:                                               ; preds = %27
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = load ptr, ptr %9, align 8, !tbaa !18
  %41 = getelementptr inbounds %struct.tb_cell, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !22
  %43 = load i64, ptr %10, align 8, !tbaa !21
  %44 = sub i64 %43, 1
  %45 = getelementptr inbounds i32, ptr %42, i64 %44
  store i32 %39, ptr %45, align 4, !tbaa !5
  br label %66

46:                                               ; preds = %22
  store i64 2, ptr %10, align 8, !tbaa !21
  %47 = load ptr, ptr %9, align 8, !tbaa !18
  %48 = load i64, ptr %10, align 8, !tbaa !21
  %49 = call i32 @cell_reserve_ech(ptr noundef %47, i64 noundef %48)
  store i32 %49, ptr %8, align 4, !tbaa !5
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %53

51:                                               ; preds = %46
  %52 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %52, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %75

53:                                               ; preds = %46
  %54 = load ptr, ptr %9, align 8, !tbaa !18
  %55 = getelementptr inbounds %struct.tb_cell, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !23
  %57 = load ptr, ptr %9, align 8, !tbaa !18
  %58 = getelementptr inbounds %struct.tb_cell, ptr %57, i32 0, i32 3
  %59 = load ptr, ptr %58, align 8, !tbaa !22
  %60 = getelementptr inbounds i32, ptr %59, i64 0
  store i32 %56, ptr %60, align 4, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !18
  %63 = getelementptr inbounds %struct.tb_cell, ptr %62, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !22
  %65 = getelementptr inbounds i32, ptr %64, i64 1
  store i32 %61, ptr %65, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %53, %38
  %67 = load ptr, ptr %9, align 8, !tbaa !18
  %68 = getelementptr inbounds %struct.tb_cell, ptr %67, i32 0, i32 3
  %69 = load ptr, ptr %68, align 8, !tbaa !22
  %70 = load i64, ptr %10, align 8, !tbaa !21
  %71 = getelementptr inbounds i32, ptr %69, i64 %70
  store i32 0, ptr %71, align 4, !tbaa !5
  %72 = load i64, ptr %10, align 8, !tbaa !21
  %73 = load ptr, ptr %9, align 8, !tbaa !18
  %74 = getelementptr inbounds %struct.tb_cell, ptr %73, i32 0, i32 4
  store i64 %72, ptr %74, align 8, !tbaa !19
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %75

75:                                               ; preds = %66, %51, %36, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %76

76:                                               ; preds = %75, %14
  %77 = load i32, ptr %4, align 4
  ret i32 %77
}

; Function Attrs: nounwind uwtable
declare hidden i32 @cell_reserve_ech(ptr noundef, i64 noundef) #1

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 556}
!10 = !{!"tb_global_t", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !7, i64 16, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68, !11, i64 72, !12, i64 80, !7, i64 88, !13, i64 376, !15, i64 408, !15, i64 432, !16, i64 456, !16, i64 472, !17, i64 488, !6, i64 548, !6, i64 552, !6, i64 556, !11, i64 560, !11, i64 568, !7, i64 576}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"cap_trie_t", !7, i64 0, !11, i64 8, !12, i64 16, !6, i64 24, !14, i64 28, !7, i64 30}
!14 = !{!"short", !7, i64 0}
!15 = !{!"bytebuf_t", !11, i64 0, !12, i64 8, !12, i64 16}
!16 = !{!"cellbuf_t", !6, i64 0, !6, i64 4, !11, i64 8}
!17 = !{!"termios", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !7, i64 16, !7, i64 17, !6, i64 52, !6, i64 56}
!18 = !{!11, !11, i64 0}
!19 = !{!20, !12, i64 24}
!20 = !{!"tb_cell", !6, i64 0, !6, i64 4, !6, i64 8, !11, i64 16, !12, i64 24, !12, i64 32}
!21 = !{!12, !12, i64 0}
!22 = !{!20, !11, i64 16}
!23 = !{!20, !6, i64 0}


; 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.tb_global_t = type { i32, i32, i32, i32, [2 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i64, [36 x ptr], %struct.cap_trie_t, %struct.bytebuf_t, %struct.bytebuf_t, %struct.cellbuf_t, %struct.cellbuf_t, %struct.termios, i32, i32, i32, ptr, ptr, [1024 x i8] }
%struct.cap_trie_t = type { i8, ptr, i64, i32, i16, i8 }
%struct.bytebuf_t = type { ptr, i64, i64 }
%struct.cellbuf_t = type { i32, i32, ptr }
%struct.termios = type { i32, i32, i32, i32, i8, [32 x i8], i32, i32 }

@global = external hidden global %struct.tb_global_t, align 8

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @cellbuf_get(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @tb_extend_cell(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @global, i64 556), align 4, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %34, label %6

6:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  %7 = call i32 @cellbuf_get(ptr noundef nonnull getelementptr inbounds (i8, ptr @global, i64 456), i32 noundef %0, i32 noundef %1, ptr noundef nonnull %4)
  %.not18 = icmp eq i32 %7, 0
  br i1 %.not18, label %8, label %33

8:                                                ; preds = %6
  %9 = load ptr, ptr %4, align 8, !tbaa !17
  %10 = getelementptr inbounds i8, ptr %9, i64 24
  %11 = load i64, ptr %10, align 8, !tbaa !18
  %.not19 = icmp eq i64 %11, 0
  br i1 %.not19, label %20, label %12

12:                                               ; preds = %8
  %13 = add i64 %11, 1
  %14 = call i32 @cell_reserve_ech(ptr noundef nonnull %9, i64 noundef %13)
  %.not21 = icmp eq i32 %14, 0
  br i1 %.not21, label %15, label %33

15:                                               ; preds = %12
  %16 = load ptr, ptr %4, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !20
  %19 = getelementptr inbounds i32, ptr %18, i64 %11
  br label %28

20:                                               ; preds = %8
  %21 = call i32 @cell_reserve_ech(ptr noundef nonnull %9, i64 noundef 2)
  %.not20 = icmp eq i32 %21, 0
  br i1 %.not20, label %22, label %33

22:                                               ; preds = %20
  %23 = load ptr, ptr %4, align 8, !tbaa !17
  %24 = load i32, ptr %23, align 8, !tbaa !21
  %25 = getelementptr inbounds i8, ptr %23, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !20
  store i32 %24, ptr %26, align 4, !tbaa !22
  %27 = getelementptr inbounds i8, ptr %26, i64 4
  br label %28

28:                                               ; preds = %22, %15
  %.sink = phi ptr [ %27, %22 ], [ %19, %15 ]
  %29 = phi ptr [ %26, %22 ], [ %18, %15 ]
  %30 = phi ptr [ %23, %22 ], [ %16, %15 ]
  %.0 = phi i64 [ 2, %22 ], [ %13, %15 ]
  store i32 %2, ptr %.sink, align 4, !tbaa !22
  %31 = getelementptr inbounds i32, ptr %29, i64 %.0
  store i32 0, ptr %31, align 4, !tbaa !22
  %32 = getelementptr inbounds i8, ptr %30, i64 24
  store i64 %.0, ptr %32, align 8, !tbaa !18
  br label %33

33:                                               ; preds = %20, %12, %6, %28
  %.013 = phi i32 [ 0, %28 ], [ %7, %6 ], [ %14, %12 ], [ %21, %20 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  br label %34

34:                                               ; preds = %3, %33
  %.1 = phi i32 [ %.013, %33 ], [ -8, %3 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden i32 @cell_reserve_ech(ptr noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { 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 556}
!6 = !{!"tb_global_t", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !10, i64 72, !11, i64 80, !8, i64 88, !12, i64 376, !14, i64 408, !14, i64 432, !15, i64 456, !15, i64 472, !16, i64 488, !7, i64 548, !7, i64 552, !7, i64 556, !10, i64 560, !10, i64 568, !8, i64 576}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"cap_trie_t", !8, i64 0, !10, i64 8, !11, i64 16, !7, i64 24, !13, i64 28, !8, i64 30}
!13 = !{!"short", !8, i64 0}
!14 = !{!"bytebuf_t", !10, i64 0, !11, i64 8, !11, i64 16}
!15 = !{!"cellbuf_t", !7, i64 0, !7, i64 4, !10, i64 8}
!16 = !{!"termios", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !8, i64 17, !7, i64 52, !7, i64 56}
!17 = !{!10, !10, i64 0}
!18 = !{!19, !11, i64 24}
!19 = !{!"tb_cell", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !11, i64 24, !11, i64 32}
!20 = !{!19, !10, i64 16}
!21 = !{!19, !7, i64 0}
!22 = !{!7, !7, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass