; LLVM IR from JessonYue/LeetCodeLearning :: Array/caiweixiong/c (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.241 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.242 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.243 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.244 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.245 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.246 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.247 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.248 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.249 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.250 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.251 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.252 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.253 = external hidden unnamed_addr constant [26 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

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

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

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #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 [16 x i8], align 16
  %10 = alloca [12 x i8], align 1
  %11 = 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
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = call i32 @fseek(ptr noundef %12, i64 noundef %14, i32 noundef 0)
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call i64 @ftell(ptr noundef %16)
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.241, i64 noundef %17)
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.242)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = mul i64 %21, 32
  %23 = call noalias ptr @malloc(i64 noundef %22) #6
  store ptr %23, ptr %7, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i64 @fread(ptr noundef %26, i64 noundef 32, i64 noundef %28, ptr noundef %29)
  %31 = icmp eq i64 %25, %30
  br i1 %31, label %32, label %76

32:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %33, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 12, ptr %10) #5
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.243, ptr noundef @.str.244, ptr noundef @.str.245, ptr noundef @.str.246, ptr noundef @.str.247, ptr noundef @.str.248, ptr noundef @.str.249, ptr noundef @.str.250, ptr noundef @.str.251)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %70, %32
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %75

40:                                               ; preds = %35
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Elf32_Phdr, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = getelementptr inbounds [16 x i8], ptr %9, i64 0, i64 0
  call void @getSegmentTypeNameByType(i32 noundef %43, ptr noundef %44)
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Elf32_Phdr, ptr %45, i32 0, i32 6
  %47 = load i32, ptr %46, align 4, !tbaa !13
  %48 = getelementptr inbounds [12 x i8], ptr %10, i64 0, i64 0
  call void @getSegmentFlagNameByFlags(i32 noundef %47, ptr noundef %48)
  %49 = getelementptr inbounds [16 x i8], ptr %9, i64 0, i64 0
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Elf32_Phdr, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !14
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Elf32_Phdr, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 4, !tbaa !15
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.Elf32_Phdr, ptr %56, i32 0, i32 3
  %58 = load i32, ptr %57, align 4, !tbaa !16
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Elf32_Phdr, ptr %59, i32 0, i32 4
  %61 = load i32, ptr %60, align 4, !tbaa !17
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Elf32_Phdr, ptr %62, i32 0, i32 5
  %64 = load i32, ptr %63, align 4, !tbaa !18
  %65 = getelementptr inbounds [12 x i8], ptr %10, i64 0, i64 0
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.Elf32_Phdr, ptr %66, i32 0, i32 7
  %68 = load i32, ptr %67, align 4, !tbaa !19
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.252, ptr noundef %49, i32 noundef %52, i32 noundef %55, i32 noundef %58, i32 noundef %61, i32 noundef %64, ptr noundef %65, i32 noundef %68)
  br label %70

70:                                               ; preds = %40
  %71 = load i32, ptr %11, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %11, align 4, !tbaa !9
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.Elf32_Phdr, ptr %73, i32 1
  store ptr %74, ptr %8, align 8, !tbaa !5
  br label %35, !llvm.loop !20

75:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 12, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %78

76:                                               ; preds = %3
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.253)
  br label %78

78:                                               ; preds = %76, %75
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %79) #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) #1

declare i64 @ftell(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @getSegmentTypeNameByType(i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @getSegmentFlagNameByFlags(i32 noundef, ptr noundef) #2

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

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 = { 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 24}
!14 = !{!12, !10, i64 4}
!15 = !{!12, !10, i64 8}
!16 = !{!12, !10, i64 12}
!17 = !{!12, !10, i64 16}
!18 = !{!12, !10, i64 20}
!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.241 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.242 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.243 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.244 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.245 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.246 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.247 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.248 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.249 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.250 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.251 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.252 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.253 = external hidden unnamed_addr constant [26 x i8], align 1

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

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

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

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

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

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %5) #6
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.243, ptr noundef nonnull @.str.244, ptr noundef nonnull @.str.245, ptr noundef nonnull @.str.246, ptr noundef nonnull @.str.247, ptr noundef nonnull @.str.248, ptr noundef nonnull @.str.249, ptr noundef nonnull @.str.250, ptr noundef nonnull @.str.251)
  %18 = icmp sgt i32 %2, 0
  br i1 %18, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %16
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #6
  br label %39

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

37:                                               ; preds = %3
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.253)
  br label %39

39:                                               ; preds = %37, %._crit_edge
  call void @free(ptr noundef %13) #6
  ret void
}

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

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

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

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

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #4 = { 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 #5 = { nounwind allocsize(0) }
attributes #6 = { 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 24}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 12}
!14 = !{!6, !7, i64 16}
!15 = !{!6, !7, i64 20}
!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