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

; 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] }
%struct.BUFFER = type { ptr, ptr, i32, ptr, i32, ptr, i32, i32, [128 x i8], [128 x i8] }

; Function Attrs: nounwind uwtable
define dso_local i32 @addline(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call i64 @strlen(ptr noundef %10) #5
  %12 = trunc i64 %11 to i32
  store i32 %12, ptr %8, align 4, !tbaa !9
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = call ptr (i32, ...) @lalloc(i32 noundef %13)
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %73

17:                                               ; preds = %2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %33, %17
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %36

22:                                               ; preds = %18
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.LINE, ptr %28, i32 0, i32 4
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [32768 x i8], ptr %29, i64 0, i64 %31
  store i8 %27, ptr %32, align 1, !tbaa !11
  br label %33

33:                                               ; preds = %22
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !9
  br label %18, !llvm.loop !12

36:                                               ; preds = %18
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.BUFFER, ptr %38, i32 0, i32 5
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = getelementptr inbounds %struct.LINE, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = getelementptr inbounds %struct.LINE, ptr %42, i32 0, i32 0
  store ptr %37, ptr %43, align 8, !tbaa !19
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.BUFFER, ptr %44, i32 0, i32 5
  %46 = load ptr, ptr %45, align 8, !tbaa !14
  %47 = getelementptr inbounds %struct.LINE, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.LINE, ptr %49, i32 0, i32 1
  store ptr %48, ptr %50, align 8, !tbaa !16
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.BUFFER, ptr %52, i32 0, i32 5
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  %55 = getelementptr inbounds %struct.LINE, ptr %54, i32 0, i32 1
  store ptr %51, ptr %55, align 8, !tbaa !16
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.BUFFER, ptr %56, i32 0, i32 5
  %58 = load ptr, ptr %57, align 8, !tbaa !14
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.LINE, ptr %59, i32 0, i32 0
  store ptr %58, ptr %60, align 8, !tbaa !19
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.BUFFER, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !20
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.BUFFER, ptr %64, i32 0, i32 5
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = icmp eq ptr %63, %66
  br i1 %67, label %68, label %72

68:                                               ; preds = %36
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.BUFFER, ptr %70, i32 0, i32 1
  store ptr %69, ptr %71, align 8, !tbaa !20
  br label %72

72:                                               ; preds = %68, %36
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %73

73:                                               ; preds = %72, %16
  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
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

; 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 @lalloc(...) #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 = !{!"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"}
!14 = !{!15, !6, i64 40}
!15 = !{!"BUFFER", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !7, i64 56, !7, i64 184}
!16 = !{!17, !6, i64 8}
!17 = !{!"LINE", !6, i64 0, !6, i64 8, !18, i64 16, !18, i64 18, !7, i64 20}
!18 = !{!"short", !7, i64 0}
!19 = !{!17, !6, i64 0}
!20 = !{!15, !6, i64 8}


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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @addline(ptr nocapture noundef readonly %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = ptrtoint ptr %0 to i64
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %5 = trunc i64 %4 to i32
  %6 = tail call ptr (i32, ...) @lalloc(i32 noundef %5) #4
  %7 = ptrtoint ptr %6 to i64
  %8 = icmp eq ptr %6, null
  br i1 %8, label %48, label %.preheader

.preheader:                                       ; preds = %2
  %9 = icmp sgt i32 %5, 0
  br i1 %9, label %iter.check, label %._crit_edge

iter.check:                                       ; preds = %.preheader
  %10 = getelementptr inbounds i8, ptr %6, i64 20
  %wide.trip.count = and i64 %4, 2147483647
  %min.iters.check = icmp ult i64 %wide.trip.count, 8
  br i1 %min.iters.check, label %vec.epilog.scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %iter.check
  %11 = add i64 %7, 20
  %12 = sub i64 %11, %3
  %diff.check = icmp ult i64 %12, 32
  br i1 %diff.check, label %vec.epilog.scalar.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %vector.memcheck
  %min.iters.check25 = icmp ult i64 %wide.trip.count, 32
  br i1 %min.iters.check25, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.mod.vf = and i64 %4, 31
  %n.vec = sub nsw i64 %wide.trip.count, %n.mod.vf
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %13 = getelementptr inbounds i8, ptr %0, i64 %index
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %wide.load = load <16 x i8>, ptr %13, align 1, !tbaa !5
  %wide.load26 = load <16 x i8>, ptr %14, align 1, !tbaa !5
  %15 = getelementptr inbounds [32768 x i8], ptr %10, i64 0, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store <16 x i8> %wide.load, ptr %15, align 1, !tbaa !5
  store <16 x i8> %wide.load26, ptr %16, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %17 = icmp eq i64 %index.next, %n.vec
  br i1 %17, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.mod.vf, 0
  br i1 %cmp.n, label %._crit_edge, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %min.epilog.iters.check = icmp ult i64 %n.mod.vf, 8
  br i1 %min.epilog.iters.check, label %vec.epilog.scalar.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.mod.vf27 = and i64 %4, 7
  %n.vec28 = sub nsw i64 %wide.trip.count, %n.mod.vf27
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index29 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next31, %vec.epilog.vector.body ]
  %18 = getelementptr inbounds i8, ptr %0, i64 %index29
  %wide.load30 = load <8 x i8>, ptr %18, align 1, !tbaa !5
  %19 = getelementptr inbounds [32768 x i8], ptr %10, i64 0, i64 %index29
  store <8 x i8> %wide.load30, ptr %19, align 1, !tbaa !5
  %index.next31 = add nuw i64 %index29, 8
  %20 = icmp eq i64 %index.next31, %n.vec28
  br i1 %20, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !12

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n32 = icmp eq i64 %n.mod.vf27, 0
  br i1 %cmp.n32, label %._crit_edge, label %vec.epilog.scalar.ph.preheader

vec.epilog.scalar.ph.preheader:                   ; preds = %vec.epilog.middle.block, %vector.memcheck, %iter.check, %vec.epilog.iter.check
  %indvars.iv.ph = phi i64 [ 0, %iter.check ], [ 0, %vector.memcheck ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec28, %vec.epilog.middle.block ]
  %21 = sub i64 %4, %indvars.iv.ph
  %xtraiter = and i64 %21, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %vec.epilog.scalar.ph.prol.loopexit, label %vec.epilog.scalar.ph.prol

vec.epilog.scalar.ph.prol:                        ; preds = %vec.epilog.scalar.ph.preheader, %vec.epilog.scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %vec.epilog.scalar.ph.prol ], [ %indvars.iv.ph, %vec.epilog.scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %vec.epilog.scalar.ph.prol ], [ 0, %vec.epilog.scalar.ph.preheader ]
  %22 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.prol
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = getelementptr inbounds [32768 x i8], ptr %10, i64 0, i64 %indvars.iv.prol
  store i8 %23, ptr %24, align 1, !tbaa !5
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %vec.epilog.scalar.ph.prol.loopexit, label %vec.epilog.scalar.ph.prol, !llvm.loop !13

vec.epilog.scalar.ph.prol.loopexit:               ; preds = %vec.epilog.scalar.ph.prol, %vec.epilog.scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %vec.epilog.scalar.ph.preheader ], [ %indvars.iv.next.prol, %vec.epilog.scalar.ph.prol ]
  %25 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %26 = icmp ugt i64 %25, -4
  br i1 %26, label %._crit_edge, label %vec.epilog.scalar.ph

vec.epilog.scalar.ph:                             ; preds = %vec.epilog.scalar.ph.prol.loopexit, %vec.epilog.scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %vec.epilog.scalar.ph ], [ %indvars.iv.unr, %vec.epilog.scalar.ph.prol.loopexit ]
  %27 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = getelementptr inbounds [32768 x i8], ptr %10, i64 0, i64 %indvars.iv
  store i8 %28, ptr %29, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %30 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %32 = getelementptr inbounds [32768 x i8], ptr %10, i64 0, i64 %indvars.iv.next
  store i8 %31, ptr %32, align 1, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %33 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.1
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %35 = getelementptr inbounds [32768 x i8], ptr %10, i64 0, i64 %indvars.iv.next.1
  store i8 %34, ptr %35, align 1, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %36 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.2
  %37 = load i8, ptr %36, align 1, !tbaa !5
  %38 = getelementptr inbounds [32768 x i8], ptr %10, i64 0, i64 %indvars.iv.next.2
  store i8 %37, ptr %38, align 1, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %vec.epilog.scalar.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %vec.epilog.scalar.ph.prol.loopexit, %vec.epilog.scalar.ph, %middle.block, %vec.epilog.middle.block, %.preheader
  %39 = getelementptr inbounds i8, ptr %1, i64 40
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  %41 = getelementptr inbounds i8, ptr %40, i64 8
  %42 = load ptr, ptr %41, align 8, !tbaa !20
  store ptr %6, ptr %42, align 8, !tbaa !23
  %43 = getelementptr inbounds i8, ptr %6, i64 8
  store ptr %42, ptr %43, align 8, !tbaa !20
  store ptr %6, ptr %41, align 8, !tbaa !20
  store ptr %40, ptr %6, align 8, !tbaa !23
  %44 = getelementptr inbounds i8, ptr %1, i64 8
  %45 = load ptr, ptr %44, align 8, !tbaa !24
  %46 = icmp eq ptr %45, %40
  br i1 %46, label %47, label %48

47:                                               ; preds = %._crit_edge
  store ptr %6, ptr %44, align 8, !tbaa !24
  br label %48

48:                                               ; preds = %._crit_edge, %47, %2
  %.0 = phi i32 [ 0, %2 ], [ 1, %47 ], [ 1, %._crit_edge ]
  ret i32 %.0
}

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

declare ptr @lalloc(...) local_unnamed_addr #2

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 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 = { nounwind willreturn memory(read) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9, !10, !11}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !9, !10, !11}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !9, !10}
!16 = !{!17, !18, i64 40}
!17 = !{!"BUFFER", !18, i64 0, !18, i64 8, !19, i64 16, !18, i64 24, !19, i64 32, !18, i64 40, !19, i64 48, !19, i64 52, !6, i64 56, !6, i64 184}
!18 = !{!"any pointer", !6, i64 0}
!19 = !{!"int", !6, i64 0}
!20 = !{!21, !18, i64 8}
!21 = !{!"LINE", !18, i64 0, !18, i64 8, !22, i64 16, !22, i64 18, !6, i64 20}
!22 = !{!"short", !6, i64 0}
!23 = !{!21, !18, i64 0}
!24 = !{!17, !18, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass