; LLVM IR from AlgoGenesis/C :: Infix to Prefix/evaluation (program)

; 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.Stack = type { i32, [100 x i32] }

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @evaluatePrefix(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.Stack, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 404, ptr %3) #4
  call void @initStack(ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call i64 @strlen(ptr noundef %9) #5
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr %7, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = sub nsw i32 %12, 1
  store i32 %13, ptr %4, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %60, %1
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = icmp sge i32 %15, 0
  br i1 %16, label %17, label %63

17:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %18, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11
  store i8 %22, ptr %8, align 1, !tbaa !11
  %23 = call ptr @__ctype_b_loc() #6
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = load i8, ptr %8, align 1, !tbaa !11
  %26 = sext i8 %25 to i32
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i16, ptr %24, i64 %27
  %29 = load i16, ptr %28, align 2, !tbaa !12
  %30 = zext i16 %29 to i32
  %31 = and i32 %30, 2048
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %37

33:                                               ; preds = %17
  %34 = load i8, ptr %8, align 1, !tbaa !11
  %35 = sext i8 %34 to i32
  %36 = sub nsw i32 %35, 48
  call void @push(ptr noundef %3, i32 noundef %36)
  br label %59

37:                                               ; preds = %17
  %38 = call i32 @pop(ptr noundef %3)
  store i32 %38, ptr %5, align 4, !tbaa !9
  %39 = call i32 @pop(ptr noundef %3)
  store i32 %39, ptr %6, align 4, !tbaa !9
  %40 = load i8, ptr %8, align 1, !tbaa !11
  %41 = sext i8 %40 to i32
  switch i32 %41, label %58 [
    i32 43, label %42
    i32 45, label %46
    i32 42, label %50
    i32 47, label %54
  ]

42:                                               ; preds = %37
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = add nsw i32 %43, %44
  call void @push(ptr noundef %3, i32 noundef %45)
  br label %58

46:                                               ; preds = %37
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = sub nsw i32 %47, %48
  call void @push(ptr noundef %3, i32 noundef %49)
  br label %58

50:                                               ; preds = %37
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = mul nsw i32 %51, %52
  call void @push(ptr noundef %3, i32 noundef %53)
  br label %58

54:                                               ; preds = %37
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = sdiv i32 %55, %56
  call void @push(ptr noundef %3, i32 noundef %57)
  br label %58

58:                                               ; preds = %54, %50, %46, %42, %37
  br label %59

59:                                               ; preds = %58, %33
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %4, align 4, !tbaa !9
  %62 = add nsw i32 %61, -1
  store i32 %62, ptr %4, align 4, !tbaa !9
  br label %14, !llvm.loop !14

63:                                               ; preds = %14
  %64 = call i32 @pop(ptr noundef %3)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 404, ptr %3) #4
  ret i32 %64
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #3

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

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 = { nounwind willreturn 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 #3 = { nounwind willreturn memory(none) "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 }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

%struct.Stack = type { i32, [100 x i32] }

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @evaluatePrefix(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca %struct.Stack, align 4
  call void @llvm.lifetime.start.p0(i64 404, ptr nonnull %2) #4
  call void @initStack(ptr noundef nonnull %2)
  %3 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #5
  %4 = trunc i64 %3 to i32
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %6 = tail call ptr @__ctype_b_loc() #6
  %7 = and i64 %3, 2147483647
  br label %8

8:                                                ; preds = %.lr.ph, %30
  %indvars.iv = phi i64 [ %7, %.lr.ph ], [ %indvars.iv.next, %30 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %9 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !8
  %12 = sext i8 %10 to i64
  %13 = getelementptr inbounds i16, ptr %11, i64 %12
  %14 = load i16, ptr %13, align 2, !tbaa !10
  %15 = and i16 %14, 2048
  %.not = icmp eq i16 %15, 0
  br i1 %.not, label %19, label %16

16:                                               ; preds = %8
  %17 = sext i8 %10 to i32
  %18 = add nsw i32 %17, -48
  br label %.sink.split

19:                                               ; preds = %8
  %20 = call i32 @pop(ptr noundef nonnull %2)
  %21 = call i32 @pop(ptr noundef nonnull %2)
  switch i8 %10, label %30 [
    i8 43, label %22
    i8 45, label %24
    i8 42, label %26
    i8 47, label %28
  ]

22:                                               ; preds = %19
  %23 = add nsw i32 %21, %20
  br label %.sink.split

24:                                               ; preds = %19
  %25 = sub nsw i32 %20, %21
  br label %.sink.split

26:                                               ; preds = %19
  %27 = mul nsw i32 %21, %20
  br label %.sink.split

28:                                               ; preds = %19
  %29 = sdiv i32 %20, %21
  br label %.sink.split

.sink.split:                                      ; preds = %16, %28, %26, %24, %22
  %.sink = phi i32 [ %23, %22 ], [ %25, %24 ], [ %27, %26 ], [ %29, %28 ], [ %18, %16 ]
  call void @push(ptr noundef nonnull %2, i32 noundef %.sink)
  br label %30

30:                                               ; preds = %.sink.split, %19
  %31 = icmp ugt i64 %indvars.iv, 1
  br i1 %31, label %8, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %30, %1
  %32 = call i32 @pop(ptr noundef nonnull %2)
  call void @llvm.lifetime.end.p0(i64 404, ptr nonnull %2) #4
  ret i32 %32
}

; 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 nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #3

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

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 = { mustprogress nofree nounwind willreturn memory(argmem: 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 #3 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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