; LLVM IR from ybj366533/YY-Camera :: yy_videolib/src/main/jni/png/contrib/gregbook (readppm)

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

@stderr = external global ptr, align 8
@readpng_init.ppmline = external hidden global [256 x i8], align 16
@saved_infile = external dso_local global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [24 x i8], align 1
@color_type = external dso_local global i32, align 4
@channels = external dso_local global i32, align 4
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@width = external dso_local global i64, align 8
@height = external dso_local global i64, align 8
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@bit_depth = external dso_local global i32, align 4

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @readpng_init(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %10, ptr @saved_infile, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call ptr @fgets(ptr noundef @readpng_init.ppmline, i32 noundef 256, ptr noundef %11)
  %13 = load i8, ptr @readpng_init.ppmline, align 16, !tbaa !9
  %14 = zext i8 %13 to i32
  %15 = icmp ne i32 %14, 80
  br i1 %15, label %20, label %16

16:                                               ; preds = %3
  %17 = load i8, ptr getelementptr inbounds ([256 x i8], ptr @readpng_init.ppmline, i64 0, i64 1), align 1, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = icmp ne i32 %18, 54
  br i1 %19, label %20, label %23

20:                                               ; preds = %16, %3
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str.1) #4
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

23:                                               ; preds = %16
  %24 = load i8, ptr getelementptr inbounds ([256 x i8], ptr @readpng_init.ppmline, i64 0, i64 1), align 1, !tbaa !9
  %25 = zext i8 %24 to i32
  %26 = icmp eq i32 %25, 54
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  store i32 2, ptr @color_type, align 4, !tbaa !10
  store i32 3, ptr @channels, align 4, !tbaa !10
  br label %35

28:                                               ; preds = %23
  %29 = load i8, ptr getelementptr inbounds ([256 x i8], ptr @readpng_init.ppmline, i64 0, i64 1), align 1, !tbaa !9
  %30 = zext i8 %29 to i32
  %31 = icmp eq i32 %30, 56
  br i1 %31, label %32, label %33

32:                                               ; preds = %28
  store i32 6, ptr @color_type, align 4, !tbaa !10
  store i32 4, ptr @channels, align 4, !tbaa !10
  br label %34

33:                                               ; preds = %28
  store i32 0, ptr @color_type, align 4, !tbaa !10
  store i32 1, ptr @channels, align 4, !tbaa !10
  br label %34

34:                                               ; preds = %33, %32
  br label %35

35:                                               ; preds = %34, %27
  br label %36

36:                                               ; preds = %39, %35
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = call ptr @fgets(ptr noundef @readpng_init.ppmline, i32 noundef 256, ptr noundef %37)
  br label %39

39:                                               ; preds = %36
  %40 = load i8, ptr @readpng_init.ppmline, align 16, !tbaa !9
  %41 = zext i8 %40 to i32
  %42 = icmp eq i32 %41, 35
  br i1 %42, label %36, label %43, !llvm.loop !12

43:                                               ; preds = %39
  %44 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef @readpng_init.ppmline, ptr noundef @.str.2, ptr noundef @width, ptr noundef @height) #4
  br label %45

45:                                               ; preds = %48, %43
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = call ptr @fgets(ptr noundef @readpng_init.ppmline, i32 noundef 256, ptr noundef %46)
  br label %48

48:                                               ; preds = %45
  %49 = load i8, ptr @readpng_init.ppmline, align 16, !tbaa !9
  %50 = zext i8 %49 to i32
  %51 = icmp eq i32 %50, 35
  br i1 %51, label %45, label %52, !llvm.loop !14

52:                                               ; preds = %48
  %53 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef @readpng_init.ppmline, ptr noundef @.str.3, ptr noundef %8) #4
  %54 = load i32, ptr %8, align 4, !tbaa !10
  %55 = icmp ne i32 %54, 255
  br i1 %55, label %56, label %60

56:                                               ; preds = %52
  %57 = load ptr, ptr @stderr, align 8, !tbaa !5
  %58 = load i32, ptr %8, align 4, !tbaa !10
  %59 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %57, ptr noundef @.str.4, i32 noundef %58) #4
  store i32 2, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

