#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 scalar_t__ uint32_t;
struct netent {
  scalar_t__ n_net;
  int n_addrtype;
};

/* Variables and functions */
int /*<<< orphan*/ endnetent();
struct netent *getnetent();
int /*<<< orphan*/ setnetent(int);
struct netent *getnetbyaddr(uint32_t net, int type) {
  struct netent *ne;
  setnetent(1);
  while ((ne = getnetent()) != NULL) {
    if ((ne->n_net == net) && (ne->n_addrtype == type)) {
      break;
    }
  }
  endnetent();
  return ne;
}


x86 assembly (clang, -O0):
<getnetbyaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x1,%edi
call   1050 <setnetent@plt>
mov    $0x0,%al
call   1030 <getnetent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1189 <getnetbyaddr+0x59>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
cmp    -0x8(%rbp),%rax
jne    1184 <getnetbyaddr+0x54>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
cmp    -0xc(%rbp),%eax
jne    1184 <getnetbyaddr+0x54>
jmp    1189 <getnetbyaddr+0x59>
jmp    1149 <getnetbyaddr+0x19>
mov    $0x0,%al
call   1040 <endnetent@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnetbyaddr>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    $0x1,%edi
call   1050 <setnetent@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <getnetent@plt>
test   %rax,%rax
je     117f <getnetbyaddr+0x4f>
mov    %rax,%rbp
jmp    116f <getnetbyaddr+0x3f>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getnetent@plt>
mov    %rax,%rbp
test   %rax,%rax
je     117d <getnetbyaddr+0x4d>
cmp    %rbx,0x0(%rbp)
jne    1160 <getnetbyaddr+0x30>
cmp    %r14d,0x8(%rbp)
jne    1160 <getnetbyaddr+0x30>
jmp    117f <getnetbyaddr+0x4f>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <endnetent@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.netent = type { i64, i32 }
define %struct.netent* @getnetbyaddr(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca %struct.netent*
store i64 %0, i64* %3
store i32 %1, i32* %4
%6 = call i32 @setnetent(i32 1)
br label %7
7: ; preds = %23, %2
%8 = call %struct.netent* (...) @getnetent()
store %struct.netent* %8, %struct.netent** %5
%9 = icmp ne %struct.netent* %8, null
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = load %struct.netent*, %struct.netent** %5
%12 = getelementptr inbounds %struct.netent, %struct.netent* %11, i32 0, i32 0
%13 = load i64, i64* %12
%14 = load i64, i64* %3
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %23
16: ; preds = %10
%17 = load %struct.netent*, %struct.netent** %5
%18 = getelementptr inbounds %struct.netent, %struct.netent* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load i32, i32* %4
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %16
br label %24
23: ; preds = %16, %10
br label %7
24: ; preds = %22, %7
%25 = call i32 (...) @endnetent()
%26 = load %struct.netent*, %struct.netent** %5
ret %struct.netent* %26
}

LLVM IR (-O2):
%struct.netent = type { i64, i32 }
define %struct.netent* @getnetbyaddr(i64 %0, i32 %1) {
%3 = tail call i32 @setnetent(i32 1)
%4 = tail call %struct.netent* (...) @getnetent()
%5 = icmp eq %struct.netent* %4, null
br i1 %5, label %18, label %6
6: ; preds = %2, %15
%7 = phi %struct.netent* [ %16, %15 ], [ %4, %2 ]
%8 = getelementptr inbounds %struct.netent, %struct.netent* %7, i64 0, i32 0
%9 = load i64, i64* %8
%10 = icmp eq i64 %9, %0
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = getelementptr inbounds %struct.netent, %struct.netent* %7, i64 0, i32 1
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, %1
br i1 %14, label %18, label %15
15: ; preds = %11, %6
%16 = tail call %struct.netent* (...) @getnetent()
%17 = icmp eq %struct.netent* %16, null
br i1 %17, label %18, label %6
18: ; preds = %15, %11, %2
%19 = phi %struct.netent* [ null, %2 ], [ %7, %11 ], [ null, %15 ]
%20 = tail call i32 (...) @endnetent()
ret %struct.netent* %19
}