; LLVM IR from jspd-group/pegit :: src (delta)

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

@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [35 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @delta_backtrace_table_minimal(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.delta_table, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.delta_table, ptr %17, i32 0, i32 4
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = sub nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr %16, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = sext i32 %23 to i64
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.basic_delta_result, ptr %25, i32 0, i32 2
  store i64 %24, ptr %26, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.delta_table, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  store ptr %29, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.delta_table, ptr %30, i32 0, i32 3
  %32 = load i32, ptr %31, align 8, !tbaa !19
  store i32 %32, ptr %12, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.delta_table, ptr %33, i32 0, i32 4
  %35 = load i32, ptr %34, align 4, !tbaa !12
  store i32 %35, ptr %13, align 4, !tbaa !13
  %36 = load i32, ptr %12, align 4, !tbaa !13
  %37 = sub nsw i32 %36, 1
  store i32 %37, ptr %9, align 4, !tbaa !13
  %38 = load i32, ptr %13, align 4, !tbaa !13
  %39 = sub nsw i32 %38, 1
  store i32 %39, ptr %10, align 4, !tbaa !13
  br label %40

40:                                               ; preds = %91, %4
  %41 = load i32, ptr %9, align 4, !tbaa !13
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %46

43:                                               ; preds = %40
  %44 = load i32, ptr %10, align 4, !tbaa !13
  %45 = icmp ne i32 %44, 0
  br label %46

46:                                               ; preds = %43, %40
  %47 = phi i1 [ false, %40 ], [ %45, %43 ]
  br i1 %47, label %48, label %92

48:                                               ; preds = %46
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = load i32, ptr %9, align 4, !tbaa !13
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds ptr, ptr %49, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  %54 = load i32, ptr %10, align 4, !tbaa !13
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %53, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !13
  switch i32 %57, label %77 [
    i32 0, label %58
    i32 1, label %65
    i32 2, label %72
  ]

58:                                               ; preds = %48
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.basic_delta_result, ptr %59, i32 0, i32 1
  %61 = load i64, ptr %60, align 8, !tbaa !20
  %62 = add i64 %61, 1
  store i64 %62, ptr %60, align 8, !tbaa !20
  %63 = load i32, ptr %9, align 4, !tbaa !13
  %64 = add nsw i32 %63, -1
  store i32 %64, ptr %9, align 4, !tbaa !13
  br label %91

65:                                               ; preds = %48
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.basic_delta_result, ptr %66, i32 0, i32 0
  %68 = load i64, ptr %67, align 8, !tbaa !21
  %69 = add i64 %68, 1
  store i64 %69, ptr %67, align 8, !tbaa !21
  %70 = load i32, ptr %10, align 4, !tbaa !13
  %71 = add nsw i32 %70, -1
  store i32 %71, ptr %10, align 4, !tbaa !13
  br label %91

72:                                               ; preds = %48
  %73 = load i32, ptr %10, align 4, !tbaa !13
  %74 = add nsw i32 %73, -1
  store i32 %74, ptr %10, align 4, !tbaa !13
  %75 = load i32, ptr %9, align 4, !tbaa !13
  %76 = add nsw i32 %75, -1
  store i32 %76, ptr %9, align 4, !tbaa !13
  br label %91

77:                                               ; preds = %48
  br label %78

78:                                               ; preds = %77
  %79 = load ptr, ptr @stderr, align 8, !tbaa !5
  %80 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %79, ptr noundef @.str.2) #4
  %81 = load ptr, ptr @stderr, align 8, !tbaa !5
  %82 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %81, ptr noundef @.str.3) #4
  %83 = load ptr, ptr @stderr, align 8, !tbaa !5
  %84 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %83, ptr noundef @.str.4) #4
  %85 = load ptr, ptr @stderr, align 8, !tbaa !5
  %86 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %85, ptr noundef @.str.5) #4
  %87 = load ptr, ptr @stderr, align 8, !tbaa !5
  %88 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %87, ptr noundef @.str.6) #4
  call void @exit(i32 noundef 1) #5
  unreachable

89:                                               ; No predecessors!
  br label %90

90:                                               ; preds = %89
  br label %91

91:                                               ; preds = %90, %72, %65, %58
  br label %40, !llvm.loop !22

92:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { noreturn nounwind "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 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 }
attributes #5 = { noreturn 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 16}
!10 = !{!"delta_table", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 28}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !16, i64 16}
!15 = !{!"basic_delta_result", !16, i64 0, !16, i64 8, !16, i64 16, !6, i64 24, !17, i64 32, !17, i64 56}
!16 = !{!"long", !7, i64 0}
!17 = !{!"strbuf_list", !6, i64 0, !6, i64 8, !16, i64 16}
!18 = !{!10, !6, i64 0}
!19 = !{!10, !11, i64 24}
!20 = !{!15, !16, i64 8}
!21 = !{!15, !16, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @delta_backtrace_table_minimal(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readnone %2, ptr nocapture noundef readnone %3) local_unnamed_addr #2 {
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 28
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = sext i32 %8 to i64
  %10 = getelementptr i32, ptr %6, i64 %9
  %11 = getelementptr i8, ptr %10, i64 -4
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %13, ptr %14, align 8, !tbaa !13
  %15 = load ptr, ptr %1, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %1, i64 24
  %17 = load i32, ptr %16, align 8, !tbaa !18
  %18 = add nsw i32 %17, -1
  %19 = add nsw i32 %8, -1
  %20 = icmp ne i32 %18, 0
  %21 = icmp ne i32 %19, 0
  %22 = select i1 %20, i1 %21, i1 false
  br i1 %22, label %.lr.ph, label %._crit_edge

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

24:                                               ; preds = %.lr.ph, %53
  %.021 = phi i32 [ %18, %.lr.ph ], [ %.1, %53 ]
  %.01820 = phi i32 [ %19, %.lr.ph ], [ %.119, %53 ]
  %25 = sext i32 %.021 to i64
  %26 = getelementptr inbounds ptr, ptr %15, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !19
  %28 = sext i32 %.01820 to i64
  %29 = getelementptr inbounds i32, ptr %27, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !12
  switch i32 %30, label %42 [
    i32 0, label %31
    i32 1, label %35
    i32 2, label %39
  ]

31:                                               ; preds = %24
  %32 = load i64, ptr %23, align 8, !tbaa !20
  %33 = add i64 %32, 1
  store i64 %33, ptr %23, align 8, !tbaa !20
  %34 = add nsw i32 %.021, -1
  br label %53

35:                                               ; preds = %24
  %36 = load i64, ptr %0, align 8, !tbaa !21
  %37 = add i64 %36, 1
  store i64 %37, ptr %0, align 8, !tbaa !21
  %38 = add nsw i32 %.01820, -1
  br label %53

39:                                               ; preds = %24
  %40 = add nsw i32 %.01820, -1
  %41 = add nsw i32 %.021, -1
  br label %53

42:                                               ; preds = %24
  %43 = load ptr, ptr @stderr, align 8, !tbaa !19
  %44 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef nonnull @.str.2) #3
  %45 = load ptr, ptr @stderr, align 8, !tbaa !19
  %46 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef nonnull @.str.3) #3
  %47 = load ptr, ptr @stderr, align 8, !tbaa !19
  %48 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef nonnull @.str.4) #3
  %49 = load ptr, ptr @stderr, align 8, !tbaa !19
  %50 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef nonnull @.str.5) #3
  %51 = load ptr, ptr @stderr, align 8, !tbaa !19
  %52 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef nonnull @.str.6) #3
  tail call void @exit(i32 noundef 1) #4
  unreachable

53:                                               ; preds = %39, %35, %31
  %.119 = phi i32 [ %40, %39 ], [ %38, %35 ], [ %.01820, %31 ]
  %.1 = phi i32 [ %41, %39 ], [ %.021, %35 ], [ %34, %31 ]
  %54 = icmp ne i32 %.1, 0
  %55 = icmp ne i32 %.119, 0
  %56 = select i1 %54, i1 %55, i1 false
  br i1 %56, label %24, label %._crit_edge, !llvm.loop !22

._crit_edge:                                      ; preds = %53, %4
  ret i32 0
}

attributes #0 = { nofree nounwind "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 = { noreturn nounwind "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 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 = { cold nounwind }
attributes #4 = { noreturn 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 16}
!6 = !{!"delta_table", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 28}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !15, i64 16}
!14 = !{!"basic_delta_result", !15, i64 0, !15, i64 8, !15, i64 16, !7, i64 24, !16, i64 32, !16, i64 56}
!15 = !{!"long", !8, i64 0}
!16 = !{!"strbuf_list", !7, i64 0, !7, i64 8, !15, i64 16}
!17 = !{!6, !7, i64 0}
!18 = !{!6, !10, i64 24}
!19 = !{!7, !7, i64 0}
!20 = !{!14, !15, i64 8}
!21 = !{!14, !15, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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