#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);
  if (o1 == o2 && (res = strncmp(p1, p2, o1)) == 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    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jne    126f <nl_cmp_addr+0xff>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1040 <strncmp@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jne    126f <nl_cmp_addr+0xff>
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     126a <nl_cmp_addr+0xfa>
mov    -0x20(%rbp),%rdi
movslq -0x30(%rbp),%rax
add    %rax,%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
jle    126a <nl_cmp_addr+0xfa>
mov    -0x28(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
jle    126a <nl_cmp_addr+0xfa>
movl   $0x1,-0x38(%rbp)
jmp    127f <nl_cmp_addr+0x10f>
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     12a5 <nl_cmp_addr+0x135>
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,0x8(%rsp)
mov    %rsi,%rbx
call   1050 <nl_nid_addr@plt>
mov    %rax,%rbp
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <nl_nid_addr@plt>
mov    %rax,%r12
mov    %rax,%r14
mov    %rbp,%rdi
call   1080 <nl_nid_parse_addr@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1080 <nl_nid_parse_addr@plt>
cmp    %eax,%ebx
jne    11c6 <nl_cmp_addr+0x56>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     1205 <nl_cmp_addr+0x95>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
mov    %eax,%r13d
xor    %ebx,%ebx
mov    0x8(%rsp),%rbp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
test   %rbp,%rbp
je     11f3 <nl_cmp_addr+0x83>
mov    %ebx,0x0(%rbp)
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movslq %ebx,%rax
mov    %rax,0x10(%rsp)
add    %rax,%rbp
xor    %ebx,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <strtoul@plt>
mov    %eax,%r13d
add    0x10(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <strtoul@plt>
sub    %eax,%r13d
cmpq   $0x0,0x8(%rsp)
je     11d6 <nl_cmp_addr+0x66>
mov    %rbp,%rdi
call   1060 <strlen@plt>
test   %rax,%rax
jle    11d6 <nl_cmp_addr+0x66>
mov    %r12,%rdi
call   1060 <strlen@plt>
xor    %ebx,%ebx
test   %rax,%rax
setg   %bl
jmp    11d6 <nl_cmp_addr+0x66>

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 i32, i32* %10
%22 = load i32, i32* %11
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %60
24: ; preds = %3
%25 = load i8*, i8** %7
%26 = load i8*, i8** %8
%27 = load i32, i32* %10
%28 = call i32 @strncmp(i8* %25, i8* %26, i32 %27)
store i32 %28, i32* %9
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %60
30: ; preds = %24
%31 = load i8*, i8** %7
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = call i32 @strtoul(i8* %34, i32* null, i32 10)
%36 = load i8*, i8** %8
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = call i32 @strtoul(i8* %39, i32* null, i32 10)
%41 = sub nsw i32 %35, %40
store i32 %41, i32* %9
%42 = load i32*, i32** %6
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %59
44: ; preds = %30
%45 = load i8*, i8** %7
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = call i64 @strlen(i8* %48)
%50 = icmp sgt i64 %49, 0
br i1 %50, label %51, label %59
51: ; preds = %44
%52 = load i8*, i8** %8
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = call i64 @strlen(i8* %55)
%57 = icmp sgt i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %51
store i32 1, i32* %12
br label %59
59: ; preds = %58, %51, %44, %30
br label %64
60: ; preds = %24, %3
%61 = load i8*, i8** %7
%62 = load i8*, i8** %8
%63 = call i32 @strcmp(i8* %61, i8* %62)
store i32 %63, i32* %9
br label %64
64: ; preds = %60, %59
%65 = load i8*, i8** %7
%66 = call i32 @free(i8* %65)
%67 = load i8*, i8** %8
%68 = call i32 @free(i8* %67)
%69 = load i32*, i32** %6
%70 = icmp ne i32* %69, null
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = load i32, i32* %12
%73 = load i32*, i32** %6
store i32 %72, i32* %73
br label %74
74: ; preds = %71, %64
%75 = load i32, i32* %9
ret i32 %75
}

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 = icmp eq i32 %6, %7
br i1 %8, label %9, label %27
9: ; preds = %3
%10 = tail call i32 @strncmp(i8* %4, i8* %5, i32 %6)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %9
%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 = %9, %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
}