; LLVM IR from UtkarshPathrabe/Competitive-Coding :: HackerRank Solutions/Algorithms/Strings/Bigger Is Greater.ll (Z3calPc)

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

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3calPc(ptr noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i64 @strlen(ptr noundef %9) #5
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr %4, align 4, !tbaa !9
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %1
  %15 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str)
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %127

16:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = sub nsw i32 %17, 1
  store i32 %18, ptr %6, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %39, %16
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %22, label %37

22:                                               ; preds = %19
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = sub nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %23, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = sext i8 %28 to i32
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = sext i8 %34 to i32
  %36 = icmp sge i32 %29, %35
  br label %37

37:                                               ; preds = %22, %19
  %38 = phi i1 [ false, %19 ], [ %36, %22 ]
  br i1 %38, label %39, label %42

39:                                               ; preds = %37
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = add nsw i32 %40, -1
  store i32 %41, ptr %6, align 4, !tbaa !9
  br label %19, !llvm.loop !12

42:                                               ; preds = %37
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %42
  %46 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str)
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %126

47:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %48 = load i32, ptr %4, align 4, !tbaa !9
  %49 = sub nsw i32 %48, 1
  %50 = sext i32 %49 to i64
  store i64 %50, ptr %7, align 8, !tbaa !14
  br label %51

51:                                               ; preds = %65, %47
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = load i64, ptr %7, align 8, !tbaa !14
  %54 = getelementptr inbounds i8, ptr %52, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !11
  %56 = sext i8 %55 to i32
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = sub nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %57, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !11
  %63 = sext i8 %62 to i32
  %64 = icmp sle i32 %56, %63
  br i1 %64, label %65, label %68

65:                                               ; preds = %51
  %66 = load i64, ptr %7, align 8, !tbaa !14
  %67 = add i64 %66, -1
  store i64 %67, ptr %7, align 8, !tbaa !14
  br label %51, !llvm.loop !16

68:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = load i32, ptr %6, align 4, !tbaa !9
  %71 = sub nsw i32 %70, 1
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i8, ptr %69, i64 %72
  %74 = load i8, ptr %73, align 1, !tbaa !11
  %75 = sext i8 %74 to i32
  store i32 %75, ptr %8, align 4, !tbaa !9
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = load i64, ptr %7, align 8, !tbaa !14
  %78 = getelementptr inbounds i8, ptr %76, i64 %77
  %79 = load i8, ptr %78, align 1, !tbaa !11
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = load i32, ptr %6, align 4, !tbaa !9
  %82 = sub nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %80, i64 %83
  store i8 %79, ptr %84, align 1, !tbaa !11
  %85 = load i32, ptr %8, align 4, !tbaa !9
  %86 = trunc i32 %85 to i8
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = load i64, ptr %7, align 8, !tbaa !14
  %89 = getelementptr inbounds i8, ptr %87, i64 %88
  store i8 %86, ptr %89, align 1, !tbaa !11
  %90 = load i32, ptr %4, align 4, !tbaa !9
  %91 = sub nsw i32 %90, 1
  %92 = sext i32 %91 to i64
  store i64 %92, ptr %7, align 8, !tbaa !14
  br label %93

93:                                               ; preds = %98, %68
  %94 = load i32, ptr %6, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = load i64, ptr %7, align 8, !tbaa !14
  %97 = icmp ult i64 %95, %96
  br i1 %97, label %98, label %122

98:                                               ; preds = %93
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  %100 = load i32, ptr %6, align 4, !tbaa !9
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds i8, ptr %99, i64 %101
  %103 = load i8, ptr %102, align 1, !tbaa !11
  %104 = sext i8 %103 to i32
  store i32 %104, ptr %8, align 4, !tbaa !9
  %105 = load ptr, ptr %3, align 8, !tbaa !5
  %106 = load i64, ptr %7, align 8, !tbaa !14
  %107 = getelementptr inbounds i8, ptr %105, i64 %106
  %108 = load i8, ptr %107, align 1, !tbaa !11
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  %110 = load i32, ptr %6, align 4, !tbaa !9
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds i8, ptr %109, i64 %111
  store i8 %108, ptr %112, align 1, !tbaa !11
  %113 = load i32, ptr %8, align 4, !tbaa !9
  %114 = trunc i32 %113 to i8
  %115 = load ptr, ptr %3, align 8, !tbaa !5
  %116 = load i64, ptr %7, align 8, !tbaa !14
  %117 = getelementptr inbounds i8, ptr %115, i64 %116
  store i8 %114, ptr %117, align 1, !tbaa !11
  %118 = load i32, ptr %6, align 4, !tbaa !9
  %119 = add nsw i32 %118, 1
  store i32 %119, ptr %6, align 4, !tbaa !9
  %120 = load i64, ptr %7, align 8, !tbaa !14
  %121 = add i64 %120, -1
  store i64 %121, ptr %7, align 8, !tbaa !14
  br label %93, !llvm.loop !17

122:                                              ; preds = %93
  %123 = load ptr, ptr %3, align 8, !tbaa !5
  %124 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef %123)
  %125 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %124, ptr noundef @.str.1)
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %126

126:                                              ; preds = %122, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %127

127:                                              ; preds = %126, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %128 = load i1, ptr %2, align 1
  ret i1 %128
}

; 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: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), 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 = { mustprogress 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 = { inlinehint mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !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"

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3calPc(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %3 = trunc i64 %2 to i32
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %5, label %7

5:                                                ; preds = %1
  %6 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str)
  br label %39

7:                                                ; preds = %1
  %8 = add nsw i32 %3, -1
  %9 = icmp sgt i32 %3, 1
  br i1 %9, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %7, %15
  %.04053 = phi i32 [ %16, %15 ], [ %8, %7 ]
  %10 = zext nneg i32 %.04053 to i64
  %11 = getelementptr i8, ptr %0, i64 %10
  %12 = getelementptr i8, ptr %11, i64 -1
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = load i8, ptr %11, align 1, !tbaa !5
  %.not = icmp slt i8 %13, %14
  br i1 %.not, label %.critedge.thread, label %15

15:                                               ; preds = %.lr.ph
  %16 = add nsw i32 %.04053, -1
  %17 = icmp sgt i32 %.04053, 1
  br i1 %17, label %.lr.ph, label %.critedge.thread61, !llvm.loop !8

.critedge:                                        ; preds = %7
  %.not47 = icmp eq i32 %8, 0
  br i1 %.not47, label %.critedge.thread61, label %.critedge.thread

.critedge.thread61:                               ; preds = %15, %.critedge
  %18 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str)
  br label %39

.critedge.thread:                                 ; preds = %.lr.ph, %.critedge
  %.04052 = phi i32 [ %8, %.critedge ], [ %.04053, %.lr.ph ]
  %19 = sext i32 %8 to i64
  %20 = sext i32 %.04052 to i64
  %21 = getelementptr i8, ptr %0, i64 %20
  %22 = getelementptr i8, ptr %21, i64 -1
  %23 = load i8, ptr %22, align 1, !tbaa !5
  br label %24

24:                                               ; preds = %24, %.critedge.thread
  %.0 = phi i64 [ %19, %.critedge.thread ], [ %27, %24 ]
  %25 = getelementptr inbounds i8, ptr %0, i64 %.0
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %.not46 = icmp sgt i8 %26, %23
  %27 = add i64 %.0, -1
  br i1 %.not46, label %28, label %24, !llvm.loop !10

28:                                               ; preds = %24
  %29 = getelementptr inbounds i8, ptr %0, i64 %.0
  store i8 %26, ptr %22, align 1, !tbaa !5
  store i8 %23, ptr %29, align 1, !tbaa !5
  %30 = icmp ugt i32 %8, %.04052
  br i1 %30, label %.lr.ph57, label %._crit_edge

.lr.ph57:                                         ; preds = %28, %.lr.ph57
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph57 ], [ %20, %28 ]
  %.156 = phi i64 [ %35, %.lr.ph57 ], [ %19, %28 ]
  %31 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %0, i64 %.156
  %34 = load i8, ptr %33, align 1, !tbaa !5
  store i8 %34, ptr %31, align 1, !tbaa !5
  store i8 %32, ptr %33, align 1, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %35 = add i64 %.156, -1
  %36 = icmp ugt i64 %35, %indvars.iv.next
  br i1 %36, label %.lr.ph57, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph57, %28
  %37 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull %0)
  %38 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %37, ptr noundef nonnull @.str.1)
  br label %39

39:                                               ; preds = %.critedge.thread61, %._crit_edge, %5
  %.143 = phi i1 [ false, %5 ], [ true, %._crit_edge ], [ false, %.critedge.thread61 ]
  ret i1 %.143
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 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 #2 = { inlinehint mustprogress 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 #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++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = distinct !{!11, !9}


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