; LLVM IR from clunietp/libgmsd :: 3rdparty (bmpread)

; 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.read_context = type { i32, ptr, %struct.bmp_header, %struct.bmp_info, i32, i32, i32, i64, i64, i64, [4 x %struct.bitfield], ptr, ptr, ptr }
%struct.bmp_header = type { [2 x i8], i32, i32, i32 }
%struct.bmp_info = type { i32, i32, i32, i16, i16, i32, [3 x i32], i32, i32, [4 x i32] }
%struct.bitfield = type { i32, i32 }
%struct.bmpread_t = type { i32, i32, i32, ptr }

@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @bmpread(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.read_context, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 184, ptr %8) #4
  call void @llvm.memset.p0.i64(ptr align 8 %8, i8 0, i64 184, i1 false)
  br label %9

9:                                                ; preds = %3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  br label %53

13:                                               ; preds = %9
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  br label %53

17:                                               ; preds = %13
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %18, i8 0, i64 24, i1 false)
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = getelementptr inbounds %struct.read_context, ptr %8, i32 0, i32 0
  store i32 %19, ptr %20, align 8, !tbaa !11
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call noalias ptr @fopen(ptr noundef %21, ptr noundef @.str)
  %23 = getelementptr inbounds %struct.read_context, ptr %8, i32 0, i32 1
  store ptr %22, ptr %23, align 8, !tbaa !17
  %24 = icmp ne ptr %22, null
  br i1 %24, label %26, label %25

25:                                               ; preds = %17
  br label %53

26:                                               ; preds = %17
  %27 = call i32 @Validate(ptr noundef %8)
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  br label %53

30:                                               ; preds = %26
  %31 = call i32 @Decode(ptr noundef %8)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  br label %53

34:                                               ; preds = %30
  %35 = getelementptr inbounds %struct.read_context, ptr %8, i32 0, i32 3
  %36 = getelementptr inbounds %struct.bmp_info, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !18
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.bmpread_t, ptr %38, i32 0, i32 0
  store i32 %37, ptr %39, align 8, !tbaa !19
  %40 = getelementptr inbounds %struct.read_context, ptr %8, i32 0, i32 6
  %41 = load i32, ptr %40, align 8, !tbaa !21
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.bmpread_t, ptr %42, i32 0, i32 1
  store i32 %41, ptr %43, align 4, !tbaa !22
  %44 = getelementptr inbounds %struct.read_context, ptr %8, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !11
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.bmpread_t, ptr %46, i32 0, i32 2
  store i32 %45, ptr %47, align 8, !tbaa !23
  %48 = getelementptr inbounds %struct.read_context, ptr %8, i32 0, i32 13
  %49 = load ptr, ptr %48, align 8, !tbaa !24
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.bmpread_t, ptr %50, i32 0, i32 3
  store ptr %49, ptr %51, align 8, !tbaa !25
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %34
  br label %53

