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

; 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] }

@curbp = external global ptr, align 8
@curwp = 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 i32 @deblank(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %10 = load ptr, ptr @curwp, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.WINDOW, ptr %10, i32 0, i32 3
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  store ptr %12, ptr %6, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %30, %2
  %14 = load ptr, ptr %6, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.LINE, ptr %14, i32 0, i32 3
  %16 = load i16, ptr %15, align 2, !tbaa !13
  %17 = sext i16 %16 to i32
  %18 = and i32 65535, %17
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %28

20:                                               ; preds = %13
  %21 = load ptr, ptr %6, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.LINE, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  store ptr %23, ptr %7, align 8, !tbaa !9
  %24 = load ptr, ptr @curbp, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.BUFFER, ptr %24, i32 0, i32 5
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = icmp ne ptr %23, %26
  br label %28

28:                                               ; preds = %20, %13
  %29 = phi i1 [ false, %13 ], [ %27, %20 ]
  br i1 %29, label %30, label %32

30:                                               ; preds = %28
  %31 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %31, ptr %6, align 8, !tbaa !9
  br label %13, !llvm.loop !19

32:                                               ; preds = %28
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %33, ptr %7, align 8, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %51, %32
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.LINE, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !21
  store ptr %37, ptr %7, align 8, !tbaa !9
  %38 = load ptr, ptr @curbp, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.BUFFER, ptr %38, i32 0, i32 5
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = icmp ne ptr %37, %40
  br i1 %41, label %42, label %49

42:                                               ; preds = %34
  %43 = load ptr, ptr %7, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.LINE, ptr %43, i32 0, i32 3
  %45 = load i16, ptr %44, align 2, !tbaa !13
  %46 = sext i16 %45 to i32
  %47 = and i32 65535, %46
  %48 = icmp eq i32 %47, 0
  br label %49

49:                                               ; preds = %42, %34
  %50 = phi i1 [ false, %34 ], [ %48, %42 ]
  br i1 %50, label %51, label %54

51:                                               ; preds = %49
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %8, align 4, !tbaa !5
  br label %34, !llvm.loop !22

54:                                               ; preds = %49
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %54
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %68

58:                                               ; preds = %54
  %59 = load ptr, ptr %6, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.LINE, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !21
  %62 = load ptr, ptr @curwp, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.WINDOW, ptr %62, i32 0, i32 3
  store ptr %61, ptr %63, align 8, !tbaa !11
  %64 = load ptr, ptr @curwp, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.WINDOW, ptr %64, i32 0, i32 4
  store i32 0, ptr %65, align 8, !tbaa !23
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = call i32 @ldelete(i32 noundef %66, i32 noundef 1)
  store i32 %67, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %68

68:                                               ; preds = %58, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %69 = load i32, ptr %3, align 4
  ret i32 %69
}

declare i32 @ldelete(i32 noundef, i32 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 = { "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 = !{!"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, !10, i64 24}
!12 = !{!"WINDOW", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68}
!13 = !{!14, !15, i64 18}
!14 = !{!"LINE", !10, i64 0, !10, i64 8, !15, i64 16, !15, i64 18, !7, i64 20}
!15 = !{!"short", !7, i64 0}
!16 = !{!14, !10, i64 8}
!17 = !{!18, !10, i64 40}
!18 = !{!"BUFFER", !10, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !6, i64 52, !7, i64 56, !7, i64 184}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!14, !10, i64 0}
!22 = distinct !{!22, !20}
!23 = !{!12, !6, i64 32}


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

@curbp = external local_unnamed_addr global ptr, align 8
@curwp = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @deblank(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @curwp, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 24
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr @curbp, align 8
  %7 = getelementptr inbounds i8, ptr %6, i64 40
  %.pre.pre = load ptr, ptr %7, align 8, !tbaa !12
  br label %8

8:                                                ; preds = %12, %2
  %.013 = phi ptr [ %5, %2 ], [ %14, %12 ]
  %9 = getelementptr inbounds i8, ptr %.013, i64 18
  %10 = load i16, ptr %9, align 2, !tbaa !14
  %11 = icmp eq i16 %10, 0
  br i1 %11, label %12, label %.critedge

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %.013, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %.not = icmp eq ptr %14, %.pre.pre
  br i1 %.not, label %.critedge, label %8, !llvm.loop !18

.critedge:                                        ; preds = %8, %12
  %15 = load ptr, ptr %.013, align 8, !tbaa !20
  %.not1718 = icmp eq ptr %15, %.pre.pre
  br i1 %.not1718, label %.critedge2.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.critedge, %20
  %16 = phi ptr [ %22, %20 ], [ %15, %.critedge ]
  %.019 = phi i32 [ %21, %20 ], [ 0, %.critedge ]
  %17 = getelementptr inbounds i8, ptr %16, i64 18
  %18 = load i16, ptr %17, align 2, !tbaa !14
  %19 = icmp eq i16 %18, 0
  br i1 %19, label %20, label %.critedge2

20:                                               ; preds = %.lr.ph
  %21 = add nuw nsw i32 %.019, 1
  %22 = load ptr, ptr %16, align 8, !tbaa !20
  %.not17 = icmp eq ptr %22, %.pre.pre
  br i1 %.not17, label %.critedge2.thread23, label %.lr.ph, !llvm.loop !21

.critedge2:                                       ; preds = %.lr.ph
  %23 = icmp eq i32 %.019, 0
  br i1 %23, label %.critedge2.thread, label %.critedge2.thread23

.critedge2.thread23:                              ; preds = %20, %.critedge2
  %.0.lcssa25 = phi i32 [ %.019, %.critedge2 ], [ %21, %20 ]
  store ptr %15, ptr %4, align 8, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %3, i64 32
  store i32 0, ptr %24, align 8, !tbaa !22
  %25 = tail call i32 @ldelete(i32 noundef %.0.lcssa25, i32 noundef 1) #2
  br label %.critedge2.thread

.critedge2.thread:                                ; preds = %.critedge, %.critedge2, %.critedge2.thread23
  %.014 = phi i32 [ %25, %.critedge2.thread23 ], [ 1, %.critedge2 ], [ 1, %.critedge ]
  ret i32 %.014
}

declare i32 @ldelete(i32 noundef, i32 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 = { "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 24}
!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 40}
!13 = !{!"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}
!14 = !{!15, !16, i64 18}
!15 = !{!"LINE", !6, i64 0, !6, i64 8, !16, i64 16, !16, i64 18, !7, i64 20}
!16 = !{!"short", !7, i64 0}
!17 = !{!15, !6, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!15, !6, i64 0}
!21 = distinct !{!21, !19}
!22 = !{!10, !11, i64 32}


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