; LLVM IR from sfu-dis/mosaicdb :: benchmarks/egen/Person.ll (ZN4TPCE7CPerson11GetLastNameEx)

; 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.TPCE::CPerson" = type { ptr, ptr, ptr, %"class.TPCE::CRandom", i8, i32, i64, ptr, ptr }
%"class.TPCE::CRandom" = type { i64 }
%"struct.TPCE::TLastNameInputRow" = type <{ %"struct.TPCE::TBaseInputRow", [26 x i8], [6 x i8] }>
%"struct.TPCE::TBaseInputRow" = type { ptr }

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN4TPCE7CPerson11GetLastNameEx(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 6
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = sub nsw i64 %11, %13
  store i64 %14, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  %15 = load i64, ptr %6, align 8, !tbaa !9
  %16 = icmp sge i64 %15, 0
  br i1 %16, label %17, label %23

17:                                               ; preds = %2
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 5
  %20 = load i32, ptr %19, align 4, !tbaa !16
  %21 = sext i32 %20 to i64
  %22 = icmp slt i64 %18, %21
  br label %23

23:                                               ; preds = %17, %2
  %24 = phi i1 [ false, %2 ], [ %22, %17 ]
  %25 = zext i1 %24 to i8
  store i8 %25, ptr %7, align 1, !tbaa !17
  %26 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 4
  %27 = load i8, ptr %26, align 8, !tbaa !18, !range !19, !noundef !20
  %28 = trunc i8 %27 to i1
  br i1 %28, label %29, label %38

29:                                               ; preds = %23
  %30 = load i8, ptr %7, align 1, !tbaa !17, !range !19, !noundef !20
  %31 = trunc i8 %30 to i1
  br i1 %31, label %32, label %38

32:                                               ; preds = %29
  %33 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 8
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = getelementptr inbounds ptr, ptr %34, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  store ptr %37, ptr %5, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %32, %29, %23
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %75

41:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %42 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 3
  %43 = call noundef i64 @_ZN4TPCE7CRandom7GetSeedEv(ptr noundef nonnull align 8 dereferenceable(8) %42)
  store i64 %43, ptr %8, align 8, !tbaa !9
  %44 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 3
  %45 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 3
  %46 = load i64, ptr %4, align 8, !tbaa !9
  %47 = call noundef i64 @_ZN4TPCE7CRandom13RndNthElementEyy(ptr noundef nonnull align 8 dereferenceable(8) %45, i64 noundef 35846049, i64 noundef %46)
  call void @_ZN4TPCE7CRandom7SetSeedEy(ptr noundef nonnull align 8 dereferenceable(8) %44, i64 noundef %47)
  %48 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 3
  %49 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !22
  %51 = call noundef i32 @_ZN4TPCE10CInputFileINS_17TLastNameInputRowENS_16TLastNamesLimitsEE14GetGreatestKeyEv(ptr noundef nonnull align 8 dereferenceable(40) %50)
  %52 = sub nsw i32 %51, 1
  %53 = call noundef i32 @_ZN4TPCE7CRandom11RndIntRangeEii(ptr noundef nonnull align 8 dereferenceable(8) %48, i32 noundef 0, i32 noundef %52)
  store i32 %53, ptr %9, align 4, !tbaa !23
  %54 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !22
  %56 = load i32, ptr %9, align 4, !tbaa !23
  %57 = call noundef ptr @_ZN4TPCE10CInputFileINS_17TLastNameInputRowENS_16TLastNamesLimitsEE9GetRecordEi(ptr noundef nonnull align 8 dereferenceable(40) %55, i32 noundef %56)
  %58 = getelementptr inbounds %"struct.TPCE::TLastNameInputRow", ptr %57, i32 0, i32 1
  %59 = getelementptr inbounds [26 x i8], ptr %58, i64 0, i64 0
  store ptr %59, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 3
  %61 = load i64, ptr %8, align 8, !tbaa !9
  call void @_ZN4TPCE7CRandom7SetSeedEy(ptr noundef nonnull align 8 dereferenceable(8) %60, i64 noundef %61)
  %62 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 4
  %63 = load i8, ptr %62, align 8, !tbaa !18, !range !19, !noundef !20
  %64 = trunc i8 %63 to i1
  br i1 %64, label %65, label %74

65:                                               ; preds = %41
  %66 = load i8, ptr %7, align 1, !tbaa !17, !range !19, !noundef !20
  %67 = trunc i8 %66 to i1
  br i1 %67, label %68, label %74

68:                                               ; preds = %65
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %"class.TPCE::CPerson", ptr %10, i32 0, i32 8
  %71 = load ptr, ptr %70, align 8, !tbaa !21
  %72 = load i64, ptr %6, align 8, !tbaa !9
  %73 = getelementptr inbounds ptr, ptr %71, i64 %72
  store ptr %69, ptr %73, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %68, %65, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %75

75:                                               ; preds = %74, %38
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret ptr %76
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4TPCE7CRandom7GetSeedEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

declare void @_ZN4TPCE7CRandom7SetSeedEy(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #3

declare noundef i64 @_ZN4TPCE7CRandom13RndNthElementEyy(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef, i64 noundef) #3

declare noundef i32 @_ZN4TPCE7CRandom11RndIntRangeEii(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef, i32 noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4TPCE10CInputFileINS_17TLastNameInputRowENS_16TLastNamesLimitsEE14GetGreatestKeyEv(ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN4TPCE10CInputFileINS_17TLastNameInputRowENS_16TLastNamesLimitsEE9GetRecordEi(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { inlinehint 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 #3 = { "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)"}
!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 = !{!"long long", !7, i64 0}
!11 = !{!12, !10, i64 40}
!12 = !{!"_ZTSN4TPCE7CPersonE", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !14, i64 32, !15, i64 36, !10, i64 40, !6, i64 48, !6, i64 56}
!13 = !{!"_ZTSN4TPCE7CRandomE", !10, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!12, !15, i64 36}
!17 = !{!14, !14, i64 0}
!18 = !{!12, !14, i64 32}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!12, !6, i64 56}
!22 = !{!12, !6, i64 0}
!23 = !{!15, !15, 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"

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull ptr @_ZN4TPCE7CPerson11GetLastNameEx(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = sub nsw i64 %1, %4
  %6 = icmp slt i64 %5, 0
  %7 = getelementptr inbounds i8, ptr %0, i64 36
  %8 = load i32, ptr %7, align 4
  %9 = sext i32 %8 to i64
  %10 = icmp sge i64 %5, %9
  %.not21 = select i1 %6, i1 true, i1 %10
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  %12 = load i8, ptr %11, align 8, !tbaa !14, !range !15, !noundef !16
  %13 = trunc nuw i8 %12 to i1
  %.not = xor i1 %13, true
  %brmerge = select i1 %.not, i1 true, i1 %.not21
  br i1 %brmerge, label %.thread, label %14

14:                                               ; preds = %2
  %15 = getelementptr inbounds i8, ptr %0, i64 56
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  %17 = getelementptr inbounds ptr, ptr %16, i64 %5
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %19 = icmp eq ptr %18, null
  br i1 %19, label %.thread, label %36

.thread:                                          ; preds = %2, %14
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = tail call noundef i64 @_ZN4TPCE7CRandom7GetSeedEv(ptr noundef nonnull align 8 dereferenceable(8) %20)
  %22 = tail call noundef i64 @_ZN4TPCE7CRandom13RndNthElementEyy(ptr noundef nonnull align 8 dereferenceable(8) %20, i64 noundef 35846049, i64 noundef %1)
  tail call void @_ZN4TPCE7CRandom7SetSeedEy(ptr noundef nonnull align 8 dereferenceable(8) %20, i64 noundef %22)
  %23 = load ptr, ptr %0, align 8, !tbaa !19
  %24 = tail call noundef i32 @_ZN4TPCE10CInputFileINS_17TLastNameInputRowENS_16TLastNamesLimitsEE14GetGreatestKeyEv(ptr noundef nonnull align 8 dereferenceable(40) %23)
  %25 = add nsw i32 %24, -1
  %26 = tail call noundef i32 @_ZN4TPCE7CRandom11RndIntRangeEii(ptr noundef nonnull align 8 dereferenceable(8) %20, i32 noundef 0, i32 noundef %25)
  %27 = load ptr, ptr %0, align 8, !tbaa !19
  %28 = tail call noundef ptr @_ZN4TPCE10CInputFileINS_17TLastNameInputRowENS_16TLastNamesLimitsEE9GetRecordEi(ptr noundef nonnull align 8 dereferenceable(40) %27, i32 noundef %26)
  %29 = getelementptr inbounds i8, ptr %28, i64 8
  tail call void @_ZN4TPCE7CRandom7SetSeedEy(ptr noundef nonnull align 8 dereferenceable(8) %20, i64 noundef %21)
  %30 = load i8, ptr %11, align 8, !tbaa !14, !range !15, !noundef !16
  %31 = trunc nuw i8 %30 to i1
  %.not15 = xor i1 %31, true
  %brmerge17 = select i1 %.not15, i1 true, i1 %.not21
  br i1 %brmerge17, label %36, label %32

32:                                               ; preds = %.thread
  %33 = getelementptr inbounds i8, ptr %0, i64 56
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = getelementptr inbounds ptr, ptr %34, i64 %5
  store ptr %29, ptr %35, align 8, !tbaa !18
  br label %36

36:                                               ; preds = %32, %.thread, %14
  %.1 = phi ptr [ %18, %14 ], [ %29, %.thread ], [ %29, %32 ]
  ret ptr %.1
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4TPCE7CRandom7GetSeedEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

declare void @_ZN4TPCE7CRandom7SetSeedEy(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #2

declare noundef i64 @_ZN4TPCE7CRandom13RndNthElementEyy(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef, i64 noundef) local_unnamed_addr #2

declare noundef i32 @_ZN4TPCE7CRandom11RndIntRangeEii(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4TPCE10CInputFileINS_17TLastNameInputRowENS_16TLastNamesLimitsEE14GetGreatestKeyEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN4TPCE10CInputFileINS_17TLastNameInputRowENS_16TLastNamesLimitsEE9GetRecordEi(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) local_unnamed_addr #0 align 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 = { inlinehint 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 #2 = { "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, !11, i64 40}
!6 = !{!"_ZTSN4TPCE7CPersonE", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !12, i64 32, !13, i64 36, !11, i64 40, !7, i64 48, !7, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN4TPCE7CRandomE", !11, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!6, !12, i64 32}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!6, !7, i64 56}
!18 = !{!7, !7, i64 0}
!19 = !{!6, !7, i64 0}


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