53:                                               ; preds = %52, %33, %29, %25, %16, %12
  %54 = load i32, ptr %7, align 4, !tbaa !9
  call void @FreeContext(ptr noundef %8, i32 noundef %54)
  %55 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 184, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i32 %55
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @Validate(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @Decode(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @FreeContext(ptr noundef, i32 noundef) #0

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"read_context", !10, i64 0, !6, i64 8, !13, i64 16, !14, i64 32, !10, i64 88, !10, i64 92, !10, i64 96, !16, i64 104, !16, i64 112, !16, i64 120, !7, i64 128, !6, i64 160, !6, i64 168, !6, i64 176}
!13 = !{!"bmp_header", !7, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!14 = !{!"bmp_info", !10, i64 0, !10, i64 4, !10, i64 8, !15, i64 12, !15, i64 14, !10, i64 16, !7, i64 20, !10, i64 32, !10, i64 36, !7, i64 40}
!15 = !{!"short", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!12, !6, i64 8}
!18 = !{!12, !10, i64 36}
!19 = !{!20, !10, i64 0}
!20 = !{!"bmpread_t", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16}
!21 = !{!12, !10, i64 96}
!22 = !{!20, !10, i64 4}
!23 = !{!20, !10, i64 8}
!24 = !{!12, !6, i64 176}
!25 = !{!20, !6, i64 16}


; 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.read_context = type { i32, ptr, %struct.bmp_header, %struct.bmp_info, i32, i32, i32, i64, i64, i64, [4 x %struct.bitfield], ptr, ptr, ptr }
%struct.bmp_header = type { [2 x i8], i32, i32, i32 }
%struct.bmp_info = type { i32, i32, i32, i16, i16, i32, [3 x i32], i32, i32, [4 x i32] }
%struct.bitfield = type { i32, i32 }

@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @bmpread(ptr noundef readonly %0, i32 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = alloca %struct.read_context, align 8
  call void @llvm.lifetime.start.p0(i64 184, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(184) %4, i8 0, i64 184, i1 false)
  %5 = icmp ne ptr %0, null
  %6 = icmp ne ptr %2, null
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %7, label %25

7:                                                ; preds = %3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %2, i8 0, i64 24, i1 false)
  store i32 %1, ptr %4, align 8, !tbaa !5
  %8 = tail call noalias ptr @fopen(ptr noundef nonnull %0, ptr noundef nonnull @.str)
  %9 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %8, ptr %9, align 8, !tbaa !15
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %25, label %10

10:                                               ; preds = %7
  %11 = call i32 @Validate(ptr noundef nonnull %4)
  %.not13 = icmp eq i32 %11, 0
  br i1 %.not13, label %25, label %12

12:                                               ; preds = %10
  %13 = call i32 @Decode(ptr noundef nonnull %4)
  %.not14 = icmp eq i32 %13, 0
  br i1 %.not14, label %25, label %14

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %4, i64 36
  %16 = load i32, ptr %15, align 4, !tbaa !16
  store i32 %16, ptr %2, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %4, i64 96
  %18 = load i32, ptr %17, align 8, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %18, ptr %19, align 4, !tbaa !20
  %20 = load i32, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 %20, ptr %21, align 8, !tbaa !21
  %22 = getelementptr inbounds i8, ptr %4, i64 176
  %23 = load ptr, ptr %22, align 8, !tbaa !22
  %24 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %23, ptr %24, align 8, !tbaa !23
  br label %25

25:                                               ; preds = %12, %10, %7, %3, %14
  %.0 = phi i32 [ 1, %14 ], [ 0, %12 ], [ 0, %10 ], [ 0, %7 ], [ 0, %3 ]
  call void @FreeContext(ptr noundef nonnull %4, i32 noundef %.0)
  call void @llvm.lifetime.end.p0(i64 184, ptr nonnull %4) #4
  ret i32 %.0
}

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

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @Validate(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @Decode(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @FreeContext(ptr noundef, i32 noundef) 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) #1

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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 = !{!"read_context", !7, i64 0, !10, i64 8, !11, i64 16, !12, i64 32, !7, i64 88, !7, i64 92, !7, i64 96, !14, i64 104, !14, i64 112, !14, i64 120, !8, i64 128, !10, i64 160, !10, i64 168, !10, i64 176}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"bmp_header", !8, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!12 = !{!"bmp_info", !7, i64 0, !7, i64 4, !7, i64 8, !13, i64 12, !13, i64 14, !7, i64 16, !8, i64 20, !7, i64 32, !7, i64 36, !8, i64 40}
!13 = !{!"short", !8, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!6, !10, i64 8}
!16 = !{!6, !7, i64 36}
!17 = !{!18, !7, i64 0}
!18 = !{!"bmpread_t", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!19 = !{!6, !7, i64 96}
!20 = !{!18, !7, i64 4}
!21 = !{!18, !7, i64 8}
!22 = !{!6, !10, i64 176}
!23 = !{!18, !10, i64 16}


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