; LLVM IR from howerj/shrink :: shrink (shrink_buffer)

; 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.buffer_t = type { ptr, i64, i64 }
%struct.shrink_t = type { ptr, ptr, ptr, ptr, i64, i64 }

@.str.1 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@__PRETTY_FUNCTION__.shrink_buffer = external hidden unnamed_addr constant [86 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @shrink(ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @shrink_buffer(i32 noundef %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca %struct.buffer_t, align 8
  %14 = alloca %struct.buffer_t, align 8
  %15 = alloca %struct.shrink_t, align 8
  %16 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !11
  store ptr %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !9
  %17 = load ptr, ptr %9, align 8, !tbaa !9
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %6
  br label %21

20:                                               ; preds = %6
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 747, ptr noundef @__PRETTY_FUNCTION__.shrink_buffer) #3
  unreachable

21:                                               ; preds = %19
  %22 = load ptr, ptr %11, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  br label %26

25:                                               ; preds = %21
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.1, i32 noundef 748, ptr noundef @__PRETTY_FUNCTION__.shrink_buffer) #3
  unreachable

26:                                               ; preds = %24
  %27 = load ptr, ptr %12, align 8, !tbaa !9
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  br label %31

30:                                               ; preds = %26
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.1, i32 noundef 749, ptr noundef @__PRETTY_FUNCTION__.shrink_buffer) #3
  unreachable

31:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #4
  %32 = getelementptr inbounds %struct.buffer_t, ptr %13, i32 0, i32 0
  %33 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %33, ptr %32, align 8, !tbaa !13
  %34 = getelementptr inbounds %struct.buffer_t, ptr %13, i32 0, i32 1
  store i64 0, ptr %34, align 8, !tbaa !15
  %35 = getelementptr inbounds %struct.buffer_t, ptr %13, i32 0, i32 2
  %36 = load i64, ptr %10, align 8, !tbaa !11
  store i64 %36, ptr %35, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 24, ptr %14) #4
  %37 = getelementptr inbounds %struct.buffer_t, ptr %14, i32 0, i32 0
  %38 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %38, ptr %37, align 8, !tbaa !13
  %39 = getelementptr inbounds %struct.buffer_t, ptr %14, i32 0, i32 1
  store i64 0, ptr %39, align 8, !tbaa !15
  %40 = getelementptr inbounds %struct.buffer_t, ptr %14, i32 0, i32 2
  %41 = load ptr, ptr %12, align 8, !tbaa !9
  %42 = load i64, ptr %41, align 8, !tbaa !11
  store i64 %42, ptr %40, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 48, ptr %15) #4
  %43 = getelementptr inbounds %struct.shrink_t, ptr %15, i32 0, i32 0
  store ptr @buffer_get, ptr %43, align 8, !tbaa !17
  %44 = getelementptr inbounds %struct.shrink_t, ptr %15, i32 0, i32 1
  store ptr @buffer_put, ptr %44, align 8, !tbaa !19
  %45 = getelementptr inbounds %struct.shrink_t, ptr %15, i32 0, i32 2
  store ptr %13, ptr %45, align 8, !tbaa !20
  %46 = getelementptr inbounds %struct.shrink_t, ptr %15, i32 0, i32 3
  store ptr %14, ptr %46, align 8, !tbaa !21
  %47 = getelementptr inbounds %struct.shrink_t, ptr %15, i32 0, i32 4
  store i64 0, ptr %47, align 8, !tbaa !22
  %48 = getelementptr inbounds %struct.shrink_t, ptr %15, i32 0, i32 5
  store i64 0, ptr %48, align 8, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = call i32 @shrink(ptr noundef %15, i32 noundef %49, i32 noundef %50)
  store i32 %51, ptr %16, align 4, !tbaa !5
  %52 = load i32, ptr %16, align 4, !tbaa !5
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %57

54:                                               ; preds = %31
  %55 = getelementptr inbounds %struct.shrink_t, ptr %15, i32 0, i32 5
  %56 = load i64, ptr %55, align 8, !tbaa !23
  br label %58

57:                                               ; preds = %31
  br label %58

58:                                               ; preds = %57, %54
  %59 = phi i64 [ %56, %54 ], [ 0, %57 ]
  %60 = load ptr, ptr %12, align 8, !tbaa !9
  store i64 %59, ptr %60, align 8, !tbaa !11
  %61 = load i32, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #4
  ret i32 %61
}

; Function Attrs: nounwind uwtable
declare hidden i32 @buffer_get(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @buffer_put(i32 noundef, ptr noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { noreturn nounwind }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !12, i64 8, !12, i64 16}
!15 = !{!14, !12, i64 8}
!16 = !{!14, !12, i64 16}
!17 = !{!18, !10, i64 0}
!18 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !12, i64 32, !12, i64 40}
!19 = !{!18, !10, i64 8}
!20 = !{!18, !10, i64 16}
!21 = !{!18, !10, i64 24}
!22 = !{!18, !12, i64 32}
!23 = !{!18, !12, i64 40}


; 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.buffer_t = type { ptr, i64, i64 }
%struct.shrink_t = type { ptr, ptr, ptr, ptr, i64, i64 }

@.str.1 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@__PRETTY_FUNCTION__.shrink_buffer = external hidden unnamed_addr constant [86 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @shrink(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @shrink_buffer(i32 noundef %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #2 {
  %7 = alloca %struct.buffer_t, align 8
  %8 = alloca %struct.buffer_t, align 8
  %9 = alloca %struct.shrink_t, align 8
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %10, label %11

10:                                               ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 747, ptr noundef nonnull @__PRETTY_FUNCTION__.shrink_buffer) #4
  unreachable

11:                                               ; preds = %6
  %.not13 = icmp eq ptr %4, null
  br i1 %.not13, label %12, label %13

12:                                               ; preds = %11
  tail call void @__assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.1, i32 noundef 748, ptr noundef nonnull @__PRETTY_FUNCTION__.shrink_buffer) #4
  unreachable

13:                                               ; preds = %11
  %.not14 = icmp eq ptr %5, null
  br i1 %.not14, label %14, label %15

14:                                               ; preds = %13
  tail call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.1, i32 noundef 749, ptr noundef nonnull @__PRETTY_FUNCTION__.shrink_buffer) #4
  unreachable

15:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %7, i64 8
  store i64 0, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %7, i64 16
  store i64 %3, ptr %17, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %8) #5
  store ptr %4, ptr %8, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %8, i64 8
  store i64 0, ptr %18, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %8, i64 16
  %20 = load i64, ptr %5, align 8, !tbaa !13
  store i64 %20, ptr %19, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %9) #5
  store ptr @buffer_get, ptr %9, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %9, i64 8
  store ptr @buffer_put, ptr %21, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %7, ptr %22, align 8, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %9, i64 24
  store ptr %8, ptr %23, align 8, !tbaa !18
  %24 = getelementptr inbounds i8, ptr %9, i64 32
  %25 = getelementptr inbounds i8, ptr %9, i64 40
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %24, i8 0, i64 16, i1 false)
  %26 = call i32 @shrink(ptr noundef nonnull %9, i32 noundef %0, i32 noundef %1)
  %27 = icmp eq i32 %26, 0
  %28 = load i64, ptr %25, align 8
  %29 = select i1 %27, i64 %28, i64 0
  store i64 %29, ptr %5, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #5
  ret i32 %26
}

; Function Attrs: nounwind uwtable
declare hidden i32 @buffer_get(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @buffer_put(i32 noundef, ptr noundef) #2

; 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 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 16}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !7, i64 0}
!15 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 40}
!16 = !{!15, !7, i64 8}
!17 = !{!15, !7, i64 16}
!18 = !{!15, !7, i64 24}


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