; LLVM IR from lionsoul2014/friso :: src (friso_string)

; 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.string_buffer_entry = type { ptr, i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local void @string_buffer_append_char(ptr noundef %0, i8 noundef signext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.string_buffer_entry, ptr %5, i32 0, i32 1
  %7 = load i32, ptr %6, align 8, !tbaa !10
  %8 = add i32 %7, 1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.string_buffer_entry, ptr %9, i32 0, i32 2
  %11 = load i32, ptr %10, align 4, !tbaa !13
  %12 = icmp ugt i32 %8, %11
  br i1 %12, label %13, label %21

13:                                               ; preds = %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.string_buffer_entry, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !10
  %18 = mul i32 %17, 2
  %19 = add i32 %18, 1
  %20 = call ptr @resize_buffer(ptr noundef %14, i32 noundef %19)
  store ptr %20, ptr %3, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %13, %2
  %22 = load i8, ptr %4, align 1, !tbaa !9
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.string_buffer_entry, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.string_buffer_entry, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !10
  %29 = add i32 %28, 1
  store i32 %29, ptr %27, align 8, !tbaa !10
  %30 = zext i32 %28 to i64
  %31 = getelementptr inbounds i8, ptr %25, i64 %30
  store i8 %22, ptr %31, align 1, !tbaa !9
  ret void
}

attributes #0 = { inlinehint 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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 8}
!11 = !{!"", !6, i64 0, !12, i64 8, !12, i64 12}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !12, i64 12}
!14 = !{!11, !6, i64 0}


; 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: inlinehint nounwind uwtable
declare hidden ptr @resize_buffer(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @string_buffer_append_char(ptr noundef %0, i8 noundef signext %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = add i32 %4, 1
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = icmp ugt i32 %5, %7
  br i1 %8, label %9, label %13

9:                                                ; preds = %2
  %10 = shl i32 %4, 1
  %11 = or disjoint i32 %10, 1
  %12 = tail call ptr @resize_buffer(ptr noundef nonnull %0, i32 noundef %11)
  %.phi.trans.insert = getelementptr inbounds i8, ptr %12, i64 8
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !5
  %.pre6 = add i32 %.pre, 1
  br label %13

13:                                               ; preds = %9, %2
  %.pre-phi = phi i32 [ %.pre6, %9 ], [ %5, %2 ]
  %14 = phi i32 [ %.pre, %9 ], [ %4, %2 ]
  %.0 = phi ptr [ %12, %9 ], [ %0, %2 ]
  %15 = load ptr, ptr %.0, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %.0, i64 8
  store i32 %.pre-phi, ptr %16, align 8, !tbaa !5
  %17 = zext i32 %14 to i64
  %18 = getelementptr inbounds i8, ptr %15, i64 %17
  store i8 %1, ptr %18, align 1, !tbaa !13
  ret void
}

attributes #0 = { inlinehint 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 = { 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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !7, i64 0}
!13 = !{!8, !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass