; LLVM IR from bartobri/data-structures-c :: symbol-table/linked-list-ordered (st)

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

@N = external hidden global i32, align 4
@z = external hidden global ptr, align 8
@head = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
declare hidden ptr @NEW(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @STinsert(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %5 = load ptr, ptr @head, align 8, !tbaa !5
  %6 = load ptr, ptr @z, align 8, !tbaa !5
  %7 = icmp eq ptr %5, %6
  br i1 %7, label %18, label %8

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.anon, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = load ptr, ptr @head, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.STnode, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds %struct.anon, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = icmp slt i32 %11, %16
  br i1 %17, label %18, label %24

18:                                               ; preds = %8, %1
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = load ptr, ptr @head, align 8, !tbaa !5
  %21 = call ptr @NEW(ptr noundef %19, ptr noundef %20)
  store ptr %21, ptr @head, align 8, !tbaa !5
  %22 = load i32, ptr @N, align 4, !tbaa !14
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @N, align 4, !tbaa !14
  store i32 1, ptr %4, align 4
  br label %60

24:                                               ; preds = %8
  %25 = load ptr, ptr @head, align 8, !tbaa !5
  store ptr %25, ptr %3, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %46, %24
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.STnode, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = load ptr, ptr @z, align 8, !tbaa !5
  %31 = icmp ne ptr %29, %30
  br i1 %31, label %32, label %50

32:                                               ; preds = %26
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.anon, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.STnode, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = getelementptr inbounds %struct.STnode, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !12
  %41 = getelementptr inbounds %struct.anon, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = icmp slt i32 %35, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %32
  br label %50

45:                                               ; preds = %32
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.STnode, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  store ptr %49, ptr %3, align 8, !tbaa !5
  br label %26, !llvm.loop !16

50:                                               ; preds = %44, %26
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.STnode, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = call ptr @NEW(ptr noundef %51, ptr noundef %54)
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.STnode, ptr %56, i32 0, i32 1
  store ptr %55, ptr %57, align 8, !tbaa !15
  %58 = load i32, ptr @N, align 4, !tbaa !14
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr @N, align 4, !tbaa !14
  store i32 0, ptr %4, align 4
  br label %60

60:                                               ; preds = %50, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  %61 = load i32, ptr %4, align 4
  switch i32 %61, label %63 [
    i32 0, label %62
    i32 1, label %62
  ]

62:                                               ; preds = %60, %60
  ret void

63:                                               ; preds = %60
  unreachable
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 0}
!10 = !{!"", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"STnode", !6, i64 0, !6, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!13, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@N = external hidden local_unnamed_addr global i32, align 4
@z = external hidden local_unnamed_addr global ptr, align 8
@head = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare hidden ptr @NEW(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @STinsert(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @head, align 8, !tbaa !5
  %3 = load ptr, ptr @z, align 8, !tbaa !5
  %4 = icmp eq ptr %2, %3
  br i1 %4, label %10, label %5

5:                                                ; preds = %1
  %6 = load i32, ptr %0, align 4, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !12
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp slt i32 %6, %8
  br i1 %9, label %10, label %.preheader

10:                                               ; preds = %5, %1
  %11 = tail call ptr @NEW(ptr noundef %0, ptr noundef %2)
  store ptr %11, ptr @head, align 8, !tbaa !5
  br label %21

.preheader:                                       ; preds = %5, %14
  %.0 = phi ptr [ %13, %14 ], [ %2, %5 ]
  %12 = getelementptr inbounds i8, ptr %.0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %.not = icmp eq ptr %13, %3
  br i1 %.not, label %18, label %14

14:                                               ; preds = %.preheader
  %15 = load ptr, ptr %13, align 8, !tbaa !12
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = icmp slt i32 %6, %16
  br i1 %17, label %18, label %.preheader, !llvm.loop !15

18:                                               ; preds = %14, %.preheader
  %19 = getelementptr inbounds i8, ptr %.0, i64 8
  %20 = tail call ptr @NEW(ptr noundef nonnull %0, ptr noundef %13)
  store ptr %20, ptr %19, align 8, !tbaa !14
  br label %21

21:                                               ; preds = %18, %10
  %storemerge.in = load i32, ptr @N, align 4, !tbaa !17
  %storemerge = add nsw i32 %storemerge.in, 1
  store i32 %storemerge, ptr @N, align 4, !tbaa !17
  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" }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass