; LLVM IR from davidesantangelo/krep :: test (test_directory)

; 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.search_params = type { ptr, i64, ptr, ptr, i64, i8, i8, i8, i8, i8, i8, ptr, ptr, i64 }

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [87 x i8], align 1

declare i32 @printf(ptr noundef, ...) #0

; 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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #5

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

; 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 void @test_binary_file_handling() #6 {
  %1 = alloca ptr, align 8
  %2 = alloca %struct.search_params, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = call i32 (ptr, ...) @printf(ptr noundef @.str.12)
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #7
  store ptr @.str.13, ptr %1, align 8, !tbaa !5
  %7 = load ptr, ptr %1, align 8, !tbaa !5
  call void @create_binary_file(ptr noundef %7)
  call void @llvm.lifetime.start.p0(i64 72, ptr %2) #7
  call void @llvm.memset.p0.i64(ptr align 8 %2, i8 0, i64 72, i1 false)
  %8 = call noalias ptr @malloc(i64 noundef 8) #8
  %9 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 2
  store ptr %8, ptr %9, align 8, !tbaa !9
  %10 = call noalias ptr @malloc(i64 noundef 8) #8
  %11 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 3
  store ptr %10, ptr %11, align 8, !tbaa !13
  %12 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %19

15:                                               ; preds = %0
  %16 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 3
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = icmp ne ptr %17, null
  br i1 %18, label %24, label %19

19:                                               ; preds = %15, %0
  %20 = load ptr, ptr @stderr, align 8, !tbaa !5
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str.1) #7
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = call i32 @unlink(ptr noundef %22) #7
  store i32 1, ptr %3, align 4
  br label %52

24:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  store ptr @.str.14, ptr %4, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds ptr, ptr %27, i64 0
  store ptr %25, ptr %28, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i64 @strlen(ptr noundef %29) #9
  %31 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = getelementptr inbounds i64, ptr %32, i64 0
  store i64 %30, ptr %33, align 8, !tbaa !14
  %34 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 4
  store i64 1, ptr %34, align 8, !tbaa !15
  %35 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 5
  store i8 1, ptr %35, align 8, !tbaa !16
  %36 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 6
  store i8 0, ptr %36, align 1, !tbaa !17
  %37 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 7
  store i8 0, ptr %37, align 2, !tbaa !18
  %38 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 9
  store i8 1, ptr %38, align 4, !tbaa !19
  %39 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 13
  store i64 -1, ptr %39, align 8, !tbaa !20
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.15)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  %41 = load ptr, ptr %1, align 8, !tbaa !5
  %42 = call i32 @search_file(ptr noundef %2, ptr noundef %41, i32 noundef 1)
  store i32 %42, ptr %5, align 4, !tbaa !21
  %43 = load i32, ptr %5, align 4, !tbaa !21
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.16, i32 noundef %43)
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.17)
  %46 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  call void @free(ptr noundef %47) #7
  %48 = getelementptr inbounds %struct.search_params, ptr %2, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  call void @free(ptr noundef %49) #7
  %50 = load ptr, ptr %1, align 8, !tbaa !5
  %51 = call i32 @unlink(ptr noundef %50) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  store i32 0, ptr %3, align 4
  br label %52

52:                                               ; preds = %24, %19
  call void @llvm.lifetime.end.p0(i64 72, ptr %2) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #7
  %53 = load i32, ptr %3, align 4
  switch i32 %53, label %55 [
    i32 0, label %54
    i32 1, label %54
  ]

54:                                               ; preds = %52, %52
  ret void

55:                                               ; preds = %52
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden void @create_binary_file(ptr noundef) #6

; Function Attrs: nounwind
declare i32 @unlink(ptr noundef) #4

declare i32 @search_file(ptr noundef, ptr noundef, i32 noundef) #0

attributes #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 = { nounwind 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 "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 #5 = { nounwind willreturn memory(read) "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 #6 = { 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 #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { nounwind willreturn memory(read) }

!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, !6, i64 16}
!10 = !{!"search_params", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !12, i64 40, !12, i64 41, !12, i64 42, !12, i64 43, !12, i64 44, !12, i64 45, !6, i64 48, !6, i64 56, !11, i64 64}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !6, i64 24}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 32}
!16 = !{!10, !12, i64 40}
!17 = !{!10, !12, i64 41}
!18 = !{!10, !12, i64 42}
!19 = !{!10, !12, i64 44}
!20 = !{!10, !11, i64 64}
!21 = !{!22, !22, i64 0}
!22 = !{!"int", !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"

%struct.search_params = type { ptr, i64, ptr, ptr, i64, i8, i8, i8, i8, i8, i8, ptr, ptr, i64 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [87 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: mustprogress 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 void @test_binary_file_handling() local_unnamed_addr #6 {
  %1 = alloca %struct.search_params, align 8
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12)
  tail call void @create_binary_file(ptr noundef nonnull @.str.13)
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %1) #8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(72) %1, i8 0, i64 64, i1 false)
  %3 = tail call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8) #9
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr %3, ptr %4, align 8, !tbaa !5
  %5 = tail call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8) #9
  %6 = getelementptr inbounds i8, ptr %1, i64 24
  store ptr %5, ptr %6, align 8, !tbaa !12
  %7 = icmp ne ptr %3, null
  %8 = icmp ne ptr %5, null
  %or.cond = and i1 %7, %8
  br i1 %or.cond, label %13, label %9

9:                                                ; preds = %0
  %10 = load ptr, ptr @stderr, align 8, !tbaa !13
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str.1) #10
  %12 = tail call i32 @unlink(ptr noundef nonnull @.str.13) #8
  br label %28

13:                                               ; preds = %0
  store ptr @.str.14, ptr %3, align 8, !tbaa !13
  %14 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @.str.14) #11
  store i64 %14, ptr %5, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %1, i64 32
  store i64 1, ptr %15, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %1, i64 40
  store i8 1, ptr %16, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %1, i64 41
  store i8 0, ptr %17, align 1, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %1, i64 42
  store i8 0, ptr %18, align 2, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %1, i64 44
  store i8 1, ptr %19, align 4, !tbaa !19
  %20 = getelementptr inbounds i8, ptr %1, i64 64
  store i64 -1, ptr %20, align 8, !tbaa !20
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.15)
  %22 = call i32 @search_file(ptr noundef nonnull %1, ptr noundef nonnull @.str.13, i32 noundef 1) #8
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16, i32 noundef %22)
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.17)
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %25) #8
  %26 = load ptr, ptr %6, align 8, !tbaa !12
  call void @free(ptr noundef %26) #8
  %27 = call i32 @unlink(ptr noundef nonnull @.str.13) #8
  br label %28

28:                                               ; preds = %13, %9
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %1) #8
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @create_binary_file(ptr noundef) local_unnamed_addr #6

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

declare i32 @search_file(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #7

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 #5 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #6 = { 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 #7 = { "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 #8 = { nounwind }
attributes #9 = { nounwind allocsize(0) }
attributes #10 = { cold nounwind }
attributes #11 = { nounwind willreturn memory(read) }

!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 16}
!6 = !{!"search_params", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !11, i64 41, !11, i64 42, !11, i64 43, !11, i64 44, !11, i64 45, !7, i64 48, !7, i64 56, !10, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!6, !7, i64 24}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !10, i64 0}
!15 = !{!6, !10, i64 32}
!16 = !{!6, !11, i64 40}
!17 = !{!6, !11, i64 41}
!18 = !{!6, !11, i64 42}
!19 = !{!6, !11, i64 44}
!20 = !{!6, !10, i64 64}


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