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

@x4a = external hidden global ptr, 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
define dso_local void @Configtable_clear(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %5 = load ptr, ptr @x4a, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %12, label %7

7:                                                ; preds = %1
  %8 = load ptr, ptr @x4a, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.s_x4, ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %7, %1
  store i32 1, ptr %4, align 4
  br label %58

13:                                               ; preds = %7
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %38

16:                                               ; preds = %13
  store i32 0, ptr %3, align 4, !tbaa !12
  br label %17

17:                                               ; preds = %34, %16
  %18 = load i32, ptr %3, align 4, !tbaa !12
  %19 = load ptr, ptr @x4a, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.s_x4, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %23, label %37

23:                                               ; preds = %17
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = load ptr, ptr @x4a, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.s_x4, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = load i32, ptr %3, align 4, !tbaa !12
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %struct.s_x4node, ptr %27, i64 %29
  %31 = getelementptr inbounds %struct.s_x4node, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = call i32 %24(ptr noundef %32)
  br label %34

34:                                               ; preds = %23
  %35 = load i32, ptr %3, align 4, !tbaa !12
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %3, align 4, !tbaa !12
  br label %17, !llvm.loop !16

37:                                               ; preds = %17
  br label %38

38:                                               ; preds = %37, %13
  store i32 0, ptr %3, align 4, !tbaa !12
  br label %39

39:                                               ; preds = %52, %38
  %40 = load i32, ptr %3, align 4, !tbaa !12
  %41 = load ptr, ptr @x4a, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.s_x4, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !18
  %44 = icmp slt i32 %40, %43
  br i1 %44, label %45, label %55

45:                                               ; preds = %39
  %46 = load ptr, ptr @x4a, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.s_x4, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !19
  %49 = load i32, ptr %3, align 4, !tbaa !12
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds ptr, ptr %48, i64 %50
  store ptr null, ptr %51, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %45
  %53 = load i32, ptr %3, align 4, !tbaa !12
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %3, align 4, !tbaa !12
  br label %39, !llvm.loop !20

55:                                               ; preds = %39
  %56 = load ptr, ptr @x4a, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.s_x4, ptr %56, i32 0, i32 1
  store i32 0, ptr %57, align 4, !tbaa !9
  store i32 1, ptr %4, align 4
  br label %58

58:                                               ; preds = %55, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"s_x4", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!15, !6, i64 0}
!15 = !{!"s_x4node", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !11, i64 0}
!19 = !{!10, !6, i64 16}
!20 = distinct !{!20, !17}


; 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.s_x4node = type { ptr, ptr, ptr }

@x4a = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @Configtable_clear(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @x4a, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %33, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %2, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %33, label %8

8:                                                ; preds = %4
  %.not = icmp ne ptr %0, null
  %9 = icmp sgt i32 %6, 0
  %or.cond = and i1 %.not, %9
  br i1 %or.cond, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %8, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %8 ]
  %10 = phi ptr [ %16, %.lr.ph ], [ %2, %8 ]
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %13 = getelementptr inbounds %struct.s_x4node, ptr %12, i64 %indvars.iv
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = tail call i32 %0(ptr noundef %14) #1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load ptr, ptr @x4a, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %.lr.ph, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph, %8
  %21 = phi ptr [ %2, %8 ], [ %16, %.lr.ph ]
  %22 = load i32, ptr %21, align 8, !tbaa !17
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph11, label %._crit_edge

.lr.ph11:                                         ; preds = %.loopexit, %.lr.ph11
  %indvars.iv14 = phi i64 [ %indvars.iv.next15, %.lr.ph11 ], [ 0, %.loopexit ]
  %24 = phi ptr [ %28, %.lr.ph11 ], [ %21, %.loopexit ]
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !18
  %27 = getelementptr inbounds ptr, ptr %26, i64 %indvars.iv14
  store ptr null, ptr %27, align 8, !tbaa !5
  %indvars.iv.next15 = add nuw nsw i64 %indvars.iv14, 1
  %28 = load ptr, ptr @x4a, align 8, !tbaa !5
  %29 = load i32, ptr %28, align 8, !tbaa !17
  %30 = sext i32 %29 to i64
  %31 = icmp slt i64 %indvars.iv.next15, %30
  br i1 %31, label %.lr.ph11, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph11, %.loopexit
  %.lcssa = phi ptr [ %21, %.loopexit ], [ %28, %.lr.ph11 ]
  %32 = getelementptr inbounds i8, ptr %.lcssa, i64 4
  store i32 0, ptr %32, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %1, %4, %._crit_edge
  ret void
}

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 = { 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, !11, i64 4}
!10 = !{!"s_x4", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !6, i64 0}
!14 = !{!"s_x4node", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !11, i64 0}
!18 = !{!10, !6, i64 16}
!19 = distinct !{!19, !16}


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