; 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.LINE = type { ptr, ptr, i16, i16, [32768 x i8] }
%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.17 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.18 = 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 @mlyesno(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @fileread(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 i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [128 x i8], align 16
  %10 = 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 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 128, ptr %9) #3
  %11 = load ptr, ptr @curbp, align 8, !tbaa !9
  store ptr %11, ptr %6, align 8, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.BUFFER, ptr %12, i32 0, i32 5
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.LINE, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = load ptr, ptr %6, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.BUFFER, ptr %17, i32 0, i32 5
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = icmp ne ptr %16, %19
  br i1 %20, label %21, label %38

21:                                               ; preds = %2
  %22 = call i32 @mlyesno(ptr noundef @.str.17)
  store i32 %22, ptr %8, align 4, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = icmp eq i32 %23, 2
  br i1 %24, label %25, label %27

25:                                               ; preds = %21
  %26 = call i32 (...) @ctrlg()
  store i32 %26, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %83

27:                                               ; preds = %21
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = icmp ne i32 %28, 1
  br i1 %29, label %30, label %37

30:                                               ; preds = %27
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  %32 = call i32 @bclear(ptr noundef %31)
  store i32 %32, ptr %7, align 4, !tbaa !5
  %33 = icmp ne i32 %32, 1
  br i1 %33, label %34, label %36

34:                                               ; preds = %30
  %35 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %35, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %83

36:                                               ; preds = %30
  br label %37

37:                                               ; preds = %36, %27
  br label %39

38:                                               ; preds = %2
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %38, %37
  %40 = getelementptr inbounds [128 x i8], ptr %9, i64 0, i64 0
  %41 = call i32 @choosefile(ptr noundef @.str.18, ptr noundef %40, i32 noundef 1)
  %42 = icmp ne i32 %41, 1
  br i1 %42, label %43, label %52

43:                                               ; preds = %39
  %44 = load ptr, ptr %6, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.BUFFER, ptr %44, i32 0, i32 8
  %46 = getelementptr inbounds [128 x i8], ptr %45, i64 0, i64 0
  store i8 0, ptr %46, align 8, !tbaa !16
  %47 = load ptr, ptr @curwp, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.WINDOW, ptr %47, i32 0, i32 11
  %49 = load i32, ptr %48, align 4, !tbaa !17
  %50 = or i32 %49, 16
  store i32 %50, ptr %48, align 4, !tbaa !17
  %51 = call i32 (...) @ctrlg()
  store i32 %51, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %83

52:                                               ; preds = %39
  %53 = getelementptr inbounds [128 x i8], ptr %9, i64 0, i64 0
  %54 = call i32 @readin(ptr noundef %53)
  store i32 %54, ptr %7, align 4, !tbaa !5
  %55 = icmp ne i32 %54, 2
  br i1 %55, label %56, label %57

56:                                               ; preds = %52
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %83

57:                                               ; preds = %52
  %58 = load ptr, ptr %6, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.BUFFER, ptr %58, i32 0, i32 7
  %60 = load i32, ptr %59, align 4, !tbaa !19
  %61 = and i32 %60, -2
  store i32 %61, ptr %59, align 4, !tbaa !19
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %69

64:                                               ; preds = %57
  %65 = load ptr, ptr %6, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.BUFFER, ptr %65, i32 0, i32 7
  %67 = load i32, ptr %66, align 4, !tbaa !19
  %68 = or i32 %67, 2
  store i32 %68, ptr %66, align 4, !tbaa !19
  br label %78

69:                                               ; preds = %57
  %70 = load ptr, ptr %6, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.BUFFER, ptr %70, i32 0, i32 8
  %72 = getelementptr inbounds [128 x i8], ptr %71, i64 0, i64 0
  %73 = getelementptr inbounds [128 x i8], ptr %9, i64 0, i64 0
  call void @cpyfname(ptr noundef %72, ptr noundef %73)
  %74 = load ptr, ptr %6, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.BUFFER, ptr %74, i32 0, i32 7
  %76 = load i32, ptr %75, align 4, !tbaa !19
  %77 = and i32 %76, -3
  store i32 %77, ptr %75, align 4, !tbaa !19
  br label %78

78:                                               ; preds = %69, %64
  %79 = load ptr, ptr %6, align 8, !tbaa !9
  %80 = getelementptr inbounds %struct.BUFFER, ptr %79, i32 0, i32 7
  %81 = load i32, ptr %80, align 4, !tbaa !19
  %82 = or i32 %81, 4
  store i32 %82, ptr %80, align 4, !tbaa !19
  store i32 1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %83

83:                                               ; preds = %78, %56, %43, %34, %25
  call void @llvm.lifetime.end.p0(i64 128, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %84 = load i32, ptr %3, align 4
  ret i32 %84
}

declare i32 @ctrlg(...) #2

declare i32 @bclear(ptr noundef) #2

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


; 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.17 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.18 = 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 @mlyesno(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @fileread(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 = load ptr, ptr @curbp, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 40
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %.not = icmp eq ptr %7, %6
  br i1 %.not, label %14, label %8

8:                                                ; preds = %2
  %9 = tail call i32 @mlyesno(ptr noundef nonnull @.str.17) #3
  switch i32 %9, label %12 [
    i32 2, label %10
    i32 1, label %14
  ]

10:                                               ; preds = %8
  %11 = tail call i32 (...) @ctrlg() #3
  br label %37

12:                                               ; preds = %8
  %13 = tail call i32 @bclear(ptr noundef nonnull %4) #3
  %.not17 = icmp eq i32 %13, 1
  br i1 %.not17, label %14, label %37

14:                                               ; preds = %2, %8, %12
  %.0 = phi i32 [ %9, %12 ], [ %9, %8 ], [ 0, %2 ]
  %15 = call i32 @choosefile(ptr noundef nonnull @.str.18, ptr noundef nonnull %3, i32 noundef 1)
  %.not18 = icmp eq i32 %15, 1
  br i1 %.not18, label %23, label %16

16:                                               ; preds = %14
  %17 = getelementptr inbounds i8, ptr %4, i64 56
  store i8 0, ptr %17, align 8, !tbaa !15
  %18 = load ptr, ptr @curwp, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 68
  %20 = load i32, ptr %19, align 4, !tbaa !16
  %21 = or i32 %20, 16
  store i32 %21, ptr %19, align 4, !tbaa !16
  %22 = call i32 (...) @ctrlg() #3
  br label %37

23:                                               ; preds = %14
  %24 = call i32 @readin(ptr noundef nonnull %3)
  %.not19 = icmp eq i32 %24, 2
  br i1 %.not19, label %25, label %37

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %4, i64 52
  %27 = load i32, ptr %26, align 4, !tbaa !18
  %28 = and i32 %27, -2
  store i32 %28, ptr %26, align 4, !tbaa !18
  %.not20 = icmp eq i32 %.0, 0
  br i1 %.not20, label %31, label %29

29:                                               ; preds = %25
  %30 = or i32 %28, 2
  br label %35

31:                                               ; preds = %25
  %32 = getelementptr inbounds i8, ptr %4, i64 56
  call void @cpyfname(ptr noundef nonnull %32, ptr noundef nonnull %3)
  %33 = load i32, ptr %26, align 4, !tbaa !18
  %34 = and i32 %33, -3
  br label %35

35:                                               ; preds = %31, %29
  %storemerge = phi i32 [ %34, %31 ], [ %30, %29 ]
  %36 = or i32 %storemerge, 4
  store i32 %36, ptr %26, align 4, !tbaa !18
  br label %37

37:                                               ; preds = %23, %12, %35, %16, %10
  %.013 = phi i32 [ %11, %10 ], [ %22, %16 ], [ 1, %35 ], [ %13, %12 ], [ 0, %23 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %3) #3
  ret i32 %.013
}

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

declare i32 @bclear(ptr noundef) local_unnamed_addr #2

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


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