; LLVM IR from AlgoGenesis/C :: Infix To Postfix/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 @evaluatePostfix(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 i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 404, ptr %3) #3
  call void @initStack(ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  br label %8

8:                                                ; preds = %58, %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i8, ptr %9, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = sext i8 %13 to i32
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %61

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

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

36:                                               ; preds = %16
  %37 = call i32 @pop(ptr noundef %3)
  store i32 %37, ptr %6, align 4, !tbaa !9
  %38 = call i32 @pop(ptr noundef %3)
  store i32 %38, ptr %5, align 4, !tbaa !9
  %39 = load i8, ptr %7, align 1, !tbaa !11
  %40 = sext i8 %39 to i32
  switch i32 %40, label %57 [
    i32 43, label %41
    i32 45, label %45
    i32 42, label %49
    i32 47, label %53
  ]

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

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

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

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

57:                                               ; preds = %53, %49, %45, %41, %36
  br label %58

58:                                               ; preds = %57, %32
  %59 = load i32, ptr %4, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  br label %8, !llvm.loop !14

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

; 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(none)
declare ptr @__ctype_b_loc() #2

; 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(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 #3 = { nounwind }
attributes #4 = { 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 @evaluatePostfix(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) #3
  call void @initStack(ptr noundef nonnull %2)
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %.not17 = icmp eq i8 %3, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = tail call ptr @__ctype_b_loc() #4
  br label %5

5:                                                ; preds = %.lr.ph, %26
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %26 ]
  %6 = phi i8 [ %3, %.lr.ph ], [ %28, %26 ]
  %7 = load ptr, ptr %4, align 8, !tbaa !8
  %8 = sext i8 %6 to i64
  %9 = getelementptr inbounds i16, ptr %7, i64 %8
  %10 = load i16, ptr %9, align 2, !tbaa !10
  %11 = and i16 %10, 2048
  %.not16 = icmp eq i16 %11, 0
  br i1 %.not16, label %15, label %12

12:                                               ; preds = %5
  %13 = sext i8 %6 to i32
  %14 = add nsw i32 %13, -48
  br label %.sink.split

15:                                               ; preds = %5
  %16 = call i32 @pop(ptr noundef nonnull %2)
  %17 = call i32 @pop(ptr noundef nonnull %2)
  switch i8 %6, label %26 [
    i8 43, label %18
    i8 45, label %20
    i8 42, label %22
    i8 47, label %24
  ]

18:                                               ; preds = %15
  %19 = add nsw i32 %17, %16
  br label %.sink.split

20:                                               ; preds = %15
  %21 = sub nsw i32 %17, %16
  br label %.sink.split

22:                                               ; preds = %15
  %23 = mul nsw i32 %17, %16
  br label %.sink.split

24:                                               ; preds = %15
  %25 = sdiv i32 %17, %16
  br label %.sink.split

.sink.split:                                      ; preds = %12, %24, %22, %20, %18
  %.sink = phi i32 [ %19, %18 ], [ %21, %20 ], [ %23, %22 ], [ %25, %24 ], [ %14, %12 ]
  call void @push(ptr noundef nonnull %2, i32 noundef %.sink)
  br label %26

26:                                               ; preds = %.sink.split, %15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %.not = icmp eq i8 %28, 0
  br i1 %.not, label %._crit_edge, label %5, !llvm.loop !12

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

; 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 nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #2

; 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 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 #3 = { nounwind }
attributes #4 = { 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: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass