; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2015-16/Open 2016/Plat/bcs_editorial.ll (Z3getc)

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

%"struct.std::array" = type { [2 x %struct.mi] }
%struct.mi = type { i32 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2miC2Ex(ptr noundef nonnull align 4 dereferenceable(4), i64 noundef) unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local i64 @_Z3getc(i8 noundef signext %0) #1 {
  %2 = alloca %"struct.std::array", align 4
  %3 = alloca i8, align 1
  store i8 %0, ptr %3, align 1, !tbaa !5
  %4 = getelementptr inbounds %"struct.std::array", ptr %2, i32 0, i32 0
  %5 = load i8, ptr %3, align 1, !tbaa !5
  %6 = call noundef i32 @_Z3valc(i8 noundef signext %5)
  %7 = sext i32 %6 to i64
  call void @_ZN2miC2Ex(ptr noundef nonnull align 4 dereferenceable(4) %4, i64 noundef %7)
  %8 = getelementptr inbounds %struct.mi, ptr %4, i64 1
  %9 = load i8, ptr %3, align 1, !tbaa !5
  %10 = call noundef i32 @_Z3valc(i8 noundef signext %9)
  %11 = sext i32 %10 to i64
  call void @_ZN2miC2Ex(ptr noundef nonnull align 4 dereferenceable(4) %8, i64 noundef %11)
  %12 = getelementptr inbounds %"struct.std::array", ptr %2, i32 0, i32 0
  %13 = load i64, ptr %12, align 4
  ret i64 %13
}

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

!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"}


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

%"struct.std::array" = type { [2 x %struct.mi] }
%struct.mi = type { i32 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2miC2Ex(ptr noundef nonnull align 4 dereferenceable(4), i64 noundef) unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local i64 @_Z3getc(i8 noundef signext %0) local_unnamed_addr #0 {
  %2 = alloca %"struct.std::array", align 8
  %3 = tail call noundef i32 @_Z3valc(i8 noundef signext %0)
  %4 = sext i32 %3 to i64
  call void @_ZN2miC2Ex(ptr noundef nonnull align 4 dereferenceable(4) %2, i64 noundef %4)
  %5 = getelementptr inbounds i8, ptr %2, i64 4
  %6 = call noundef i32 @_Z3valc(i8 noundef signext %0)
  %7 = sext i32 %6 to i64
  call void @_ZN2miC2Ex(ptr noundef nonnull align 4 dereferenceable(4) %5, i64 noundef %7)
  %8 = load i64, ptr %2, align 8
  ret i64 %8
}

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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass