; LLVM IR from erwincoumans/tiny-differentiable-simulator :: third_party/zeromq/src/ipc_address.ll (ZN3zmq13ipc_address_t7resolveEPKc)

; 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"

%"class.zmq::ipc_address_t" = type { %struct.sockaddr_un, i64 }
%struct.sockaddr_un = type { i16, [108 x i8] }

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3zmq13ipc_address_t7resolveEPKc(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = call i64 @strlen(ptr noundef %9) #6
  store i64 %10, ptr %6, align 8, !tbaa !9
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = icmp uge i64 %11, 108
  br i1 %12, label %13, label %15

13:                                               ; preds = %2
  %14 = call ptr @__errno_location() #7
  store i32 36, ptr %14, align 4, !tbaa !11
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 0
  %18 = load i8, ptr %17, align 1, !tbaa !13
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 %19, 64
  br i1 %20, label %21, label %28

21:                                               ; preds = %15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 1
  %24 = load i8, ptr %23, align 1, !tbaa !13
  %25 = icmp ne i8 %24, 0
  br i1 %25, label %28, label %26

26:                                               ; preds = %21
  %27 = call ptr @__errno_location() #7
  store i32 22, ptr %27, align 4, !tbaa !11
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

28:                                               ; preds = %21, %15
  %29 = getelementptr inbounds %"class.zmq::ipc_address_t", ptr %8, i32 0, i32 0
  %30 = getelementptr inbounds %struct.sockaddr_un, ptr %29, i32 0, i32 0
  store i16 1, ptr %30, align 8, !tbaa !14
  %31 = getelementptr inbounds %"class.zmq::ipc_address_t", ptr %8, i32 0, i32 0
  %32 = getelementptr inbounds %struct.sockaddr_un, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds [108 x i8], ptr %32, i64 0, i64 0
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = add i64 %35, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %33, ptr align 1 %34, i64 %36, i1 false)
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 0
  %39 = load i8, ptr %38, align 1, !tbaa !13
  %40 = sext i8 %39 to i32
  %41 = icmp eq i32 %40, 64
  br i1 %41, label %42, label %46

42:                                               ; preds = %28
  %43 = getelementptr inbounds %"class.zmq::ipc_address_t", ptr %8, i32 0, i32 0
  %44 = getelementptr inbounds %struct.sockaddr_un, ptr %43, i32 0, i32 1
  %45 = getelementptr inbounds [108 x i8], ptr %44, i64 0, i64 0
  store i8 0, ptr %45, align 2, !tbaa !13
  br label %46

46:                                               ; preds = %42, %28
  %47 = load i64, ptr %6, align 8, !tbaa !9
  %48 = add i64 2, %47
  %49 = getelementptr inbounds %"class.zmq::ipc_address_t", ptr %8, i32 0, i32 1
  store i64 %48, ptr %49, align 8, !tbaa !18
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

50:                                               ; preds = %46, %26, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %51 = load i32, ptr %3, align 4
  ret i32 %51
}

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

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

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

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

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !17, i64 0}
!15 = !{!"_ZTSN3zmq13ipc_address_tE", !16, i64 0, !10, i64 112}
!16 = !{!"_ZTS11sockaddr_un", !17, i64 0, !7, i64 2}
!17 = !{!"short", !7, i64 0}
!18 = !{!15, !10, i64 112}


; 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"

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 -1, 1) i32 @_ZN3zmq13ipc_address_t7resolveEPKc(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(120) %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 align 2 {
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #4
  %4 = icmp ugt i64 %3, 107
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = tail call ptr @__errno_location() #5
  store i32 36, ptr %6, align 4, !tbaa !5
  br label %24

7:                                                ; preds = %2
  %8 = load i8, ptr %1, align 1, !tbaa !9
  %9 = icmp eq i8 %8, 64
  br i1 %9, label %10, label %15

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %1, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %.not = icmp eq i8 %12, 0
  br i1 %.not, label %13, label %15

13:                                               ; preds = %10
  %14 = tail call ptr @__errno_location() #5
  store i32 22, ptr %14, align 4, !tbaa !5
  br label %24

15:                                               ; preds = %10, %7
  store i16 1, ptr %0, align 8, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %0, i64 2
  %17 = add nuw nsw i64 %3, 1
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(1) %16, ptr noundef nonnull align 1 dereferenceable(1) %1, i64 %17, i1 false)
  %18 = load i8, ptr %1, align 1, !tbaa !9
  %19 = icmp eq i8 %18, 64
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store i8 0, ptr %16, align 2, !tbaa !9
  br label %21

21:                                               ; preds = %20, %15
  %22 = add nuw nsw i64 %3, 2
  %23 = getelementptr inbounds i8, ptr %0, i64 112
  store i64 %22, ptr %23, align 8, !tbaa !15
  br label %24

24:                                               ; preds = %21, %13, %5
  %.0 = phi i32 [ -1, %5 ], [ 0, %21 ], [ -1, %13 ]
  ret i32 %.0
}

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) 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 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 #3 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 willreturn memory(read) }
attributes #5 = { nounwind willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !13, i64 0}
!11 = !{!"_ZTSN3zmq13ipc_address_tE", !12, i64 0, !14, i64 112}
!12 = !{!"_ZTS11sockaddr_un", !13, i64 0, !7, i64 2}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!11, !14, i64 112}


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