; LLVM IR from pandax381/microps :: ip (ip_protocol_register)

; 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.ip_protocol = type { ptr, [16 x i8], i8, ptr }

@stderr = external global ptr, align 8
@.str.12 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [23 x i8], align 1
@protocols = external hidden global ptr, align 8
@__func__.ip_protocol_register = external hidden unnamed_addr constant [21 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [28 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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @memory_alloc(i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @ip_protocol_register(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %10 = load ptr, ptr @protocols, align 8, !tbaa !5
  store ptr %10, ptr %8, align 8, !tbaa !5
  br label %11

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

14:                                               ; preds = %11
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ip_protocol, ptr %15, i32 0, i32 2
  %17 = load i8, ptr %16, align 8, !tbaa !10
  %18 = zext i8 %17 to i32
  %19 = load i8, ptr %6, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = icmp eq i32 %18, %20
  br i1 %21, label %22, label %35

22:                                               ; preds = %14
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i8, ptr %6, align 1, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ip_protocol, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds [16 x i8], ptr %28, i64 0, i64 0
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ip_protocol, ptr %30, i32 0, i32 2
  %32 = load i8, ptr %31, align 8, !tbaa !10
  %33 = zext i8 %32 to i32
  %34 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %23, i32 noundef 69, ptr noundef @.str.12, i32 noundef 457, ptr noundef @__func__.ip_protocol_register, ptr noundef @.str.23, ptr noundef %24, i32 noundef %26, ptr noundef %29, i32 noundef %33)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %72

35:                                               ; preds = %14
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ip_protocol, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !12
  store ptr %39, ptr %8, align 8, !tbaa !5
  br label %11, !llvm.loop !13

40:                                               ; preds = %11
  %41 = call ptr @memory_alloc(i64 noundef 40)
  store ptr %41, ptr %8, align 8, !tbaa !5
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %47, label %44

44:                                               ; preds = %40
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %45, i32 noundef 69, ptr noundef @.str.12, i32 noundef 463, ptr noundef @__func__.ip_protocol_register, ptr noundef @.str.15)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %72

47:                                               ; preds = %40
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ip_protocol, ptr %48, i32 0, i32 1
  %50 = getelementptr inbounds [16 x i8], ptr %49, i64 0, i64 0
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = call ptr @strncpy(ptr noundef %50, ptr noundef %51, i64 noundef 15) #5
  %53 = load i8, ptr %6, align 1, !tbaa !9
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ip_protocol, ptr %54, i32 0, i32 2
  store i8 %53, ptr %55, align 8, !tbaa !10
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ip_protocol, ptr %57, i32 0, i32 3
  store ptr %56, ptr %58, align 8, !tbaa !15
  %59 = load ptr, ptr @protocols, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ip_protocol, ptr %60, i32 0, i32 0
  store ptr %59, ptr %61, align 8, !tbaa !12
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %62, ptr @protocols, align 8, !tbaa !5
  %63 = load ptr, ptr @stderr, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.ip_protocol, ptr %64, i32 0, i32 1
  %66 = getelementptr inbounds [16 x i8], ptr %65, i64 0, i64 0
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.ip_protocol, ptr %67, i32 0, i32 2
  %69 = load i8, ptr %68, align 8, !tbaa !10
  %70 = zext i8 %69 to i32
  %71 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %63, i32 noundef 73, ptr noundef @.str.12, i32 noundef 471, ptr noundef @__func__.ip_protocol_register, ptr noundef @.str.24, ptr noundef %66, i32 noundef %70)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %72

72:                                               ; preds = %47, %44, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %73 = load i32, ptr %4, align 4
  ret i32 %73
}

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 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 = { inlinehint 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 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 24}
!11 = !{!"ip_protocol", !6, i64 0, !7, i64 8, !7, i64 24, !6, i64 32}
!12 = !{!11, !6, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!11, !6, i64 32}


; 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.12 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [23 x i8], align 1
@protocols = external hidden local_unnamed_addr global ptr, align 8
@__func__.ip_protocol_register = external hidden unnamed_addr constant [21 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [28 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: inlinehint nounwind uwtable
declare hidden ptr @memory_alloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @ip_protocol_register(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #2 {
  br label %4

4:                                                ; preds = %5, %3
  %.0.in = phi ptr [ @protocols, %3 ], [ %.0, %5 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %14, label %5

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

9:                                                ; preds = %5
  %10 = zext i8 %1 to i32
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.0, i64 8
  %13 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %11, i32 noundef 69, ptr noundef nonnull @.str.12, i32 noundef 457, ptr noundef nonnull @__func__.ip_protocol_register, ptr noundef nonnull @.str.23, ptr noundef %0, i32 noundef %10, ptr noundef nonnull %12, i32 noundef %10) #4
  br label %28

14:                                               ; preds = %4
  %15 = tail call ptr @memory_alloc(i64 noundef 40)
  %.not23 = icmp eq ptr %15, null
  br i1 %.not23, label %16, label %19

16:                                               ; preds = %14
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  %18 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %17, i32 noundef 69, ptr noundef nonnull @.str.12, i32 noundef 463, ptr noundef nonnull @__func__.ip_protocol_register, ptr noundef nonnull @.str.15) #4
  br label %28

19:                                               ; preds = %14
  %20 = getelementptr inbounds i8, ptr %15, i64 8
  %21 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %20, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 15) #4
  %22 = getelementptr inbounds i8, ptr %15, i64 24
  store i8 %1, ptr %22, align 8, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %15, i64 32
  store ptr %2, ptr %23, align 8, !tbaa !13
  %24 = load ptr, ptr @protocols, align 8, !tbaa !5
  store ptr %24, ptr %15, align 8, !tbaa !14
  store ptr %15, ptr @protocols, align 8, !tbaa !5
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = zext i8 %1 to i32
  %27 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %25, i32 noundef 73, ptr noundef nonnull @.str.12, i32 noundef 471, ptr noundef nonnull @__func__.ip_protocol_register, ptr noundef nonnull @.str.24, ptr noundef nonnull %20, i32 noundef %26) #4
  br label %28

28:                                               ; preds = %19, %16, %9
  %.019 = phi i32 [ -1, %9 ], [ 0, %19 ], [ -1, %16 ]
  ret i32 %.019
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #3

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 = { inlinehint 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 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 }

!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, !7, i64 24}
!10 = !{!"ip_protocol", !6, i64 0, !7, i64 8, !7, i64 24, !6, i64 32}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !6, i64 32}
!14 = !{!10, !6, i64 0}


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