#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 {
  char *n_name;
  int n_addrtype;
  int n_net;
  char **n_aliases;
};

/* Variables and functions */
int /*<<< orphan*/ endnetent();
struct netent *getnetent();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ setnetent(int);
int _getnetent(char const *progname) {
  struct netent *ne;
  unsigned int i;
  char *const *p;
  char const *sep;
  printf("%s: Testing getnetent()\n", progname);
  setnetent(1);
  for (i = 0; (ne = getnetent()) != NULL; i++) {
    printf("%s\t%d %u", ne->n_name, ne->n_addrtype, ne->n_net);
    if (ne->n_aliases != NULL) {
      sep = "\t";
      for (p = ne->n_aliases; *p != NULL; p++) {
        printf("%s%s", sep, *p);
        sep = ", ";
      }
    }
    putchar('\n');
  }
  endnetent();
  printf("%u networks listed\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<_getnetent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <setnetent@plt>
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getnetent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     123d <_getnetent+0xed>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edx
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%ecx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1225 <_getnetent+0xd5>
lea    0xe55(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1220 <_getnetent+0xd0>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1e(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11dd <_getnetent+0x8d>
jmp    1225 <_getnetent+0xd5>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117f <_getnetent+0x2f>
mov    $0x0,%al
call   1060 <endnetent@plt>
mov    -0x14(%rbp),%esi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_getnetent>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rsi
lea    0xe9b(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <setnetent@plt>
xor    %eax,%eax
call   1050 <getnetent@plt>
test   %rax,%rax
je     122c <_getnetent+0xdc>
mov    %rax,%rbp
lea    0xe87(%rip),%r14
lea    0xe8b(%rip),%r15
lea    0xe82(%rip),%r12
lea    0xe82(%rip),%r13
xor    %ebx,%ebx
jmp    11cc <_getnetent+0x7c>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
xor    %eax,%eax
call   1050 <getnetent@plt>
mov    %rax,%rbp
test   %rax,%rax
je     122c <_getnetent+0xdc>
mov    0x0(%rbp),%rsi
mov    0x8(%rbp),%edx
mov    0xc(%rbp),%ecx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbp),%rbp
test   %rbp,%rbp
je     11b0 <_getnetent+0x60>
mov    0x0(%rbp),%rdx
test   %rdx,%rdx
je     11b0 <_getnetent+0x60>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbp),%rdx
test   %rdx,%rdx
je     11b0 <_getnetent+0x60>
add    $0x10,%rbp
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp),%rdx
add    $0x8,%rbp
test   %rdx,%rdx
jne    1210 <_getnetent+0xc0>
jmp    11b0 <_getnetent+0x60>
xor    %eax,%eax
call   1060 <endnetent@plt>
lea    0xdf2(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.netent = type { i8*, i32, i32, i8** }
@.str = [25 x i8] c"%s: Testing getnetent()\0A\00"
@.str.1 = [9 x i8] c"%s\09%d %u\00"
@.str.2 = [2 x i8] c"\09\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [3 x i8] c", \00"
@.str.5 = [20 x i8] c"%u networks listed\0A\00"
define i32 @_getnetent(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.netent*
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = call i32 @setnetent(i32 1)
store i32 0, i32* %4
br label %10
10: ; preds = %47, %1
%11 = call %struct.netent* (...) @getnetent()
store %struct.netent* %11, %struct.netent** %3
%12 = icmp ne %struct.netent* %11, null
br i1 %12, label %13, label %50
13: ; preds = %10
%14 = load %struct.netent*, %struct.netent** %3
%15 = getelementptr inbounds %struct.netent, %struct.netent* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = load %struct.netent*, %struct.netent** %3
%18 = getelementptr inbounds %struct.netent, %struct.netent* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load %struct.netent*, %struct.netent** %3
%21 = getelementptr inbounds %struct.netent, %struct.netent* %20, i32 0, i32 2
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %16, i32 %19, i32 %22)
%24 = load %struct.netent*, %struct.netent** %3
%25 = getelementptr inbounds %struct.netent, %struct.netent* %24, i32 0, i32 3
%26 = load i8**, i8*** %25
%27 = icmp ne i8** %26, null
br i1 %27, label %28, label %45
28: ; preds = %13
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %6
%29 = load %struct.netent*, %struct.netent** %3
%30 = getelementptr inbounds %struct.netent, %struct.netent* %29, i32 0, i32 3
%31 = load i8**, i8*** %30
store i8** %31, i8*** %5
br label %32
32: ; preds = %41, %28
%33 = load i8**, i8*** %5
%34 = load i8*, i8** %33
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = load i8*, i8** %6
%38 = load i8**, i8*** %5
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %37, i8* %39)
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %6
br label %41
41: ; preds = %36
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i32 1
store i8** %43, i8*** %5
br label %32
44: ; preds = %32
br label %45
45: ; preds = %44, %13
%46 = call i32 @putchar(i8 signext 10)
br label %47
47: ; preds = %45
%48 = load i32, i32* %4
%49 = add i32 %48, 1
store i32 %49, i32* %4
br label %10
50: ; preds = %10
%51 = call i32 (...) @endnetent()
%52 = load i32, i32* %4
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %52)
ret i32 0
}

LLVM IR (-O2):
%struct.netent = type { i8*, i32, i32, i8** }
@.str = [25 x i8] c"%s: Testing getnetent()\0A\00"
@.str.1 = [9 x i8] c"%s\09%d %u\00"
@.str.2 = [2 x i8] c"\09\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [3 x i8] c", \00"
@.str.5 = [20 x i8] c"%u networks listed\0A\00"
define i32 @_getnetent(i8* %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i32 @setnetent(i32 1)
%4 = tail call %struct.netent* (...) @getnetent()
%5 = icmp eq %struct.netent* %4, null
br i1 %5, label %39, label %6
6: ; preds = %1, %34
%7 = phi %struct.netent* [ %37, %34 ], [ %4, %1 ]
%8 = phi i32 [ %36, %34 ], [ 0, %1 ]
%9 = getelementptr inbounds %struct.netent, %struct.netent* %7, i64 0, i32 0
%10 = load i8*, i8** %9
%11 = getelementptr inbounds %struct.netent, %struct.netent* %7, i64 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.netent, %struct.netent* %7, i64 0, i32 2
%14 = load i32, i32* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %12, i32 %14)
%16 = getelementptr inbounds %struct.netent, %struct.netent* %7, i64 0, i32 3
%17 = load i8**, i8*** %16
%18 = icmp eq i8** %17, null
br i1 %18, label %34, label %19
19: ; preds = %6
%20 = load i8*, i8** %17
%21 = icmp eq i8* %20, null
br i1 %21, label %34, label %22
22: ; preds = %19
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%24 = getelementptr inbounds i8*, i8** %17, i64 1
%25 = load i8*, i8** %24
%26 = icmp eq i8* %25, null
br i1 %26, label %34, label %27
27: ; preds = %22, %27
%28 = phi i8* [ %32, %27 ], [ %25, %22 ]
%29 = phi i8** [ %31, %27 ], [ %24, %22 ]
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%31 = getelementptr inbounds i8*, i8** %29, i64 1
%32 = load i8*, i8** %31
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %27
34: ; preds = %27, %22, %19, %6
%35 = tail call i32 @putchar(i8 signext 10)
%36 = add i32 %8, 1
%37 = tail call %struct.netent* (...) @getnetent()
%38 = icmp eq %struct.netent* %37, null
br i1 %38, label %39, label %6
39: ; preds = %34, %1
%40 = phi i32 [ 0, %1 ], [ %36, %34 ]
%41 = tail call i32 (...) @endnetent()
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %40)
ret i32 0
}