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

@.str.268 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.269 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.270 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.271 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.272 = external hidden unnamed_addr constant [26 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
define dso_local void @printfElf32_PhdrMessage(ptr noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = call i32 @fseek(ptr noundef %10, i64 noundef %12, i32 noundef 0)
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call i64 @ftell(ptr noundef %14)
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str.268, i64 noundef %15)
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.269)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = mul i64 %19, 32
  %21 = call noalias ptr @malloc(i64 noundef %20) #6
  store ptr %21, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = call i64 @fread(ptr noundef %24, i64 noundef 32, i64 noundef %26, ptr noundef %27)
  %29 = icmp eq i64 %23, %28
  br i1 %29, label %30, label %70

30:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %31, ptr %8, align 8, !tbaa !5
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str.270)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %64, %30
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %69

38:                                               ; preds = %33
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Elf32_Phdr, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Elf32_Phdr, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !13
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Elf32_Phdr, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 4, !tbaa !14
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Elf32_Phdr, ptr %48, i32 0, i32 3
  %50 = load i32, ptr %49, align 4, !tbaa !15
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.Elf32_Phdr, ptr %51, i32 0, i32 4
  %53 = load i32, ptr %52, align 4, !tbaa !16
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Elf32_Phdr, ptr %54, i32 0, i32 5
  %56 = load i32, ptr %55, align 4, !tbaa !17
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Elf32_Phdr, ptr %57, i32 0, i32 6
  %59 = load i32, ptr %58, align 4, !tbaa !18
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Elf32_Phdr, ptr %60, i32 0, i32 7
  %62 = load i32, ptr %61, align 4, !tbaa !19
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.271, i32 noundef %41, i32 noundef %44, i32 noundef %47, i32 noundef %50, i32 noundef %53, i32 noundef %56, i32 noundef %59, i32 noundef %62)
  br label %64

64:                                               ; preds = %38
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %9, align 4, !tbaa !9
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.Elf32_Phdr, ptr %67, i32 1
  store ptr %68, ptr %8, align 8, !tbaa !5
  br label %33, !llvm.loop !20

69:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %72

70:                                               ; preds = %3
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.272)
  br label %72

72:                                               ; preds = %70, %69
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %73) #5
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void
}

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #0

declare i64 @ftell(ptr noundef) #0

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

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 = { nounwind allocsize(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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 12}
!16 = !{!12, !10, i64 16}
!17 = !{!12, !10, i64 20}
!18 = !{!12, !10, i64 24}
!19 = !{!12, !10, i64 28}
!20 = distinct !{!20, !21}
!21 = !{!"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"

@.str.268 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.269 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.270 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.271 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.272 = external hidden unnamed_addr constant [26 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @printfElf32_PhdrMessage(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = sext i32 %1 to i64
  %5 = tail call i32 @fseek(ptr noundef %0, i64 noundef %4, i32 noundef 0)
  %6 = tail call i64 @ftell(ptr noundef %0)
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.268, i64 noundef %6)
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.269)
  %9 = sext i32 %2 to i64
  %10 = shl nsw i64 %9, 5
  %11 = tail call noalias ptr @malloc(i64 noundef %10) #4
  %12 = tail call i64 @fread(ptr noundef %11, i64 noundef 32, i64 noundef %9, ptr noundef %0)
  %13 = icmp eq i64 %12, %9
  br i1 %13, label %14, label %35

14:                                               ; preds = %3
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.270)
  %16 = icmp sgt i32 %2, 0
  br i1 %16, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %14, %.lr.ph
  %.023 = phi i32 [ %33, %.lr.ph ], [ 0, %14 ]
  %.02122 = phi ptr [ %34, %.lr.ph ], [ %11, %14 ]
  %17 = load i32, ptr %.02122, align 4, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.02122, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !10
  %20 = getelementptr inbounds i8, ptr %.02122, i64 8
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %.02122, i64 12
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = getelementptr inbounds i8, ptr %.02122, i64 16
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %.02122, i64 20
  %27 = load i32, ptr %26, align 4, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %.02122, i64 24
  %29 = load i32, ptr %28, align 4, !tbaa !15
  %30 = getelementptr inbounds i8, ptr %.02122, i64 28
  %31 = load i32, ptr %30, align 4, !tbaa !16
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.271, i32 noundef %17, i32 noundef %19, i32 noundef %21, i32 noundef %23, i32 noundef %25, i32 noundef %27, i32 noundef %29, i32 noundef %31)
  %33 = add nuw nsw i32 %.023, 1
  %34 = getelementptr inbounds i8, ptr %.02122, i64 32
  %exitcond.not = icmp eq i32 %33, %2
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !17

35:                                               ; preds = %3
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.272)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %14, %35
  tail call void @free(ptr noundef %11) #5
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @fseek(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i64 @ftell(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

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 = { 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }
attributes #5 = { 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, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 12}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !7, i64 20}
!15 = !{!6, !7, i64 24}
!16 = !{!6, !7, i64 28}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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