; LLVM IR from lionsoul2014/friso :: src (tst-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 }

@.str = external hidden unnamed_addr constant [91 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [4 x i8], align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr @.str, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %13 = load ptr, ptr %6, align 8, !tbaa !9
  %14 = call i64 @strlen(ptr noundef %13) #5
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %16 = call ptr @new_string_buffer_with_opacity(i32 noundef 8)
  store ptr %16, ptr %12, align 8, !tbaa !9
  %17 = load ptr, ptr %6, align 8, !tbaa !9
  %18 = load i32, ptr %11, align 4, !tbaa !5
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %17, i32 noundef %18)
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %62, %2
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = load i32, ptr %11, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %66

24:                                               ; preds = %20
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = call i32 @get_utf8_bytes(i8 noundef signext %29)
  store i32 %30, ptr %8, align 4, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %24
  br label %62

34:                                               ; preds = %24
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %51, %34
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %39, label %54

39:                                               ; preds = %35
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !11
  %48 = load i32, ptr %10, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 %49
  store i8 %47, ptr %50, align 1, !tbaa !11
  br label %51

51:                                               ; preds = %39
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %10, align 4, !tbaa !5
  br label %35, !llvm.loop !12

54:                                               ; preds = %35
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 %56
  store i8 0, ptr %57, align 1, !tbaa !11
  %58 = load ptr, ptr %12, align 8, !tbaa !9
  %59 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  call void @string_buffer_append(ptr noundef %58, ptr noundef %59)
  %60 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %60)
  br label %62

62:                                               ; preds = %54, %33
  %63 = load i32, ptr %8, align 4, !tbaa !5
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = add nsw i32 %64, %63
  store i32 %65, ptr %9, align 4, !tbaa !5
  br label %20, !llvm.loop !14

66:                                               ; preds = %20
  %67 = load ptr, ptr %12, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.string_buffer_entry, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 8, !tbaa !15
  %70 = load ptr, ptr %12, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.string_buffer_entry, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !17
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %69, ptr noundef %72)
  %74 = load ptr, ptr %12, align 8, !tbaa !9
  %75 = call ptr @string_buffer_remove(ptr noundef %74, i32 noundef 0, i32 noundef 3)
  %76 = load ptr, ptr %12, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.string_buffer_entry, ptr %76, i32 0, i32 1
  %78 = load i32, ptr %77, align 8, !tbaa !15
  %79 = load ptr, ptr %12, align 8, !tbaa !9
  %80 = getelementptr inbounds %struct.string_buffer_entry, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !17
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %78, ptr noundef %81)
  %83 = load ptr, ptr %12, align 8, !tbaa !9
  %84 = call ptr @string_buffer_remove(ptr noundef %83, i32 noundef 0, i32 noundef 3)
  %85 = load ptr, ptr %12, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.string_buffer_entry, ptr %85, i32 0, i32 1
  %87 = load i32, ptr %86, align 8, !tbaa !15
  %88 = load ptr, ptr %12, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct.string_buffer_entry, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !17
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %87, ptr noundef %90)
  %92 = load ptr, ptr %12, align 8, !tbaa !9
  %93 = load ptr, ptr %12, align 8, !tbaa !9
  %94 = getelementptr inbounds %struct.string_buffer_entry, ptr %93, i32 0, i32 1
  %95 = load i32, ptr %94, align 8, !tbaa !15
  %96 = sub i32 %95, 3
  %97 = call ptr @string_buffer_remove(ptr noundef %92, i32 noundef %96, i32 noundef 6)
  %98 = load ptr, ptr %12, align 8, !tbaa !9
  %99 = call ptr @string_buffer_trim(ptr noundef %98)
  store ptr %99, ptr %12, align 8, !tbaa !9
  %100 = load ptr, ptr %12, align 8, !tbaa !9
  %101 = getelementptr inbounds %struct.string_buffer_entry, ptr %100, i32 0, i32 1
  %102 = load i32, ptr %101, align 8, !tbaa !15
  %103 = load ptr, ptr %12, align 8, !tbaa !9
  %104 = call ptr @string_buffer_devote(ptr noundef %103)
  %105 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %102, ptr noundef %104)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  ret i32 0
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

declare ptr @new_string_buffer_with_opacity(i32 noundef) #3

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

declare i32 @get_utf8_bytes(i8 noundef signext) #3

declare void @string_buffer_append(ptr noundef, ptr noundef) #3

declare ptr @string_buffer_remove(ptr noundef, i32 noundef, i32 noundef) #3

declare ptr @string_buffer_trim(ptr noundef) #3

declare ptr @string_buffer_devote(ptr noundef) #3

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

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

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!16, !6, i64 8}
!16 = !{!"", !10, i64 0, !6, i64 8, !6, i64 12}
!17 = !{!16, !10, 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"

@.str = external hidden unnamed_addr constant [91 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca [4 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @.str) #7
  %5 = trunc i64 %4 to i32
  %6 = tail call ptr @new_string_buffer_with_opacity(i32 noundef 8) #6
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef nonnull @.str, i32 noundef %5)
  %8 = icmp sgt i32 %5, 0
  br i1 %8, label %.lr.ph36, label %._crit_edge37

.lr.ph36:                                         ; preds = %2, %19
  %.034 = phi i32 [ %20, %19 ], [ 0, %2 ]
  %9 = sext i32 %.034 to i64
  %10 = getelementptr inbounds i8, ptr @.str, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = call i32 @get_utf8_bytes(i8 noundef signext %11) #6
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %19, label %.preheader

.preheader:                                       ; preds = %.lr.ph36
  %14 = icmp sgt i32 %12, 0
  br i1 %14, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %15 = zext nneg i32 %12 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %3, ptr nonnull align 1 %10, i64 %15, i1 false), !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %.preheader
  %.031.lcssa = phi i32 [ 0, %.preheader ], [ %12, %.lr.ph.preheader ]
  %16 = zext nneg i32 %.031.lcssa to i64
  %17 = getelementptr inbounds [4 x i8], ptr %3, i64 0, i64 %16
  store i8 0, ptr %17, align 1, !tbaa !5
  call void @string_buffer_append(ptr noundef %6, ptr noundef nonnull %3) #6
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %3)
  br label %19

19:                                               ; preds = %.lr.ph36, %._crit_edge
  %20 = add nsw i32 %12, %.034
  %21 = icmp slt i32 %20, %5
  br i1 %21, label %.lr.ph36, label %._crit_edge37, !llvm.loop !8

._crit_edge37:                                    ; preds = %19, %2
  %22 = getelementptr inbounds i8, ptr %6, i64 8
  %23 = load i32, ptr %22, align 8, !tbaa !10
  %24 = load ptr, ptr %6, align 8, !tbaa !14
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %23, ptr noundef %24)
  %26 = call ptr @string_buffer_remove(ptr noundef nonnull %6, i32 noundef 0, i32 noundef 3) #6
  %27 = load i32, ptr %22, align 8, !tbaa !10
  %28 = load ptr, ptr %6, align 8, !tbaa !14
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %27, ptr noundef %28)
  %30 = call ptr @string_buffer_remove(ptr noundef nonnull %6, i32 noundef 0, i32 noundef 3) #6
  %31 = load i32, ptr %22, align 8, !tbaa !10
  %32 = load ptr, ptr %6, align 8, !tbaa !14
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %31, ptr noundef %32)
  %34 = load i32, ptr %22, align 8, !tbaa !10
  %35 = add i32 %34, -3
  %36 = call ptr @string_buffer_remove(ptr noundef nonnull %6, i32 noundef %35, i32 noundef 6) #6
  %37 = call ptr @string_buffer_trim(ptr noundef nonnull %6) #6
  %38 = getelementptr inbounds i8, ptr %37, i64 8
  %39 = load i32, ptr %38, align 8, !tbaa !10
  %40 = call ptr @string_buffer_devote(ptr noundef %37) #6
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %39, ptr noundef %40)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  ret i32 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 nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

declare ptr @new_string_buffer_with_opacity(i32 noundef) local_unnamed_addr #3

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

declare i32 @get_utf8_bytes(i8 noundef signext) local_unnamed_addr #3

declare void @string_buffer_append(ptr noundef, ptr noundef) local_unnamed_addr #3

declare ptr @string_buffer_remove(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

declare ptr @string_buffer_trim(ptr noundef) local_unnamed_addr #3

declare ptr @string_buffer_devote(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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) #5

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !13, i64 8}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12}
!12 = !{!"any pointer", !6, i64 0}
!13 = !{!"int", !6, i64 0}
!14 = !{!11, !12, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass