; 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.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.10 = external hidden unnamed_addr constant [36 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
define dso_local i32 @showcpos(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %13 = load ptr, ptr @curbp, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.BUFFER, ptr %13, i32 0, i32 5
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct.LINE, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  store ptr %17, ptr %5, align 8, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !5
  store i64 0, ptr %7, align 8, !tbaa !16
  store i64 -1, ptr %8, align 8, !tbaa !16
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %63, %2
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = load ptr, ptr @curbp, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.BUFFER, ptr %20, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = icmp ne ptr %19, %22
  br i1 %23, label %24, label %72

24:                                               ; preds = %18
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.LINE, ptr %25, i32 0, i32 3
  %27 = load i16, ptr %26, align 2, !tbaa !18
  %28 = sext i16 %27 to i32
  %29 = and i32 65535, %28
  store i32 %29, ptr %6, align 4, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = load ptr, ptr @curwp, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.WINDOW, ptr %31, i32 0, i32 3
  %33 = load ptr, ptr %32, align 8, !tbaa !19
  %34 = icmp eq ptr %30, %33
  br i1 %34, label %35, label %57

35:                                               ; preds = %24
  %36 = load ptr, ptr @curwp, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.WINDOW, ptr %36, i32 0, i32 4
  %38 = load i32, ptr %37, align 8, !tbaa !21
  store i32 %38, ptr %10, align 4, !tbaa !5
  %39 = load i64, ptr %7, align 8, !tbaa !16
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = add nsw i64 %39, %41
  store i64 %42, ptr %8, align 8, !tbaa !16
  %43 = load i32, ptr %10, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = icmp eq i32 %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %35
  store i32 10, ptr %10, align 4, !tbaa !5
  br label %56

47:                                               ; preds = %35
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.LINE, ptr %48, i32 0, i32 4
  %50 = load i32, ptr %10, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [32768 x i8], ptr %49, i64 0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !22
  %54 = sext i8 %53 to i32
  %55 = and i32 %54, 255
  store i32 %55, ptr %10, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %47, %46
  br label %57

57:                                               ; preds = %56, %24
  %58 = load i64, ptr %8, align 8, !tbaa !16
  %59 = icmp slt i64 %58, 0
  br i1 %59, label %60, label %63

60:                                               ; preds = %57
  %61 = load i32, ptr %9, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %9, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %60, %57
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = load i64, ptr %7, align 8, !tbaa !16
  %68 = add nsw i64 %67, %66
  store i64 %68, ptr %7, align 8, !tbaa !16
  %69 = load ptr, ptr %5, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.LINE, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !13
  store ptr %71, ptr %5, align 8, !tbaa !9
  br label %18, !llvm.loop !23

72:                                               ; preds = %18
  %73 = load i64, ptr %8, align 8, !tbaa !16
  %74 = icmp slt i64 %73, 0
  br i1 %74, label %75, label %77

75:                                               ; preds = %72
  %76 = load i64, ptr %7, align 8, !tbaa !16
  store i64 %76, ptr %8, align 8, !tbaa !16
  br label %77

77:                                               ; preds = %75, %72
  %78 = call i32 @getccol(i32 noundef 0)
  store i32 %78, ptr %12, align 4, !tbaa !5
  store i32 0, ptr %11, align 4, !tbaa !5
  %79 = load i64, ptr %7, align 8, !tbaa !16
  %80 = icmp ne i64 %79, 0
  br i1 %80, label %81, label %87

81:                                               ; preds = %77
  %82 = load i64, ptr %8, align 8, !tbaa !16
  %83 = mul nsw i64 100, %82
  %84 = load i64, ptr %7, align 8, !tbaa !16
  %85 = sdiv i64 %83, %84
  %86 = trunc i64 %85 to i32
  store i32 %86, ptr %11, align 4, !tbaa !5
  br label %87

87:                                               ; preds = %81, %77
  %88 = load i32, ptr %12, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  %90 = load i32, ptr %9, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  %92 = load i32, ptr %10, align 4, !tbaa !5
  %93 = load i64, ptr %8, align 8, !tbaa !16
  %94 = load i32, ptr %11, align 4, !tbaa !5
  %95 = load i64, ptr %7, align 8, !tbaa !16
  call void (ptr, ...) @mlwrite(ptr noundef @.str.10, i32 noundef %89, i32 noundef %91, i32 noundef %92, i64 noundef %93, i32 noundef %94, i64 noundef %95)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i32 1
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @getccol(i32 noundef) #2

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 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 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!14, !15, i64 18}
!19 = !{!20, !10, i64 24}
!20 = !{!"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}
!21 = !{!20, !6, i64 32}
!22 = !{!7, !7, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"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
@curwp = external local_unnamed_addr global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [36 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @showcpos(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr @curbp, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 40
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %.033 = load ptr, ptr %5, align 8, !tbaa !12
  %.not34 = icmp eq ptr %.033, %5
  br i1 %.not34, label %36, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %6 = load ptr, ptr @curwp, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %6, i64 32
  br label %10

10:                                               ; preds = %.lr.ph, %25
  %.039 = phi ptr [ %.033, %.lr.ph ], [ %.0, %25 ]
  %.02538 = phi i32 [ 0, %.lr.ph ], [ %.1, %25 ]
  %.02637 = phi i32 [ 0, %.lr.ph ], [ %spec.select, %25 ]
  %.02836 = phi i64 [ -1, %.lr.ph ], [ %.129.fr, %25 ]
  %.03035 = phi i64 [ 0, %.lr.ph ], [ %29, %25 ]
  %11 = getelementptr inbounds i8, ptr %.039, i64 18
  %12 = load i16, ptr %11, align 2, !tbaa !17
  %13 = zext i16 %12 to i32
  %14 = icmp eq ptr %.039, %8
  br i1 %14, label %15, label %25

15:                                               ; preds = %10
  %16 = load i32, ptr %9, align 8, !tbaa !18
  %17 = sext i32 %16 to i64
  %18 = add nsw i64 %.03035, %17
  %19 = icmp eq i32 %16, %13
  br i1 %19, label %25, label %20

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %.039, i64 20
  %22 = getelementptr inbounds [32768 x i8], ptr %21, i64 0, i64 %17
  %23 = load i8, ptr %22, align 1, !tbaa !19
  %24 = zext i8 %23 to i32
  br label %25

25:                                               ; preds = %15, %20, %10
  %.129 = phi i64 [ %18, %20 ], [ %.02836, %10 ], [ %18, %15 ]
  %.1 = phi i32 [ %24, %20 ], [ %.02538, %10 ], [ 10, %15 ]
  %.129.fr = freeze i64 %.129
  %.129.lobit = lshr i64 %.129.fr, 63
  %26 = trunc nuw nsw i64 %.129.lobit to i32
  %spec.select = add nuw nsw i32 %.02637, %26
  %27 = add nuw nsw i32 %13, 1
  %28 = zext nneg i32 %27 to i64
  %29 = add nuw nsw i64 %.03035, %28
  %.0 = load ptr, ptr %.039, align 8, !tbaa !12
  %.not = icmp eq ptr %.0, %5
  br i1 %.not, label %._crit_edge, label %10, !llvm.loop !20

._crit_edge:                                      ; preds = %25
  %30 = add nuw nsw i32 %spec.select, 1
  %31 = icmp slt i64 %.129.fr, 0
  %spec.select64 = select i1 %31, i64 %29, i64 %.129.fr
  %32 = tail call i32 @getccol(i32 noundef 0)
  %33 = mul nuw nsw i64 %spec.select64, 100
  %34 = udiv i64 %33, %29
  %35 = trunc i64 %34 to i32
  br label %38

36:                                               ; preds = %2
  %37 = tail call i32 @getccol(i32 noundef 0)
  br label %38

38:                                               ; preds = %36, %._crit_edge
  %39 = phi i32 [ %32, %._crit_edge ], [ %37, %36 ]
  %40 = phi i64 [ %spec.select64, %._crit_edge ], [ 0, %36 ]
  %.030.lcssa4863 = phi i64 [ %29, %._crit_edge ], [ 0, %36 ]
  %.026.lcssa5061 = phi i32 [ %30, %._crit_edge ], [ 1, %36 ]
  %.025.lcssa5259 = phi i32 [ %.1, %._crit_edge ], [ 0, %36 ]
  %.024 = phi i32 [ %35, %._crit_edge ], [ 0, %36 ]
  %41 = add nsw i32 %39, 1
  tail call void (ptr, ...) @mlwrite(ptr noundef nonnull @.str.10, i32 noundef %41, i32 noundef %.026.lcssa5061, i32 noundef %.025.lcssa5259, i64 noundef %40, i32 noundef %.024, i64 noundef %.030.lcssa4863) #2
  ret i32 1
}

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

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 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 = !{!16, !6, i64 24}
!16 = !{!"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}
!17 = !{!13, !14, i64 18}
!18 = !{!16, !11, i64 32}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass