; LLVM IR from ChenyangZhang-cs/iMLBench :: MLP/co-run&zero-copy/examples/image_io.ll (Z15read_24bits_bmpPKcPiS1_)

; 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.BMPINFOHEADER = type { i64, i64, i64, i16, i16, i64, i64, i64, i64, i64, i64 }

@.str.4 = external hidden unnamed_addr constant [3 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

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

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

declare i32 @fclose(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z15read_24bits_bmpPKcPiS1_(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.BMPINFOHEADER, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  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 8, ptr %8) #4
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call noalias ptr @fopen(ptr noundef %13, ptr noundef @.str.4)
  store ptr %14, ptr %8, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %55

18:                                               ; preds = %3
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = call i32 @fseek(ptr noundef %19, i64 noundef 22, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 80, ptr %10) #4
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = call i64 @fread(ptr noundef %10, i64 noundef 80, i64 noundef 1, ptr noundef %21)
  %23 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %10, i32 0, i32 4
  %24 = load i16, ptr %23, align 2, !tbaa !9
  %25 = zext i16 %24 to i32
  %26 = icmp ne i32 %25, 24
  br i1 %26, label %27, label %28

27:                                               ; preds = %18
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %54

28:                                               ; preds = %18
  %29 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %10, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !13
  %31 = trunc i64 %30 to i32
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %31, ptr %32, align 4, !tbaa !14
  %33 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %10, i32 0, i32 2
  %34 = load i64, ptr %33, align 8, !tbaa !16
  %35 = trunc i64 %34 to i32
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %35, ptr %36, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i32, ptr %37, align 4, !tbaa !14
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i32, ptr %39, align 4, !tbaa !14
  %41 = mul nsw i32 %38, %40
  %42 = mul nsw i32 %41, 3
  store i32 %42, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %43 = load i32, ptr %11, align 4, !tbaa !14
  %44 = sext i32 %43 to i64
  %45 = call noalias noundef nonnull ptr @_Znam(i64 noundef %44) #5
  store ptr %45, ptr %12, align 8, !tbaa !5
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = load i32, ptr %11, align 4, !tbaa !14
  %48 = sext i32 %47 to i64
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = call i64 @fread(ptr noundef %46, i64 noundef 1, i64 noundef %48, ptr noundef %49)
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = call i32 @fclose(ptr noundef %51)
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %53, ptr %4, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %54

54:                                               ; preds = %28, %27
  call void @llvm.lifetime.end.p0(i64 80, ptr %10) #4
  br label %55

55:                                               ; preds = %54, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %56 = load ptr, ptr %4, align 8
  ret ptr %56
}

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #1

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #3

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 = { mustprogress 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 = { nobuiltin 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 }
attributes #5 = { builtin 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++ TBAA"}
!9 = !{!10, !12, i64 26}
!10 = !{!"_ZTS13BMPINFOHEADER", !11, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !12, i64 26, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72}
!11 = !{!"long", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!10, !11, 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.BMPINFOHEADER = type { i64, i64, i64, i16, i16, i64, i64, i64, i64, i64, i64 }

@.str.4 = external hidden unnamed_addr constant [3 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: 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 noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local noalias noundef ptr @_Z15read_24bits_bmpPKcPiS1_(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #2 {
  %4 = alloca %struct.BMPINFOHEADER, align 8
  %5 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str.4)
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %26, label %6

6:                                                ; preds = %3
  %7 = tail call i32 @fseek(ptr noundef nonnull %5, i64 noundef 22, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %4) #4
  %8 = call i64 @fread(ptr noundef nonnull %4, i64 noundef 80, i64 noundef 1, ptr noundef nonnull %5)
  %9 = getelementptr inbounds i8, ptr %4, i64 26
  %10 = load i16, ptr %9, align 2, !tbaa !5
  %.not15 = icmp eq i16 %10, 24
  br i1 %.not15, label %11, label %25

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %4, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %1, align 4, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %4, i64 16
  %16 = load i64, ptr %15, align 8, !tbaa !14
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr %2, align 4, !tbaa !12
  %18 = load i32, ptr %1, align 4, !tbaa !12
  %19 = mul i32 %17, 3
  %20 = mul i32 %19, %18
  %21 = sext i32 %20 to i64
  %22 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %21) #5
  %23 = tail call i64 @fread(ptr noundef nonnull %22, i64 noundef 1, i64 noundef %21, ptr noundef nonnull %5)
  %24 = tail call i32 @fclose(ptr noundef nonnull %5)
  br label %25

25:                                               ; preds = %6, %11
  %.0 = phi ptr [ %22, %11 ], [ null, %6 ]
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %4) #4
  br label %26

26:                                               ; preds = %3, %25
  %.1 = phi ptr [ %.0, %25 ], [ null, %3 ]
  ret ptr %.1
}

; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #3

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 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 = { nobuiltin 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 }
attributes #5 = { builtin 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, !10, i64 26}
!6 = !{!"_ZTS13BMPINFOHEADER", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 26, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!6, !7, i64 16}


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