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

; 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.TERM = type { i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@term = external global %struct.TERM, 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
define dso_local i32 @mlputc(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %6 = load ptr, ptr getelementptr inbounds (%struct.TERM, ptr @term, i32 0, i32 5), align 8, !tbaa !9
  store ptr %6, ptr %5, align 8, !tbaa !12
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = and i32 %7, 255
  store i32 %8, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %9, ptr %3, align 4, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 10
  br i1 %11, label %12, label %15

12:                                               ; preds = %1
  %13 = load ptr, ptr %5, align 8, !tbaa !12
  %14 = call i32 (i32, ...) %13(i32 noundef 60)
  store i32 60, ptr %3, align 4, !tbaa !5
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %51

15:                                               ; preds = %1
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = icmp eq i32 %16, 9
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = load ptr, ptr %5, align 8, !tbaa !12
  %20 = call i32 (i32, ...) %19(i32 noundef 62)
  store i32 62, ptr %3, align 4, !tbaa !5
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %50

21:                                               ; preds = %15
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = icmp eq i32 %22, 13
  br i1 %23, label %24, label %27

24:                                               ; preds = %21
  %25 = load ptr, ptr %5, align 8, !tbaa !12
  %26 = call i32 (i32, ...) %25(i32 noundef 95)
  store i32 95, ptr %3, align 4, !tbaa !5
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %49

27:                                               ; preds = %21
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 31
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  store i32 46, ptr %3, align 4, !tbaa !5
  br label %48

31:                                               ; preds = %27
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = icmp eq i32 %32, 255
  br i1 %33, label %34, label %35

34:                                               ; preds = %31
  store i32 33, ptr %3, align 4, !tbaa !5
  br label %47

35:                                               ; preds = %31
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = icmp slt i32 %36, 32
  br i1 %37, label %41, label %38

38:                                               ; preds = %35
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 127
  br i1 %40, label %41, label %46

41:                                               ; preds = %38, %35
  %42 = load ptr, ptr %5, align 8, !tbaa !12
  %43 = call i32 (i32, ...) %42(i32 noundef 94)
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = xor i32 %44, 64
  store i32 %45, ptr %3, align 4, !tbaa !5
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %41, %38
  br label %47

47:                                               ; preds = %46, %34
  br label %48

48:                                               ; preds = %47, %30
  br label %49

49:                                               ; preds = %48, %24
  br label %50

50:                                               ; preds = %49, %18
  br label %51

51:                                               ; preds = %50, %12
  %52 = load ptr, ptr %5, align 8, !tbaa !12
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = call i32 (i32, ...) %52(i32 noundef %53)
  %55 = load i32, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %55
}

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, !11, i64 32}
!10 = !{!"", !6, i64 0, !6, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, 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"

%struct.TERM = type { i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@term = external local_unnamed_addr global %struct.TERM, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @mlputc(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr getelementptr inbounds (i8, ptr @term, i64 32), align 8, !tbaa !5
  %3 = and i32 %0, 255
  %trunc = trunc i32 %0 to i8
  switch i8 %trunc, label %11 [
    i8 10, label %4
    i8 9, label %6
    i8 13, label %8
    i8 31, label %17
    i8 -1, label %10
  ]

4:                                                ; preds = %1
  %5 = tail call i32 (i32, ...) %2(i32 noundef 60) #1
  br label %17

6:                                                ; preds = %1
  %7 = tail call i32 (i32, ...) %2(i32 noundef 62) #1
  br label %17

8:                                                ; preds = %1
  %9 = tail call i32 (i32, ...) %2(i32 noundef 95) #1
  br label %17

10:                                               ; preds = %1
  br label %17

11:                                               ; preds = %1
  %12 = icmp ult i32 %3, 32
  %13 = icmp eq i32 %3, 127
  %or.cond = or i1 %12, %13
  br i1 %or.cond, label %14, label %17

14:                                               ; preds = %11
  %15 = tail call i32 (i32, ...) %2(i32 noundef 94) #1
  %16 = xor i32 %3, 64
  br label %17

17:                                               ; preds = %1, %6, %14, %11, %10, %8, %4
  %.017 = phi i32 [ 60, %4 ], [ 62, %6 ], [ 95, %8 ], [ 33, %10 ], [ %16, %14 ], [ %3, %11 ], [ 46, %1 ]
  %.0 = phi i32 [ 1, %4 ], [ 1, %6 ], [ 1, %8 ], [ 0, %10 ], [ 1, %14 ], [ 0, %11 ], [ 0, %1 ]
  %18 = tail call i32 (i32, ...) %2(i32 noundef %.017) #1
  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" }
attributes #1 = { 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, !10, i64 32}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}


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