; LLVM IR from AllAlgorithms/c :: algorithms/strings (C_Program_to_reverse_words_in_a_ line)

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

@__const.main.line = external hidden unnamed_addr constant [51 x i8], align 16
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [51 x i8], align 16
  %3 = alloca [100 x i8], align 16
  %4 = alloca [50 x i8], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 51, ptr %2) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %2, ptr align 16 @__const.main.line, i64 51, i1 false)
  call void @llvm.lifetime.start.p0(i64 100, ptr %3) #6
  call void @llvm.memset.p0.i64(ptr align 16 %3, i8 0, i64 100, i1 false)
  call void @llvm.lifetime.start.p0(i64 50, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %8 = getelementptr inbounds [51 x i8], ptr %2, i64 0, i64 0
  %9 = call i32 @string_length(ptr noundef %8)
  store i32 %9, ptr %7, align 4, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %51, %0
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %54

14:                                               ; preds = %10
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %36, %14
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %26

19:                                               ; preds = %15
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [51 x i8], ptr %2, i64 0, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = sext i8 %23 to i32
  %25 = icmp ne i32 %24, 32
  br label %26

26:                                               ; preds = %19, %15
  %27 = phi i1 [ false, %15 ], [ %25, %19 ]
  br i1 %27, label %28, label %41

28:                                               ; preds = %26
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [51 x i8], ptr %2, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [50 x i8], ptr %4, i64 0, i64 %34
  store i8 %32, ptr %35, align 1, !tbaa !9
  br label %36

36:                                               ; preds = %28
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %5, align 4, !tbaa !5
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %6, align 4, !tbaa !5
  br label %15, !llvm.loop !10

41:                                               ; preds = %26
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [50 x i8], ptr %4, i64 0, i64 %43
  store i8 0, ptr %44, align 1, !tbaa !9
  %45 = getelementptr inbounds [50 x i8], ptr %4, i64 0, i64 0
  call void @string_reverse(ptr noundef %45)
  %46 = getelementptr inbounds [100 x i8], ptr %3, i64 0, i64 0
  %47 = getelementptr inbounds [50 x i8], ptr %4, i64 0, i64 0
  %48 = call ptr @strcat(ptr noundef %46, ptr noundef %47) #6
  %49 = getelementptr inbounds [100 x i8], ptr %3, i64 0, i64 0
  %50 = call ptr @strcat(ptr noundef %49, ptr noundef @.str) #6
  br label %51

51:                                               ; preds = %41
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %5, align 4, !tbaa !5
  br label %10, !llvm.loop !12

54:                                               ; preds = %10
  %55 = getelementptr inbounds [51 x i8], ptr %2, i64 0, i64 0
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %55)
  %57 = getelementptr inbounds [100 x i8], ptr %3, i64 0, i64 0
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %57)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 50, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 100, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 51, ptr %2) #6
  ret i32 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind
declare ptr @strcat(ptr noundef, ptr noundef) #4

declare i32 @printf(ptr noundef, ...) #5

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { "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 #6 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

@__const.main.line = external hidden unnamed_addr constant [51 x i8], align 16
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1

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

; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [51 x i8], align 16
  %2 = alloca [100 x i8], align 16
  %3 = alloca [50 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 51, ptr nonnull %1) #7
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(51) %1, ptr noundef nonnull align 16 dereferenceable(51) @__const.main.line, i64 51, i1 false)
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %2) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(100) %2, i8 0, i64 100, i1 false)
  call void @llvm.lifetime.start.p0(i64 50, ptr nonnull %3) #7
  %4 = call i32 @string_length(ptr noundef nonnull %1)
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %0
  %6 = zext nneg i32 %4 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.critedge
  %.015 = phi i32 [ %20, %.critedge ], [ 0, %.preheader.preheader ]
  %7 = sext i32 %.015 to i64
  %8 = add nsw i32 %.015, 1
  %smax = call i32 @llvm.smax.i32(i32 %4, i32 %8)
  br label %9

9:                                                ; preds = %.preheader, %12
  %indvars.iv16 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next17, %12 ]
  %indvars.iv = phi i64 [ %7, %.preheader ], [ %indvars.iv.next, %12 ]
  %10 = getelementptr inbounds [51 x i8], ptr %1, i64 0, i64 %indvars.iv
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %.not = icmp eq i8 %11, 32
  br i1 %.not, label %.critedge.split.loop.exit21, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds [50 x i8], ptr %3, i64 0, i64 %indvars.iv16
  store i8 %11, ptr %13, align 1, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %indvars.iv.next17 = add nuw nsw i64 %indvars.iv16, 1
  %14 = icmp slt i64 %indvars.iv.next, %6
  br i1 %14, label %9, label %.critedge, !llvm.loop !8

.critedge.split.loop.exit21:                      ; preds = %9
  %15 = trunc nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %12, %.critedge.split.loop.exit21
  %.011.lcssa.in = phi i64 [ %indvars.iv16, %.critedge.split.loop.exit21 ], [ %indvars.iv.next17, %12 ]
  %.1.lcssa = phi i32 [ %15, %.critedge.split.loop.exit21 ], [ %smax, %12 ]
  %16 = and i64 %.011.lcssa.in, 4294967295
  %17 = getelementptr inbounds [50 x i8], ptr %3, i64 0, i64 %16
  store i8 0, ptr %17, align 1, !tbaa !5
  call void @string_reverse(ptr noundef nonnull %3)
  %18 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) %3) #7
  %19 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str) #7
  %20 = add nsw i32 %.1.lcssa, 1
  %21 = icmp slt i32 %20, %4
  br i1 %21, label %.preheader, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %.critedge, %0
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef nonnull %1)
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %2)
  call void @llvm.lifetime.end.p0(i64 50, ptr nonnull %3) #7
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %2) #7
  call void @llvm.lifetime.end.p0(i64 51, ptr nonnull %1) #7
  ret i32 0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcat(ptr noalias noundef returned, ptr noalias nocapture noundef readonly) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #5

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #6

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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 #5 = { 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 #6 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { 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"}
!10 = distinct !{!10, !9}


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