; LLVM IR from vabold/Kinoko :: source/abstract/memory/List.ll (ZN8Abstract6Memory7MEMList6removeEPv)

; 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.Abstract::Memory::MEMLink" = type { ptr, ptr }
%"struct.Abstract::Memory::MEMList" = type <{ ptr, ptr, i16, i16, [4 x i8] }>

@.str.1 = external hidden unnamed_addr constant [29 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @abort() #1

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN8Abstract6Memory7MEMList7getLinkEPv(ptr noundef nonnull align 8 dereferenceable(20), ptr noundef) #3 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8Abstract6Memory7MEMList6removeEPv(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  br label %7

7:                                                ; preds = %2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %12, label %10

10:                                               ; preds = %7
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @abort() #4
  unreachable

12:                                               ; preds = %7
  br label %13

13:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call noundef ptr @_ZN8Abstract6Memory7MEMList7getLinkEPv(ptr noundef nonnull align 8 dereferenceable(20) %6, ptr noundef %14)
  store ptr %15, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.Abstract::Memory::MEMLink", ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %25, label %20

20:                                               ; preds = %13
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.Abstract::Memory::MEMLink", ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = getelementptr inbounds %"struct.Abstract::Memory::MEMList", ptr %6, i32 0, i32 0
  store ptr %23, ptr %24, align 8, !tbaa !12
  br label %34

25:                                               ; preds = %13
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.Abstract::Memory::MEMLink", ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.Abstract::Memory::MEMLink", ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = call noundef ptr @_ZN8Abstract6Memory7MEMList7getLinkEPv(ptr noundef nonnull align 8 dereferenceable(20) %6, ptr noundef %31)
  %33 = getelementptr inbounds %"struct.Abstract::Memory::MEMLink", ptr %32, i32 0, i32 1
  store ptr %28, ptr %33, align 8, !tbaa !11
  br label %34

34:                                               ; preds = %25, %20
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.Abstract::Memory::MEMLink", ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = icmp ne ptr %37, null
  br i1 %38, label %44, label %39

39:                                               ; preds = %34
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.Abstract::Memory::MEMLink", ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %"struct.Abstract::Memory::MEMList", ptr %6, i32 0, i32 1
  store ptr %42, ptr %43, align 8, !tbaa !15
  br label %53

44:                                               ; preds = %34
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.Abstract::Memory::MEMLink", ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.Abstract::Memory::MEMLink", ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = call noundef ptr @_ZN8Abstract6Memory7MEMList7getLinkEPv(ptr noundef nonnull align 8 dereferenceable(20) %6, ptr noundef %50)
  %52 = getelementptr inbounds %"struct.Abstract::Memory::MEMLink", ptr %51, i32 0, i32 0
  store ptr %47, ptr %52, align 8, !tbaa !9
  br label %53

53:                                               ; preds = %44, %39
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.Abstract::Memory::MEMLink", ptr %54, i32 0, i32 0
  store ptr null, ptr %55, align 8, !tbaa !9
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %"struct.Abstract::Memory::MEMLink", ptr %56, i32 0, i32 1
  store ptr null, ptr %57, align 8, !tbaa !11
  %58 = getelementptr inbounds %"struct.Abstract::Memory::MEMList", ptr %6, i32 0, i32 2
  %59 = load i16, ptr %58, align 8, !tbaa !16
  %60 = add i16 %59, -1
  store i16 %60, ptr %58, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

attributes #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 = { noreturn 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress 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 = { noreturn nounwind }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN8Abstract6Memory7MEMLinkE", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !6, i64 0}
!13 = !{!"_ZTSN8Abstract6Memory7MEMListE", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 18}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !6, i64 8}
!16 = !{!13, !14, i64 16}


; 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.1 = external hidden unnamed_addr constant [29 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN8Abstract6Memory7MEMList7getLinkEPv(ptr noundef nonnull align 8 dereferenceable(20), ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8Abstract6Memory7MEMList6removeEPv(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef %1) local_unnamed_addr #2 align 2 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %3, label %5

3:                                                ; preds = %2
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  tail call void @abort() #4
  unreachable

5:                                                ; preds = %2
  %6 = tail call noundef ptr @_ZN8Abstract6Memory7MEMList7getLinkEPv(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef nonnull %1)
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not15 = icmp eq ptr %7, null
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !10
  br i1 %.not15, label %10, label %11

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

11:                                               ; preds = %5
  %12 = tail call noundef ptr @_ZN8Abstract6Memory7MEMList7getLinkEPv(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef nonnull %7)
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  store ptr %9, ptr %13, align 8, !tbaa !10
  %.pre = load ptr, ptr %8, align 8, !tbaa !10
  br label %14

14:                                               ; preds = %11, %10
  %15 = phi ptr [ %.pre, %11 ], [ %9, %10 ]
  %.not16 = icmp eq ptr %15, null
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  br i1 %.not16, label %17, label %19

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  br label %21

19:                                               ; preds = %14
  %20 = tail call noundef ptr @_ZN8Abstract6Memory7MEMList7getLinkEPv(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef nonnull %15)
  br label %21

21:                                               ; preds = %19, %17
  %.sink = phi ptr [ %20, %19 ], [ %18, %17 ]
  store ptr %16, ptr %.sink, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %6, i8 0, i64 16, i1 false)
  %23 = load i16, ptr %22, align 8, !tbaa !15
  %24 = add i16 %23, -1
  store i16 %24, ptr %22, align 8, !tbaa !15
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { noreturn 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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { noreturn 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 = !{!"_ZTSN8Abstract6Memory7MEMLinkE", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !7, i64 0}
!12 = !{!"_ZTSN8Abstract6Memory7MEMListE", !7, i64 0, !7, i64 8, !13, i64 16, !13, i64 18}
!13 = !{!"short", !8, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!12, !13, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass