; LLVM IR from Water-Melon/Melon :: src (mln_error)

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

@mln_error_filenames = external dso_local global ptr, align 8
@mln_error_errmsgs = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @mln_error_string(i32 noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca [8 x i8], align 1
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %14, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store ptr @.str, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store ptr @.str.1, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store ptr @.str.2, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.memset.p0.i64(ptr align 1 %13, i8 0, i64 8, i1 false)
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %17, label %22

17:                                               ; preds = %3
  %18 = load ptr, ptr %9, align 8, !tbaa !9
  %19 = load i64, ptr %6, align 8, !tbaa !11
  %20 = sub i64 %19, 1
  %21 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %18, i64 noundef %20, ptr noundef @.str.3) #4
  store i32 %21, ptr %7, align 4, !tbaa !5
  br label %101

22:                                               ; preds = %3
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %25, label %83

25:                                               ; preds = %22
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sub nsw i32 0, %26
  store i32 %27, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = ashr i32 %28, 22
  %30 = and i32 %29, 511
  store i32 %30, ptr %7, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = ashr i32 %31, 8
  %33 = and i32 %32, 16383
  store i32 %33, ptr %8, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = and i32 %34, 255
  store i32 %35, ptr %4, align 4, !tbaa !5
  %36 = getelementptr inbounds [8 x i8], ptr %13, i64 0, i64 0
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %36, i64 noundef 7, ptr noundef @.str.4, i32 noundef %37) #4
  %39 = load ptr, ptr %9, align 8, !tbaa !9
  %40 = load i64, ptr %6, align 8, !tbaa !11
  %41 = sub i64 %40, 1
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 511
  br i1 %43, label %47, label %44

44:                                               ; preds = %25
  %45 = load ptr, ptr @mln_error_filenames, align 8, !tbaa !9
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %49

47:                                               ; preds = %44, %25
  %48 = load ptr, ptr %10, align 8, !tbaa !9
  br label %56

49:                                               ; preds = %44
  %50 = load ptr, ptr @mln_error_filenames, align 8, !tbaa !9
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct.mln_string_t, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct.mln_string_t, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  br label %56

56:                                               ; preds = %49, %47
  %57 = phi ptr [ %48, %47 ], [ %55, %49 ]
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = icmp eq i32 %58, 16383
  br i1 %59, label %60, label %62

60:                                               ; preds = %56
  %61 = load ptr, ptr %11, align 8, !tbaa !9
  br label %64

62:                                               ; preds = %56
  %63 = getelementptr inbounds [8 x i8], ptr %13, i64 0, i64 0
  br label %64

64:                                               ; preds = %62, %60
  %65 = phi ptr [ %61, %60 ], [ %63, %62 ]
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = icmp eq i32 %66, 255
  br i1 %67, label %71, label %68

68:                                               ; preds = %64
  %69 = load ptr, ptr @mln_error_errmsgs, align 8, !tbaa !9
  %70 = icmp eq ptr %69, null
  br i1 %70, label %71, label %73

71:                                               ; preds = %68, %64
  %72 = load ptr, ptr %12, align 8, !tbaa !9
  br label %80

73:                                               ; preds = %68
  %74 = load ptr, ptr @mln_error_errmsgs, align 8, !tbaa !9
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds %struct.mln_string_t, ptr %74, i64 %76
  %78 = getelementptr inbounds %struct.mln_string_t, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !13
  br label %80

80:                                               ; preds = %73, %71
  %81 = phi ptr [ %72, %71 ], [ %79, %73 ]
  %82 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %39, i64 noundef %41, ptr noundef @.str.5, ptr noundef %57, ptr noundef %65, ptr noundef %81) #4
  store i32 %82, ptr %7, align 4, !tbaa !5
  br label %100

83:                                               ; preds = %22
  %84 = load ptr, ptr %9, align 8, !tbaa !9
  %85 = load i64, ptr %6, align 8, !tbaa !11
  %86 = sub i64 %85, 1
  %87 = load ptr, ptr @mln_error_errmsgs, align 8, !tbaa !9
  %88 = icmp eq ptr %87, null
  br i1 %88, label %89, label %90

89:                                               ; preds = %83
  br label %97

90:                                               ; preds = %83
  %91 = load ptr, ptr @mln_error_errmsgs, align 8, !tbaa !9
  %92 = load i32, ptr %4, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds %struct.mln_string_t, ptr %91, i64 %93
  %95 = getelementptr inbounds %struct.mln_string_t, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !13
  br label %97

97:                                               ; preds = %90, %89
  %98 = phi ptr [ @.str.7, %89 ], [ %96, %90 ]
  %99 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %84, i64 noundef %86, ptr noundef @.str.6, ptr noundef %98) #4
  store i32 %99, ptr %7, align 4, !tbaa !5
  br label %100

100:                                              ; preds = %97, %80
  br label %101

101:                                              ; preds = %100, %17
  %102 = load ptr, ptr %9, align 8, !tbaa !9
  %103 = load i32, ptr %7, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds i8, ptr %102, i64 %104
  store i8 0, ptr %105, align 1, !tbaa !15
  %106 = load ptr, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, 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
  ret ptr %106
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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, !12, i64 16, !12, i64 16}
!15 = !{!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.mln_string_t = type { ptr, i64, i32 }

@mln_error_filenames = external dso_local local_unnamed_addr global ptr, align 8
@mln_error_errmsgs = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef ptr @mln_error_string(i32 noundef %0, ptr noundef returned writeonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = alloca [8 x i8], align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store i64 0, ptr %4, align 8
  %5 = icmp sgt i32 %0, 0
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  %7 = add i64 %2, -1
  %8 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %1, i64 noundef %7, ptr noundef nonnull @.str.3) #3
  br label %49

9:                                                ; preds = %3
  %10 = icmp slt i32 %0, 0
  br i1 %10, label %11, label %40

11:                                               ; preds = %9
  %12 = sub nsw i32 0, %0
  %13 = lshr i32 %12, 22
  %14 = lshr i32 %12, 8
  %15 = and i32 %14, 16383
  %16 = and i32 %12, 255
  %17 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %4, i64 noundef 7, ptr noundef nonnull @.str.4, i32 noundef %15) #3
  %18 = add i64 %2, -1
  %19 = icmp eq i32 %13, 511
  %20 = load ptr, ptr @mln_error_filenames, align 8
  %21 = icmp eq ptr %20, null
  %or.cond = select i1 %19, i1 true, i1 %21
  br i1 %or.cond, label %26, label %22

22:                                               ; preds = %11
  %23 = zext nneg i32 %13 to i64
  %24 = getelementptr inbounds %struct.mln_string_t, ptr %20, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %11, %22
  %27 = phi ptr [ %25, %22 ], [ @.str, %11 ]
  %28 = icmp eq i32 %15, 16383
  %29 = select i1 %28, ptr @.str.1, ptr %4
  %30 = icmp eq i32 %16, 255
  %31 = load ptr, ptr @mln_error_errmsgs, align 8
  %32 = icmp eq ptr %31, null
  %or.cond3 = select i1 %30, i1 true, i1 %32
  br i1 %or.cond3, label %37, label %33

33:                                               ; preds = %26
  %34 = zext nneg i32 %16 to i64
  %35 = getelementptr inbounds %struct.mln_string_t, ptr %31, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %26, %33
  %38 = phi ptr [ %36, %33 ], [ @.str.2, %26 ]
  %39 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %1, i64 noundef %18, ptr noundef nonnull @.str.5, ptr noundef %27, ptr noundef nonnull %29, ptr noundef %38) #3
  br label %49

40:                                               ; preds = %9
  %41 = add i64 %2, -1
  %42 = load ptr, ptr @mln_error_errmsgs, align 8, !tbaa !11
  %43 = icmp eq ptr %42, null
  br i1 %43, label %46, label %44

44:                                               ; preds = %40
  %45 = load ptr, ptr %42, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %40, %44
  %47 = phi ptr [ %45, %44 ], [ @.str.7, %40 ]
  %48 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %1, i64 noundef %41, ptr noundef nonnull @.str.6, ptr noundef %47) #3
  br label %49

49:                                               ; preds = %37, %46, %6
  %.0 = phi i32 [ %8, %6 ], [ %39, %37 ], [ %48, %46 ]
  %50 = sext i32 %.0 to i64
  %51 = getelementptr inbounds i8, ptr %1, i64 %50
  store i8 0, ptr %51, align 1, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret ptr %1
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

attributes #0 = { nofree 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 = { 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 #3 = { 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, !10, i64 16, !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 = !{!7, !7, i64 0}
!12 = !{!8, !8, i64 0}


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