; LLVM IR from 0intro/wmii :: lib/libstuff/util (mfatal)

; 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"

@__const.mfatal.couldnot = external hidden unnamed_addr constant [20 x i8], align 16
@__const.mfatal.paren = external hidden unnamed_addr constant [4 x i8], align 1
@__const.mfatal.bytes = external hidden unnamed_addr constant [8 x i8], align 1
@argv0 = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @mfatal(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [20 x i8], align 16
  %6 = alloca [4 x i8], align 1
  %7 = alloca [8 x i8], align 1
  %8 = alloca [1024 x i8], align 16
  %9 = alloca [8 x i8], align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 20, ptr %5) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 @__const.mfatal.couldnot, i64 20, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %6, ptr align 1 @__const.mfatal.paren, i64 4, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %7, ptr align 1 @__const.mfatal.bytes, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 1024, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 8, ptr %10, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %22, %2
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = urem i32 %12, 10
  %14 = add i32 48, %13
  %15 = trunc i32 %14 to i8
  %16 = load i32, ptr %10, align 4, !tbaa !9
  %17 = add nsw i32 %16, -1
  store i32 %17, ptr %10, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [8 x i8], ptr %9, i64 0, i64 %18
  store i8 %15, ptr %19, align 1, !tbaa !11
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = udiv i32 %20, 10
  store i32 %21, ptr %4, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %11
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = icmp ugt i32 %23, 0
  br i1 %24, label %11, label %25, !llvm.loop !12

25:                                               ; preds = %22
  %26 = getelementptr inbounds [1024 x i8], ptr %8, i64 0, i64 0
  %27 = load ptr, ptr @argv0, align 8, !tbaa !5
  %28 = call i32 @stuff_strlcat(ptr noundef %26, ptr noundef %27, i32 noundef 1024)
  %29 = getelementptr inbounds [1024 x i8], ptr %8, i64 0, i64 0
  %30 = getelementptr inbounds [20 x i8], ptr %5, i64 0, i64 0
  %31 = call i32 @stuff_strlcat(ptr noundef %29, ptr noundef %30, i32 noundef 1024)
  %32 = getelementptr inbounds [1024 x i8], ptr %8, i64 0, i64 0
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = call i32 @stuff_strlcat(ptr noundef %32, ptr noundef %33, i32 noundef 1024)
  %35 = getelementptr inbounds [1024 x i8], ptr %8, i64 0, i64 0
  %36 = getelementptr inbounds [4 x i8], ptr %6, i64 0, i64 0
  %37 = call i32 @stuff_strlcat(ptr noundef %35, ptr noundef %36, i32 noundef 1024)
  %38 = getelementptr inbounds [1024 x i8], ptr %8, i64 0, i64 0
  %39 = getelementptr inbounds [8 x i8], ptr %9, i64 0, i64 0
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %39, i64 %41
  %43 = call i32 @stuff_strlcat(ptr noundef %38, ptr noundef %42, i32 noundef 1024)
  %44 = getelementptr inbounds [1024 x i8], ptr %8, i64 0, i64 0
  %45 = getelementptr inbounds [8 x i8], ptr %7, i64 0, i64 0
  %46 = call i32 @stuff_strlcat(ptr noundef %44, ptr noundef %45, i32 noundef 1024)
  %47 = getelementptr inbounds [1024 x i8], ptr %8, i64 0, i64 0
  %48 = getelementptr inbounds [1024 x i8], ptr %8, i64 0, i64 0
  %49 = call i64 @strlen(ptr noundef %48) #7
  %50 = call i64 @write(i32 noundef 2, ptr noundef %47, i64 noundef %49)
  call void @exit(i32 noundef 1) #8
  unreachable
}

; 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: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #3

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { noreturn 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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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"

@__const.mfatal.couldnot = external hidden unnamed_addr constant [20 x i8], align 16
@__const.mfatal.paren = external hidden unnamed_addr constant [4 x i8], align 1
@__const.mfatal.bytes = external hidden unnamed_addr constant [8 x i8], align 1
@argv0 = external local_unnamed_addr global ptr, align 8

; Function Attrs: noreturn nounwind uwtable
define dso_local void @mfatal(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [20 x i8], align 16
  %4 = alloca [4 x i8], align 4
  %5 = alloca [8 x i8], align 8
  %6 = alloca [1024 x i8], align 16
  %7 = alloca [8 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %3) #7
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(20) %3, ptr noundef nonnull align 16 dereferenceable(20) @__const.mfatal.couldnot, i64 20, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #7
  %8 = load i32, ptr @__const.mfatal.paren, align 1
  store i32 %8, ptr %4, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #7
  %9 = load i64, ptr @__const.mfatal.bytes, align 1
  store i64 %9, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %6) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #7
  br label %10

10:                                               ; preds = %10, %2
  %indvars.iv = phi i64 [ %indvars.iv.next, %10 ], [ 8, %2 ]
  %.05 = phi i32 [ %15, %10 ], [ %1, %2 ]
  %11 = urem i32 %.05, 10
  %12 = trunc nuw nsw i32 %11 to i8
  %13 = or disjoint i8 %12, 48
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %14 = getelementptr inbounds [8 x i8], ptr %7, i64 0, i64 %indvars.iv.next
  store i8 %13, ptr %14, align 1, !tbaa !5
  %15 = udiv i32 %.05, 10
  %.not = icmp ult i32 %.05, 10
  br i1 %.not, label %16, label %10, !llvm.loop !8

16:                                               ; preds = %10
  %17 = getelementptr inbounds [8 x i8], ptr %7, i64 0, i64 %indvars.iv.next
  %18 = load ptr, ptr @argv0, align 8, !tbaa !10
  %19 = call i32 @stuff_strlcat(ptr noundef nonnull %6, ptr noundef %18, i32 noundef 1024) #7
  %20 = call i32 @stuff_strlcat(ptr noundef nonnull %6, ptr noundef nonnull %3, i32 noundef 1024) #7
  %21 = call i32 @stuff_strlcat(ptr noundef nonnull %6, ptr noundef %0, i32 noundef 1024) #7
  %22 = call i32 @stuff_strlcat(ptr noundef nonnull %6, ptr noundef nonnull %4, i32 noundef 1024) #7
  %23 = call i32 @stuff_strlcat(ptr noundef nonnull %6, ptr noundef nonnull %17, i32 noundef 1024) #7
  %24 = call i32 @stuff_strlcat(ptr noundef nonnull %6, ptr noundef nonnull %5, i32 noundef 1024) #7
  %25 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %6) #8
  %26 = call i64 @write(i32 noundef 2, ptr noundef nonnull %6, i64 noundef %25) #7
  call void @exit(i32 noundef 1) #9
  unreachable
}

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

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

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #6

attributes #0 = { noreturn 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 "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 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { noreturn 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass