; 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.BUFFER = type { ptr, ptr, i32, ptr, i32, ptr, i32, i32, [128 x i8], [128 x i8] }
%struct.LINE = type { ptr, ptr, i16, i16, [32768 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
declare dso_local void @lchange(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ltwiddle(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
  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) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %9 = load ptr, ptr @curwp, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.WINDOW, ptr %9, i32 0, i32 3
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %6, align 8, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !9
  %13 = load ptr, ptr @curbp, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.BUFFER, ptr %13, i32 0, i32 5
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = icmp eq ptr %12, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %56

18:                                               ; preds = %2
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %19, ptr %7, align 8, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.LINE, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  store ptr %22, ptr %6, align 8, !tbaa !9
  %23 = load ptr, ptr %6, 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 !13
  %27 = icmp eq ptr %23, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %18
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %56

29:                                               ; preds = %18
  %30 = load ptr, ptr %7, align 8, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.LINE, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = getelementptr inbounds %struct.LINE, ptr %33, i32 0, i32 0
  store ptr %30, ptr %34, align 8, !tbaa !18
  %35 = load ptr, ptr %6, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.LINE, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = load ptr, ptr %7, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.LINE, ptr %38, i32 0, i32 1
  store ptr %37, ptr %39, align 8, !tbaa !15
  %40 = load ptr, ptr %7, align 8, !tbaa !9
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.LINE, ptr %41, i32 0, i32 1
  store ptr %40, ptr %42, align 8, !tbaa !15
  %43 = load ptr, ptr %7, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.LINE, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !18
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.LINE, ptr %46, i32 0, i32 0
  store ptr %45, ptr %47, align 8, !tbaa !18
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  %49 = load ptr, ptr %7, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.LINE, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  %52 = getelementptr inbounds %struct.LINE, ptr %51, i32 0, i32 1
  store ptr %48, ptr %52, align 8, !tbaa !15
  %53 = load ptr, ptr %6, align 8, !tbaa !9
  %54 = load ptr, ptr %7, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.LINE, ptr %54, i32 0, i32 0
  store ptr %53, ptr %55, align 8, !tbaa !18
  call void @lchange(i32 noundef 8)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %56

56:                                               ; preds = %29, %28, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %57 = load i32, ptr %3, align 4
  ret i32 %57
}

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 }

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


; 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
declare dso_local void @lchange(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ltwiddle(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, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = icmp eq ptr %5, %8
  br i1 %9, label %19, label %10

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %5, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = icmp eq ptr %12, %8
  br i1 %13, label %19, label %14

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %12, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  store ptr %5, ptr %16, align 8, !tbaa !17
  store ptr %16, ptr %11, align 8, !tbaa !14
  store ptr %5, ptr %15, align 8, !tbaa !14
  %17 = load ptr, ptr %5, align 8, !tbaa !17
  store ptr %17, ptr %12, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  store ptr %12, ptr %18, align 8, !tbaa !14
  store ptr %12, ptr %5, align 8, !tbaa !17
  tail call void @lchange(i32 noundef 8)
  br label %19

19:                                               ; preds = %10, %2, %14
  %.0 = phi i32 [ 1, %14 ], [ 0, %2 ], [ 0, %10 ]
  ret i32 %.0
}

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

!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, !6, i64 8}
!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 0}


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