; LLVM IR from JessonYue/LeetCodeLearning :: BaseDataStructure/elf (soparse)

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

@.str.25 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [42 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 @fseek(ptr noundef, i64 noundef, i32 noundef) #1

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @parseSoPargramHeader(ptr dead_on_unwind noalias writable sret(%struct.DataOffest) align 4 %0, ptr noundef %1, ptr noundef byval(%struct.DataOffest) align 8 %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca i32, align 4
  %8 = alloca %struct.Elf32_Phdr, align 4
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #4
  %9 = getelementptr inbounds %struct.DataOffest, ptr %2, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = trunc i32 %10 to i16
  store i16 %11, ptr %5, align 2, !tbaa !13
  store i32 0, ptr %7, align 4, !tbaa !14
  br label %12

12:                                               ; preds = %69, %3
  %13 = load i32, ptr %7, align 4, !tbaa !14
  %14 = getelementptr inbounds %struct.DataOffest, ptr %2, i32 0, i32 1
  %15 = load i16, ptr %14, align 4, !tbaa !15
  %16 = zext i16 %15 to i32
  %17 = icmp slt i32 %13, %16
  br i1 %17, label %18, label %72

18:                                               ; preds = %12
  %19 = load i16, ptr %5, align 2, !tbaa !13
  %20 = zext i16 %19 to i32
  %21 = load i32, ptr %7, align 4, !tbaa !14
  %22 = mul nsw i32 %21, 32
  %23 = add nsw i32 %20, %22
  %24 = trunc i32 %23 to i16
  store i16 %24, ptr %6, align 2, !tbaa !13
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i16, ptr %6, align 2, !tbaa !13
  %27 = zext i16 %26 to i64
  %28 = call i32 @fseek(ptr noundef %25, i64 noundef %27, i32 noundef 0)
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i64 @fread(ptr noundef %8, i64 noundef 1, i64 noundef 32, ptr noundef %29)
  %31 = getelementptr inbounds %struct.Elf32_Phdr, ptr %8, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !16
  switch i32 %32, label %40 [
    i32 2, label %33
  ]

33:                                               ; preds = %18
  %34 = getelementptr inbounds %struct.Elf32_Phdr, ptr %8, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !18
  %36 = getelementptr inbounds %struct.DataOffest, ptr %2, i32 0, i32 4
  store i32 %35, ptr %36, align 8, !tbaa !19
  %37 = getelementptr inbounds %struct.Elf32_Phdr, ptr %8, i32 0, i32 4
  %38 = load i32, ptr %37, align 4, !tbaa !20
  %39 = getelementptr inbounds %struct.DataOffest, ptr %2, i32 0, i32 5
  store i32 %38, ptr %39, align 4, !tbaa !21
  br label %41

40:                                               ; preds = %18
  br label %41

41:                                               ; preds = %40, %33
  %42 = load i32, ptr %7, align 4, !tbaa !14
  %43 = add nsw i32 %42, 1
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.25, i32 noundef %43)
  %45 = getelementptr inbounds %struct.Elf32_Phdr, ptr %8, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !16
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.26, i32 noundef %46)
  %48 = getelementptr inbounds %struct.Elf32_Phdr, ptr %8, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !18
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.27, i32 noundef %49)
  %51 = getelementptr inbounds %struct.Elf32_Phdr, ptr %8, i32 0, i32 2
  %52 = load i32, ptr %51, align 4, !tbaa !22
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.28, i32 noundef %52)
  %54 = getelementptr inbounds %struct.Elf32_Phdr, ptr %8, i32 0, i32 3
  %55 = load i32, ptr %54, align 4, !tbaa !23
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.29, i32 noundef %55)
  %57 = getelementptr inbounds %struct.Elf32_Phdr, ptr %8, i32 0, i32 4
  %58 = load i32, ptr %57, align 4, !tbaa !20
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.30, i32 noundef %58)
  %60 = getelementptr inbounds %struct.Elf32_Phdr, ptr %8, i32 0, i32 5
  %61 = load i32, ptr %60, align 4, !tbaa !24
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.31, i32 noundef %61)
  %63 = getelementptr inbounds %struct.Elf32_Phdr, ptr %8, i32 0, i32 6
  %64 = load i32, ptr %63, align 4, !tbaa !25
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.32, i32 noundef %64)
  %66 = getelementptr inbounds %struct.Elf32_Phdr, ptr %8, i32 0, i32 7
  %67 = load i32, ptr %66, align 4, !tbaa !26
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.33, i32 noundef %67)
  br label %69

69:                                               ; preds = %41
  %70 = load i32, ptr %7, align 4, !tbaa !14
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %7, align 4, !tbaa !14
  br label %12, !llvm.loop !27

72:                                               ; preds = %12
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 8 %2, i64 60, i1 false), !tbaa.struct !29
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #4
  ret void
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"DataOffest", !11, i64 0, !12, i64 4, !11, i64 8, !12, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !12, i64 48, !11, i64 52, !11, i64 56}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !12, i64 4}
!16 = !{!17, !11, i64 0}
!17 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!18 = !{!17, !11, i64 4}
!19 = !{!10, !11, i64 16}
!20 = !{!17, !11, i64 16}
!21 = !{!10, !11, i64 20}
!22 = !{!17, !11, i64 8}
!23 = !{!17, !11, i64 12}
!24 = !{!17, !11, i64 20}
!25 = !{!17, !11, i64 24}
!26 = !{!17, !11, i64 28}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = !{i64 0, i64 4, !14, i64 4, i64 2, !13, i64 8, i64 4, !14, i64 12, i64 2, !13, i64 16, i64 4, !14, i64 20, i64 4, !14, i64 24, i64 4, !14, i64 28, i64 4, !14, i64 32, i64 4, !14, i64 36, i64 4, !14, i64 40, i64 4, !14, i64 44, i64 4, !14, i64 48, i64 2, !13, i64 52, i64 4, !14, i64 56, i64 4, !14}


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

@.str.25 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [42 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 @fseek(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; 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 uwtable
define dso_local void @parseSoPargramHeader(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.DataOffest) align 4 %0, ptr nocapture noundef %1, ptr nocapture noundef byval(%struct.DataOffest) align 8 %2) local_unnamed_addr #3 {
  %4 = alloca %struct.Elf32_Phdr, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  %5 = load i32, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %2, i64 4
  %7 = load i16, ptr %6, align 4, !tbaa !11
  %8 = zext i16 %7 to i32
  %.not = icmp eq i16 %7, 0
  br i1 %.not, label %47, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %9 = getelementptr inbounds i8, ptr %4, i64 4
  %10 = getelementptr inbounds i8, ptr %2, i64 16
  %11 = getelementptr inbounds i8, ptr %4, i64 16
  %12 = getelementptr inbounds i8, ptr %2, i64 20
  %13 = getelementptr inbounds i8, ptr %4, i64 8
  %14 = getelementptr inbounds i8, ptr %4, i64 12
  %15 = getelementptr inbounds i8, ptr %4, i64 20
  %16 = getelementptr inbounds i8, ptr %4, i64 24
  %17 = getelementptr inbounds i8, ptr %4, i64 28
  %.promoted = load i32, ptr %10, align 8, !tbaa !12
  %.promoted8 = load i32, ptr %12, align 4, !tbaa !13
  br label %18

18:                                               ; preds = %.lr.ph, %18
  %19 = phi i32 [ %.promoted8, %.lr.ph ], [ %30, %18 ]
  %20 = phi i32 [ %.promoted, %.lr.ph ], [ %31, %18 ]
  %.07 = phi i32 [ 0, %.lr.ph ], [ %32, %18 ]
  %21 = shl nuw nsw i32 %.07, 5
  %22 = add i32 %21, %5
  %23 = and i32 %22, 65535
  %24 = zext nneg i32 %23 to i64
  %25 = tail call i32 @fseek(ptr noundef %1, i64 noundef %24, i32 noundef 0)
  %26 = call i64 @fread(ptr noundef nonnull %4, i64 noundef 1, i64 noundef 32, ptr noundef %1)
  %27 = load i32, ptr %4, align 4, !tbaa !14
  %cond = icmp eq i32 %27, 2
  %28 = load i32, ptr %9, align 4
  %29 = load i32, ptr %11, align 4
  %30 = select i1 %cond, i32 %29, i32 %19
  %31 = select i1 %cond, i32 %28, i32 %20
  %32 = add nuw nsw i32 %.07, 1
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.25, i32 noundef %32)
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.26, i32 noundef %27)
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.27, i32 noundef %28)
  %36 = load i32, ptr %13, align 4, !tbaa !16
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.28, i32 noundef %36)
  %38 = load i32, ptr %14, align 4, !tbaa !17
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.29, i32 noundef %38)
  %40 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.30, i32 noundef %29)
  %41 = load i32, ptr %15, align 4, !tbaa !18
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.31, i32 noundef %41)
  %43 = load i32, ptr %16, align 4, !tbaa !19
  %44 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.32, i32 noundef %43)
  %45 = load i32, ptr %17, align 4, !tbaa !20
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.33, i32 noundef %45)
  %exitcond.not = icmp eq i32 %32, %8
  br i1 %exitcond.not, label %._crit_edge, label %18, !llvm.loop !21

._crit_edge:                                      ; preds = %18
  store i32 %31, ptr %10, align 8, !tbaa !12
  store i32 %30, ptr %12, align 4, !tbaa !13
  br label %47

47:                                               ; preds = %._crit_edge, %3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(60) %0, ptr noundef nonnull align 8 dereferenceable(60) %2, i64 60, i1 false), !tbaa.struct !23
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  ret void
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass