; LLVM IR from JessonYue/LeetCodeLearning :: Array/huangxinyu/homework/readelf.ll (Z12printElfPhdrP10Elf64_PhdrP10Elf64_Ehdr)

; 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.Elf64_Ehdr = type { [16 x i8], i16, i16, i32, i64, i64, i64, i32, i16, i16, i16, i16, i16, i16 }
%struct.Elf64_Phdr = type { i32, i32, i64, i64, i64, i64, i64, i64 }

@.str.22 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [27 x i8], align 1

; 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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z12printElfPhdrP10Elf64_PhdrP10Elf64_Ehdr(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.22)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %56, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Elf64_Ehdr, ptr %10, i32 0, i32 10
  %12 = load i16, ptr %11, align 8, !tbaa !11
  %13 = zext i16 %12 to i32
  %14 = icmp slt i32 %9, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %59

16:                                               ; preds = %8
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.23)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds %struct.Elf64_Phdr, ptr %18, i64 %20
  store ptr %21, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Elf64_Phdr, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !15
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.24, i32 noundef %24)
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Elf64_Phdr, ptr %26, i32 0, i32 2
  %28 = load i64, ptr %27, align 8, !tbaa !17
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.25, i64 noundef %28)
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Elf64_Phdr, ptr %30, i32 0, i32 3
  %32 = load i64, ptr %31, align 8, !tbaa !18
  %33 = trunc i64 %32 to i32
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.26, i32 noundef %33)
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Elf64_Phdr, ptr %35, i32 0, i32 4
  %37 = load i64, ptr %36, align 8, !tbaa !19
  %38 = trunc i64 %37 to i32
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.27, i32 noundef %38)
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Elf64_Phdr, ptr %40, i32 0, i32 5
  %42 = load i64, ptr %41, align 8, !tbaa !20
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.28, i64 noundef %42)
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Elf64_Phdr, ptr %44, i32 0, i32 6
  %46 = load i64, ptr %45, align 8, !tbaa !21
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.29, i64 noundef %46)
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Elf64_Phdr, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !22
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.30, i32 noundef %50)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Elf64_Phdr, ptr %52, i32 0, i32 7
  %54 = load i64, ptr %53, align 8, !tbaa !23
  %55 = call i32 (ptr, ...) @printf(ptr noundef @.str.31, i64 noundef %54)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %56

56:                                               ; preds = %16
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !24

59:                                               ; preds = %15
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #2 = { 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 #3 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 56}
!12 = !{!"_ZTS10Elf64_Ehdr", !7, i64 0, !13, i64 16, !13, i64 18, !10, i64 20, !14, i64 24, !14, i64 32, !14, i64 40, !10, i64 48, !13, i64 52, !13, i64 54, !13, i64 56, !13, i64 58, !13, i64 60, !13, i64 62}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTS10Elf64_Phdr", !10, i64 0, !10, i64 4, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48}
!17 = !{!16, !14, i64 8}
!18 = !{!16, !14, i64 16}
!19 = !{!16, !14, i64 24}
!20 = !{!16, !14, i64 32}
!21 = !{!16, !14, i64 40}
!22 = !{!16, !10, i64 4}
!23 = !{!16, !14, i64 48}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; 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.Elf64_Phdr = type { i32, i32, i64, i64, i64, i64, i64, i64 }

@.str.22 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: mustprogress nofree noreturn nounwind uwtable
define dso_local noundef i32 @_Z12printElfPhdrP10Elf64_PhdrP10Elf64_Ehdr(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.22)
  %4 = getelementptr inbounds i8, ptr %1, i64 56
  br label %5

5:                                                ; preds = %5, %2
  %indvars.iv = phi i64 [ %indvars.iv.next, %5 ], [ 0, %2 ]
  %6 = load i16, ptr %4, align 8, !tbaa !5
  %7 = zext i16 %6 to i64
  %8 = icmp ult i64 %indvars.iv, %7
  tail call void @llvm.assume(i1 %8)
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.23)
  %10 = getelementptr inbounds %struct.Elf64_Phdr, ptr %0, i64 %indvars.iv
  %11 = load i32, ptr %10, align 8, !tbaa !12
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.24, i32 noundef %11)
  %13 = getelementptr inbounds i8, ptr %10, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !14
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.25, i64 noundef %14)
  %16 = getelementptr inbounds i8, ptr %10, i64 16
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %18 = trunc i64 %17 to i32
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.26, i32 noundef %18)
  %20 = getelementptr inbounds i8, ptr %10, i64 24
  %21 = load i64, ptr %20, align 8, !tbaa !16
  %22 = trunc i64 %21 to i32
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.27, i32 noundef %22)
  %24 = getelementptr inbounds i8, ptr %10, i64 32
  %25 = load i64, ptr %24, align 8, !tbaa !17
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.28, i64 noundef %25)
  %27 = getelementptr inbounds i8, ptr %10, i64 40
  %28 = load i64, ptr %27, align 8, !tbaa !18
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.29, i64 noundef %28)
  %30 = getelementptr inbounds i8, ptr %10, i64 4
  %31 = load i32, ptr %30, align 4, !tbaa !19
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.30, i32 noundef %31)
  %33 = getelementptr inbounds i8, ptr %10, i64 48
  %34 = load i64, ptr %33, align 8, !tbaa !20
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.31, i64 noundef %34)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br label %5, !llvm.loop !21
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #2

attributes #0 = { nofree 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 #1 = { mustprogress nofree noreturn 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 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }

!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, !9, i64 56}
!6 = !{!"_ZTS10Elf64_Ehdr", !7, i64 0, !9, i64 16, !9, i64 18, !10, i64 20, !11, i64 24, !11, i64 32, !11, i64 40, !10, i64 48, !9, i64 52, !9, i64 54, !9, i64 56, !9, i64 58, !9, i64 60, !9, i64 62}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"_ZTS10Elf64_Phdr", !10, i64 0, !10, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48}
!14 = !{!13, !11, i64 8}
!15 = !{!13, !11, i64 16}
!16 = !{!13, !11, i64 24}
!17 = !{!13, !11, i64 32}
!18 = !{!13, !11, i64 40}
!19 = !{!13, !10, i64 4}
!20 = !{!13, !11, i64 48}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass