; LLVM IR from jingweizhanghuai/Morn :: src/util (morn_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.__va_list_tag = type { i32, i32, ptr, ptr }
%struct.MArray = type { i32, i16, %union.anon }
%union.anon = type { ptr }

@morn_default_string = external dso_local thread_local global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [78 x i8], align 1
@__FUNCTION__.m_String = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [22 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

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

declare ptr @m_ArrayWrite(ptr noundef, i64 noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @_DefaultString(ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @m_String(ptr noundef %0, i32 noundef %1, ptr noundef %2, ...) #4 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca [1024 x i8], align 16
  %10 = alloca [1 x %struct.__va_list_tag], align 16
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %16

14:                                               ; preds = %3
  %15 = call ptr @_DefaultString(ptr noundef null)
  store ptr %15, ptr %5, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %14, %3
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %23

19:                                               ; preds = %16
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.MArray, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !11
  store i32 %22, ptr %6, align 4, !tbaa !9
  br label %48

23:                                               ; preds = %16
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.MArray, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !11
  %28 = icmp sle i32 %24, %27
  br i1 %28, label %29, label %39

29:                                               ; preds = %23
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.MArray, ptr %31, i32 0, i32 0
  store i32 %30, ptr %32, align 8, !tbaa !11
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.MArray, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %35, i64 %37
  store i8 0, ptr %38, align 1, !tbaa !14
  br label %47

39:                                               ; preds = %23
  br label %40

40:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  store i32 1, ptr %8, align 4, !tbaa !9
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %40
  %44 = load i32, ptr %8, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %44, i32 noundef -1, ptr noundef @.str.1, i32 noundef 125, ptr noundef @__FUNCTION__.m_String, ptr noundef @.str.2)
  br label %45

45:                                               ; preds = %43, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46, %29
  br label %48

48:                                               ; preds = %47, %19
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = icmp eq ptr %49, null
  br i1 %50, label %51, label %55

51:                                               ; preds = %48
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.MArray, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  store ptr %54, ptr %4, align 8
  br label %105

55:                                               ; preds = %48
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 0
  %58 = load i8, ptr %57, align 1, !tbaa !14
  %59 = sext i8 %58 to i32
  %60 = icmp eq i32 %59, 2
  br i1 %60, label %61, label %66

61:                                               ; preds = %55
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.MArray, ptr %62, i32 0, i32 0
  store i32 0, ptr %63, align 8, !tbaa !11
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i32 1
  store ptr %65, ptr %7, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %61, %55
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i64 0
  %69 = load i8, ptr %68, align 1, !tbaa !14
  %70 = sext i8 %69 to i32
  %71 = icmp eq i32 %70, 0
  br i1 %71, label %72, label %76

72:                                               ; preds = %66
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.MArray, ptr %73, i32 0, i32 2
  %75 = load ptr, ptr %74, align 8, !tbaa !14
  store ptr %75, ptr %4, align 8
  br label %105

76:                                               ; preds = %66
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @morn_default_string)
  %79 = load ptr, ptr %78, align 8, !tbaa !5
  %80 = icmp ne ptr %77, %79
  br i1 %80, label %81, label %83

81:                                               ; preds = %76
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mHandleReset(ptr noundef %82)
  br label %83

83:                                               ; preds = %81, %76
  call void @llvm.lifetime.start.p0(i64 1024, ptr %9) #7
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #7
  %84 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %10, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %84)
  %85 = getelementptr inbounds [1024 x i8], ptr %9, i64 0, i64 0
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %10, i64 0, i64 0
  %88 = call i32 @vsprintf(ptr noundef %85, ptr noundef %86, ptr noundef %87) #7
  %89 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %10, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %89)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  %90 = getelementptr inbounds [1024 x i8], ptr %9, i64 0, i64 0
  %91 = call i64 @strlen(ptr noundef %90) #8
  %92 = trunc i64 %91 to i32
  store i32 %92, ptr %11, align 4, !tbaa !9
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = getelementptr inbounds [1024 x i8], ptr %9, i64 0, i64 0
  %95 = load i32, ptr %11, align 4, !tbaa !9
  %96 = add nsw i32 %95, 1
  %97 = call ptr @m_ArrayWrite(ptr noundef %93, i64 noundef -1, ptr noundef %94, i32 noundef %96)
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.MArray, ptr %98, i32 0, i32 0
  %100 = load i32, ptr %99, align 8, !tbaa !11
  %101 = add nsw i32 %100, -1
  store i32 %101, ptr %99, align 8, !tbaa !11
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.MArray, ptr %102, i32 0, i32 2
  %104 = load ptr, ptr %103, align 8, !tbaa !14
  store ptr %104, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 1024, ptr %9) #7
  br label %105

105:                                              ; preds = %83, %72, %51
  %106 = load ptr, ptr %4, align 8
  ret ptr %106
}

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #2

declare void @mHandleReset(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #5

; Function Attrs: nounwind
declare i32 @vsprintf(ptr noundef, ptr noundef, ptr noundef) #6

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { nocallback nofree nosync nounwind willreturn }
attributes #6 = { 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 #7 = { nounwind }
attributes #8 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"MArray", !10, i64 0, !13, i64 4, !7, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!7, !7, 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"

%struct.__va_list_tag = type { i32, i32, ptr, ptr }

@morn_default_string = external dso_local thread_local local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [78 x i8], align 1
@__FUNCTION__.m_String = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [22 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: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

declare ptr @m_ArrayWrite(ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @_DefaultString(ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local ptr @m_String(ptr noundef %0, i32 noundef %1, ptr noundef readonly %2, ...) local_unnamed_addr #4 {
  %4 = alloca [1024 x i8], align 16
  %5 = alloca [1 x %struct.__va_list_tag], align 16
  %6 = icmp eq ptr %0, null
  br i1 %6, label %7, label %9

7:                                                ; preds = %3
  %8 = tail call ptr @_DefaultString(ptr noundef null)
  br label %9

9:                                                ; preds = %7, %3
  %.025 = phi ptr [ %8, %7 ], [ %0, %3 ]
  %10 = icmp slt i32 %1, 0
  br i1 %10, label %19, label %11

11:                                               ; preds = %9
  %12 = load i32, ptr %.025, align 8, !tbaa !5
  %.not = icmp slt i32 %12, %1
  br i1 %.not, label %18, label %13

13:                                               ; preds = %11
  store i32 %1, ptr %.025, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %.025, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = zext nneg i32 %1 to i64
  %17 = getelementptr inbounds i8, ptr %15, i64 %16
  store i8 0, ptr %17, align 1, !tbaa !11
  br label %19

18:                                               ; preds = %11
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str.1, i32 noundef 125, ptr noundef nonnull @__FUNCTION__.m_String, ptr noundef nonnull @.str.2) #7
  br label %19

19:                                               ; preds = %9, %13, %18
  %20 = icmp eq ptr %2, null
  br i1 %20, label %21, label %24

21:                                               ; preds = %19
  %22 = getelementptr inbounds i8, ptr %.025, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  br label %49

24:                                               ; preds = %19
  %25 = load i8, ptr %2, align 1, !tbaa !11
  %26 = icmp eq i8 %25, 2
  br i1 %26, label %27, label %29

27:                                               ; preds = %24
  store i32 0, ptr %.025, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %2, i64 1
  %.pr = load i8, ptr %28, align 1, !tbaa !11
  br label %29

29:                                               ; preds = %27, %24
  %30 = phi i8 [ %.pr, %27 ], [ %25, %24 ]
  %.026 = phi ptr [ %28, %27 ], [ %2, %24 ]
  %31 = icmp eq i8 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = getelementptr inbounds i8, ptr %.025, i64 8
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  br label %49

35:                                               ; preds = %29
  %36 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @morn_default_string)
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  %.not30 = icmp eq ptr %.025, %37
  br i1 %.not30, label %39, label %38

38:                                               ; preds = %35
  tail call void @mHandleReset(ptr noundef %.025) #7
  br label %39

39:                                               ; preds = %38, %35
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %4) #7
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #7
  call void @llvm.va_start.p0(ptr nonnull %5)
  %40 = call i32 @vsprintf(ptr noundef nonnull %4, ptr noundef nonnull %.026, ptr noundef nonnull %5) #7
  call void @llvm.va_end.p0(ptr nonnull %5)
  %41 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #8
  %42 = trunc i64 %41 to i32
  %43 = add nsw i32 %42, 1
  %44 = call ptr @m_ArrayWrite(ptr noundef %.025, i64 noundef -1, ptr noundef nonnull %4, i32 noundef %43) #7
  %45 = load i32, ptr %.025, align 8, !tbaa !5
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr %.025, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %.025, i64 8
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #7
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %4) #7
  br label %49

49:                                               ; preds = %39, %32, %21
  %.0 = phi ptr [ %23, %21 ], [ %34, %32 ], [ %48, %39 ]
  ret ptr %.0
}

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #2

declare void @mHandleReset(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #5

; Function Attrs: nofree nounwind
declare noundef i32 @vsprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ptr noundef) local_unnamed_addr #6

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #6 = { 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 #7 = { nounwind }
attributes #8 = { 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, !7, i64 0}
!6 = !{!"MArray", !7, i64 0, !10, i64 4, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass