; 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.WINDOW = type { ptr, ptr, ptr, ptr, i32, ptr, i32, i32, i32, i32, i32, i32 }
%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] }

@wheadp = external global ptr, align 8
@bheadp = external global ptr, align 8

; 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 uwtable
define dso_local void @lfree(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %5 = load ptr, ptr @wheadp, align 8, !tbaa !5
  store ptr %5, ptr %4, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %49, %1
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %53

9:                                                ; preds = %6
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.WINDOW, ptr %10, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = icmp eq ptr %12, %13
  br i1 %14, label %15, label %21

15:                                               ; preds = %9
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.LINE, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.WINDOW, ptr %19, i32 0, i32 2
  store ptr %18, ptr %20, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %15, %9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.WINDOW, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = icmp eq ptr %24, %25
  br i1 %26, label %27, label %35

27:                                               ; preds = %21
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.LINE, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.WINDOW, ptr %31, i32 0, i32 3
  store ptr %30, ptr %32, align 8, !tbaa !15
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.WINDOW, ptr %33, i32 0, i32 4
  store i32 0, ptr %34, align 8, !tbaa !16
  br label %35

35:                                               ; preds = %27, %21
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.WINDOW, ptr %36, i32 0, i32 5
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = icmp eq ptr %38, %39
  br i1 %40, label %41, label %49

41:                                               ; preds = %35
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.LINE, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !12
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.WINDOW, ptr %45, i32 0, i32 5
  store ptr %44, ptr %46, align 8, !tbaa !17
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.WINDOW, ptr %47, i32 0, i32 6
  store i32 0, ptr %48, align 8, !tbaa !18
  br label %49

49:                                               ; preds = %41, %35
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.WINDOW, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !19
  store ptr %52, ptr %4, align 8, !tbaa !5
  br label %6, !llvm.loop !20

53:                                               ; preds = %6
  %54 = load ptr, ptr @bheadp, align 8, !tbaa !5
  store ptr %54, ptr %3, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %92, %53
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %96

58:                                               ; preds = %55
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.BUFFER, ptr %59, i32 0, i32 6
  %61 = load i32, ptr %60, align 8, !tbaa !22
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %92

63:                                               ; preds = %58
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.BUFFER, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !24
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = icmp eq ptr %66, %67
  br i1 %68, label %69, label %77

69:                                               ; preds = %63
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.LINE, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !12
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.BUFFER, ptr %73, i32 0, i32 1
  store ptr %72, ptr %74, align 8, !tbaa !24
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.BUFFER, ptr %75, i32 0, i32 2
  store i32 0, ptr %76, align 8, !tbaa !25
  br label %77

77:                                               ; preds = %69, %63
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.BUFFER, ptr %78, i32 0, i32 3
  %80 = load ptr, ptr %79, align 8, !tbaa !26
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = icmp eq ptr %80, %81
  br i1 %82, label %83, label %91

83:                                               ; preds = %77
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.LINE, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !12
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.BUFFER, ptr %87, i32 0, i32 3
  store ptr %86, ptr %88, align 8, !tbaa !26
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.BUFFER, ptr %89, i32 0, i32 4
  store i32 0, ptr %90, align 8, !tbaa !27
  br label %91

91:                                               ; preds = %83, %77
  br label %92

92:                                               ; preds = %91, %58
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.BUFFER, ptr %93, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !28
  store ptr %95, ptr %3, align 8, !tbaa !5
  br label %55, !llvm.loop !29

96:                                               ; preds = %55
  %97 = load ptr, ptr %2, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.LINE, ptr %97, i32 0, i32 0
  %99 = load ptr, ptr %98, align 8, !tbaa !12
  %100 = load ptr, ptr %2, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.LINE, ptr %100, i32 0, i32 1
  %102 = load ptr, ptr %101, align 8, !tbaa !30
  %103 = getelementptr inbounds %struct.LINE, ptr %102, i32 0, i32 0
  store ptr %99, ptr %103, align 8, !tbaa !12
  %104 = load ptr, ptr %2, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.LINE, ptr %104, i32 0, i32 1
  %106 = load ptr, ptr %105, align 8, !tbaa !30
  %107 = load ptr, ptr %2, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.LINE, ptr %107, i32 0, i32 0
  %109 = load ptr, ptr %108, align 8, !tbaa !12
  %110 = getelementptr inbounds %struct.LINE, ptr %109, i32 0, i32 1
  store ptr %106, ptr %110, align 8, !tbaa !30
  %111 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %111) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"WINDOW", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"LINE", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 18, !7, i64 20}
!14 = !{!"short", !7, i64 0}
!15 = !{!10, !6, i64 24}
!16 = !{!10, !11, i64 32}
!17 = !{!10, !6, i64 40}
!18 = !{!10, !11, i64 48}
!19 = !{!10, !6, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!23, !11, i64 48}
!23 = !{!"BUFFER", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !11, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !7, i64 56, !7, i64 184}
!24 = !{!23, !6, i64 8}
!25 = !{!23, !11, i64 16}
!26 = !{!23, !6, i64 24}
!27 = !{!23, !11, i64 32}
!28 = !{!23, !6, i64 0}
!29 = distinct !{!29, !21}
!30 = !{!13, !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"

@wheadp = external local_unnamed_addr global ptr, align 8
@bheadp = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @lfree(ptr noundef %0) local_unnamed_addr #0 {
  %.037 = load ptr, ptr @wheadp, align 8, !tbaa !5
  %.not38 = icmp eq ptr %.037, null
  br i1 %.not38, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %21, %1
  %.03440 = load ptr, ptr @bheadp, align 8, !tbaa !5
  %.not3641 = icmp eq ptr %.03440, null
  br i1 %.not3641, label %._crit_edge, label %.lr.ph43

.lr.ph:                                           ; preds = %1, %21
  %.039 = phi ptr [ %.0, %21 ], [ %.037, %1 ]
  %2 = getelementptr inbounds i8, ptr %.039, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !9
  %4 = icmp eq ptr %3, %0
  br i1 %4, label %5, label %7

5:                                                ; preds = %.lr.ph
  %6 = load ptr, ptr %0, align 8, !tbaa !12
  store ptr %6, ptr %2, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %5, %.lr.ph
  %8 = getelementptr inbounds i8, ptr %.039, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = icmp eq ptr %9, %0
  br i1 %10, label %11, label %14

11:                                               ; preds = %7
  %12 = load ptr, ptr %0, align 8, !tbaa !12
  store ptr %12, ptr %8, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %.039, i64 32
  store i32 0, ptr %13, align 8, !tbaa !16
  br label %14

14:                                               ; preds = %11, %7
  %15 = getelementptr inbounds i8, ptr %.039, i64 40
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  %17 = icmp eq ptr %16, %0
  br i1 %17, label %18, label %21

18:                                               ; preds = %14
  %19 = load ptr, ptr %0, align 8, !tbaa !12
  store ptr %19, ptr %15, align 8, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %.039, i64 48
  store i32 0, ptr %20, align 8, !tbaa !18
  br label %21

21:                                               ; preds = %18, %14
  %.0 = load ptr, ptr %.039, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !19

.lr.ph43:                                         ; preds = %.preheader, %39
  %.03442 = phi ptr [ %.034, %39 ], [ %.03440, %.preheader ]
  %22 = getelementptr inbounds i8, ptr %.03442, i64 48
  %23 = load i32, ptr %22, align 8, !tbaa !21
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %39

25:                                               ; preds = %.lr.ph43
  %26 = getelementptr inbounds i8, ptr %.03442, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !23
  %28 = icmp eq ptr %27, %0
  br i1 %28, label %29, label %32

29:                                               ; preds = %25
  %30 = load ptr, ptr %0, align 8, !tbaa !12
  store ptr %30, ptr %26, align 8, !tbaa !23
  %31 = getelementptr inbounds i8, ptr %.03442, i64 16
  store i32 0, ptr %31, align 8, !tbaa !24
  br label %32

32:                                               ; preds = %29, %25
  %33 = getelementptr inbounds i8, ptr %.03442, i64 24
  %34 = load ptr, ptr %33, align 8, !tbaa !25
  %35 = icmp eq ptr %34, %0
  br i1 %35, label %36, label %39

36:                                               ; preds = %32
  %37 = load ptr, ptr %0, align 8, !tbaa !12
  store ptr %37, ptr %33, align 8, !tbaa !25
  %38 = getelementptr inbounds i8, ptr %.03442, i64 32
  store i32 0, ptr %38, align 8, !tbaa !26
  br label %39

39:                                               ; preds = %32, %36, %.lr.ph43
  %.034 = load ptr, ptr %.03442, align 8, !tbaa !5
  %.not36 = icmp eq ptr %.034, null
  br i1 %.not36, label %._crit_edge, label %.lr.ph43, !llvm.loop !27

._crit_edge:                                      ; preds = %39, %.preheader
  %40 = load ptr, ptr %0, align 8, !tbaa !12
  %41 = getelementptr inbounds i8, ptr %0, i64 8
  %42 = load ptr, ptr %41, align 8, !tbaa !28
  store ptr %40, ptr %42, align 8, !tbaa !12
  %43 = getelementptr inbounds i8, ptr %40, i64 8
  store ptr %42, ptr %43, align 8, !tbaa !28
  tail call void @free(ptr noundef %0) #2
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #2 = { 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, !6, i64 16}
!10 = !{!"WINDOW", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"LINE", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 18, !7, i64 20}
!14 = !{!"short", !7, i64 0}
!15 = !{!10, !6, i64 24}
!16 = !{!10, !11, i64 32}
!17 = !{!10, !6, i64 40}
!18 = !{!10, !11, i64 48}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!22, !11, i64 48}
!22 = !{!"BUFFER", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !11, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !7, i64 56, !7, i64 184}
!23 = !{!22, !6, i64 8}
!24 = !{!22, !11, i64 16}
!25 = !{!22, !6, i64 24}
!26 = !{!22, !11, i64 32}
!27 = distinct !{!27, !20}
!28 = !{!13, !6, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass