; LLVM IR from graphitemaster/libintrusive :: example (list)

; 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.test_list_t = type { ptr, %struct.link_s }
%struct.link_s = type { ptr, ptr }
%struct.list_s = type { ptr, ptr }

@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@__const.list.a = external hidden unnamed_addr constant %struct.test_list_t, align 8
@__const.list.b = external hidden unnamed_addr constant %struct.test_list_t, align 8
@__const.list.c = external hidden unnamed_addr constant %struct.test_list_t, align 8
@.str.7 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [7 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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local void @list() #3 {
  %1 = alloca %struct.list_s, align 8
  %2 = alloca %struct.test_list_t, align 8
  %3 = alloca %struct.test_list_t, align 8
  %4 = alloca %struct.test_list_t, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #4
  call void @list_init(ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 24, ptr %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %2, ptr align 8 @__const.list.a, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 @__const.list.b, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 @__const.list.c, i64 24, i1 false)
  %12 = getelementptr inbounds %struct.test_list_t, ptr %2, i32 0, i32 1
  call void @list_push_back(ptr noundef %1, ptr noundef %12)
  %13 = getelementptr inbounds %struct.test_list_t, ptr %3, i32 0, i32 1
  call void @list_push_back(ptr noundef %1, ptr noundef %13)
  %14 = getelementptr inbounds %struct.test_list_t, ptr %4, i32 0, i32 1
  call void @list_push_back(ptr noundef %1, ptr noundef %14)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %15 = call ptr @list_head(ptr noundef %1)
  store ptr %15, ptr %5, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %61, %0
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %65

19:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call ptr @list_next(ptr noundef %20)
  store ptr %21, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call ptr @list_prev(ptr noundef %22)
  store ptr %23, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 -8
  store ptr %25, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %31

28:                                               ; preds = %19
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 -8
  br label %32

31:                                               ; preds = %19
  br label %32

32:                                               ; preds = %31, %28
  %33 = phi ptr [ %30, %28 ], [ null, %31 ]
  store ptr %33, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %39

36:                                               ; preds = %32
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 -8
  br label %40

39:                                               ; preds = %32
  br label %40

40:                                               ; preds = %39, %36
  %41 = phi ptr [ %38, %36 ], [ null, %39 ]
  store ptr %41, ptr %10, align 8, !tbaa !5
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.test_list_t, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %51

47:                                               ; preds = %40
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.test_list_t, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  br label %52

51:                                               ; preds = %40
  br label %52

52:                                               ; preds = %51, %47
  %53 = phi ptr [ %50, %47 ], [ @.str.8, %51 ]
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %60

56:                                               ; preds = %52
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.test_list_t, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  br label %61

60:                                               ; preds = %52
  br label %61

61:                                               ; preds = %60, %56
  %62 = phi ptr [ %59, %56 ], [ @.str.8, %60 ]
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, ptr noundef %44, ptr noundef %53, ptr noundef %62)
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %64, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %16, !llvm.loop !12

65:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #4
  ret void
}

declare void @list_init(ptr noundef) #1

declare void @list_push_back(ptr noundef, ptr noundef) #1

declare ptr @list_head(ptr noundef) #1

declare ptr @list_next(ptr noundef) #1

declare ptr @list_prev(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

!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 = !{!"", !6, i64 0, !11, i64 8}
!11 = !{!"link_s", !6, i64 0, !6, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%struct.test_list_t = type { ptr, %struct.link_s }
%struct.link_s = type { ptr, ptr }
%struct.list_s = type { ptr, ptr }

@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@__const.list.a = external hidden unnamed_addr constant %struct.test_list_t, align 8
@__const.list.b = external hidden unnamed_addr constant %struct.test_list_t, align 8
@__const.list.c = external hidden unnamed_addr constant %struct.test_list_t, align 8
@.str.7 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local void @list() local_unnamed_addr #3 {
  %1 = alloca %struct.list_s, align 8
  %2 = alloca %struct.test_list_t, align 8
  %3 = alloca %struct.test_list_t, align 8
  %4 = alloca %struct.test_list_t, align 8
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #5
  call void @list_init(ptr noundef nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) @__const.list.a, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) @__const.list.b, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(24) @__const.list.c, i64 24, i1 false)
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  call void @list_push_back(ptr noundef nonnull %1, ptr noundef nonnull %6) #5
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  call void @list_push_back(ptr noundef nonnull %1, ptr noundef nonnull %7) #5
  %8 = getelementptr inbounds i8, ptr %4, i64 8
  call void @list_push_back(ptr noundef nonnull %1, ptr noundef nonnull %8) #5
  %9 = call ptr @list_head(ptr noundef nonnull %1) #5
  %.not16 = icmp eq ptr %9, null
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %22
  %.017 = phi ptr [ %10, %22 ], [ %9, %0 ]
  %10 = call ptr @list_next(ptr noundef nonnull %.017) #5
  %11 = call ptr @list_prev(ptr noundef nonnull %.017) #5
  %12 = getelementptr inbounds i8, ptr %.017, i64 -8
  %.not14 = icmp eq ptr %10, null
  %.not15 = icmp eq ptr %11, null
  %13 = getelementptr inbounds i8, ptr %11, i64 -8
  %14 = load ptr, ptr %12, align 8, !tbaa !5
  br i1 %.not14, label %18, label %15

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %10, i64 -8
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %.lr.ph, %15
  %19 = phi ptr [ %17, %15 ], [ @.str.8, %.lr.ph ]
  br i1 %.not15, label %22, label %20

20:                                               ; preds = %18
  %21 = load ptr, ptr %13, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %18, %20
  %23 = phi ptr [ %21, %20 ], [ @.str.8, %18 ]
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef %14, ptr noundef %19, ptr noundef %23)
  br i1 %.not14, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %22, %0
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #5
  ret void
}

declare void @list_init(ptr noundef) local_unnamed_addr #4

declare void @list_push_back(ptr noundef, ptr noundef) local_unnamed_addr #4

declare ptr @list_head(ptr noundef) local_unnamed_addr #4

declare ptr @list_next(ptr noundef) local_unnamed_addr #4

declare ptr @list_prev(ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 #5 = { 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 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"link_s", !7, i64 0, !7, i64 8}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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