60:                                               ; preds = %52
  store i32 8, ptr @bit_depth, align 4, !tbaa !10
  %61 = load i64, ptr @width, align 8, !tbaa !15
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %61, ptr %62, align 8, !tbaa !15
  %63 = load i64, ptr @height, align 8, !tbaa !15
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %63, ptr %64, align 8, !tbaa !15
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

65:                                               ; preds = %60, %56, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %66 = load i32, ptr %4, align 4
  ret i32 %66
}

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

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @__isoc99_sscanf(ptr noundef, ptr noundef, ...) #0

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !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"

@stderr = external local_unnamed_addr global ptr, align 8
@readpng_init.ppmline = external hidden global [256 x i8], align 16
@saved_infile = external dso_local local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [24 x i8], align 1
@color_type = external dso_local local_unnamed_addr global i32, align 4
@channels = external dso_local local_unnamed_addr global i32, align 4
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@width = external dso_local global i64, align 8
@height = external dso_local global i64, align 8
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@bit_depth = external dso_local local_unnamed_addr global i32, align 4

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

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 0, 3) i32 @readpng_init(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  store ptr %0, ptr @saved_infile, align 8, !tbaa !5
  %5 = tail call ptr @fgets(ptr noundef nonnull @readpng_init.ppmline, i32 noundef 256, ptr noundef %0)
  %6 = load i8, ptr @readpng_init.ppmline, align 16, !tbaa !9
  %7 = icmp ne i8 %6, 80
  %8 = load i8, ptr getelementptr inbounds (i8, ptr @readpng_init.ppmline, i64 1), align 1
  %9 = icmp ne i8 %8, 54
  %or.cond = select i1 %7, i1 true, i1 %9
  br i1 %or.cond, label %10, label %13

10:                                               ; preds = %3
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.1) #4
  br label %33

13:                                               ; preds = %3
  store i32 2, ptr @color_type, align 4, !tbaa !10
  store i32 3, ptr @channels, align 4, !tbaa !10
  br label %14

14:                                               ; preds = %14, %13
  %15 = tail call ptr @fgets(ptr noundef nonnull @readpng_init.ppmline, i32 noundef 256, ptr noundef %0)
  %16 = load i8, ptr @readpng_init.ppmline, align 16, !tbaa !9
  %17 = icmp eq i8 %16, 35
  br i1 %17, label %14, label %18, !llvm.loop !12

18:                                               ; preds = %14
  %19 = tail call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef nonnull @readpng_init.ppmline, ptr noundef nonnull @.str.2, ptr noundef nonnull @width, ptr noundef nonnull @height) #3
  br label %20

20:                                               ; preds = %20, %18
  %21 = tail call ptr @fgets(ptr noundef nonnull @readpng_init.ppmline, i32 noundef 256, ptr noundef %0)
  %22 = load i8, ptr @readpng_init.ppmline, align 16, !tbaa !9
  %23 = icmp eq i8 %22, 35
  br i1 %23, label %20, label %24, !llvm.loop !14

24:                                               ; preds = %20
  %25 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef nonnull @readpng_init.ppmline, ptr noundef nonnull @.str.3, ptr noundef nonnull %4) #3
  %26 = load i32, ptr %4, align 4, !tbaa !10
  %.not = icmp eq i32 %26, 255
  br i1 %.not, label %30, label %27

27:                                               ; preds = %24
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.4, i32 noundef %26) #4
  br label %33

30:                                               ; preds = %24
  store i32 8, ptr @bit_depth, align 4, !tbaa !10
  %31 = load i64, ptr @width, align 8, !tbaa !15
  store i64 %31, ptr %1, align 8, !tbaa !15
  %32 = load i64, ptr @height, align 8, !tbaa !15
  store i64 %32, ptr %2, align 8, !tbaa !15
  br label %33

33:                                               ; preds = %30, %27, %10
  %.0 = phi i32 [ 1, %10 ], [ 2, %27 ], [ 0, %30 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  ret i32 %.0
}

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

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

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

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

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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind }
attributes #4 = { cold 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}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass