; LLVM IR from musetronstar/tagd :: tagl/src (lemon)

; 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.rule = type { ptr, ptr, i32, i32, i32, ptr, ptr, i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, ptr, ptr }
%struct.symbol = type { ptr, i32, i32, ptr, ptr, i32, i32, ptr, i32, i32, ptr, i32, ptr, i32, i32, i32, ptr }

@.str.88 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.89 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.90 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.91 = external hidden unnamed_addr constant [4 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: nounwind uwtable
define dso_local void @rule_print(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.rule, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.symbol, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef @.str.88, ptr noundef %13) #3
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str.89) #3
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %17

17:                                               ; preds = %74, %2
  %18 = load i32, ptr %5, align 4, !tbaa !14
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.rule, ptr %19, i32 0, i32 4
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %23, label %77

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.rule, ptr %24, i32 0, i32 5
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = load i32, ptr %5, align 4, !tbaa !14
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds ptr, ptr %26, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  store ptr %30, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.symbol, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 4, !tbaa !17
  %34 = icmp eq i32 %33, 2
  br i1 %34, label %35, label %67

35:                                               ; preds = %23
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.symbol, ptr %37, i32 0, i32 16
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  %40 = getelementptr inbounds ptr, ptr %39, i64 0
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.symbol, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !12
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef @.str.90, ptr noundef %43) #3
  store i32 1, ptr %6, align 4, !tbaa !14
  br label %45

45:                                               ; preds = %63, %35
  %46 = load i32, ptr %6, align 4, !tbaa !14
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.symbol, ptr %47, i32 0, i32 15
  %49 = load i32, ptr %48, align 8, !tbaa !19
  %50 = icmp slt i32 %46, %49
  br i1 %50, label %51, label %66

51:                                               ; preds = %45
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.symbol, ptr %53, i32 0, i32 16
  %55 = load ptr, ptr %54, align 8, !tbaa !18
  %56 = load i32, ptr %6, align 4, !tbaa !14
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds ptr, ptr %55, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.symbol, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !12
  %62 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str.91, ptr noundef %61) #3
  br label %63

63:                                               ; preds = %51
  %64 = load i32, ptr %6, align 4, !tbaa !14
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %6, align 4, !tbaa !14
  br label %45, !llvm.loop !20

66:                                               ; preds = %45
  br label %73

67:                                               ; preds = %23
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.symbol, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !12
  %72 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str.90, ptr noundef %71) #3
  br label %73

73:                                               ; preds = %67, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %5, align 4, !tbaa !14
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %5, align 4, !tbaa !14
  br label %17, !llvm.loop !22

77:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"rule", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !6, i64 120, !6, i64 128}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"symbol", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 36, !6, i64 40, !11, i64 48, !11, i64 52, !6, i64 56, !11, i64 64, !6, i64 72, !11, i64 80, !11, i64 84, !11, i64 88, !6, i64 96}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 24}
!16 = !{!10, !6, i64 32}
!17 = !{!13, !11, i64 12}
!18 = !{!13, !6, i64 96}
!19 = !{!13, !11, i64 88}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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"

@.str.88 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.89 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.90 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.91 = external hidden unnamed_addr constant [4 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: nofree nounwind uwtable
define dso_local void @rule_print(ptr nocapture noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !11
  %5 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.88, ptr noundef %4) #2
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.89) #2
  %7 = getelementptr inbounds i8, ptr %1, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph21, label %._crit_edge

.lr.ph21:                                         ; preds = %2
  %10 = getelementptr inbounds i8, ptr %1, i64 32
  br label %11

11:                                               ; preds = %.lr.ph21, %.loopexit
  %indvars.iv23 = phi i64 [ 0, %.lr.ph21 ], [ %indvars.iv.next24, %.loopexit ]
  %12 = load ptr, ptr %10, align 8, !tbaa !14
  %13 = getelementptr inbounds ptr, ptr %12, i64 %indvars.iv23
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %14, i64 12
  %16 = load i32, ptr %15, align 4, !tbaa !16
  %17 = icmp eq i32 %16, 2
  br i1 %17, label %18, label %35

18:                                               ; preds = %11
  %19 = getelementptr inbounds i8, ptr %14, i64 96
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.90, ptr noundef %22) #2
  %24 = getelementptr inbounds i8, ptr %14, i64 88
  %25 = load i32, ptr %24, align 8, !tbaa !18
  %26 = icmp sgt i32 %25, 1
  br i1 %26, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %18, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %18 ]
  %27 = load ptr, ptr %19, align 8, !tbaa !17
  %28 = getelementptr inbounds ptr, ptr %27, i64 %indvars.iv
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.91, ptr noundef %30) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = load i32, ptr %24, align 8, !tbaa !18
  %33 = sext i32 %32 to i64
  %34 = icmp slt i64 %indvars.iv.next, %33
  br i1 %34, label %.lr.ph, label %.loopexit, !llvm.loop !19

35:                                               ; preds = %11
  %36 = load ptr, ptr %14, align 8, !tbaa !11
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.90, ptr noundef %36) #2
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %18, %35
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %38 = load i32, ptr %7, align 8, !tbaa !13
  %39 = sext i32 %38 to i64
  %40 = icmp slt i64 %indvars.iv.next24, %39
  br i1 %40, label %11, label %._crit_edge, !llvm.loop !21

._crit_edge:                                      ; preds = %.loopexit, %2
  ret void
}

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 = { nofree 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 0}
!6 = !{!"rule", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !7, i64 32, !7, i64 40, !10, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !10, i64 112, !7, i64 120, !7, i64 128}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"symbol", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36, !7, i64 40, !10, i64 48, !10, i64 52, !7, i64 56, !10, i64 64, !7, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !7, i64 96}
!13 = !{!6, !10, i64 24}
!14 = !{!6, !7, i64 32}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !10, i64 12}
!17 = !{!12, !7, i64 96}
!18 = !{!12, !10, i64 88}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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