; LLVM IR from guanzhi/GmSSL :: src/sdf (sdf)

; 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.DeviceInfo_st = type { [40 x i8], [16 x i8], [16 x i8], i32, i32, [2 x i32], i32, i32, i32 }
%struct.SDF_DEVICE = type { ptr, [41 x i8], [17 x i8], [17 x i8] }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__FUNCTION__.sdf_open_device = external hidden unnamed_addr constant [16 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sdf_open_device(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.DeviceInfo_st, align 1
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 -1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 100, ptr %7) #6
  %9 = call i32 @SDF_OpenDevice(ptr noundef %5)
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %17

11:                                               ; preds = %1
  br label %12

12:                                               ; preds = %11
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 126, ptr noundef @__FUNCTION__.sdf_open_device) #6
  br label %15

15:                                               ; preds = %12
  br label %16

16:                                               ; preds = %15
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %65

17:                                               ; preds = %1
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call i32 @SDF_OpenSession(ptr noundef %18, ptr noundef %6)
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %29

21:                                               ; preds = %17
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i32 @SDF_CloseDevice(ptr noundef %22)
  br label %24

24:                                               ; preds = %21
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 131, ptr noundef @__FUNCTION__.sdf_open_device) #6
  br label %27

27:                                               ; preds = %24
  br label %28

28:                                               ; preds = %27
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %65

29:                                               ; preds = %17
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call i32 @SDF_GetDeviceInfo(ptr noundef %30, ptr noundef %7)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %43

33:                                               ; preds = %29
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call i32 @SDF_CloseSession(ptr noundef %34)
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call i32 @SDF_CloseDevice(ptr noundef %36)
  br label %38

38:                                               ; preds = %33
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 137, ptr noundef @__FUNCTION__.sdf_open_device) #6
  br label %41

41:                                               ; preds = %38
  br label %42

42:                                               ; preds = %41
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %65

43:                                               ; preds = %29
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = call i32 @SDF_CloseSession(ptr noundef %44)
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %46, i8 0, i64 88, i1 false)
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.SDF_DEVICE, ptr %48, i32 0, i32 0
  store ptr %47, ptr %49, align 8, !tbaa !11
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.SDF_DEVICE, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds [41 x i8], ptr %51, i64 0, i64 0
  %53 = getelementptr inbounds %struct.DeviceInfo_st, ptr %7, i32 0, i32 0
  %54 = getelementptr inbounds [40 x i8], ptr %53, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %52, ptr align 1 %54, i64 40, i1 false)
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.SDF_DEVICE, ptr %55, i32 0, i32 2
  %57 = getelementptr inbounds [17 x i8], ptr %56, i64 0, i64 0
  %58 = getelementptr inbounds %struct.DeviceInfo_st, ptr %7, i32 0, i32 1
  %59 = getelementptr inbounds [16 x i8], ptr %58, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %57, ptr align 1 %59, i64 16, i1 false)
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.SDF_DEVICE, ptr %60, i32 0, i32 3
  %62 = getelementptr inbounds [17 x i8], ptr %61, i64 0, i64 0
  %63 = getelementptr inbounds %struct.DeviceInfo_st, ptr %7, i32 0, i32 2
  %64 = getelementptr inbounds [16 x i8], ptr %63, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %62, ptr align 1 %64, i64 16, i1 false)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %65

65:                                               ; preds = %43, %42, %28, %16
  call void @llvm.lifetime.end.p0(i64 100, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  %66 = load i32, ptr %2, align 4
  ret i32 %66
}

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

declare i32 @SDF_OpenDevice(ptr noundef) #3

declare i32 @SDF_OpenSession(ptr noundef, ptr noundef) #3

declare i32 @SDF_CloseDevice(ptr noundef) #3

declare i32 @SDF_GetDeviceInfo(ptr noundef, ptr noundef) #3

declare i32 @SDF_CloseSession(ptr noundef) #3

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

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

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

attributes #0 = { 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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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: write) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !7, i64 8, !7, i64 49, !7, i64 66}


; 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.DeviceInfo_st = type { [40 x i8], [16 x i8], [16 x i8], i32, i32, [2 x i32], i32, i32, i32 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__FUNCTION__.sdf_open_device = external hidden unnamed_addr constant [16 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @sdf_open_device(ptr nocapture noundef writeonly %0) local_unnamed_addr #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %struct.DeviceInfo_st, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #6
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #6
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %4) #6
  %5 = call i32 @SDF_OpenDevice(ptr noundef nonnull %2) #6
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %9, label %6

6:                                                ; preds = %1
  %7 = load ptr, ptr @stderr, align 8, !tbaa !5
  %8 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 126, ptr noundef nonnull @__FUNCTION__.sdf_open_device) #7
  br label %35

9:                                                ; preds = %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call i32 @SDF_OpenSession(ptr noundef %10, ptr noundef nonnull %3) #6
  %.not5 = icmp eq i32 %11, 0
  br i1 %.not5, label %17, label %12

12:                                               ; preds = %9
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call i32 @SDF_CloseDevice(ptr noundef %13) #6
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 131, ptr noundef nonnull @__FUNCTION__.sdf_open_device) #7
  br label %35

17:                                               ; preds = %9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call i32 @SDF_GetDeviceInfo(ptr noundef %18, ptr noundef nonnull %4) #6
  %.not6 = icmp eq i32 %19, 0
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call i32 @SDF_CloseSession(ptr noundef %20) #6
  br i1 %.not6, label %27, label %22

22:                                               ; preds = %17
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = call i32 @SDF_CloseDevice(ptr noundef %23) #6
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 137, ptr noundef nonnull @__FUNCTION__.sdf_open_device) #7
  br label %35

27:                                               ; preds = %17
  %28 = getelementptr inbounds i8, ptr %0, i64 48
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(88) %28, i8 0, i64 40, i1 false)
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %29, ptr %0, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %0, i64 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %30, ptr noundef nonnull align 1 dereferenceable(40) %4, i64 40, i1 false)
  %31 = getelementptr inbounds i8, ptr %0, i64 49
  %32 = getelementptr inbounds i8, ptr %4, i64 40
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %31, ptr noundef nonnull align 1 dereferenceable(16) %32, i64 16, i1 false)
  %33 = getelementptr inbounds i8, ptr %0, i64 66
  %34 = getelementptr inbounds i8, ptr %4, i64 56
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(16) %33, ptr noundef nonnull align 1 dereferenceable(16) %34, i64 16, i1 false)
  br label %35

35:                                               ; preds = %27, %22, %12, %6
  %.0 = phi i32 [ -1, %6 ], [ -1, %12 ], [ -1, %22 ], [ 1, %27 ]
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #6
  ret i32 %.0
}

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

declare i32 @SDF_OpenDevice(ptr noundef) local_unnamed_addr #3

declare i32 @SDF_OpenSession(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @SDF_CloseDevice(ptr noundef) local_unnamed_addr #3

declare i32 @SDF_GetDeviceInfo(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @SDF_CloseSession(ptr noundef) local_unnamed_addr #3

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

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

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

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 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { cold 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, !6, i64 0}
!10 = !{!"", !6, i64 0, !7, i64 8, !7, i64 49, !7, i64 66}


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