; LLVM IR from opencryptoki/libzpc :: src/zkey/lib (util_file)

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

@.str = external hidden unnamed_addr constant [78 x i8], align 1
@__func__.util_file_write_l = external hidden unnamed_addr constant [18 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 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
declare void @llvm.va_start.p0(ptr) #1

declare i32 @__util_vsprintf(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @file_puts(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @util_file_write_l(i64 noundef %0, i32 noundef %1, ptr noundef %2, ...) #3 {
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [4096 x i8], align 16
  %9 = alloca [1 x %struct.__va_list_tag], align 16
  %10 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4096, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  br label %11

11:                                               ; preds = %3
  %12 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %9, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %12)
  %13 = getelementptr inbounds [4096 x i8], ptr %8, i64 0, i64 0
  %14 = load ptr, ptr %6, align 8, !tbaa !11
  %15 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %9, i64 0, i64 0
  %16 = call i32 @__util_vsprintf(ptr noundef @__func__.util_file_write_l, ptr noundef @.str, i32 noundef 150, ptr noundef %13, ptr noundef %14, ptr noundef %15)
  %17 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %9, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %17)
  br label %18

18:                                               ; preds = %11
  br label %19

19:                                               ; preds = %18
  %20 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %20, label %30 [
    i32 8, label %21
    i32 10, label %24
    i32 16, label %27
  ]

21:                                               ; preds = %19
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = call i32 (ptr, ptr, i32, ptr, ptr, ...) @__util_asprintf(ptr noundef @__func__.util_file_write_l, ptr noundef @.str, i32 noundef 154, ptr noundef %7, ptr noundef @.str.1, i64 noundef %22)
  br label %32

24:                                               ; preds = %19
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = call i32 (ptr, ptr, i32, ptr, ptr, ...) @__util_asprintf(ptr noundef @__func__.util_file_write_l, ptr noundef @.str, i32 noundef 157, ptr noundef %7, ptr noundef @.str.2, i64 noundef %25)
  br label %32

27:                                               ; preds = %19
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = call i32 (ptr, ptr, i32, ptr, ptr, ...) @__util_asprintf(ptr noundef @__func__.util_file_write_l, ptr noundef @.str, i32 noundef 160, ptr noundef %7, ptr noundef @.str.3, i64 noundef %28)
  br label %32

30:                                               ; preds = %19
  %31 = load i32, ptr %5, align 4, !tbaa !9
  call void (ptr, ptr, i32, ptr, ...) @__util_panic(ptr noundef @__func__.util_file_write_l, ptr noundef @.str, i32 noundef 163, ptr noundef @.str.4, i32 noundef %31) #7
  unreachable

32:                                               ; preds = %27, %24, %21
  %33 = load ptr, ptr %7, align 8, !tbaa !11
  %34 = getelementptr inbounds [4096 x i8], ptr %8, i64 0, i64 0
  %35 = call i32 @file_puts(ptr noundef %33, ptr noundef %34)
  store i32 %35, ptr %10, align 4, !tbaa !9
  %36 = load ptr, ptr %7, align 8, !tbaa !11
  call void @free(ptr noundef %36) #6
  %37 = load i32, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4096, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  ret i32 %37
}

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

; Function Attrs: noreturn
declare void @__util_panic(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ...) #4

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn }
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 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 #4 = { noreturn "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 "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 }
attributes #7 = { noreturn }

!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 = !{!"long", !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, !12, i64 0}
!12 = !{!"any pointer", !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.__va_list_tag = type { i32, i32, ptr, ptr }

@.str = external hidden unnamed_addr constant [78 x i8], align 1
@__func__.util_file_write_l = external hidden unnamed_addr constant [18 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 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
declare void @llvm.va_start.p0(ptr) #1

declare i32 @__util_vsprintf(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @file_puts(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i32 @util_file_write_l(i64 noundef %0, i32 noundef %1, ptr noundef %2, ...) local_unnamed_addr #3 {
  %4 = alloca ptr, align 8
  %5 = alloca [4096 x i8], align 16
  %6 = alloca [1 x %struct.__va_list_tag], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #6
  call void @llvm.va_start.p0(ptr nonnull %6)
  %7 = call i32 @__util_vsprintf(ptr noundef nonnull @__func__.util_file_write_l, ptr noundef nonnull @.str, i32 noundef 150, ptr noundef nonnull %5, ptr noundef %2, ptr noundef nonnull %6) #6
  call void @llvm.va_end.p0(ptr nonnull %6)
  switch i32 %1, label %14 [
    i32 8, label %8
    i32 10, label %10
    i32 16, label %12
  ]

8:                                                ; preds = %3
  %9 = call i32 (ptr, ptr, i32, ptr, ptr, ...) @__util_asprintf(ptr noundef nonnull @__func__.util_file_write_l, ptr noundef nonnull @.str, i32 noundef 154, ptr noundef nonnull %4, ptr noundef nonnull @.str.1, i64 noundef %0) #6
  br label %15

10:                                               ; preds = %3
  %11 = call i32 (ptr, ptr, i32, ptr, ptr, ...) @__util_asprintf(ptr noundef nonnull @__func__.util_file_write_l, ptr noundef nonnull @.str, i32 noundef 157, ptr noundef nonnull %4, ptr noundef nonnull @.str.2, i64 noundef %0) #6
  br label %15

12:                                               ; preds = %3
  %13 = call i32 (ptr, ptr, i32, ptr, ptr, ...) @__util_asprintf(ptr noundef nonnull @__func__.util_file_write_l, ptr noundef nonnull @.str, i32 noundef 160, ptr noundef nonnull %4, ptr noundef nonnull @.str.3, i64 noundef %0) #6
  br label %15

14:                                               ; preds = %3
  call void (ptr, ptr, i32, ptr, ...) @__util_panic(ptr noundef nonnull @__func__.util_file_write_l, ptr noundef nonnull @.str, i32 noundef 163, ptr noundef nonnull @.str.4, i32 noundef %1) #7
  unreachable

15:                                               ; preds = %12, %10, %8
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call i32 @file_puts(ptr noundef %16, ptr noundef nonnull %5)
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %18) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  ret i32 %17
}

declare i32 @__util_asprintf(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #2

; Function Attrs: noreturn
declare void @__util_panic(ptr noundef, ptr noundef, i32 noundef, ptr 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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 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 #4 = { noreturn "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 }
attributes #7 = { noreturn 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"}


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