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

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

@.str.3 = 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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z19generate_24bits_bmpPhiiPKc(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca %struct.BMPFILEHEADER, align 2
  %12 = alloca %struct.BMPINFOHEADER, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = mul nsw i32 %15, %16
  %18 = mul nsw i32 %17, 3
  store i32 %18, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 22, ptr %11) #3
  %19 = getelementptr inbounds %struct.BMPFILEHEADER, ptr %11, i32 0, i32 0
  store i16 19778, ptr %19, align 2, !tbaa !11
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = add i64 %21, 22
  %23 = add i64 %22, 80
  %24 = getelementptr inbounds %struct.BMPFILEHEADER, ptr %11, i32 0, i32 1
  store i64 %23, ptr %24, align 2, !tbaa !15
  %25 = getelementptr inbounds %struct.BMPFILEHEADER, ptr %11, i32 0, i32 2
  store i16 0, ptr %25, align 2, !tbaa !16
  %26 = getelementptr inbounds %struct.BMPFILEHEADER, ptr %11, i32 0, i32 3
  store i16 0, ptr %26, align 2, !tbaa !17
  %27 = getelementptr inbounds %struct.BMPFILEHEADER, ptr %11, i32 0, i32 4
  store i64 102, ptr %27, align 2, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 80, ptr %12) #3
  %28 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %12, i32 0, i32 0
  store i64 80, ptr %28, align 8, !tbaa !19
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %12, i32 0, i32 1
  store i64 %30, ptr %31, align 8, !tbaa !21
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %12, i32 0, i32 2
  store i64 %33, ptr %34, align 8, !tbaa !22
  %35 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %12, i32 0, i32 3
  store i16 1, ptr %35, align 8, !tbaa !23
  %36 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %12, i32 0, i32 4
  store i16 24, ptr %36, align 2, !tbaa !24
  %37 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %12, i32 0, i32 5
  store i64 0, ptr %37, align 8, !tbaa !25
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %12, i32 0, i32 6
  store i64 %39, ptr %40, align 8, !tbaa !26
  %41 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %12, i32 0, i32 7
  store i64 0, ptr %41, align 8, !tbaa !27
  %42 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %12, i32 0, i32 8
  store i64 0, ptr %42, align 8, !tbaa !28
  %43 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %12, i32 0, i32 9
  store i64 0, ptr %43, align 8, !tbaa !29
  %44 = getelementptr inbounds %struct.BMPINFOHEADER, ptr %12, i32 0, i32 10
  store i64 0, ptr %44, align 8, !tbaa !30
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = call noalias ptr @fopen(ptr noundef %45, ptr noundef @.str.3)
  store ptr %46, ptr %13, align 8, !tbaa !5
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %50, label %49

49:                                               ; preds = %4
  store i1 false, ptr %5, align 1
  store i32 1, ptr %14, align 4
  br label %62

50:                                               ; preds = %4
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = call i64 @fwrite(ptr noundef %11, i64 noundef 22, i64 noundef 1, ptr noundef %51)
  %53 = load ptr, ptr %13, align 8, !tbaa !5
  %54 = call i64 @fwrite(ptr noundef %12, i64 noundef 80, i64 noundef 1, ptr noundef %53)
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = call i64 @fwrite(ptr noundef %55, i64 noundef 1, i64 noundef %57, ptr noundef %58)
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = call i32 @fclose(ptr noundef %60)
  store i1 true, ptr %5, align 1
  store i32 1, ptr %14, align 4
  br label %62

62:                                               ; preds = %50, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 80, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 22, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %63 = load i1, ptr %5, align 1
  ret i1 %63
}

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

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

declare i32 @fclose(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS13BMPFILEHEADER", !13, i64 0, !14, i64 2, !13, i64 10, !13, i64 12, !14, i64 14}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !14, i64 2}
!16 = !{!12, !13, i64 10}
!17 = !{!12, !13, i64 12}
!18 = !{!12, !14, i64 14}
!19 = !{!20, !14, i64 0}
!20 = !{!"_ZTS13BMPINFOHEADER", !14, i64 0, !14, i64 8, !14, i64 16, !13, i64 24, !13, i64 26, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72}
!21 = !{!20, !14, i64 8}
!22 = !{!20, !14, i64 16}
!23 = !{!20, !13, i64 24}
!24 = !{!20, !13, i64 26}
!25 = !{!20, !14, i64 32}
!26 = !{!20, !14, i64 40}
!27 = !{!20, !14, i64 48}
!28 = !{!20, !14, i64 56}
!29 = !{!20, !14, i64 64}
!30 = !{!20, !14, i64 72}


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

@.str.3 = 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: mustprogress nofree nounwind uwtable
define dso_local noundef zeroext i1 @_Z19generate_24bits_bmpPhiiPKc(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #1 {
  %5 = alloca %struct.BMPFILEHEADER, align 2
  %6 = alloca %struct.BMPINFOHEADER, align 8
  %7 = mul i32 %1, 3
  %8 = mul i32 %7, %2
  call void @llvm.lifetime.start.p0(i64 22, ptr nonnull %5) #4
  store i16 19778, ptr %5, align 2, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = add nsw i64 %9, 102
  %11 = getelementptr inbounds i8, ptr %5, i64 2
  store i64 %10, ptr %11, align 2, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %5, i64 10
  store i16 0, ptr %12, align 2, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %5, i64 12
  store i16 0, ptr %13, align 2, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %5, i64 14
  store i64 102, ptr %14, align 2, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %6) #4
  store i64 80, ptr %6, align 8, !tbaa !15
  %15 = sext i32 %1 to i64
  %16 = getelementptr inbounds i8, ptr %6, i64 8
  store i64 %15, ptr %16, align 8, !tbaa !17
  %17 = sext i32 %2 to i64
  %18 = getelementptr inbounds i8, ptr %6, i64 16
  store i64 %17, ptr %18, align 8, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %6, i64 24
  store i16 1, ptr %19, align 8, !tbaa !19
  %20 = getelementptr inbounds i8, ptr %6, i64 26
  store i16 24, ptr %20, align 2, !tbaa !20
  %21 = getelementptr inbounds i8, ptr %6, i64 32
  store i64 0, ptr %21, align 8, !tbaa !21
  %22 = getelementptr inbounds i8, ptr %6, i64 40
  store i64 %9, ptr %22, align 8, !tbaa !22
  %23 = getelementptr inbounds i8, ptr %6, i64 48
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %23, i8 0, i64 32, i1 false)
  %24 = tail call noalias ptr @fopen(ptr noundef %3, ptr noundef nonnull @.str.3)
  %.not = icmp ne ptr %24, null
  br i1 %.not, label %25, label %30

25:                                               ; preds = %4
  %26 = call i64 @fwrite(ptr noundef nonnull %5, i64 noundef 22, i64 noundef 1, ptr noundef nonnull %24)
  %27 = call i64 @fwrite(ptr noundef nonnull %6, i64 noundef 80, i64 noundef 1, ptr noundef nonnull %24)
  %28 = tail call i64 @fwrite(ptr noundef %0, i64 noundef 1, i64 noundef %9, ptr noundef nonnull %24)
  %29 = tail call i32 @fclose(ptr noundef nonnull %24)
  br label %30

30:                                               ; preds = %4, %25
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 22, ptr nonnull %5) #4
  ret i1 %.not
}

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

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

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"_ZTS13BMPFILEHEADER", !7, i64 0, !10, i64 2, !7, i64 10, !7, i64 12, !10, i64 14}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 2}
!12 = !{!6, !7, i64 10}
!13 = !{!6, !7, i64 12}
!14 = !{!6, !10, i64 14}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTS13BMPINFOHEADER", !10, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 26, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72}
!17 = !{!16, !10, i64 8}
!18 = !{!16, !10, i64 16}
!19 = !{!16, !7, i64 24}
!20 = !{!16, !7, i64 26}
!21 = !{!16, !10, i64 32}
!22 = !{!16, !10, i64 40}


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