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

@curbp = external global ptr, align 8
@curwp = external global ptr, align 8
@.str.16 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [10 x i8], align 1

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

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

; 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 i32 @yank(i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @flush_kbuf(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = 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 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = call ptr (ptr, i32, i32, ...) @bfind(ptr noundef @.str.16, i32 noundef 1, i32 noundef 7)
  store ptr %12, ptr %8, align 8, !tbaa !9
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %37

15:                                               ; preds = %2
  %16 = load ptr, ptr @curwp, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.WINDOW, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  store ptr %18, ptr %10, align 8, !tbaa !9
  %19 = load ptr, ptr @curwp, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.WINDOW, ptr %19, i32 0, i32 11
  %21 = load i32, ptr %20, align 4, !tbaa !13
  store i32 %21, ptr %7, align 4, !tbaa !5
  %22 = load ptr, ptr @curbp, align 8, !tbaa !9
  store ptr %22, ptr %9, align 8, !tbaa !9
  %23 = load ptr, ptr %8, align 8, !tbaa !9
  call void @gotobuf(ptr noundef %23)
  %24 = call i32 @yank(i32 noundef 0, i32 noundef 1)
  store i32 %24, ptr %6, align 4, !tbaa !5
  %25 = load ptr, ptr %9, align 8, !tbaa !9
  call void @gotobuf(ptr noundef %25)
  %26 = load ptr, ptr %10, align 8, !tbaa !9
  %27 = load ptr, ptr @curwp, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.WINDOW, ptr %27, i32 0, i32 2
  store ptr %26, ptr %28, align 8, !tbaa !11
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = load ptr, ptr @curwp, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.WINDOW, ptr %30, i32 0, i32 11
  store i32 %29, ptr %31, align 4, !tbaa !13
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %34, label %35

34:                                               ; preds = %15
  call void (...) @kdelete()
  call void (ptr, ...) @mlwrite(ptr noundef @.str.17)
  br label %35

35:                                               ; preds = %34, %15
  %36 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %36, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %37

37:                                               ; preds = %35, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %38 = load i32, ptr %3, align 4
  ret i32 %38
}

declare ptr @bfind(...) #1

declare void @gotobuf(ptr noundef) #1

declare void @kdelete(...) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 16}
!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 = !{!12, !6, i64 68}


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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @yank(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @flush_kbuf(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = tail call ptr (ptr, i32, i32, ...) @bfind(ptr noundef nonnull @.str.16, i32 noundef 1, i32 noundef 7) #2
  %4 = icmp eq ptr %3, null
  br i1 %4, label %18, label %5

5:                                                ; preds = %2
  %6 = load ptr, ptr @curwp, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %6, i64 68
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = load ptr, ptr @curbp, align 8, !tbaa !5
  tail call void @gotobuf(ptr noundef nonnull %3) #2
  %12 = tail call i32 @yank(i32 noundef 0, i32 noundef 1)
  tail call void @gotobuf(ptr noundef %11) #2
  %13 = load ptr, ptr @curwp, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %8, ptr %14, align 8, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %13, i64 68
  store i32 %10, ptr %15, align 4, !tbaa !12
  %16 = icmp eq i32 %12, 1
  br i1 %16, label %17, label %18

17:                                               ; preds = %5
  tail call void (...) @kdelete() #2
  tail call void (ptr, ...) @mlwrite(ptr noundef nonnull @.str.17) #2
  br label %18

18:                                               ; preds = %5, %17, %2
  %.0 = phi i32 [ 0, %2 ], [ 1, %17 ], [ %12, %5 ]
  ret i32 %.0
}

declare ptr @bfind(...) local_unnamed_addr #0

declare void @gotobuf(ptr noundef) local_unnamed_addr #0

declare void @kdelete(...) local_unnamed_addr #0

attributes #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 = { 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 = !{!"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 = !{!10, !11, i64 68}


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