; LLVM IR from At-EC/At-RTOS :: source (k_linker)

; 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.list = type { ptr }
%struct.list_node = type { ptr }

; 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 zeroext i1 @list_node_push(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  br label %67

12:                                               ; preds = %3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i1 false, ptr %4, align 1
  br label %67

16:                                               ; preds = %12
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %23

19:                                               ; preds = %16
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 1
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i1 false, ptr %4, align 1
  br label %67

23:                                               ; preds = %19, %16
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %53

26:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.list, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  store ptr %29, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %46

32:                                               ; preds = %26
  br label %33

33:                                               ; preds = %38, %32
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.list_node, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %42

38:                                               ; preds = %33
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.list_node, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  store ptr %41, ptr %8, align 8, !tbaa !5
  br label %33, !llvm.loop !15

42:                                               ; preds = %33
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.list_node, ptr %44, i32 0, i32 0
  store ptr %43, ptr %45, align 8, !tbaa !13
  br label %50

46:                                               ; preds = %26
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.list, ptr %48, i32 0, i32 0
  store ptr %47, ptr %49, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %46, %42
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.list_node, ptr %51, i32 0, i32 0
  store ptr null, ptr %52, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %66

53:                                               ; preds = %23
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %65

56:                                               ; preds = %53
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.list, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.list_node, ptr %60, i32 0, i32 0
  store ptr %59, ptr %61, align 8, !tbaa !13
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.list, ptr %63, i32 0, i32 0
  store ptr %62, ptr %64, align 8, !tbaa !11
  br label %65

65:                                               ; preds = %56, %53
  br label %66

66:                                               ; preds = %65, %50
  store i1 true, ptr %4, align 1
  br label %67

67:                                               ; preds = %66, %22, %15, %11
  %68 = load i1, ptr %4, align 1
  ret i1 %68
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"list", !6, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"list_node", !6, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @list_node_push(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp ne ptr %0, null
  %.not26 = icmp ne ptr %1, null
  %or.cond29.not31 = and i1 %.not, %.not26
  %or.cond = icmp ult i32 %2, 2
  %or.cond30.not = and i1 %or.cond29.not31, %or.cond
  br i1 %or.cond30.not, label %4, label %9

4:                                                ; preds = %3
  %switch = icmp eq i32 %2, 1
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  br i1 %switch, label %6, label %8

6:                                                ; preds = %4
  %.not27 = icmp eq ptr %5, null
  br i1 %.not27, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %6, %.preheader
  %.0 = phi ptr [ %7, %.preheader ], [ %5, %6 ]
  %7 = load ptr, ptr %.0, align 8, !tbaa !10
  %.not28 = icmp eq ptr %7, null
  br i1 %.not28, label %.loopexit, label %.preheader, !llvm.loop !12

.loopexit:                                        ; preds = %.preheader, %6
  %.sink = phi ptr [ %0, %6 ], [ %.0, %.preheader ]
  store ptr %1, ptr %.sink, align 8, !tbaa !14
  store ptr null, ptr %1, align 8, !tbaa !10
  br label %9

8:                                                ; preds = %4
  store ptr %5, ptr %1, align 8, !tbaa !10
  store ptr %1, ptr %0, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %.loopexit, %8, %3
  ret i1 %or.cond30.not
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !7, i64 0}
!6 = !{!"list", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"list_node", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!7, !7, i64 0}


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