; LLVM IR from mahendramahara/DSA-in-C-Programing :: STACK (PrefixToInfix)

; 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"

@.str = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @isOperator(i8 noundef signext) #0

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

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

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

16:                                               ; preds = %51, %2
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp sge i32 %17, 0
  br i1 %18, label %19, label %54

19:                                               ; preds = %16
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !11
  %25 = call i32 @isOperator(i8 noundef signext %24)
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %41

27:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 100, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 100, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 100, ptr %9) #4
  %28 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  call void @pop(ptr noundef %28)
  %29 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 0
  call void @pop(ptr noundef %29)
  %30 = getelementptr inbounds [100 x i8], ptr %9, i64 0, i64 0
  %31 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %32, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = sext i8 %36 to i32
  %38 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 0
  %39 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %30, ptr noundef @.str, ptr noundef %31, i32 noundef %37, ptr noundef %38) #4
  %40 = getelementptr inbounds [100 x i8], ptr %9, i64 0, i64 0
  call void @push(ptr noundef %40)
  call void @llvm.lifetime.end.p0(i64 100, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 100, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 100, ptr %7) #4
  br label %50

41:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 100, ptr %10) #4
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %42, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = getelementptr inbounds [100 x i8], ptr %10, i64 0, i64 0
  store i8 %46, ptr %47, align 16, !tbaa !11
  %48 = getelementptr inbounds [100 x i8], ptr %10, i64 0, i64 1
  store i8 0, ptr %48, align 1, !tbaa !11
  %49 = getelementptr inbounds [100 x i8], ptr %10, i64 0, i64 0
  call void @push(ptr noundef %49)
  call void @llvm.lifetime.end.p0(i64 100, ptr %10) #4
  br label %50

50:                                               ; preds = %41, %27
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = add nsw i32 %52, -1
  store i32 %53, ptr %6, align 4, !tbaa !9
  br label %16, !llvm.loop !12

54:                                               ; preds = %16
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  call void @pop(ptr noundef %55)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; 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
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #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 "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) }

!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"}


; 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"

@.str = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @isOperator(i8 noundef signext) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @prefixtoinfix(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca [100 x i8], align 16
  %4 = alloca [100 x i8], align 16
  %5 = alloca [100 x i8], align 16
  %6 = alloca [100 x i8], align 16
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %8 = trunc i64 %7 to i32
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %10 = getelementptr inbounds i8, ptr %6, i64 1
  %11 = and i64 %7, 2147483647
  br label %12

12:                                               ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ %11, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %13 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = call i32 @isOperator(i8 noundef signext %14)
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %20, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %5) #5
  call void @pop(ptr noundef nonnull %3)
  call void @pop(ptr noundef nonnull %4)
  %17 = load i8, ptr %13, align 1, !tbaa !5
  %18 = sext i8 %17 to i32
  %19 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %5, ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull %3, i32 noundef %18, ptr noundef nonnull %4) #5
  call void @push(ptr noundef nonnull %5)
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %3) #5
  br label %22

20:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %6) #5
  %21 = load i8, ptr %13, align 1, !tbaa !5
  store i8 %21, ptr %6, align 16, !tbaa !5
  store i8 0, ptr %10, align 1, !tbaa !5
  call void @push(ptr noundef nonnull %6)
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %6) #5
  br label %22

22:                                               ; preds = %16, %20
  %23 = icmp ugt i64 %indvars.iv, 1
  br i1 %23, label %12, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %22, %2
  call void @pop(ptr noundef %1)
  ret void
}

; 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: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) 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 = { 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 #4 = { nounwind willreturn memory(read) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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