; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: CodeVita Problems (string_pair)

; 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.numToWords.unit_words = external hidden unnamed_addr constant [10 x [6 x i8]], align 16
@__const.numToWords.tens_words = external hidden unnamed_addr constant [10 x [10 x i8]], align 16
@__const.numToWords.eleven_nineteen = external hidden unnamed_addr constant [10 x [20 x i8]], align 16

; Function Attrs: nounwind uwtable
define dso_local void @numToWords(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca [10 x [6 x i8]], align 16
  %6 = alloca [10 x [10 x i8]], align 16
  %7 = alloca [10 x [20 x i8]], align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca [500 x i8], align 16
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 60, ptr %5) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 @__const.numToWords.unit_words, i64 60, i1 false)
  call void @llvm.lifetime.start.p0(i64 100, ptr %6) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const.numToWords.tens_words, i64 100, i1 false)
  call void @llvm.lifetime.start.p0(i64 200, ptr %7) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %7, ptr align 16 @__const.numToWords.eleven_nineteen, i64 200, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 500, ptr %11) #5
  call void @llvm.memset.p0.i64(ptr align 16 %11, i8 0, i64 500, i1 false)
  %12 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %12, ptr %8, align 4, !tbaa !5
  %13 = load i32, ptr %8, align 4, !tbaa !5
  %14 = srem i32 %13, 10
  store i32 %14, ptr %9, align 4, !tbaa !5
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = sdiv i32 %15, 10
  store i32 %16, ptr %10, align 4, !tbaa !5
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 10
  br i1 %18, label %19, label %26

19:                                               ; preds = %2
  %20 = getelementptr inbounds [500 x i8], ptr %11, i64 0, i64 0
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [10 x [6 x i8]], ptr %5, i64 0, i64 %22
  %24 = getelementptr inbounds [6 x i8], ptr %23, i64 0, i64 0
  %25 = call ptr @strcpy(ptr noundef %20, ptr noundef %24) #5
  br label %57

26:                                               ; preds = %2
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = icmp sgt i32 %27, 10
  br i1 %28, label %29, label %39

29:                                               ; preds = %26
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = icmp slt i32 %30, 20
  br i1 %31, label %32, label %39

32:                                               ; preds = %29
  %33 = getelementptr inbounds [500 x i8], ptr %11, i64 0, i64 0
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [10 x [20 x i8]], ptr %7, i64 0, i64 %35
  %37 = getelementptr inbounds [20 x i8], ptr %36, i64 0, i64 0
  %38 = call ptr @strcpy(ptr noundef %33, ptr noundef %37) #5
  br label %56

39:                                               ; preds = %29, %26
  %40 = getelementptr inbounds [500 x i8], ptr %11, i64 0, i64 0
  %41 = load i32, ptr %10, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [10 x [10 x i8]], ptr %6, i64 0, i64 %42
  %44 = getelementptr inbounds [10 x i8], ptr %43, i64 0, i64 0
  %45 = call ptr @strcpy(ptr noundef %40, ptr noundef %44) #5
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = icmp sgt i32 %46, 0
  br i1 %47, label %48, label %55

48:                                               ; preds = %39
  %49 = getelementptr inbounds [500 x i8], ptr %11, i64 0, i64 0
  %50 = load i32, ptr %9, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [10 x [6 x i8]], ptr %5, i64 0, i64 %51
  %53 = getelementptr inbounds [6 x i8], ptr %52, i64 0, i64 0
  %54 = call ptr @strcat(ptr noundef %49, ptr noundef %53) #5
  br label %55

55:                                               ; preds = %48, %39
  br label %56

56:                                               ; preds = %55, %32
  br label %57

57:                                               ; preds = %56, %19
  %58 = load ptr, ptr %4, align 8, !tbaa !9
  %59 = getelementptr inbounds [500 x i8], ptr %11, i64 0, i64 0
  %60 = call ptr @strcpy(ptr noundef %58, ptr noundef %59) #5
  call void @llvm.lifetime.end.p0(i64 500, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 200, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 100, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 60, ptr %5) #5
  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: 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 @strcpy(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind
declare ptr @strcat(ptr noundef, 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 = { 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


; 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.numToWords.unit_words = external hidden unnamed_addr constant [10 x [6 x i8]], align 16
@__const.numToWords.tens_words = external hidden unnamed_addr constant [10 x [10 x i8]], align 16
@__const.numToWords.eleven_nineteen = external hidden unnamed_addr constant [10 x [20 x i8]], align 16

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @numToWords(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca [500 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 500, ptr nonnull %3) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(500) %3, i8 0, i64 500, i1 false)
  %4 = srem i32 %0, 10
  %5 = sdiv i32 %0, 10
  %6 = icmp slt i32 %0, 10
  br i1 %6, label %7, label %11

7:                                                ; preds = %2
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds [10 x [6 x i8]], ptr @__const.numToWords.unit_words, i64 0, i64 %8
  %10 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %9) #4
  br label %27

11:                                               ; preds = %2
  %12 = icmp ne i32 %0, 10
  %13 = icmp ult i32 %0, 20
  %or.cond = and i1 %12, %13
  br i1 %or.cond, label %14, label %18

14:                                               ; preds = %11
  %15 = zext nneg i32 %4 to i64
  %16 = getelementptr inbounds [10 x [20 x i8]], ptr @__const.numToWords.eleven_nineteen, i64 0, i64 %15
  %17 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %16) #4
  br label %27

18:                                               ; preds = %11
  %19 = zext nneg i32 %5 to i64
  %20 = getelementptr inbounds [10 x [10 x i8]], ptr @__const.numToWords.tens_words, i64 0, i64 %19
  %21 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %20) #4
  %22 = icmp sgt i32 %4, 0
  br i1 %22, label %23, label %27

23:                                               ; preds = %18
  %24 = zext nneg i32 %4 to i64
  %25 = getelementptr inbounds [10 x [6 x i8]], ptr @__const.numToWords.unit_words, i64 0, i64 %24
  %26 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %25) #4
  br label %27

27:                                               ; preds = %14, %23, %18, %7
  %28 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) %3) #4
  call void @llvm.lifetime.end.p0(i64 500, ptr nonnull %3) #4
  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 nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #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 #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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) 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: write) }
attributes #3 = { 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 #4 = { 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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass