#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *nl_nid_addr(char *);
int nl_nid_parse_addr(char *);
int strcmp(char *, char *);
scalar_t__ strlen(char *);
int strncmp(char *, char *, int);
int strtoul(char *, int /*<<< orphan*/ *, int);
int nl_cmp_addr(char *nid1, char *nid2, int *cflagp) {
  char *p1 = nl_nid_addr(nid1);
  char *p2 = nl_nid_addr(nid2);
  int res, o1, o2, cflag = 0;
  o1 = nl_nid_parse_addr(p1);
  o2 = nl_nid_parse_addr(p2);
  res = strncmp(p1, p2, o1);
  if (o1 == o2 && res == 0) {
    res = strtoul(&p1[o1], NULL, 10) - strtoul(&p2[o2], NULL, 10);
    if (cflagp && strlen(&p1[o1]) > 0 && strlen(&p2[o2]) > 0)
      cflag = 1;
  } else
    res = strcmp(p1, p2);
  free(p1);
  free(p2);
  if (cflagp)
    *cflagp = cflag;
  return res;
}


x86 assembly (clang, -O0):
<nl_cmp_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <nl_nid_addr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <nl_nid_addr@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <nl_nid_parse_addr@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <nl_nid_parse_addr@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1040 <strncmp@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jne    1270 <nl_cmp_addr+0x100>
cmpl   $0x0,-0x2c(%rbp)
jne    1270 <nl_cmp_addr+0x100>
mov    -0x20(%rbp),%rdi
movslq -0x30(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1090 <strtoul@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1090 <strtoul@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     126b <nl_cmp_addr+0xfb>
mov    -0x20(%rbp),%rdi
movslq -0x30(%rbp),%rax
add    %rax,%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
jle    126b <nl_cmp_addr+0xfb>
mov    -0x28(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
jle    126b <nl_cmp_addr+0xfb>
movl   $0x1,-0x38(%rbp)
jmp    1280 <nl_cmp_addr+0x110>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcmp@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
je     12a6 <nl_cmp_addr+0x136>
mov    -0x38(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nl_cmp_addr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r12
mov    %rsi,%rbx
call   1050 <nl_nid_addr@plt>
mov    %rax,%rbp
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <nl_nid_addr@plt>
mov    %rax,%r15
mov    %rax,0x8(%rsp)
mov    %rbp,%rdi
call   1080 <nl_nid_parse_addr@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1080 <nl_nid_parse_addr@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <strncmp@plt>
cmp    %r13d,%ebx
jne    122c <nl_cmp_addr+0xbc>
test   %eax,%eax
jne    122c <nl_cmp_addr+0xbc>
mov    %r14,0x10(%rsp)
movslq %ebx,%r14
add    %r14,%rbp
xor    %ebx,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <strtoul@plt>
mov    %eax,%r13d
add    %r14,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <strtoul@plt>
sub    %eax,%r13d
test   %r12,%r12
je     1220 <nl_cmp_addr+0xb0>
mov    %rbp,%rdi
call   1060 <strlen@plt>
test   %rax,%rax
jle    1220 <nl_cmp_addr+0xb0>
mov    %r15,%rdi
call   1060 <strlen@plt>
xor    %ebx,%ebx
test   %rax,%rax
setg   %bl
mov    0x10(%rsp),%r14
mov    0x8(%rsp),%rbp
jmp    1241 <nl_cmp_addr+0xd1>
mov    %r14,%rdi
mov    0x8(%rsp),%rbp
mov    %rbp,%rsi
call   1070 <strcmp@plt>
mov    %eax,%r13d
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
test   %r12,%r12
je     125a <nl_cmp_addr+0xea>
mov    %ebx,(%r12)
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @nl_cmp_addr(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%13 = load i8*, i8** %4
%14 = call i8* @nl_nid_addr(i8* %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %5
%16 = call i8* @nl_nid_addr(i8* %15)
store i8* %16, i8** %8
store i32 0, i32* %12
%17 = load i8*, i8** %7
%18 = call i32 @nl_nid_parse_addr(i8* %17)
store i32 %18, i32* %10
%19 = load i8*, i8** %8
%20 = call i32 @nl_nid_parse_addr(i8* %19)
store i32 %20, i32* %11
%21 = load i8*, i8** %7
%22 = load i8*, i8** %8
%23 = load i32, i32* %10
%24 = call i32 @strncmp(i8* %21, i8* %22, i32 %23)
store i32 %24, i32* %9
%25 = load i32, i32* %10
%26 = load i32, i32* %11
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %61
28: ; preds = %3
%29 = load i32, i32* %9
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %61
31: ; preds = %28
%32 = load i8*, i8** %7
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = call i32 @strtoul(i8* %35, i32* null, i32 10)
%37 = load i8*, i8** %8
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = call i32 @strtoul(i8* %40, i32* null, i32 10)
%42 = sub nsw i32 %36, %41
store i32 %42, i32* %9
%43 = load i32*, i32** %6
%44 = icmp ne i32* %43, null
br i1 %44, label %45, label %60
45: ; preds = %31
%46 = load i8*, i8** %7
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = call i64 @strlen(i8* %49)
%51 = icmp sgt i64 %50, 0
br i1 %51, label %52, label %60
52: ; preds = %45
%53 = load i8*, i8** %8
%54 = load i32, i32* %11
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = call i64 @strlen(i8* %56)
%58 = icmp sgt i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %52
store i32 1, i32* %12
br label %60
60: ; preds = %59, %52, %45, %31
br label %65
61: ; preds = %28, %3
%62 = load i8*, i8** %7
%63 = load i8*, i8** %8
%64 = call i32 @strcmp(i8* %62, i8* %63)
store i32 %64, i32* %9
br label %65
65: ; preds = %61, %60
%66 = load i8*, i8** %7
%67 = call i32 @free(i8* %66)
%68 = load i8*, i8** %8
%69 = call i32 @free(i8* %68)
%70 = load i32*, i32** %6
%71 = icmp ne i32* %70, null
br i1 %71, label %72, label %75
72: ; preds = %65
%73 = load i32, i32* %12
%74 = load i32*, i32** %6
store i32 %73, i32* %74
br label %75
75: ; preds = %72, %65
%76 = load i32, i32* %9
ret i32 %76
}

LLVM IR (-O2):
define i32 @nl_cmp_addr(i8* %0, i8* %1, i32* writeonly %2) {
%4 = tail call i8* @nl_nid_addr(i8* %0)
%5 = tail call i8* @nl_nid_addr(i8* %1)
%6 = tail call i32 @nl_nid_parse_addr(i8* %4)
%7 = tail call i32 @nl_nid_parse_addr(i8* %5)
%8 = tail call i32 @strncmp(i8* %4, i8* %5, i32 %6)
%9 = icmp eq i32 %6, %7
%10 = icmp eq i32 %8, 0
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %12, label %27
12: ; preds = %3
%13 = sext i32 %6 to i64
%14 = getelementptr inbounds i8, i8* %4, i64 %13
%15 = tail call i32 @strtoul(i8* nocapture %14, i32* null, i32 10)
%16 = getelementptr inbounds i8, i8* %5, i64 %13
%17 = tail call i32 @strtoul(i8* nocapture %16, i32* null, i32 10)
%18 = sub nsw i32 %15, %17
%19 = icmp eq i32* %2, null
br i1 %19, label %29, label %20
20: ; preds = %12
%21 = tail call i64 @strlen(i8* dereferenceable(1) %14)
%22 = icmp sgt i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = tail call i64 @strlen(i8* dereferenceable(1) %16)
%25 = icmp sgt i64 %24, 0
%26 = zext i1 %25 to i32
br label %29
27: ; preds = %3
%28 = tail call i32 @strcmp(i8* dereferenceable(1) %4, i8* dereferenceable(1) %5)
br label %29
29: ; preds = %23, %12, %20, %27
%30 = phi i32 [ %18, %20 ], [ %18, %12 ], [ %28, %27 ], [ %18, %23 ]
%31 = phi i32 [ 0, %20 ], [ 0, %12 ], [ 0, %27 ], [ %26, %23 ]
%32 = tail call i32 @free(i8* %4)
%33 = tail call i32 @free(i8* %5)
%34 = icmp eq i32* %2, null
br i1 %34, label %36, label %35
35: ; preds = %29
store i32 %31, i32* %2
br label %36
36: ; preds = %35, %29
ret i32 %30
}