; LLVM IR from QiaoLiuHit/LSOTB-TIR :: vlfeat-0.9.19/vl (pgm)

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

@.str.5 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @vl_pgm_get_npixels(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @vl_pgm_get_bpp(ptr noundef) #0

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

declare i32 @vl_set_last_error(i32 noundef, ptr noundef, ...) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @vl_pgm_insert(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = 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 8, ptr %8) #5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = call i64 @vl_pgm_get_bpp(ptr noundef %15)
  store i64 %16, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = call i64 @vl_pgm_get_npixels(ptr noundef %17)
  store i64 %18, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._VlPgmImage, ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = trunc i64 %22 to i32
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._VlPgmImage, ptr %24, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !14
  %27 = trunc i64 %26 to i32
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._VlPgmImage, ptr %28, i32 0, i32 2
  %30 = load i64, ptr %29, align 8, !tbaa !15
  %31 = trunc i64 %30 to i32
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str.5, i32 noundef %23, i32 noundef %27, i32 noundef %31) #5
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = icmp eq i64 %33, 2
  br i1 %34, label %35, label %75

35:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %36 = load i64, ptr %9, align 8, !tbaa !9
  %37 = mul i64 2, %36
  %38 = call ptr @vl_malloc(i64 noundef %37)
  store ptr %38, ptr %12, align 8, !tbaa !5
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = mul i64 2, %41
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %39, ptr align 1 %40, i64 %42, i1 false)
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %66, %35
  %44 = load i64, ptr %11, align 8, !tbaa !9
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = mul i64 2, %45
  %47 = icmp ult i64 %44, %46
  br i1 %47, label %48, label %69

48:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #5
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = load i64, ptr %11, align 8, !tbaa !9
  %51 = getelementptr inbounds i8, ptr %49, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !16
  store i8 %52, ptr %13, align 1, !tbaa !16
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = load i64, ptr %11, align 8, !tbaa !9
  %55 = add i64 %54, 1
  %56 = getelementptr inbounds i8, ptr %53, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !16
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = load i64, ptr %11, align 8, !tbaa !9
  %60 = getelementptr inbounds i8, ptr %58, i64 %59
  store i8 %57, ptr %60, align 1, !tbaa !16
  %61 = load i8, ptr %13, align 1, !tbaa !16
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = add i64 %63, 1
  %65 = getelementptr inbounds i8, ptr %62, i64 %64
  store i8 %61, ptr %65, align 1, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #5
  br label %66

66:                                               ; preds = %48
  %67 = load i64, ptr %11, align 8, !tbaa !9
  %68 = add i64 %67, 2
  store i64 %68, ptr %11, align 8, !tbaa !9
  br label %43, !llvm.loop !17

69:                                               ; preds = %43
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = load i64, ptr %9, align 8, !tbaa !9
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = call i64 @fwrite(ptr noundef %70, i64 noundef 2, i64 noundef %71, ptr noundef %72)
  store i64 %73, ptr %10, align 8, !tbaa !19
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  call void @vl_free(ptr noundef %74)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %81

75:                                               ; preds = %3
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = load i64, ptr %8, align 8, !tbaa !9
  %78 = load i64, ptr %9, align 8, !tbaa !9
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = call i64 @fwrite(ptr noundef %76, i64 noundef %77, i64 noundef %78, ptr noundef %79)
  store i64 %80, ptr %10, align 8, !tbaa !19
  br label %81

81:                                               ; preds = %75, %69
  %82 = load i64, ptr %10, align 8, !tbaa !19
  %83 = load i64, ptr %9, align 8, !tbaa !9
  %84 = icmp ne i64 %82, %83
  br i1 %84, label %85, label %87

85:                                               ; preds = %81
  %86 = call i32 (i32, ptr, ...) @vl_set_last_error(i32 noundef 104, ptr noundef @.str.6)
  store i32 %86, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %88

87:                                               ; preds = %81
  store i32 0, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %88

88:                                               ; preds = %87, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %89 = load i32, ptr %4, align 4
  ret i32 %89
}

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

declare ptr @vl_malloc(i64 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

declare void @vl_free(ptr noundef) #2

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

@.str.5 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @vl_pgm_get_npixels(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @vl_pgm_get_bpp(ptr noundef) local_unnamed_addr #0

declare i32 @vl_set_last_error(i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @vl_pgm_insert(ptr nocapture noundef %0, ptr noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = tail call i64 @vl_pgm_get_bpp(ptr noundef %1)
  %5 = tail call i64 @vl_pgm_get_npixels(ptr noundef %1)
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %7 = trunc i64 %6 to i32
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = trunc i64 %9 to i32
  %11 = getelementptr inbounds i8, ptr %1, i64 16
  %12 = load i64, ptr %11, align 8, !tbaa !12
  %13 = trunc i64 %12 to i32
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %0, ptr noundef nonnull @.str.5, i32 noundef %7, i32 noundef %10, i32 noundef %13) #4
  %15 = icmp eq i64 %4, 2
  br i1 %15, label %16, label %42

16:                                               ; preds = %3
  %17 = shl i64 %5, 1
  %18 = tail call ptr @vl_malloc(i64 noundef %17) #4
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %18, ptr align 1 %2, i64 %17, i1 false)
  %.not37 = icmp eq i64 %17, 0
  br i1 %.not37, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %16
  %19 = add i64 %17, -1
  %20 = icmp eq i64 %19, 1
  br i1 %20, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %21 = lshr i64 %19, 1
  %22 = add nuw i64 %21, 1
  %unroll_iter = and i64 %22, -2
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.03436 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %34, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %23 = getelementptr inbounds i8, ptr %18, i64 %.03436
  %24 = load i8, ptr %23, align 1, !tbaa !13
  %25 = or disjoint i64 %.03436, 1
  %26 = getelementptr inbounds i8, ptr %18, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !13
  store i8 %27, ptr %23, align 1, !tbaa !13
  store i8 %24, ptr %26, align 1, !tbaa !13
  %28 = or disjoint i64 %.03436, 2
  %29 = getelementptr inbounds i8, ptr %18, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !13
  %31 = or disjoint i64 %.03436, 3
  %32 = getelementptr inbounds i8, ptr %18, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !13
  store i8 %33, ptr %29, align 1, !tbaa !13
  store i8 %30, ptr %32, align 1, !tbaa !13
  %34 = add nuw i64 %.03436, 4
  %niter.next.1 = add nuw i64 %niter, 2
  %niter.ncmp.1.not = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1.not, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !14

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.03436.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %34, %.lr.ph ]
  %35 = and i64 %19, 2
  %lcmp.mod.not.not = icmp eq i64 %35, 0
  br i1 %lcmp.mod.not.not, label %.lr.ph.epil, label %._crit_edge

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %36 = getelementptr inbounds i8, ptr %18, i64 %.03436.unr
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = or disjoint i64 %.03436.unr, 1
  %39 = getelementptr inbounds i8, ptr %18, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !13
  store i8 %40, ptr %36, align 1, !tbaa !13
  store i8 %37, ptr %39, align 1, !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %16
  %41 = tail call i64 @fwrite(ptr noundef %18, i64 noundef 2, i64 noundef %5, ptr noundef %0)
  tail call void @vl_free(ptr noundef %18) #4
  br label %44

42:                                               ; preds = %3
  %43 = tail call i64 @fwrite(ptr noundef %2, i64 noundef %4, i64 noundef %5, ptr noundef %0)
  br label %44

44:                                               ; preds = %42, %._crit_edge
  %.033 = phi i64 [ %41, %._crit_edge ], [ %43, %42 ]
  %.not = icmp eq i64 %.033, %5
  br i1 %.not, label %47, label %45

45:                                               ; preds = %44
  %46 = tail call i32 (i32, ptr, ...) @vl_set_last_error(i32 noundef 104, ptr noundef nonnull @.str.6) #4
  br label %47

47:                                               ; preds = %44, %45
  %.0 = phi i32 [ %46, %45 ], [ 0, %44 ]
  ret i32 %.0
}

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

declare ptr @vl_malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

declare void @vl_free(ptr noundef) local_unnamed_addr #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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"_VlPgmImage", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 16}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass