; LLVM IR from JessonYue/LeetCodeLearning :: Array/yangxin/第五周练习6_28-7_4/elf解析 (elf)

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

@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.263 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.264 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.265 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.266 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.267 = external hidden unnamed_addr constant [7 x i8], align 1

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @getSectionTypeNameByType(i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @getSectionFlagNameByFlags(i64 noundef, ptr noundef) #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 uwtable
define dso_local void @printElf64_Shdr(i32 noundef %0, ptr noundef byval(%struct.Elf64_Shdr) align 8 %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [24 x i8], align 16
  %7 = alloca i32, align 4
  %8 = alloca [12 x i8], align 1
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %2, ptr %5, align 8, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.263, i32 noundef %9)
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #4
  %11 = getelementptr inbounds [24 x i8], ptr %6, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %11, i8 0, i64 24, i1 false)
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.Elf64_Shdr, ptr %1, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %12, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !14
  %18 = getelementptr inbounds [24 x i8], ptr %6, i64 0, i64 0
  store i8 %17, ptr %18, align 16, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %30, %3
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.Elf64_Shdr, ptr %1, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = add i32 %22, %23
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %20, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !14
  %28 = sext i8 %27 to i32
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %44

30:                                               ; preds = %19
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.Elf64_Shdr, ptr %1, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = add i32 %33, %34
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %31, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !14
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [24 x i8], ptr %6, i64 0, i64 %40
  store i8 %38, ptr %41, align 1, !tbaa !14
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %7, align 4, !tbaa !5
  br label %19, !llvm.loop !15

44:                                               ; preds = %19
  %45 = getelementptr inbounds [24 x i8], ptr %6, i64 0, i64 0
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.264, ptr noundef %45)
  %47 = getelementptr inbounds %struct.Elf64_Shdr, ptr %1, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !17
  %49 = zext i32 %48 to i64
  %50 = call ptr @getSectionTypeNameByType(i64 noundef %49)
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.265, ptr noundef %50)
  call void @llvm.lifetime.start.p0(i64 12, ptr %8) #4
  %52 = getelementptr inbounds %struct.Elf64_Shdr, ptr %1, i32 0, i32 2
  %53 = load i64, ptr %52, align 8, !tbaa !18
  %54 = getelementptr inbounds [12 x i8], ptr %8, i64 0, i64 0
  call void @getSectionFlagNameByFlags(i64 noundef %53, ptr noundef %54)
  %55 = getelementptr inbounds [12 x i8], ptr %8, i64 0, i64 0
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.266, ptr noundef %55)
  %57 = getelementptr inbounds %struct.Elf64_Shdr, ptr %1, i32 0, i32 3
  %58 = load i64, ptr %57, align 8, !tbaa !19
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.267, i64 noundef %58)
  %60 = getelementptr inbounds %struct.Elf64_Shdr, ptr %1, i32 0, i32 4
  %61 = load i64, ptr %60, align 8, !tbaa !20
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.267, i64 noundef %61)
  %63 = getelementptr inbounds %struct.Elf64_Shdr, ptr %1, i32 0, i32 5
  %64 = load i64, ptr %63, align 8, !tbaa !21
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.267, i64 noundef %64)
  %66 = getelementptr inbounds %struct.Elf64_Shdr, ptr %1, i32 0, i32 6
  %67 = load i32, ptr %66, align 8, !tbaa !22
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.267, i32 noundef %67)
  %69 = getelementptr inbounds %struct.Elf64_Shdr, ptr %1, i32 0, i32 7
  %70 = load i32, ptr %69, align 4, !tbaa !23
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.267, i32 noundef %70)
  %72 = getelementptr inbounds %struct.Elf64_Shdr, ptr %1, i32 0, i32 8
  %73 = load i64, ptr %72, align 8, !tbaa !24
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.267, i64 noundef %73)
  %75 = getelementptr inbounds %struct.Elf64_Shdr, ptr %1, i32 0, i32 9
  %76 = load i64, ptr %75, align 8, !tbaa !25
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.267, i64 noundef %76)
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @llvm.lifetime.end.p0(i64 12, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #4
  ret void
}

attributes #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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 4, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !6, i64 40, !6, i64 44, !13, i64 48, !13, i64 56}
!13 = !{!"long", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !6, i64 4}
!18 = !{!12, !13, i64 8}
!19 = !{!12, !13, i64 16}
!20 = !{!12, !13, i64 24}
!21 = !{!12, !13, i64 32}
!22 = !{!12, !6, i64 40}
!23 = !{!12, !6, i64 44}
!24 = !{!12, !13, i64 48}
!25 = !{!12, !13, i64 56}


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

@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.263 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.264 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.265 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.266 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.267 = external hidden unnamed_addr constant [7 x i8], align 1

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @getSectionTypeNameByType(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @getSectionFlagNameByFlags(i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
define dso_local void @printElf64_Shdr(i32 noundef %0, ptr nocapture noundef readonly byval(%struct.Elf64_Shdr) align 8 %1, ptr nocapture noundef readonly %2) local_unnamed_addr #2 {
  %4 = alloca [24 x i8], align 16
  %5 = alloca [12 x i8], align 1
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.263, i32 noundef %0)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %4, i8 0, i64 24, i1 false)
  %7 = load i32, ptr %1, align 8, !tbaa !5
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds i8, ptr %2, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !11
  store i8 %10, ptr %4, align 16, !tbaa !11
  %11 = add i32 %7, 1
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr %2, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %.not7 = icmp eq i8 %14, 0
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %3 ]
  %15 = phi i8 [ %21, %.lr.ph ], [ %14, %3 ]
  %16 = getelementptr inbounds [24 x i8], ptr %4, i64 0, i64 %indvars.iv
  store i8 %15, ptr %16, align 1, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = trunc nuw nsw i64 %indvars.iv.next to i32
  %18 = add i32 %7, %17
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %2, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %.not = icmp eq i8 %21, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %3
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.264, ptr noundef nonnull %4)
  %23 = getelementptr inbounds i8, ptr %1, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = zext i32 %24 to i64
  %26 = call ptr @getSectionTypeNameByType(i64 noundef %25)
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.265, ptr noundef %26)
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %5) #4
  %28 = getelementptr inbounds i8, ptr %1, i64 8
  %29 = load i64, ptr %28, align 8, !tbaa !15
  call void @getSectionFlagNameByFlags(i64 noundef %29, ptr noundef nonnull %5)
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.266, ptr noundef nonnull %5)
  %31 = getelementptr inbounds i8, ptr %1, i64 16
  %32 = load i64, ptr %31, align 8, !tbaa !16
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.267, i64 noundef %32)
  %34 = getelementptr inbounds i8, ptr %1, i64 24
  %35 = load i64, ptr %34, align 8, !tbaa !17
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.267, i64 noundef %35)
  %37 = getelementptr inbounds i8, ptr %1, i64 32
  %38 = load i64, ptr %37, align 8, !tbaa !18
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.267, i64 noundef %38)
  %40 = getelementptr inbounds i8, ptr %1, i64 40
  %41 = load i32, ptr %40, align 8, !tbaa !19
  %42 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.267, i32 noundef %41)
  %43 = getelementptr inbounds i8, ptr %1, i64 44
  %44 = load i32, ptr %43, align 4, !tbaa !20
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.267, i32 noundef %44)
  %46 = getelementptr inbounds i8, ptr %1, i64 48
  %47 = load i64, ptr %46, align 8, !tbaa !21
  %48 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.267, i64 noundef %47)
  %49 = getelementptr inbounds i8, ptr %1, i64 56
  %50 = load i64, ptr %49, align 8, !tbaa !22
  %51 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.267, i64 noundef %50)
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  ret void
}

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !7, i64 44, !10, i64 48, !10, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !7, i64 4}
!15 = !{!6, !10, i64 8}
!16 = !{!6, !10, i64 16}
!17 = !{!6, !10, i64 24}
!18 = !{!6, !10, i64 32}
!19 = !{!6, !7, i64 40}
!20 = !{!6, !7, i64 44}
!21 = !{!6, !10, i64 48}
!22 = !{!6, !10, i64 56}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass