; 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"

@.str.3 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [16 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: nounwind uwtable
define dso_local void @checkElfFile(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca [16 x i8], align 16
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  br i1 %5, label %7, label %6

6:                                                ; preds = %1
  br label %55

7:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #3
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  call void @rewind(ptr noundef %8)
  %9 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 0
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call i64 @fread(ptr noundef %9, i64 noundef 16, i64 noundef 1, ptr noundef %10)
  %12 = icmp eq i64 1, %11
  br i1 %12, label %13, label %52

13:                                               ; preds = %7
  %14 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 0
  %15 = load i8, ptr %14, align 16, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = icmp eq i32 127, %16
  br i1 %17, label %18, label %49

18:                                               ; preds = %13
  %19 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = zext i8 %20 to i32
  %22 = icmp eq i32 69, %21
  br i1 %22, label %23, label %49

23:                                               ; preds = %18
  %24 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 2
  %25 = load i8, ptr %24, align 2, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = icmp eq i32 76, %26
  br i1 %27, label %28, label %49

28:                                               ; preds = %23
  %29 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 3
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = zext i8 %30 to i32
  %32 = icmp eq i32 70, %31
  br i1 %32, label %33, label %49

33:                                               ; preds = %28
  %34 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 4
  %35 = load i8, ptr %34, align 4, !tbaa !9
  %36 = zext i8 %35 to i32
  switch i32 %36, label %43 [
    i32 0, label %37
    i32 1, label %39
    i32 2, label %41
  ]

37:                                               ; preds = %33
  %38 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %48

39:                                               ; preds = %33
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  call void @printfElf32_Message(ptr noundef %40)
  br label %48

41:                                               ; preds = %33
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %48

43:                                               ; preds = %33
  %44 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 4
  %45 = load i8, ptr %44, align 4, !tbaa !9
  %46 = zext i8 %45 to i32
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %46)
  br label %48

48:                                               ; preds = %43, %41, %39, %37
  br label %51

49:                                               ; preds = %28, %23, %18, %13
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  br label %51

51:                                               ; preds = %49, %48
  br label %54

52:                                               ; preds = %7
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %54

54:                                               ; preds = %52, %51
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #3
  br label %55

55:                                               ; preds = %54, %6
  ret void
}

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

declare void @rewind(ptr noundef) #1

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

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

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 }

!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 = !{!7, !7, i64 0}


; 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.3 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [16 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: nounwind uwtable
define dso_local void @checkElfFile(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca [16 x i8], align 16
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %25, label %3

3:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  tail call void @rewind(ptr noundef nonnull %0)
  %4 = call i64 @fread(ptr noundef nonnull %2, i64 noundef 16, i64 noundef 1, ptr noundef nonnull %0)
  %5 = icmp eq i64 %4, 1
  br i1 %5, label %6, label %22

6:                                                ; preds = %3
  %7 = load <4 x i8>, ptr %2, align 16
  %.fr = freeze <4 x i8> %7
  %.fr.scalar = bitcast <4 x i8> %.fr to i32
  %8 = icmp eq i32 %.fr.scalar, 1179403647
  br i1 %8, label %9, label %20

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %2, i64 4
  %11 = load i8, ptr %10, align 4, !tbaa !5
  switch i8 %11, label %17 [
    i8 0, label %12
    i8 1, label %14
    i8 2, label %15
  ]

12:                                               ; preds = %9
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %24

14:                                               ; preds = %9
  tail call void @printfElf32_Message(ptr noundef nonnull %0)
  br label %24

15:                                               ; preds = %9
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %24

17:                                               ; preds = %9
  %18 = zext i8 %11 to i32
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %18)
  br label %24

20:                                               ; preds = %6
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  br label %24

22:                                               ; preds = %3
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %24

24:                                               ; preds = %20, %17, %15, %14, %12, %22
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  br label %25

25:                                               ; preds = %1, %24
  ret void
}

; 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 void @rewind(ptr nocapture 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: nounwind uwtable
declare dso_local void @printfElf32_Message(ptr noundef) local_unnamed_addr #2

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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass