; LLVM IR from CerebusOSS/CereLink :: samples/TestAnalogOut/test_analog_out.ll (Z8testOpenv)

; 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._cbSdkVersion = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct._cbSdkConnection = type <{ i32, i32, i32, [4 x i8], ptr, ptr, i32, [4 x i8] }>

@.str.20 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [37 x i8], align 1
@__const._Z8testOpenv.strConnection = external hidden unnamed_addr constant [5 x [8 x i8]], align 16
@__const._Z8testOpenv.strInstrument = external hidden unnamed_addr constant [5 x [13 x i8]], align 16
@.str.22 = external hidden unnamed_addr constant [75 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z12handleResult12_cbSdkResult(i32 noundef) #0

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z14testGetVersionv(ptr dead_on_unwind noalias writable sret(%struct._cbSdkVersion) align 4) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z8testOpenv() #0 {
  %1 = alloca %struct._cbSdkVersion, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca %struct._cbSdkConnection, align 8
  %5 = alloca i32, align 4
  %6 = alloca [5 x [8 x i8]], align 16
  %7 = alloca [5 x [13 x i8]], align 16
  %8 = alloca %struct._cbSdkVersion, align 4
  call void @llvm.lifetime.start.p0(i64 48, ptr %1) #5
  call void @_Z14testGetVersionv(ptr dead_on_unwind writable sret(%struct._cbSdkVersion) align 4 %1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  call void @_ZN16_cbSdkConnectionC2Ev(ptr noundef nonnull align 8 dereferenceable(36) %4)
  %10 = call i32 @cbSdkOpen(i32 noundef 0, i32 noundef %9, ptr noundef byval(%struct._cbSdkConnection) align 8 %4)
  store i32 %10, ptr %3, align 4, !tbaa !9
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %0
  %14 = call i32 (ptr, ...) @printf(ptr noundef @.str.20)
  br label %15

15:                                               ; preds = %13, %0
  %16 = load i32, ptr %3, align 4, !tbaa !9
  call void @_Z12handleResult12_cbSdkResult(i32 noundef %16)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = icmp sge i32 %17, 0
  br i1 %18, label %19, label %58

19:                                               ; preds = %15
  %20 = call i32 @cbSdkGetType(i32 noundef 0, ptr noundef %2, ptr noundef %5)
  store i32 %20, ptr %3, align 4, !tbaa !9
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %19
  %24 = call i32 (ptr, ...) @printf(ptr noundef @.str.21)
  br label %25

25:                                               ; preds = %23, %19
  %26 = load i32, ptr %3, align 4, !tbaa !9
  call void @_Z12handleResult12_cbSdkResult(i32 noundef %26)
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %32, label %29

29:                                               ; preds = %25
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = icmp sgt i32 %30, 3
  br i1 %31, label %32, label %33

32:                                               ; preds = %29, %25
  store i32 4, ptr %2, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %32, %29
  %34 = load i32, ptr %5, align 4, !tbaa !11
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %39, label %36

36:                                               ; preds = %33
  %37 = load i32, ptr %5, align 4, !tbaa !11
  %38 = icmp sgt i32 %37, 4
  br i1 %38, label %39, label %40

39:                                               ; preds = %36, %33
  store i32 4, ptr %5, align 4, !tbaa !11
  br label %40

40:                                               ; preds = %39, %36
  call void @llvm.lifetime.start.p0(i64 40, ptr %6) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const._Z8testOpenv.strConnection, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 65, ptr %7) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %7, ptr align 16 @__const._Z8testOpenv.strInstrument, i64 65, i1 false)
  call void @llvm.lifetime.start.p0(i64 48, ptr %8) #5
  call void @_Z14testGetVersionv(ptr dead_on_unwind writable sret(%struct._cbSdkVersion) align 4 %8)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %1, ptr align 4 %8, i64 48, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 48, ptr %8) #5
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds [5 x [8 x i8]], ptr %6, i64 0, i64 %42
  %44 = getelementptr inbounds [8 x i8], ptr %43, i64 0, i64 0
  %45 = load i32, ptr %5, align 4, !tbaa !11
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds [5 x [13 x i8]], ptr %7, i64 0, i64 %46
  %48 = getelementptr inbounds [13 x i8], ptr %47, i64 0, i64 0
  %49 = getelementptr inbounds %struct._cbSdkVersion, ptr %1, i32 0, i32 6
  %50 = load i32, ptr %49, align 4, !tbaa !16
  %51 = getelementptr inbounds %struct._cbSdkVersion, ptr %1, i32 0, i32 7
  %52 = load i32, ptr %51, align 4, !tbaa !18
  %53 = getelementptr inbounds %struct._cbSdkVersion, ptr %1, i32 0, i32 8
  %54 = load i32, ptr %53, align 4, !tbaa !19
  %55 = getelementptr inbounds %struct._cbSdkVersion, ptr %1, i32 0, i32 9
  %56 = load i32, ptr %55, align 4, !tbaa !20
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.22, ptr noundef %44, ptr noundef %48, i32 noundef %50, i32 noundef %52, i32 noundef %54, i32 noundef %56)
  call void @llvm.lifetime.end.p0(i64 65, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr %6) #5
  br label %58

58:                                               ; preds = %40, %15
  %59 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr %1) #5
  ret i32 %59
}

declare i32 @cbSdkOpen(i32 noundef, i32 noundef, ptr noundef byval(%struct._cbSdkConnection) align 8) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN16_cbSdkConnectionC2Ev(ptr noundef nonnull align 8 dereferenceable(36)) unnamed_addr #3 align 2

declare i32 @cbSdkGetType(i32 noundef, ptr noundef, ptr noundef) #1

; 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

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress 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 = { 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 = !{!"_ZTS20_cbSdkConnectionType", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTS12_cbSdkResult", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTS20_cbSdkInstrumentType", !7, i64 0}
!13 = !{i64 0, i64 4, !14, i64 4, i64 4, !14, i64 8, i64 4, !14, i64 12, i64 4, !14, i64 16, i64 4, !14, i64 20, i64 4, !14, i64 24, i64 4, !14, i64 28, i64 4, !14, i64 32, i64 4, !14, i64 36, i64 4, !14, i64 40, i64 4, !14, i64 44, i64 4, !14}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !15, i64 24}
!17 = !{!"_ZTS13_cbSdkVersion", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20, !15, i64 24, !15, i64 28, !15, i64 32, !15, i64 36, !15, i64 40, !15, i64 44}
!18 = !{!17, !15, i64 28}
!19 = !{!17, !15, i64 32}
!20 = !{!17, !15, i64 36}


; 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._cbSdkVersion = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct._cbSdkConnection = type <{ i32, i32, i32, [4 x i8], ptr, ptr, i32, [4 x i8] }>

@.str.20 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [37 x i8], align 1
@__const._Z8testOpenv.strConnection = external hidden unnamed_addr constant [5 x [8 x i8]], align 16
@__const._Z8testOpenv.strInstrument = external hidden unnamed_addr constant [5 x [13 x i8]], align 16
@.str.22 = external hidden unnamed_addr constant [75 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z12handleResult12_cbSdkResult(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z14testGetVersionv(ptr dead_on_unwind noalias writable sret(%struct._cbSdkVersion) align 4) 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) #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z8testOpenv() local_unnamed_addr #0 {
  %1 = alloca %struct._cbSdkVersion, align 4
  %2 = alloca i32, align 4
  %3 = alloca %struct._cbSdkConnection, align 8
  %4 = alloca i32, align 4
  %5 = alloca [5 x [8 x i8]], align 16
  %6 = alloca [5 x [13 x i8]], align 16
  %7 = alloca %struct._cbSdkVersion, align 4
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %1) #6
  call void @_Z14testGetVersionv(ptr dead_on_unwind nonnull writable sret(%struct._cbSdkVersion) align 4 %1)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @_ZN16_cbSdkConnectionC2Ev(ptr noundef nonnull align 8 dereferenceable(36) %3)
  %8 = call i32 @cbSdkOpen(i32 noundef 0, i32 noundef 0, ptr noundef nonnull byval(%struct._cbSdkConnection) align 8 %3)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %.thread, label %9

.thread:                                          ; preds = %0
  call void @_Z12handleResult12_cbSdkResult(i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  br label %12

9:                                                ; preds = %0
  %10 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.20)
  call void @_Z12handleResult12_cbSdkResult(i32 noundef %8)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  %11 = icmp sgt i32 %8, -1
  br i1 %11, label %12, label %38

12:                                               ; preds = %.thread, %9
  %13 = call i32 @cbSdkGetType(i32 noundef 0, ptr noundef nonnull %2, ptr noundef nonnull %4)
  %.not10 = icmp eq i32 %13, 0
  br i1 %.not10, label %16, label %14

14:                                               ; preds = %12
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21)
  br label %16

16:                                               ; preds = %14, %12
  call void @_Z12handleResult12_cbSdkResult(i32 noundef %13)
  %17 = load i32, ptr %2, align 4
  %or.cond = icmp ugt i32 %17, 3
  br i1 %or.cond, label %18, label %19

18:                                               ; preds = %16
  store i32 4, ptr %2, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %16, %18
  %20 = load i32, ptr %4, align 4
  %or.cond3 = icmp ugt i32 %20, 4
  br i1 %or.cond3, label %21, label %22

21:                                               ; preds = %19
  store i32 4, ptr %4, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %19, %21
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %5) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %5, ptr noundef nonnull align 16 dereferenceable(40) @__const._Z8testOpenv.strConnection, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 65, ptr nonnull %6) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(65) %6, ptr noundef nonnull align 16 dereferenceable(65) @__const._Z8testOpenv.strInstrument, i64 65, i1 false)
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %7) #6
  call void @_Z14testGetVersionv(ptr dead_on_unwind nonnull writable sret(%struct._cbSdkVersion) align 4 %7)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(48) %1, ptr noundef nonnull align 4 dereferenceable(48) %7, i64 48, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %7) #6
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds [5 x [8 x i8]], ptr %5, i64 0, i64 %24
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [5 x [13 x i8]], ptr %6, i64 0, i64 %27
  %29 = getelementptr inbounds i8, ptr %1, i64 24
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %31 = getelementptr inbounds i8, ptr %1, i64 28
  %32 = load i32, ptr %31, align 4, !tbaa !16
  %33 = getelementptr inbounds i8, ptr %1, i64 32
  %34 = load i32, ptr %33, align 4, !tbaa !17
  %35 = getelementptr inbounds i8, ptr %1, i64 36
  %36 = load i32, ptr %35, align 4, !tbaa !18
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.22, ptr noundef nonnull %25, ptr noundef nonnull %28, i32 noundef %30, i32 noundef %32, i32 noundef %34, i32 noundef %36)
  call void @llvm.lifetime.end.p0(i64 65, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %5) #6
  br label %38

38:                                               ; preds = %22, %9
  %.0 = phi i32 [ %13, %22 ], [ %8, %9 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #6
  ret i32 %.0
}

declare i32 @cbSdkOpen(i32 noundef, i32 noundef, ptr noundef byval(%struct._cbSdkConnection) align 8) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN16_cbSdkConnectionC2Ev(ptr noundef nonnull align 8 dereferenceable(36)) unnamed_addr #4 align 2

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

; 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

attributes #0 = { mustprogress 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 = { 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 = { 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 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 #5 = { mustprogress 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 = !{!"_ZTS20_cbSdkConnectionType", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTS20_cbSdkInstrumentType", !7, i64 0}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !12, i64 8, i64 4, !12, i64 12, i64 4, !12, i64 16, i64 4, !12, i64 20, i64 4, !12, i64 24, i64 4, !12, i64 28, i64 4, !12, i64 32, i64 4, !12, i64 36, i64 4, !12, i64 40, i64 4, !12, i64 44, i64 4, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 24}
!15 = !{!"_ZTS13_cbSdkVersion", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44}
!16 = !{!15, !13, i64 28}
!17 = !{!15, !13, i64 32}
!18 = !{!15, !13, i64 36}


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