; LLVM IR from pandax381/microps :: net (net_device_add_iface)

; 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.net_device = type { ptr, ptr, i32, [16 x i8], i16, i16, i16, i16, i16, [16 x i8], %union.anon, ptr, ptr }
%union.anon = type { [16 x i8] }
%struct.net_iface = type { ptr, ptr, i32 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [57 x i8], align 1
@__func__.net_device_add_iface = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [34 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 @lprintf(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, 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 @net_device_add_iface(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.net_device, ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %6, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %32, %2
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %36

14:                                               ; preds = %11
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.net_iface, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.net_iface, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = icmp eq i32 %17, %20
  br i1 %21, label %22, label %31

22:                                               ; preds = %14
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.net_device, ptr %24, i32 0, i32 3
  %26 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.net_iface, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !13
  %30 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %23, i32 noundef 69, ptr noundef @.str, i32 noundef 122, ptr noundef @__func__.net_device_add_iface, ptr noundef @.str.4, ptr noundef %26, i32 noundef %29)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %48

31:                                               ; preds = %14
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.net_iface, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  store ptr %35, ptr %6, align 8, !tbaa !5
  br label %11, !llvm.loop !16

36:                                               ; preds = %11
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.net_device, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.net_iface, ptr %40, i32 0, i32 0
  store ptr %39, ptr %41, align 8, !tbaa !15
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.net_iface, ptr %43, i32 0, i32 1
  store ptr %42, ptr %44, align 8, !tbaa !18
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.net_device, ptr %46, i32 0, i32 1
  store ptr %45, ptr %47, align 8, !tbaa !9
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %48

48:                                               ; preds = %36, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %49 = load i32, ptr %3, align 4
  ret i32 %49
}

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 = { 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 8}
!10 = !{!"net_device", !6, i64 0, !6, i64 8, !11, i64 16, !7, i64 20, !12, i64 36, !12, i64 38, !12, i64 40, !12, i64 42, !12, i64 44, !7, i64 46, !7, i64 62, !6, i64 80, !6, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !11, i64 16}
!14 = !{!"net_iface", !6, i64 0, !6, i64 8, !11, i64 16}
!15 = !{!14, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!14, !6, i64 8}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [57 x i8], align 1
@__func__.net_device_add_iface = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [34 x i8], align 1

declare i32 @lprintf(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @net_device_add_iface(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  br label %5

5:                                                ; preds = %6, %2
  %.0.in = phi ptr [ %3, %2 ], [ %.0, %6 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %15, label %6

6:                                                ; preds = %5
  %7 = getelementptr inbounds i8, ptr %.0, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = load i32, ptr %4, align 8, !tbaa !9
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %11, label %5, !llvm.loop !12

11:                                               ; preds = %6
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 20
  %14 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %12, i32 noundef 69, ptr noundef nonnull @.str, i32 noundef 122, ptr noundef nonnull @__func__.net_device_add_iface, ptr noundef nonnull @.str.4, ptr noundef nonnull %13, i32 noundef %8) #2
  br label %18

15:                                               ; preds = %5
  %16 = load ptr, ptr %3, align 8, !tbaa !14
  store ptr %16, ptr %1, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %0, ptr %17, align 8, !tbaa !18
  store ptr %1, ptr %3, align 8, !tbaa !14
  br label %18

18:                                               ; preds = %15, %11
  %.013 = phi i32 [ -1, %11 ], [ 0, %15 ]
  ret i32 %.013
}

attributes #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 = { 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 = { 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, !11, i64 16}
!10 = !{!"net_iface", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !6, i64 8}
!15 = !{!"net_device", !6, i64 0, !6, i64 8, !11, i64 16, !7, i64 20, !16, i64 36, !16, i64 38, !16, i64 40, !16, i64 42, !16, i64 44, !7, i64 46, !7, i64 62, !6, i64 80, !6, i64 88}
!16 = !{!"short", !7, i64 0}
!17 = !{!10, !6, i64 0}
!18 = !{!10, !6, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass