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

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

@curbp = external global ptr, align 8
@wheadp = external global ptr, align 8
@.str.24 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @cpyfname(ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @choosefile(ptr noundef, ptr noundef, i32 noundef) #0

declare i32 @ctrlg(...) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @filename(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca [128 x i8], align 16
  %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) #3
  call void @llvm.lifetime.start.p0(i64 128, ptr %7) #3
  %9 = getelementptr inbounds [128 x i8], ptr %7, i64 0, i64 0
  %10 = call i32 @choosefile(ptr noundef @.str.24, ptr noundef %9, i32 noundef 1)
  %11 = icmp ne i32 %10, 1
  br i1 %11, label %12, label %14

12:                                               ; preds = %2
  %13 = call i32 (...) @ctrlg()
  store i32 %13, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %43

14:                                               ; preds = %2
  %15 = load ptr, ptr @curbp, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.BUFFER, ptr %15, i32 0, i32 8
  %17 = getelementptr inbounds [128 x i8], ptr %16, i64 0, i64 0
  %18 = getelementptr inbounds [128 x i8], ptr %7, i64 0, i64 0
  call void @cpyfname(ptr noundef %17, ptr noundef %18)
  %19 = load ptr, ptr @curbp, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.BUFFER, ptr %19, i32 0, i32 7
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = or i32 %21, 4
  store i32 %22, ptr %20, align 4, !tbaa !11
  %23 = load ptr, ptr @wheadp, align 8, !tbaa !9
  store ptr %23, ptr %6, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %38, %14
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %42

27:                                               ; preds = %24
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.WINDOW, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = load ptr, ptr @curbp, align 8, !tbaa !9
  %32 = icmp eq ptr %30, %31
  br i1 %32, label %33, label %38

33:                                               ; preds = %27
  %34 = load ptr, ptr %6, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.WINDOW, ptr %34, i32 0, i32 11
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = or i32 %36, 16
  store i32 %37, ptr %35, align 4, !tbaa !15
  br label %38

38:                                               ; preds = %33, %27
  %39 = load ptr, ptr %6, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.WINDOW, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  store ptr %41, ptr %6, align 8, !tbaa !9
  br label %24, !llvm.loop !17

42:                                               ; preds = %24
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %43

43:                                               ; preds = %42, %12
  call void @llvm.lifetime.end.p0(i64 128, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %44 = load i32, ptr %3, align 4
  ret i32 %44
}

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 = { "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, !6, i64 52}
!12 = !{!"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}
!13 = !{!14, !10, i64 8}
!14 = !{!"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}
!15 = !{!14, !6, i64 68}
!16 = !{!14, !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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
@wheadp = external local_unnamed_addr global ptr, align 8
@.str.24 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @cpyfname(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @choosefile(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @ctrlg(...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @filename(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [128 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %3) #3
  %4 = call i32 @choosefile(ptr noundef nonnull @.str.24, ptr noundef nonnull %3, i32 noundef 1)
  %.not = icmp eq i32 %4, 1
  br i1 %.not, label %7, label %5

5:                                                ; preds = %2
  %6 = call i32 (...) @ctrlg() #3
  br label %.loopexit

7:                                                ; preds = %2
  %8 = load ptr, ptr @curbp, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 56
  call void @cpyfname(ptr noundef nonnull %9, ptr noundef nonnull %3)
  %10 = load ptr, ptr @curbp, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 52
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = or i32 %12, 4
  store i32 %13, ptr %11, align 4, !tbaa !9
  %.06 = load ptr, ptr @wheadp, align 8, !tbaa !5
  %.not57 = icmp eq ptr %.06, null
  br i1 %.not57, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %7, %21
  %.08 = phi ptr [ %.0, %21 ], [ %.06, %7 ]
  %14 = getelementptr inbounds i8, ptr %.08, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = icmp eq ptr %15, %10
  br i1 %16, label %17, label %21

17:                                               ; preds = %.lr.ph
  %18 = getelementptr inbounds i8, ptr %.08, i64 68
  %19 = load i32, ptr %18, align 4, !tbaa !14
  %20 = or i32 %19, 16
  store i32 %20, ptr %18, align 4, !tbaa !14
  br label %21

21:                                               ; preds = %17, %.lr.ph
  %.0 = load ptr, ptr %.08, align 8, !tbaa !5
  %.not5 = icmp eq ptr %.0, null
  br i1 %.not5, label %.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %21, %7, %5
  %.04 = phi i32 [ %6, %5 ], [ 1, %7 ], [ 1, %21 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %3) #3
  ret i32 %.04
}

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 52}
!10 = !{!"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}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"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}
!14 = !{!13, !11, i64 68}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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