; LLVM IR from freakout42/macrocalc :: mc/mex (line)

; 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.LINE = type { ptr, ptr, i16, i16, [32768 x i8] }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @lalloc(i32 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = add nsw i32 %8, 18
  store i32 %9, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, 65535
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  store i32 65535, ptr %5, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %12, %1
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %13
  call void (ptr, ...) @mlwrite(ptr noundef @.str)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %46

18:                                               ; preds = %13
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = add i64 24, %20
  %22 = trunc i64 %21 to i32
  store i32 %22, ptr %6, align 4, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = call noalias ptr @malloc(i64 noundef %24) #5
  store ptr %25, ptr %4, align 8, !tbaa !9
  %26 = load ptr, ptr %4, align 8, !tbaa !9
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %36

28:                                               ; preds = %18
  call void (...) @dtmpbufs()
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = call noalias ptr @malloc(i64 noundef %30) #5
  store ptr %31, ptr %4, align 8, !tbaa !9
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %28
  call void (ptr, ...) @mlwrite(ptr noundef @.str.1)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %46

35:                                               ; preds = %28
  br label %36

36:                                               ; preds = %35, %18
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = trunc i32 %37 to i16
  %39 = load ptr, ptr %4, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.LINE, ptr %39, i32 0, i32 2
  store i16 %38, ptr %40, align 8, !tbaa !11
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = trunc i32 %41 to i16
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.LINE, ptr %43, i32 0, i32 3
  store i16 %42, ptr %44, align 2, !tbaa !14
  %45 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %45, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %46

46:                                               ; preds = %36, %34, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %47 = load ptr, ptr %2, align 8
  ret ptr %47
}

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

declare void @mlwrite(ptr noundef, ...) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

declare void @dtmpbufs(...) #2

; 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 = { "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 allocsize(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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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, !13, i64 16}
!12 = !{!"LINE", !10, i64 0, !10, i64 8, !13, i64 16, !13, i64 18, !7, i64 20}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 18}


; 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 [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @lalloc(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @llvm.smin.i32(i32 %0, i32 65517)
  %spec.store.select = add nsw i32 %2, 18
  %3 = icmp slt i32 %spec.store.select, %0
  br i1 %3, label %4, label %5

4:                                                ; preds = %1
  tail call void (ptr, ...) @mlwrite(ptr noundef nonnull @.str) #4
  br label %18

5:                                                ; preds = %1
  %narrow = add nsw i32 %2, 42
  %6 = sext i32 %narrow to i64
  %7 = tail call noalias ptr @malloc(i64 noundef %6) #5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %13

9:                                                ; preds = %5
  tail call void (...) @dtmpbufs() #4
  %10 = tail call noalias ptr @malloc(i64 noundef %6) #5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %9
  tail call void (ptr, ...) @mlwrite(ptr noundef nonnull @.str.1) #4
  br label %18

13:                                               ; preds = %9, %5
  %.014 = phi ptr [ %10, %9 ], [ %7, %5 ]
  %14 = trunc i32 %spec.store.select to i16
  %15 = getelementptr inbounds i8, ptr %.014, i64 16
  store i16 %14, ptr %15, align 8, !tbaa !5
  %16 = trunc i32 %0 to i16
  %17 = getelementptr inbounds i8, ptr %.014, i64 18
  store i16 %16, ptr %17, align 2, !tbaa !11
  br label %18

18:                                               ; preds = %13, %12, %4
  %.0 = phi ptr [ null, %4 ], [ null, %12 ], [ %.014, %13 ]
  ret ptr %.0
}

declare void @mlwrite(ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

declare void @dtmpbufs(...) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #3

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 = { "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #5 = { nounwind allocsize(0) }

!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 16}
!6 = !{!"LINE", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 18, !8, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !10, i64 18}


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