#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 */
struct netent {
  int dummy;
};

/* Variables and functions */
int AF_INET;
int /*<<< orphan*/ EAFNOSUPPORT;
int MAXDNAME;
struct netent *_getnetbynis(char *, char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ sprintf(char *, char *, unsigned int, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
struct netent *_getnetbynisaddr(unsigned long addr, int af) {
  char *str, *cp;
  unsigned long net2;
  int nn;
  unsigned int netbr[4];
  char buf[MAXDNAME];
  if (af != AF_INET) {
    errno = EAFNOSUPPORT;
    return (NULL);
  }
  for (nn = 4, net2 = addr; net2; net2 >>= 8) {
    netbr[--nn] = net2 & 0xff;
  }
  switch (nn) {
  case 3:
    sprintf(buf, "%u", netbr[3]);
    break;
  case 2:
    sprintf(buf, "%u.%u", netbr[2], netbr[3]);
    break;
  case 1:
    sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]);
    break;
  case 0:
    sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1], netbr[2], netbr[3]);
    break;
  }
  str = (char *)&buf;
  cp = str + (strlen(str) - 2);
  while (!strcmp(cp, ".0")) {
    *cp = '\0';
    cp = str + (strlen(str) - 2);
  }
  return _getnetbynis(str, "networks.byaddr", af);
}


x86 assembly (clang, -O0):
<_getnetbynisaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%eax
je     11b6 <_getnetbynisaddr+0x76>
mov    0x2e31(%rip),%rax
mov    (%rax),%ecx
mov    0x2e30(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    133e <_getnetbynisaddr+0x1fe>
movl   $0x4,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11fc <_getnetbynisaddr+0xbc>
mov    -0x30(%rbp),%rax
and    $0xff,%rax
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
cltq
mov    %ecx,-0x50(%rbp,%rax,4)
mov    -0x30(%rbp),%rax
shr    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    11c5 <_getnetbynisaddr+0x85>
mov    -0x34(%rbp),%eax
mov    %rax,-0x78(%rbp)
sub    $0x3,%rax
ja     1299 <_getnetbynisaddr+0x159>
mov    -0x78(%rbp),%rax
lea    0xde8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x70(%rbp),%rdi
mov    -0x44(%rbp),%edx
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    1299 <_getnetbynisaddr+0x159>
mov    -0x70(%rbp),%rdi
mov    -0x48(%rbp),%edx
mov    -0x44(%rbp),%ecx
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    1299 <_getnetbynisaddr+0x159>
mov    -0x70(%rbp),%rdi
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%ecx
mov    -0x44(%rbp),%r8d
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    1299 <_getnetbynisaddr+0x159>
mov    -0x70(%rbp),%rdi
mov    -0x50(%rbp),%edx
mov    -0x4c(%rbp),%ecx
mov    -0x48(%rbp),%r8d
mov    -0x44(%rbp),%r9d
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x70(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x80(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd4c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12ea <_getnetbynisaddr+0x1aa>
jmp    1320 <_getnetbynisaddr+0x1e0>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    12c5 <_getnetbynisaddr+0x185>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xcf1(%rip),%rsi
call   1050 <_getnetbynis@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x64(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_getnetbynisaddr>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%r13
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    0x2e73(%rip),%rax
cmp    %esi,(%rax)
jne    11ec <_getnetbynisaddr+0xac>
mov    %esi,%r14d
test   %rdi,%rdi
je     124f <_getnetbynisaddr+0x10f>
mov    $0x3,%eax
mov    %rdi,%rcx
nopl   (%rax)
movzbl %dil,%edx
mov    %edx,-0x40(%rbp,%rax,4)
shr    $0x8,%rcx
add    $0xffffffffffffffff,%rax
cmp    $0xff,%rdi
mov    %rcx,%rdi
ja     1190 <_getnetbynisaddr+0x50>
add    $0x1,%rax
cmp    $0x3,%eax
ja     124f <_getnetbynisaddr+0x10f>
mov    %eax,%eax
lea    0xe3e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x40(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    -0x34(%rbp),%r9d
lea    0xe30(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
jmp    124f <_getnetbynisaddr+0x10f>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    0x2dd4(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
jmp    12b6 <_getnetbynisaddr+0x176>
mov    -0x3c(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    -0x34(%rbp),%r8d
lea    0xdfd(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
jmp    124f <_getnetbynisaddr+0x10f>
mov    -0x38(%rbp),%edx
mov    -0x34(%rbp),%ecx
lea    0xde7(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
jmp    124f <_getnetbynisaddr+0x10f>
mov    -0x34(%rbp),%edx
lea    0xdd4(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%r15,1),%rbx
add    $0xfffffffffffffffe,%rbx
lea    0xdb4(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    12a4 <_getnetbynisaddr+0x164>
lea    0xda1(%rip),%r12
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rbx)
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%r15,1),%rbx
add    $0xfffffffffffffffe,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1280 <_getnetbynisaddr+0x140>
lea    0xd74(%rip),%rsi
mov    %r15,%rdi
mov    %r14d,%edx
call   1050 <_getnetbynis@plt>
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.netent = type { i32 }
@MAXDNAME = global i32 0
@AF_INET = global i32 0
@EAFNOSUPPORT = global i32 0
@errno = global i32 0
@.str = [3 x i8] c"%u\00"
@.str.1 = [6 x i8] c"%u.%u\00"
@.str.2 = [9 x i8] c"%u.%u.%u\00"
@.str.3 = [12 x i8] c"%u.%u.%u.%u\00"
@.str.4 = [3 x i8] c".0\00"
@.str.5 = [16 x i8] c"networks.byaddr\00"
define %struct.netent* @_getnetbynisaddr(i64 %0, i32 %1) {
%3 = alloca %struct.netent*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca [4 x i32]
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i64 %0, i64* %4
store i32 %1, i32* %5
%14 = load i32, i32* @MAXDNAME
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %11
%17 = alloca i8, i64 %15
store i64 %15, i64* %12
%18 = load i32, i32* %5
%19 = load i32, i32* @AF_INET
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = load i32, i32* @EAFNOSUPPORT
store i32 %22, i32* @errno
store %struct.netent* null, %struct.netent** %3
store i32 1, i32* %13
br label %93
23: ; preds = %2
store i32 4, i32* %9
%24 = load i64, i64* %4
store i64 %24, i64* %8
br label %25
25: ; preds = %36, %23
%26 = load i64, i64* %8
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %25
%29 = load i64, i64* %8
%30 = and i64 %29, 255
%31 = trunc i64 %30 to i32
%32 = load i32, i32* %9
%33 = add nsw i32 %32, -1
store i32 %33, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 %34
store i32 %31, i32* %35
br label %36
36: ; preds = %28
%37 = load i64, i64* %8
%38 = lshr i64 %37, 8
store i64 %38, i64* %8
br label %25
39: ; preds = %25
%40 = load i32, i32* %9
switch i32 %40, label %69 [
i32 3, label %41
i32 2, label %45
i32 1, label %51
i32 0, label %59
]
41: ; preds = %39
%42 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 3
%43 = load i32, i32* %42
%44 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %43)
br label %69
45: ; preds = %39
%46 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 2
%47 = load i32, i32* %46
%48 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 3
%49 = load i32, i32* %48
%50 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %47, i32 %49)
br label %69
51: ; preds = %39
%52 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 1
%53 = load i32, i32* %52
%54 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 2
%55 = load i32, i32* %54
%56 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 3
%57 = load i32, i32* %56
%58 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %53, i32 %55, i32 %57)
br label %69
59: ; preds = %39
%60 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 0
%61 = load i32, i32* %60
%62 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 1
%63 = load i32, i32* %62
%64 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 2
%65 = load i32, i32* %64
%66 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 3
%67 = load i32, i32* %66
%68 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %61, i32 %63, i32 %65, i32 %67)
br label %69
69: ; preds = %39, %59, %51, %45, %41
store i8* %17, i8** %6
%70 = load i8*, i8** %6
%71 = load i8*, i8** %6
%72 = call i32 @strlen(i8* %71)
%73 = sub nsw i32 %72, 2
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %70, i64 %74
store i8* %75, i8** %7
br label %76
76: ; preds = %81, %69
%77 = load i8*, i8** %7
%78 = call i32 @strcmp(i8* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%79 = icmp ne i32 %78, 0
%80 = xor i1 %79, true
br i1 %80, label %81, label %89
81: ; preds = %76
%82 = load i8*, i8** %7
store i8 0, i8* %82
%83 = load i8*, i8** %6
%84 = load i8*, i8** %6
%85 = call i32 @strlen(i8* %84)
%86 = sub nsw i32 %85, 2
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %83, i64 %87
store i8* %88, i8** %7
br label %76
89: ; preds = %76
%90 = load i8*, i8** %6
%91 = load i32, i32* %5
%92 = call %struct.netent* @_getnetbynis(i8* %90, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %91)
store %struct.netent* %92, %struct.netent** %3
store i32 1, i32* %13
br label %93
93: ; preds = %89, %21
%94 = load i8*, i8** %11
%95 = load %struct.netent*, %struct.netent** %3
ret %struct.netent* %95
}

LLVM IR (-O2):
%struct.netent = type { i32 }
@MAXDNAME = global i32 0
@AF_INET = global i32 0
@EAFNOSUPPORT = global i32 0
@errno = global i32 0
@.str = [3 x i8] c"%u\00"
@.str.1 = [6 x i8] c"%u.%u\00"
@.str.2 = [9 x i8] c"%u.%u.%u\00"
@.str.3 = [12 x i8] c"%u.%u.%u.%u\00"
@.str.4 = [3 x i8] c".0\00"
@.str.5 = [16 x i8] c"networks.byaddr\00"
define %struct.netent* @_getnetbynisaddr(i64 %0, i32 %1) {
%3 = alloca [4 x i32]
%4 = bitcast [4 x i32]* %3 to i8*
%5 = load i32, i32* @MAXDNAME
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = load i32, i32* @AF_INET
%10 = icmp eq i32 %9, %1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = icmp eq i64 %0, 0
br i1 %12, label %54, label %15
13: ; preds = %2
%14 = load i32, i32* @EAFNOSUPPORT
store i32 %14, i32* @errno
br label %71
15: ; preds = %11, %15
%16 = phi i64 [ %20, %15 ], [ 4, %11 ]
%17 = phi i64 [ %22, %15 ], [ %0, %11 ]
%18 = trunc i64 %17 to i32
%19 = and i32 %18, 255
%20 = add nsw i64 %16, -1
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %20
store i32 %19, i32* %21
%22 = lshr i64 %17, 8
%23 = icmp ult i64 %17, 256
br i1 %23, label %24, label %15
24: ; preds = %15
%25 = trunc i64 %20 to i32
switch i32 %25, label %54 [
i32 3, label %26
i32 2, label %30
i32 1, label %36
i32 0, label %44
]
26: ; preds = %24
%27 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%28 = load i32, i32* %27
%29 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %28)
br label %54
30: ; preds = %24
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%32 = load i32, i32* %31
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%34 = load i32, i32* %33
%35 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %34)
br label %54
36: ; preds = %24
%37 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%38 = load i32, i32* %37
%39 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%40 = load i32, i32* %39
%41 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%42 = load i32, i32* %41
%43 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %38, i32 %40, i32 %42)
br label %54
44: ; preds = %24
%45 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%46 = load i32, i32* %45
%47 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%48 = load i32, i32* %47
%49 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%50 = load i32, i32* %49
%51 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%52 = load i32, i32* %51
%53 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %48, i32 %50, i32 %52)
br label %54
54: ; preds = %11, %24, %44, %36, %30, %26
%55 = call i32 @strlen(i8* %8)
%56 = add nsw i32 %55, -2
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %8, i64 %57
%59 = call i32 @strcmp(i8* %58, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %69
61: ; preds = %54, %61
%62 = phi i8* [ %66, %61 ], [ %58, %54 ]
store i8 0, i8* %62
%63 = call i32 @strlen(i8* %8)
%64 = add nsw i32 %63, -2
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %8, i64 %65
%67 = call i32 @strcmp(i8* %66, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%68 = icmp eq i32 %67, 0
br i1 %68, label %61, label %69
69: ; preds = %61, %54
%70 = call %struct.netent* @_getnetbynis(i8* %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %1)
br label %71
71: ; preds = %69, %13
%72 = phi %struct.netent* [ null, %13 ], [ %70, %69 ]
ret %struct.netent* %72
}