; LLVM IR from imeplusplus/icpc-notebook :: strings/eertree.ll (Z10add_letterc)

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

@s = external dso_local global [1000007 x i8], align 16
@len = external dso_local global [1000007 x i32], align 16
@link = external dso_local global [1000007 x i32], align 16
@to = external dso_local global [26 x [1000007 x i32]], align 16
@n = external dso_local global i32, align 4
@last = external dso_local global i32, align 4
@sz = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z8get_linki(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z10add_letterc(i8 noundef signext %0) #0 {
  %2 = alloca i8, align 1
  store i8 %0, ptr %2, align 1, !tbaa !5
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !8
  %5 = add nsw i32 %4, 1
  store i32 %5, ptr @n, align 4, !tbaa !8
  %6 = sext i32 %4 to i64
  %7 = getelementptr inbounds [1000007 x i8], ptr @s, i64 0, i64 %6
  store i8 %3, ptr %7, align 1, !tbaa !5
  %8 = load i32, ptr @last, align 4, !tbaa !8
  %9 = call noundef i32 @_Z8get_linki(i32 noundef %8)
  store i32 %9, ptr @last, align 4, !tbaa !8
  %10 = load i8, ptr %2, align 1, !tbaa !5
  %11 = sext i8 %10 to i32
  %12 = sub nsw i32 %11, 97
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [26 x [1000007 x i32]], ptr @to, i64 0, i64 %13
  %15 = load i32, ptr @last, align 4, !tbaa !8
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1000007 x i32], ptr %14, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !8
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %55, label %20

20:                                               ; preds = %1
  %21 = load i32, ptr @last, align 4, !tbaa !8
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1000007 x i32], ptr @len, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !8
  %25 = add nsw i32 %24, 2
  %26 = load i32, ptr @sz, align 4, !tbaa !8
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1000007 x i32], ptr @len, i64 0, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !8
  %29 = load i8, ptr %2, align 1, !tbaa !5
  %30 = sext i8 %29 to i32
  %31 = sub nsw i32 %30, 97
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [26 x [1000007 x i32]], ptr @to, i64 0, i64 %32
  %34 = load i32, ptr @last, align 4, !tbaa !8
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [1000007 x i32], ptr @link, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !8
  %38 = call noundef i32 @_Z8get_linki(i32 noundef %37)
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1000007 x i32], ptr %33, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !8
  %42 = load i32, ptr @sz, align 4, !tbaa !8
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1000007 x i32], ptr @link, i64 0, i64 %43
  store i32 %41, ptr %44, align 4, !tbaa !8
  %45 = load i32, ptr @sz, align 4, !tbaa !8
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr @sz, align 4, !tbaa !8
  %47 = load i8, ptr %2, align 1, !tbaa !5
  %48 = sext i8 %47 to i32
  %49 = sub nsw i32 %48, 97
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [26 x [1000007 x i32]], ptr @to, i64 0, i64 %50
  %52 = load i32, ptr @last, align 4, !tbaa !8
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1000007 x i32], ptr %51, i64 0, i64 %53
  store i32 %45, ptr %54, align 4, !tbaa !8
  br label %55

55:                                               ; preds = %20, %1
  %56 = load i8, ptr %2, align 1, !tbaa !5
  %57 = sext i8 %56 to i32
  %58 = sub nsw i32 %57, 97
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [26 x [1000007 x i32]], ptr @to, i64 0, i64 %59
  %61 = load i32, ptr @last, align 4, !tbaa !8
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [1000007 x i32], ptr %60, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !8
  store i32 %64, ptr @last, align 4, !tbaa !8
  ret void
}

attributes #0 = { mustprogress 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" }

!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 = !{!9, !9, i64 0}
!9 = !{!"int", !6, 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"

@s = external dso_local local_unnamed_addr global [1000007 x i8], align 16
@len = external dso_local local_unnamed_addr global [1000007 x i32], align 16
@link = external dso_local local_unnamed_addr global [1000007 x i32], align 16
@to = external dso_local local_unnamed_addr global [26 x [1000007 x i32]], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@last = external dso_local local_unnamed_addr global i32, align 4
@sz = external dso_local local_unnamed_addr global i32, align 4

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z10add_letterc(i8 noundef signext %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @n, align 4, !tbaa !5
  %4 = sext i32 %2 to i64
  %5 = getelementptr inbounds [1000007 x i8], ptr @s, i64 0, i64 %4
  store i8 %0, ptr %5, align 1, !tbaa !9
  %6 = load i32, ptr @last, align 4, !tbaa !5
  %7 = tail call noundef i32 @_Z8get_linki(i32 noundef %6)
  store i32 %7, ptr @last, align 4, !tbaa !5
  %8 = sext i8 %0 to i64
  %9 = add nsw i64 %8, -97
  %10 = sext i32 %7 to i64
  %11 = getelementptr inbounds [26 x [1000007 x i32]], ptr @to, i64 0, i64 %9, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %33

13:                                               ; preds = %1
  %14 = getelementptr inbounds [1000007 x i32], ptr @len, i64 0, i64 %10
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %15, 2
  %17 = load i32, ptr @sz, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1000007 x i32], ptr @len, i64 0, i64 %18
  store i32 %16, ptr %19, align 4, !tbaa !5
  %20 = getelementptr inbounds [1000007 x i32], ptr @link, i64 0, i64 %10
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = tail call noundef i32 @_Z8get_linki(i32 noundef %21)
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [26 x [1000007 x i32]], ptr @to, i64 0, i64 %9, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = load i32, ptr @sz, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1000007 x i32], ptr @link, i64 0, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !5
  %29 = add nsw i32 %26, 1
  store i32 %29, ptr @sz, align 4, !tbaa !5
  %30 = load i32, ptr @last, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [26 x [1000007 x i32]], ptr @to, i64 0, i64 %9, i64 %31
  store i32 %26, ptr %32, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %13, %1
  %34 = phi i32 [ %26, %13 ], [ %12, %1 ]
  store i32 %34, ptr @last, align 4, !tbaa !5
  ret void
}

attributes #0 = { mustprogress 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" }

!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++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass