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

@curbp = external global ptr, align 8
@ffp = external hidden global ptr, align 8
@foreignformat = external hidden global i32, align 4
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1
@longline = external hidden global i32, align 4
@.str.4 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [32 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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @ffgetline(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr %5, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %65, %2
  %13 = load ptr, ptr @ffp, align 8, !tbaa !5
  %14 = call i32 @getc(ptr noundef %13)
  store i32 %14, ptr %6, align 4, !tbaa !9
  %15 = icmp ne i32 %14, -1
  br i1 %15, label %16, label %66

16:                                               ; preds = %12
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 10
  br i1 %18, label %19, label %28

19:                                               ; preds = %16
  %20 = load ptr, ptr @ffp, align 8, !tbaa !5
  %21 = call i32 @getc(ptr noundef %20)
  store i32 %21, ptr %8, align 4, !tbaa !9
  %22 = icmp ne i32 %21, 13
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = load ptr, ptr @ffp, align 8, !tbaa !5
  %26 = call i32 @ungetc(i32 noundef %24, ptr noundef %25)
  br label %27

27:                                               ; preds = %23, %19
  br label %66

28:                                               ; preds = %16
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 13
  br i1 %30, label %31, label %44

31:                                               ; preds = %28
  %32 = load ptr, ptr @ffp, align 8, !tbaa !5
  %33 = call i32 @getc(ptr noundef %32)
  store i32 %33, ptr %8, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 10
  br i1 %34, label %35, label %39

35:                                               ; preds = %31
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = load ptr, ptr @ffp, align 8, !tbaa !5
  %38 = call i32 @ungetc(i32 noundef %36, ptr noundef %37)
  br label %39

39:                                               ; preds = %35, %31
  store i32 10, ptr %6, align 4, !tbaa !9
  %40 = load i32, ptr @foreignformat, align 4, !tbaa !9
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %43, label %42

42:                                               ; preds = %39
  call void (ptr, ...) @mlwrite(ptr noundef @.str.3)
  store i32 1, ptr @foreignformat, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %42, %39
  br label %66

44:                                               ; preds = %28
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = trunc i32 %45 to i8
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %7, align 4, !tbaa !9
  %50 = sext i32 %48 to i64
  %51 = getelementptr inbounds i8, ptr %47, i64 %50
  store i8 %46, ptr %51, align 1, !tbaa !11
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = icmp sge i32 %52, %53
  br i1 %54, label %55, label %65

55:                                               ; preds = %44
  %56 = load i32, ptr @longline, align 4, !tbaa !9
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %64, label %58

58:                                               ; preds = %55
  %59 = call i32 @mlyesno(ptr noundef @.str.4)
  store i32 %59, ptr %8, align 4, !tbaa !9
  call void (...) @mlerase()
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %63, label %62

62:                                               ; preds = %58
  store i32 3, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %113

63:                                               ; preds = %58
  call void (ptr, ...) @mlwrite(ptr noundef @.str.5)
  br label %64

64:                                               ; preds = %63, %55
  br label %66

65:                                               ; preds = %44
  br label %12, !llvm.loop !12

66:                                               ; preds = %64, %43, %27, %12
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %67, i64 %69
  store i8 0, ptr %70, align 1, !tbaa !11
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = icmp eq i32 %71, -1
  br i1 %72, label %73, label %112

73:                                               ; preds = %66
  %74 = load ptr, ptr @ffp, align 8, !tbaa !5
  %75 = call i32 @ferror(ptr noundef %74) #4
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %77, label %78

77:                                               ; preds = %73
  call void (ptr, ...) @mlwrite(ptr noundef @.str.6)
  store i32 3, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %113

78:                                               ; preds = %73
  %79 = load i32, ptr %7, align 4, !tbaa !9
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %111

81:                                               ; preds = %78
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = icmp eq i32 %82, 1
  br i1 %83, label %84, label %100

84:                                               ; preds = %81
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds i8, ptr %85, i64 0
  %87 = load i8, ptr %86, align 1, !tbaa !11
  %88 = sext i8 %87 to i32
  %89 = icmp eq i32 %88, 26
  br i1 %89, label %90, label %100

90:                                               ; preds = %84
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = load i32, ptr %7, align 4, !tbaa !9
  %93 = add nsw i32 %92, -1
  store i32 %93, ptr %7, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds i8, ptr %91, i64 %94
  store i8 0, ptr %95, align 1, !tbaa !11
  %96 = load i32, ptr @foreignformat, align 4, !tbaa !9
  %97 = icmp ne i32 %96, 0
  br i1 %97, label %99, label %98

98:                                               ; preds = %90
  call void (ptr, ...) @mlwrite(ptr noundef @.str.7)
  br label %99

99:                                               ; preds = %98, %90
  br label %110

100:                                              ; preds = %84, %81
  %101 = load i32, ptr @foreignformat, align 4, !tbaa !9
  %102 = icmp ne i32 %101, 0
  br i1 %102, label %104, label %103

103:                                              ; preds = %100
  call void (ptr, ...) @mlwrite(ptr noundef @.str.8)
  br label %109

104:                                              ; preds = %100
  %105 = load ptr, ptr @curbp, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.BUFFER, ptr %105, i32 0, i32 7
  %107 = load i32, ptr %106, align 4, !tbaa !14
  %108 = or i32 %107, 16
  store i32 %108, ptr %106, align 4, !tbaa !14
  br label %109

109:                                              ; preds = %104, %103
  br label %110

110:                                              ; preds = %109, %99
  store i32 4, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %113

111:                                              ; preds = %78
  store i32 2, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %113

112:                                              ; preds = %66
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %113

113:                                              ; preds = %112, %111, %110, %77, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %114 = load i32, ptr %3, align 4
  ret i32 %114
}

declare i32 @getc(ptr noundef) #1

declare i32 @ungetc(i32 noundef, ptr noundef) #1

declare i32 @mlyesno(ptr noundef) #1

declare void @mlerase(...) #1

; Function Attrs: nounwind
declare i32 @ferror(ptr noundef) #3

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 "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 #4 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !10, i64 52}
!15 = !{!"BUFFER", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !7, i64 56, !7, i64 184}


; 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
@ffp = external hidden local_unnamed_addr global ptr, align 8
@foreignformat = external hidden local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1
@longline = external hidden local_unnamed_addr global i32, align 4
@.str.4 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [32 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 5) i32 @ffgetline(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = add i32 %1, -1
  %smax = tail call i32 @llvm.smax.i32(i32 %3, i32 1)
  %wide.trip.count = zext nneg i32 %smax to i64
  br label %4

4:                                                ; preds = %24, %2
  %indvars.iv = phi i64 [ %indvars.iv.next, %24 ], [ 0, %2 ]
  %5 = load ptr, ptr @ffp, align 8, !tbaa !5
  %6 = tail call i32 @getc(ptr noundef %5)
  switch i32 %6, label %24 [
    i32 -1, label %34
    i32 10, label %7
    i32 13, label %14
  ]

7:                                                ; preds = %4
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  %9 = load ptr, ptr @ffp, align 8, !tbaa !5
  %10 = tail call i32 @getc(ptr noundef %9)
  %.not32 = icmp eq i32 %10, 13
  br i1 %.not32, label %.thread, label %11

11:                                               ; preds = %7
  %12 = load ptr, ptr @ffp, align 8, !tbaa !5
  %13 = tail call i32 @ungetc(i32 noundef %10, ptr noundef %12)
  br label %.thread

14:                                               ; preds = %4
  %15 = trunc nuw nsw i64 %indvars.iv to i32
  %16 = load ptr, ptr @ffp, align 8, !tbaa !5
  %17 = tail call i32 @getc(ptr noundef %16)
  %.not30 = icmp eq i32 %17, 10
  br i1 %.not30, label %21, label %18

18:                                               ; preds = %14
  %19 = load ptr, ptr @ffp, align 8, !tbaa !5
  %20 = tail call i32 @ungetc(i32 noundef %17, ptr noundef %19)
  br label %21

21:                                               ; preds = %18, %14
  %22 = load i32, ptr @foreignformat, align 4, !tbaa !9
  %.not31 = icmp eq i32 %22, 0
  br i1 %.not31, label %23, label %.thread

23:                                               ; preds = %21
  tail call void (ptr, ...) @mlwrite(ptr noundef nonnull @.str.3) #5
  store i32 1, ptr @foreignformat, align 4, !tbaa !9
  br label %.thread

24:                                               ; preds = %4
  %25 = trunc i32 %6 to i8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  store i8 %25, ptr %26, align 1, !tbaa !11
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %27, label %4, !llvm.loop !12

27:                                               ; preds = %24
  %28 = load i32, ptr @longline, align 4, !tbaa !9
  %.not28 = icmp eq i32 %28, 0
  br i1 %.not28, label %29, label %.thread

29:                                               ; preds = %27
  %30 = tail call i32 @mlyesno(ptr noundef nonnull @.str.4) #5
  tail call void (...) @mlerase() #5
  %.not29 = icmp eq i32 %30, 0
  br i1 %.not29, label %56, label %31

31:                                               ; preds = %29
  tail call void (ptr, ...) @mlwrite(ptr noundef nonnull @.str.5) #5
  br label %.thread

.thread:                                          ; preds = %11, %7, %21, %23, %27, %31
  %.1.ph = phi i32 [ %smax, %31 ], [ %smax, %27 ], [ %15, %23 ], [ %15, %21 ], [ %8, %7 ], [ %8, %11 ]
  %32 = sext i32 %.1.ph to i64
  %33 = getelementptr inbounds i8, ptr %0, i64 %32
  store i8 0, ptr %33, align 1, !tbaa !11
  br label %56

34:                                               ; preds = %4
  %35 = and i64 %indvars.iv, 4294967295
  %36 = getelementptr inbounds i8, ptr %0, i64 %35
  store i8 0, ptr %36, align 1, !tbaa !11
  %37 = load ptr, ptr @ffp, align 8, !tbaa !5
  %38 = tail call i32 @ferror(ptr noundef %37) #5
  %.not33 = icmp eq i32 %38, 0
  br i1 %.not33, label %40, label %39

39:                                               ; preds = %34
  tail call void (ptr, ...) @mlwrite(ptr noundef nonnull @.str.6) #5
  br label %56

40:                                               ; preds = %34
  %41 = trunc nuw nsw i64 %indvars.iv to i32
  switch i32 %41, label %48 [
    i32 0, label %56
    i32 1, label %42
  ]

42:                                               ; preds = %40
  %43 = load i8, ptr %0, align 1, !tbaa !11
  %44 = icmp eq i8 %43, 26
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  store i8 0, ptr %0, align 1, !tbaa !11
  %46 = load i32, ptr @foreignformat, align 4, !tbaa !9
  %.not36 = icmp eq i32 %46, 0
  br i1 %.not36, label %47, label %56

47:                                               ; preds = %45
  tail call void (ptr, ...) @mlwrite(ptr noundef nonnull @.str.7) #5
  br label %56

48:                                               ; preds = %40, %42
  %49 = load i32, ptr @foreignformat, align 4, !tbaa !9
  %.not35 = icmp eq i32 %49, 0
  br i1 %.not35, label %50, label %51

50:                                               ; preds = %48
  tail call void (ptr, ...) @mlwrite(ptr noundef nonnull @.str.8) #5
  br label %56

51:                                               ; preds = %48
  %52 = load ptr, ptr @curbp, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 52
  %54 = load i32, ptr %53, align 4, !tbaa !14
  %55 = or i32 %54, 16
  store i32 %55, ptr %53, align 4, !tbaa !14
  br label %56

56:                                               ; preds = %.thread, %40, %47, %45, %51, %50, %29, %39
  %.020 = phi i32 [ 3, %39 ], [ 3, %29 ], [ 4, %50 ], [ 4, %51 ], [ 4, %45 ], [ 4, %47 ], [ 2, %40 ], [ 0, %.thread ]
  ret i32 %.020
}

; Function Attrs: nofree nounwind
declare noundef i32 @getc(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @ungetc(i32 noundef, ptr nocapture noundef) local_unnamed_addr #2

declare i32 @mlyesno(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nofree nounwind memory(read)
declare noundef i32 @ferror(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

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 = { nofree nounwind "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 = { nofree nounwind memory(read) "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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !10, i64 52}
!15 = !{!"BUFFER", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !7, i64 56, !7, i64 184}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass