; LLVM IR from xuxping/codelife :: leetcode (151)

; 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 [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @reverseWords(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = sext i8 %10 to i32
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %11)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %13, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = call i64 @strlen(ptr noundef %14) #5
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %4, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !10
  %17 = load i32, ptr %5, align 4, !tbaa !10
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %17)
  br label %19

19:                                               ; preds = %25, %1
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i32 1
  store ptr %21, ptr %3, align 8, !tbaa !5
  %22 = load i8, ptr %20, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = icmp eq i32 %23, 32
  br i1 %24, label %25, label %30

25:                                               ; preds = %19
  %26 = load i32, ptr %5, align 4, !tbaa !10
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %26)
  %28 = load i32, ptr %5, align 4, !tbaa !10
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %5, align 4, !tbaa !10
  br label %19, !llvm.loop !12

30:                                               ; preds = %19
  %31 = load i32, ptr %5, align 4, !tbaa !10
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %31)
  %33 = load i32, ptr %5, align 4, !tbaa !10
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %97

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !10
  br label %36

36:                                               ; preds = %92, %35
  %37 = load i32, ptr %7, align 4, !tbaa !10
  %38 = load i32, ptr %4, align 4, !tbaa !10
  %39 = load i32, ptr %5, align 4, !tbaa !10
  %40 = sub nsw i32 %38, %39
  %41 = icmp slt i32 %37, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %36
  store i32 4, ptr %8, align 4
  br label %95

43:                                               ; preds = %36
  br label %44

44:                                               ; preds = %72, %43
  %45 = load i32, ptr %5, align 4, !tbaa !10
  %46 = icmp sgt i32 %45, 0
  br i1 %46, label %47, label %70

47:                                               ; preds = %44
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !10
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i8, ptr %48, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !9
  %53 = sext i8 %52 to i32
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !10
  %56 = sub nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %54, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !9
  %60 = sext i8 %59 to i32
  %61 = icmp eq i32 %53, %60
  br i1 %61, label %62, label %70

62:                                               ; preds = %47
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !10
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %63, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !9
  %68 = sext i8 %67 to i32
  %69 = icmp eq i32 %68, 32
  br label %70

70:                                               ; preds = %62, %47, %44
  %71 = phi i1 [ false, %47 ], [ false, %44 ], [ %69, %62 ]
  br i1 %71, label %72, label %75

72:                                               ; preds = %70
  %73 = load i32, ptr %5, align 4, !tbaa !10
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %5, align 4, !tbaa !10
  br label %44, !llvm.loop !14

75:                                               ; preds = %70
  %76 = load i32, ptr %5, align 4, !tbaa !10
  %77 = load i32, ptr %4, align 4, !tbaa !10
  %78 = icmp sge i32 %76, %77
  br i1 %78, label %79, label %80

79:                                               ; preds = %75
  store i32 4, ptr %8, align 4
  br label %95

80:                                               ; preds = %75
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = load i32, ptr %5, align 4, !tbaa !10
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %81, i64 %83
  %85 = load i8, ptr %84, align 1, !tbaa !9
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = load i32, ptr %7, align 4, !tbaa !10
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds i8, ptr %86, i64 %88
  store i8 %85, ptr %89, align 1, !tbaa !9
  %90 = load i32, ptr %5, align 4, !tbaa !10
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %5, align 4, !tbaa !10
  br label %92

92:                                               ; preds = %80
  %93 = load i32, ptr %7, align 4, !tbaa !10
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %7, align 4, !tbaa !10
  br label %36, !llvm.loop !15

95:                                               ; preds = %79, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %96

96:                                               ; preds = %95
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %97

97:                                               ; preds = %96, %30
  %98 = load ptr, ptr %2, align 8, !tbaa !5
  %99 = load i8, ptr %98, align 1, !tbaa !9
  %100 = sext i8 %99 to i32
  %101 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %100)
  %102 = load ptr, ptr %2, align 8, !tbaa !5
  store i32 1, ptr %8, align 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 8, ptr %3) #4
  ret ptr %102
}

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

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

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

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

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


; 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 [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef ptr @reverseWords(ptr noundef returned %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %3 = sext i8 %2 to i32
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %3)
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %6 = trunc i64 %5 to i32
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef 0)
  %8 = getelementptr inbounds i8, ptr %0, i64 1
  %9 = load i8, ptr %0, align 1, !tbaa !5
  %10 = icmp eq i8 %9, 32
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %11 = phi ptr [ %14, %.lr.ph ], [ %8, %1 ]
  %.03034 = phi i32 [ %13, %.lr.ph ], [ 0, %1 ]
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.03034)
  %13 = add nuw nsw i32 %.03034, 1
  %14 = getelementptr inbounds i8, ptr %11, i64 1
  %15 = load i8, ptr %11, align 1, !tbaa !5
  %16 = icmp eq i8 %15, 32
  br i1 %16, label %.lr.ph, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.030.lcssa = phi i32 [ 0, %1 ], [ %13, %.lr.ph ]
  %.lcssa = phi ptr [ %8, %1 ], [ %14, %.lr.ph ]
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.030.lcssa)
  %.not = icmp ne i32 %.030.lcssa, 0
  %18 = icmp slt i32 %.030.lcssa, %6
  %or.cond44 = select i1 %.not, i1 %18, i1 false
  br i1 %or.cond44, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %._crit_edge, %28
  %indvars.iv48 = phi i64 [ %indvars.iv.next49, %28 ], [ 0, %._crit_edge ]
  %.141 = phi i32 [ %33, %28 ], [ %.030.lcssa, %._crit_edge ]
  %19 = icmp sgt i32 %.141, 0
  br i1 %19, label %.lr.ph37.preheader, label %.critedge

.lr.ph37.preheader:                               ; preds = %.preheader
  %20 = zext nneg i32 %.141 to i64
  br label %.lr.ph37

.lr.ph37:                                         ; preds = %.lr.ph37, %.lr.ph37.preheader
  %indvars.iv = phi i64 [ %20, %.lr.ph37.preheader ], [ %indvars.iv.next, %.lr.ph37 ]
  %21 = getelementptr inbounds i8, ptr %.lcssa, i64 %indvars.iv
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = getelementptr i8, ptr %21, i64 -1
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %25 = icmp eq i8 %22, 32
  %26 = icmp eq i8 %24, 32
  %or.cond = and i1 %25, %26
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %or.cond, label %.lr.ph37, label %.critedge.loopexit

.critedge.loopexit:                               ; preds = %.lr.ph37
  %27 = trunc nuw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.preheader
  %.2.lcssa = phi i32 [ %.141, %.preheader ], [ %27, %.critedge.loopexit ]
  %.not32 = icmp slt i32 %.2.lcssa, %6
  br i1 %.not32, label %28, label %.loopexit

28:                                               ; preds = %.critedge
  %29 = sext i32 %.2.lcssa to i64
  %30 = getelementptr inbounds i8, ptr %.lcssa, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv48
  store i8 %31, ptr %32, align 1, !tbaa !5
  %33 = add nsw i32 %.2.lcssa, 1
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %34 = sub nsw i32 %6, %33
  %35 = sext i32 %34 to i64
  %36 = icmp slt i64 %indvars.iv.next49, %35
  br i1 %36, label %.preheader, label %.loopexit, !llvm.loop !10

.loopexit:                                        ; preds = %.critedge, %28, %._crit_edge
  %37 = load i8, ptr %0, align 1, !tbaa !5
  %38 = sext i8 %37 to i32
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %38)
  ret ptr %0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { nofree 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 = { 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 #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 = { 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 = !{!"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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass