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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ endnetent();
struct netent *getnetbyaddr(int /*<<< orphan*/, int /*<<< orphan*/);
struct netent *getnetbyname(char *);
struct netent *getnetent();
int /*<<< orphan*/ inet_network(char *);
int /*<<< orphan*/ output_netent(char *, struct netent *);
int /*<<< orphan*/ setnetent(int /*<<< orphan*/);
void test_network(void) {
  struct netent *nptr;
  u_int32_t ip;
  nptr = getnetbyname("loopback");
  output_netent("getnetbyname (\"loopback\")", nptr);
  nptr = getnetbyname("LoopBACK");
  output_netent("getnetbyname (\"LoopBACK\")", nptr);
  ip = inet_network("127.0.0.0");
  nptr = getnetbyaddr(ip, AF_INET);
  output_netent("getnetbyaddr (inet_network (\"127.0.0.0\"), AF_INET)", nptr);
  setnetent(0);
  do {
    nptr = getnetent();
    output_netent("getnetent ()", nptr);
  } while (nptr != NULL);
  endnetent();
}


x86 assembly (clang, -O0):
<test_network>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe81(%rip),%rdi
call   1040 <getnetbyname@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1060 <output_netent@plt>
lea    0xe84(%rip),%rdi
call   1040 <getnetbyname@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1060 <output_netent@plt>
lea    0xe87(%rip),%rdi
call   1030 <inet_network@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
call   1080 <getnetbyaddr@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1060 <output_netent@plt>
xor    %edi,%edi
call   1090 <setnetent@plt>
mov    $0x0,%al
call   1050 <getnetent@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1060 <output_netent@plt>
cmpq   $0x0,-0x8(%rbp)
jne    11f3 <test_network+0x83>
mov    $0x0,%al
call   1070 <endnetent@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_network>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
call   1040 <getnetbyname@plt>
lea    0xe82(%rip),%rdi
mov    %rax,%rsi
call   1060 <output_netent@plt>
lea    0xe8d(%rip),%rdi
call   1040 <getnetbyname@plt>
lea    0xe8a(%rip),%rdi
mov    %rax,%rsi
call   1060 <output_netent@plt>
lea    0xe95(%rip),%rdi
call   1030 <inet_network@plt>
mov    0x2e2b(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1080 <getnetbyaddr@plt>
lea    0xe83(%rip),%rdi
mov    %rax,%rsi
call   1060 <output_netent@plt>
xor    %edi,%edi
call   1090 <setnetent@plt>
lea    0xea0(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <getnetent@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <output_netent@plt>
test   %rbx,%rbx
jne    11f0 <test_network+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <endnetent@plt>

LLVM IR (-O0):
%struct.netent = type { i32 }
@.str = [9 x i8] c"loopback\00"
@.str.1 = [26 x i8] c"getnetbyname (\22loopback\22)\00"
@.str.2 = [9 x i8] c"LoopBACK\00"
@.str.3 = [26 x i8] c"getnetbyname (\22LoopBACK\22)\00"
@.str.4 = [10 x i8] c"127.0.0.0\00"
@AF_INET = global i32 0
@.str.5 = [51 x i8] c"getnetbyaddr (inet_network (\22127.0.0.0\22), AF_INET)\00"
@.str.6 = [13 x i8] c"getnetent ()\00"
define void @test_network() {
%1 = alloca %struct.netent*
%2 = alloca i32
%3 = call %struct.netent* @getnetbyname(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store %struct.netent* %3, %struct.netent** %1
%4 = load %struct.netent*, %struct.netent** %1
%5 = call i32 @output_netent(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), %struct.netent* %4)
%6 = call %struct.netent* @getnetbyname(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store %struct.netent* %6, %struct.netent** %1
%7 = load %struct.netent*, %struct.netent** %1
%8 = call i32 @output_netent(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), %struct.netent* %7)
%9 = call i32 @inet_network(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = load i32, i32* @AF_INET
%12 = call %struct.netent* @getnetbyaddr(i32 %10, i32 %11)
store %struct.netent* %12, %struct.netent** %1
%13 = load %struct.netent*, %struct.netent** %1
%14 = call i32 @output_netent(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), %struct.netent* %13)
%15 = call i32 @setnetent(i32 0)
br label %16
16: ; preds = %20, %0
%17 = call %struct.netent* (...) @getnetent()
store %struct.netent* %17, %struct.netent** %1
%18 = load %struct.netent*, %struct.netent** %1
%19 = call i32 @output_netent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), %struct.netent* %18)
br label %20
20: ; preds = %16
%21 = load %struct.netent*, %struct.netent** %1
%22 = icmp ne %struct.netent* %21, null
br i1 %22, label %16, label %23
23: ; preds = %20
%24 = call i32 (...) @endnetent()
ret void
}

LLVM IR (-O2):
%struct.netent = type { i32 }
@.str = [9 x i8] c"loopback\00"
@.str.1 = [26 x i8] c"getnetbyname (\22loopback\22)\00"
@.str.2 = [9 x i8] c"LoopBACK\00"
@.str.3 = [26 x i8] c"getnetbyname (\22LoopBACK\22)\00"
@.str.4 = [10 x i8] c"127.0.0.0\00"
@AF_INET = global i32 0
@.str.5 = [51 x i8] c"getnetbyaddr (inet_network (\22127.0.0.0\22), AF_INET)\00"
@.str.6 = [13 x i8] c"getnetent ()\00"
define void @test_network() {
%1 = tail call %struct.netent* @getnetbyname(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @output_netent(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), %struct.netent* %1)
%3 = tail call %struct.netent* @getnetbyname(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i32 @output_netent(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), %struct.netent* %3)
%5 = tail call i32 @inet_network(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%6 = load i32, i32* @AF_INET
%7 = tail call %struct.netent* @getnetbyaddr(i32 %5, i32 %6)
%8 = tail call i32 @output_netent(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), %struct.netent* %7)
%9 = tail call i32 @setnetent(i32 0)
br label %10
10: ; preds = %10, %0
%11 = tail call %struct.netent* (...) @getnetent()
%12 = tail call i32 @output_netent(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), %struct.netent* %11)
%13 = icmp eq %struct.netent* %11, null
br i1 %13, label %14, label %10
14: ; preds = %10
%15 = tail call i32 (...) @endnetent()
ret void
}