; LLVM IR from ARMmbed/mbed-crypto :: library (psa_its_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.psa_its_file_header_t = type { [8 x i8], [4 x i8], [4 x i8] }

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = 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

declare i32 @fclose(ptr noundef) #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
define dso_local i32 @psa_its_set(i64 noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca [25 x i8], align 16
  %11 = alloca ptr, align 8
  %12 = alloca %struct.psa_its_file_header_t, align 1
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !11
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 -146, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 25, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store ptr null, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %15 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %12, i32 0, i32 0
  %16 = getelementptr inbounds [8 x i8], ptr %15, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %16, ptr align 1 @.str, i64 8, i1 false)
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = and i32 %17, 255
  %19 = trunc i32 %18 to i8
  %20 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %12, i32 0, i32 1
  %21 = getelementptr inbounds [4 x i8], ptr %20, i64 0, i64 0
  store i8 %19, ptr %21, align 1, !tbaa !13
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = lshr i32 %22, 8
  %24 = and i32 %23, 255
  %25 = trunc i32 %24 to i8
  %26 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %12, i32 0, i32 1
  %27 = getelementptr inbounds [4 x i8], ptr %26, i64 0, i64 1
  store i8 %25, ptr %27, align 1, !tbaa !13
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = lshr i32 %28, 16
  %30 = and i32 %29, 255
  %31 = trunc i32 %30 to i8
  %32 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %12, i32 0, i32 1
  %33 = getelementptr inbounds [4 x i8], ptr %32, i64 0, i64 2
  store i8 %31, ptr %33, align 1, !tbaa !13
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = lshr i32 %34, 24
  %36 = and i32 %35, 255
  %37 = trunc i32 %36 to i8
  %38 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %12, i32 0, i32 1
  %39 = getelementptr inbounds [4 x i8], ptr %38, i64 0, i64 3
  store i8 %37, ptr %39, align 1, !tbaa !13
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = and i32 %40, 255
  %42 = trunc i32 %41 to i8
  %43 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %12, i32 0, i32 2
  %44 = getelementptr inbounds [4 x i8], ptr %43, i64 0, i64 0
  store i8 %42, ptr %44, align 1, !tbaa !13
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = lshr i32 %45, 8
  %47 = and i32 %46, 255
  %48 = trunc i32 %47 to i8
  %49 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %12, i32 0, i32 2
  %50 = getelementptr inbounds [4 x i8], ptr %49, i64 0, i64 1
  store i8 %48, ptr %50, align 1, !tbaa !13
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = lshr i32 %51, 16
  %53 = and i32 %52, 255
  %54 = trunc i32 %53 to i8
  %55 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %12, i32 0, i32 2
  %56 = getelementptr inbounds [4 x i8], ptr %55, i64 0, i64 2
  store i8 %54, ptr %56, align 1, !tbaa !13
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = lshr i32 %57, 24
  %59 = and i32 %58, 255
  %60 = trunc i32 %59 to i8
  %61 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %12, i32 0, i32 2
  %62 = getelementptr inbounds [4 x i8], ptr %61, i64 0, i64 3
  store i8 %60, ptr %62, align 1, !tbaa !13
  %63 = load i64, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds [25 x i8], ptr %10, i64 0, i64 0
  call void @psa_its_fill_filename(i64 noundef %63, ptr noundef %64)
  %65 = call noalias ptr @fopen(ptr noundef @.str.1, ptr noundef @.str.2)
  store ptr %65, ptr %11, align 8, !tbaa !11
  %66 = load ptr, ptr %11, align 8, !tbaa !11
  %67 = icmp eq ptr %66, null
  br i1 %67, label %68, label %69

68:                                               ; preds = %4
  br label %91

69:                                               ; preds = %4
  store i32 -142, ptr %9, align 4, !tbaa !9
  %70 = load ptr, ptr %11, align 8, !tbaa !11
  %71 = call i64 @fwrite(ptr noundef %12, i64 noundef 1, i64 noundef 16, ptr noundef %70)
  store i64 %71, ptr %13, align 8, !tbaa !5
  %72 = load i64, ptr %13, align 8, !tbaa !5
  %73 = icmp ne i64 %72, 16
  br i1 %73, label %74, label %75

74:                                               ; preds = %69
  br label %91

75:                                               ; preds = %69
  %76 = load i32, ptr %6, align 4, !tbaa !9
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %90

78:                                               ; preds = %75
  %79 = load ptr, ptr %7, align 8, !tbaa !11
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = zext i32 %80 to i64
  %82 = load ptr, ptr %11, align 8, !tbaa !11
  %83 = call i64 @fwrite(ptr noundef %79, i64 noundef 1, i64 noundef %81, ptr noundef %82)
  store i64 %83, ptr %13, align 8, !tbaa !5
  %84 = load i64, ptr %13, align 8, !tbaa !5
  %85 = load i32, ptr %6, align 4, !tbaa !9
  %86 = zext i32 %85 to i64
  %87 = icmp ne i64 %84, %86
  br i1 %87, label %88, label %89

88:                                               ; preds = %78
  br label %91

89:                                               ; preds = %78
  br label %90

90:                                               ; preds = %89, %75
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %91

91:                                               ; preds = %90, %88, %74, %68
  %92 = load ptr, ptr %11, align 8, !tbaa !11
  %93 = icmp ne ptr %92, null
  br i1 %93, label %94, label %104

94:                                               ; preds = %91
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %95 = load ptr, ptr %11, align 8, !tbaa !11
  %96 = call i32 @fclose(ptr noundef %95)
  store i32 %96, ptr %14, align 4, !tbaa !9
  %97 = load i32, ptr %9, align 4, !tbaa !9
  %98 = icmp eq i32 %97, 0
  br i1 %98, label %99, label %103

99:                                               ; preds = %94
  %100 = load i32, ptr %14, align 4, !tbaa !9
  %101 = icmp ne i32 %100, 0
  br i1 %101, label %102, label %103

102:                                              ; preds = %99
  store i32 -142, ptr %9, align 4, !tbaa !9
  br label %103

103:                                              ; preds = %102, %99, %94
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %104

104:                                              ; preds = %103, %91
  %105 = load i32, ptr %9, align 4, !tbaa !9
  %106 = icmp eq i32 %105, 0
  br i1 %106, label %107, label %113

107:                                              ; preds = %104
  %108 = getelementptr inbounds [25 x i8], ptr %10, i64 0, i64 0
  %109 = call i32 @rename(ptr noundef @.str.1, ptr noundef %108) #5
  %110 = icmp ne i32 %109, 0
  br i1 %110, label %111, label %112

111:                                              ; preds = %107
  store i32 -146, ptr %9, align 4, !tbaa !9
  br label %112

112:                                              ; preds = %111, %107
  br label %113

113:                                              ; preds = %112, %104
  %114 = call i32 @remove(ptr noundef @.str.1) #5
  %115 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 25, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret i32 %115
}

; 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) #3

; Function Attrs: nounwind uwtable
declare hidden void @psa_its_fill_filename(i64 noundef, ptr noundef) #2

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

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

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

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

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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

!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}
!13 = !{!7, !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.psa_its_file_header_t = type { [8 x i8], [4 x i8], [4 x i8] }

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = 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: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #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
define dso_local range(i32 -146, 1) i32 @psa_its_set(i64 noundef %0, i32 noundef %1, ptr nocapture noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca [25 x i8], align 16
  %6 = alloca %struct.psa_its_file_header_t, align 8
  call void @llvm.lifetime.start.p0(i64 25, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #3
  %7 = load i64, ptr @.str, align 1
  store i64 %7, ptr %6, align 8
  %8 = trunc i32 %1 to i8
  %9 = getelementptr inbounds i8, ptr %6, i64 8
  store i8 %8, ptr %9, align 8, !tbaa !5
  %10 = lshr i32 %1, 8
  %11 = trunc i32 %10 to i8
  %12 = getelementptr inbounds i8, ptr %6, i64 9
  store i8 %11, ptr %12, align 1, !tbaa !5
  %13 = lshr i32 %1, 16
  %14 = trunc i32 %13 to i8
  %15 = getelementptr inbounds i8, ptr %6, i64 10
  store i8 %14, ptr %15, align 2, !tbaa !5
  %16 = lshr i32 %1, 24
  %17 = trunc nuw i32 %16 to i8
  %18 = getelementptr inbounds i8, ptr %6, i64 11
  store i8 %17, ptr %18, align 1, !tbaa !5
  %19 = trunc i32 %3 to i8
  %20 = getelementptr inbounds i8, ptr %6, i64 12
  store i8 %19, ptr %20, align 4, !tbaa !5
  %21 = lshr i32 %3, 8
  %22 = trunc i32 %21 to i8
  %23 = getelementptr inbounds i8, ptr %6, i64 13
  store i8 %22, ptr %23, align 1, !tbaa !5
  %24 = lshr i32 %3, 16
  %25 = trunc i32 %24 to i8
  %26 = getelementptr inbounds i8, ptr %6, i64 14
  store i8 %25, ptr %26, align 2, !tbaa !5
  %27 = lshr i32 %3, 24
  %28 = trunc nuw i32 %27 to i8
  %29 = getelementptr inbounds i8, ptr %6, i64 15
  store i8 %28, ptr %29, align 1, !tbaa !5
  call void @psa_its_fill_filename(i64 noundef %0, ptr noundef nonnull %5)
  %30 = call noalias ptr @fopen(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2)
  %31 = icmp eq ptr %30, null
  br i1 %31, label %.thread34, label %32

32:                                               ; preds = %4
  %33 = call i64 @fwrite(ptr noundef nonnull %6, i64 noundef 1, i64 noundef 16, ptr noundef nonnull %30)
  %.not = icmp eq i64 %33, 16
  br i1 %.not, label %34, label %40

34:                                               ; preds = %32
  %.not27 = icmp eq i32 %1, 0
  br i1 %.not27, label %38, label %35

35:                                               ; preds = %34
  %36 = zext i32 %1 to i64
  %37 = call i64 @fwrite(ptr noundef %2, i64 noundef 1, i64 noundef %36, ptr noundef nonnull %30)
  %.not28 = icmp eq i64 %37, %36
  br i1 %.not28, label %38, label %40

38:                                               ; preds = %34, %35
  %39 = call i32 @fclose(ptr noundef nonnull %30)
  %.not43 = icmp eq i32 %39, 0
  br i1 %.not43, label %42, label %.thread34

40:                                               ; preds = %35, %32
  %41 = call i32 @fclose(ptr noundef nonnull %30)
  br label %.thread34

42:                                               ; preds = %38
  %43 = call i32 @rename(ptr noundef nonnull @.str.1, ptr noundef nonnull %5) #3
  %.not30 = icmp eq i32 %43, 0
  %spec.select = select i1 %.not30, i32 0, i32 -146
  br label %.thread34

.thread34:                                        ; preds = %40, %38, %4, %42
  %.2 = phi i32 [ -142, %40 ], [ %spec.select, %42 ], [ -146, %4 ], [ -142, %38 ]
  %44 = call i32 @remove(ptr noundef nonnull @.str.1) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 25, ptr nonnull %5) #3
  ret i32 %.2
}

; Function Attrs: nounwind uwtable
declare hidden void @psa_its_fill_filename(i64 noundef, ptr noundef) local_unnamed_addr #2

; 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 i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

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

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

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 = { 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass