; LLVM IR from wuzhouhui/leetcode :: 168_excel_sheet_col_title (convertToTitle)

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

; Function Attrs: nounwind uwtable
define dso_local ptr @convertToTitle(i32 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp sle i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %104

12:                                               ; preds = %1
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = icmp sle i32 %13, 26
  br i1 %14, label %15, label %26

15:                                               ; preds = %12
  %16 = call noalias ptr @malloc(i64 noundef 2) #6
  store ptr %16, ptr %4, align 8, !tbaa !9
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = add nsw i32 65, %17
  %19 = sub nsw i32 %18, 1
  %20 = trunc i32 %19 to i8
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %21, i64 0
  store i8 %20, ptr %22, align 1, !tbaa !11
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %23, i64 1
  store i8 0, ptr %24, align 1, !tbaa !11
  %25 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %25, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %104

26:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %27 = call noalias ptr @malloc(i64 noundef 1) #6
  store ptr %27, ptr %4, align 8, !tbaa !9
  store ptr null, ptr %4, align 8, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %57, %26
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %31, label %58

31:                                               ; preds = %28
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = srem i32 %32, 26
  store i32 %33, ptr %7, align 4, !tbaa !5
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sub nsw i32 %34, 1
  %36 = sdiv i32 %35, 26
  store i32 %36, ptr %3, align 4, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !9
  %38 = call ptr @realloc(ptr noundef %37, i64 noundef 9) #7
  store ptr %38, ptr %4, align 8, !tbaa !9
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %47

41:                                               ; preds = %31
  %42 = load ptr, ptr %4, align 8, !tbaa !9
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %6, align 4, !tbaa !5
  %45 = sext i32 %43 to i64
  %46 = getelementptr inbounds i8, ptr %42, i64 %45
  store i8 90, ptr %46, align 1, !tbaa !11
  br label %57

47:                                               ; preds = %31
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = add nsw i32 65, %48
  %50 = sub nsw i32 %49, 1
  %51 = trunc i32 %50 to i8
  %52 = load ptr, ptr %4, align 8, !tbaa !9
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %6, align 4, !tbaa !5
  %55 = sext i32 %53 to i64
  %56 = getelementptr inbounds i8, ptr %52, i64 %55
  store i8 %51, ptr %56, align 1, !tbaa !11
  br label %57

57:                                               ; preds = %47, %41
  br label %28, !llvm.loop !12

58:                                               ; preds = %28
  %59 = load ptr, ptr %4, align 8, !tbaa !9
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i8, ptr %59, i64 %61
  store i8 0, ptr %62, align 1, !tbaa !11
  %63 = load ptr, ptr %4, align 8, !tbaa !9
  %64 = call i64 @strlen(ptr noundef %63) #8
  %65 = trunc i64 %64 to i32
  store i32 %65, ptr %8, align 4, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %99, %58
  %67 = load i32, ptr %7, align 4, !tbaa !5
  %68 = load i32, ptr %8, align 4, !tbaa !5
  %69 = sdiv i32 %68, 2
  %70 = icmp slt i32 %67, %69
  br i1 %70, label %71, label %102

71:                                               ; preds = %66
  %72 = load ptr, ptr %4, align 8, !tbaa !9
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = sub nsw i32 %73, 1
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = sub nsw i32 %74, %75
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i8, ptr %72, i64 %77
  %79 = load i8, ptr %78, align 1, !tbaa !11
  %80 = sext i8 %79 to i32
  store i32 %80, ptr %6, align 4, !tbaa !5
  %81 = load ptr, ptr %4, align 8, !tbaa !9
  %82 = load i32, ptr %7, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %81, i64 %83
  %85 = load i8, ptr %84, align 1, !tbaa !11
  %86 = load ptr, ptr %4, align 8, !tbaa !9
  %87 = load i32, ptr %8, align 4, !tbaa !5
  %88 = sub nsw i32 %87, 1
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = sub nsw i32 %88, %89
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds i8, ptr %86, i64 %91
  store i8 %85, ptr %92, align 1, !tbaa !11
  %93 = load i32, ptr %6, align 4, !tbaa !5
  %94 = trunc i32 %93 to i8
  %95 = load ptr, ptr %4, align 8, !tbaa !9
  %96 = load i32, ptr %7, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds i8, ptr %95, i64 %97
  store i8 %94, ptr %98, align 1, !tbaa !11
  br label %99

99:                                               ; preds = %71
  %100 = load i32, ptr %7, align 4, !tbaa !5
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %7, align 4, !tbaa !5
  br label %66, !llvm.loop !14

102:                                              ; preds = %66
  %103 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %103, ptr %2, align 8
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %104

104:                                              ; preds = %102, %15, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %105 = load ptr, ptr %2, align 8
  ret ptr %105
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

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

; 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 allocsize(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 allocsize(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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { nounwind allocsize(1) }
attributes #8 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !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"

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @convertToTitle(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i32 %0, 1
  br i1 %2, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = icmp ult i32 %0, 27
  br i1 %4, label %5, label %.lr.ph

5:                                                ; preds = %3
  %6 = tail call noalias dereferenceable_or_null(2) ptr @malloc(i64 noundef 2) #4
  %7 = trunc nuw i32 %0 to i8
  %8 = or disjoint i8 %7, 64
  store i8 %8, ptr %6, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %6, i64 1
  store i8 0, ptr %9, align 1, !tbaa !5
  br label %.loopexit

.lr.ph:                                           ; preds = %3, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %3 ]
  %.03641 = phi ptr [ %13, %.lr.ph ], [ null, %3 ]
  %.03740 = phi i32 [ %12, %.lr.ph ], [ %0, %3 ]
  %10 = urem i32 %.03740, 26
  %11 = add nsw i32 %.03740, -1
  %12 = udiv i32 %11, 26
  %13 = tail call dereferenceable_or_null(9) ptr @realloc(ptr noundef %.03641, i64 noundef 9) #5
  %14 = icmp eq i32 %10, 0
  %15 = trunc nuw nsw i32 %10 to i8
  %16 = or disjoint i8 %15, 64
  %.sink = select i1 %14, i8 90, i8 %16
  %17 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv
  store i8 %.sink, ptr %17, align 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not = icmp ult i32 %11, 26
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph
  %18 = and i64 %indvars.iv.next, 4294967295
  %19 = getelementptr inbounds i8, ptr %13, i64 %18
  store i8 0, ptr %19, align 1, !tbaa !5
  %20 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %13) #6
  %21 = trunc i64 %20 to i32
  %22 = icmp sgt i32 %21, 1
  br i1 %22, label %.lr.ph46.preheader, label %.loopexit

.lr.ph46.preheader:                               ; preds = %._crit_edge
  %23 = lshr i64 %20, 1
  %24 = and i64 %20, 2147483647
  %wide.trip.count = and i64 %23, 1073741823
  %25 = getelementptr i8, ptr %13, i64 %24
  %xtraiter = and i64 %23, 1
  %26 = icmp eq i64 %wide.trip.count, 1
  br i1 %26, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph46.preheader.new

.lr.ph46.preheader.new:                           ; preds = %.lr.ph46.preheader
  %unroll_iter = sub nsw i64 %wide.trip.count, %xtraiter
  br label %.lr.ph46

.lr.ph46:                                         ; preds = %.lr.ph46, %.lr.ph46.preheader.new
  %indvars.iv48 = phi i64 [ 0, %.lr.ph46.preheader.new ], [ %indvars.iv.next49.1, %.lr.ph46 ]
  %niter = phi i64 [ 0, %.lr.ph46.preheader.new ], [ %niter.next.1, %.lr.ph46 ]
  %27 = xor i64 %indvars.iv48, -1
  %28 = getelementptr i8, ptr %25, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv48
  %31 = load i8, ptr %30, align 1, !tbaa !5
  store i8 %31, ptr %28, align 1, !tbaa !5
  store i8 %29, ptr %30, align 1, !tbaa !5
  %indvars.iv.next49 = or disjoint i64 %indvars.iv48, 1
  %32 = xor i64 %indvars.iv48, -2
  %33 = getelementptr i8, ptr %25, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv.next49
  %36 = load i8, ptr %35, align 1, !tbaa !5
  store i8 %36, ptr %33, align 1, !tbaa !5
  store i8 %34, ptr %35, align 1, !tbaa !5
  %indvars.iv.next49.1 = add nuw nsw i64 %indvars.iv48, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph46, !llvm.loop !10

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph46, %.lr.ph46.preheader
  %indvars.iv48.unr = phi i64 [ 0, %.lr.ph46.preheader ], [ %indvars.iv.next49.1, %.lr.ph46 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph46.epil

.lr.ph46.epil:                                    ; preds = %.loopexit.loopexit.unr-lcssa
  %37 = xor i64 %indvars.iv48.unr, -1
  %38 = getelementptr i8, ptr %25, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv48.unr
  %41 = load i8, ptr %40, align 1, !tbaa !5
  store i8 %41, ptr %38, align 1, !tbaa !5
  store i8 %39, ptr %40, align 1, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph46.epil, %.loopexit.loopexit.unr-lcssa, %._crit_edge, %1, %5
  %.0 = phi ptr [ %6, %5 ], [ null, %1 ], [ %13, %._crit_edge ], [ %13, %.loopexit.loopexit.unr-lcssa ], [ %13, %.lr.ph46.epil ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

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

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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 #4 = { nounwind allocsize(0) }
attributes #5 = { nounwind allocsize(1) }
attributes #6 = { 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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass