#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_aliases;
  int /*<<< orphan*/ n_name;
};

/* Variables and functions */
struct netent *getnetent();
int /*<<< orphan*/ setnetent(int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char const *, int /*<<< orphan*/);
struct netent *getnetbyname(const char *name) {
  struct netent *s;
  setnetent(0);
  for (s = getnetent(); s; s = getnetent()) {
    char **tmp;
    if (!strcmp(name, s->n_name))
      return s;
    tmp = s->n_aliases;
    while (*tmp)
      if (!strcmp(name, *tmp++))
        return s;
  }
  return 0;
}


x86 assembly (clang, -O0):
<getnetbyname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %edi,%edi
call   1050 <setnetent@plt>
mov    $0x0,%al
call   1030 <getnetent@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e5 <getnetbyname+0xb5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%esi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    117f <getnetbyname+0x4f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ed <getnetbyname+0xbd>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11d0 <getnetbyname+0xa0>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%rax
mov    %eax,%esi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11cb <getnetbyname+0x9b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ed <getnetbyname+0xbd>
jmp    118a <getnetbyname+0x5a>
jmp    11d5 <getnetbyname+0xa5>
mov    $0x0,%al
call   1030 <getnetent@plt>
mov    %rax,-0x18(%rbp)
jmp    114e <getnetbyname+0x1e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnetbyname>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %r14d,%r14d
xor    %edi,%edi
call   1050 <setnetent@plt>
xor    %eax,%eax
call   1030 <getnetent@plt>
test   %rax,%rax
je     11a2 <getnetbyname+0x72>
mov    %rax,%r14
mov    0x8(%r14),%esi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11a2 <getnetbyname+0x72>
mov    (%r14),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1190 <getnetbyname+0x60>
add    $0x8,%rbx
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    1170 <getnetbyname+0x40>
jmp    11a2 <getnetbyname+0x72>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getnetent@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1151 <getnetbyname+0x21>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.netent = type { i8**, i32 }
define %struct.netent* @getnetbyname(i8* %0) {
%2 = alloca %struct.netent*
%3 = alloca i8*
%4 = alloca %struct.netent*
%5 = alloca i8**
store i8* %0, i8** %3
%6 = call i32 @setnetent(i32 0)
%7 = call %struct.netent* (...) @getnetent()
store %struct.netent* %7, %struct.netent** %4
br label %8
8: ; preds = %40, %1
%9 = load %struct.netent*, %struct.netent** %4
%10 = icmp ne %struct.netent* %9, null
br i1 %10, label %11, label %42
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = load %struct.netent*, %struct.netent** %4
%14 = getelementptr inbounds %struct.netent, %struct.netent* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = call i32 @strcmp(i8* %12, i32 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = load %struct.netent*, %struct.netent** %4
store %struct.netent* %19, %struct.netent** %2
br label %43
20: ; preds = %11
%21 = load %struct.netent*, %struct.netent** %4
%22 = getelementptr inbounds %struct.netent, %struct.netent* %21, i32 0, i32 0
%23 = load i8**, i8*** %22
store i8** %23, i8*** %5
br label %24
24: ; preds = %38, %20
%25 = load i8**, i8*** %5
%26 = load i8*, i8** %25
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %39
28: ; preds = %24
%29 = load i8*, i8** %3
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i32 1
store i8** %31, i8*** %5
%32 = load i8*, i8** %30
%33 = ptrtoint i8* %32 to i32
%34 = call i32 @strcmp(i8* %29, i32 %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %28
%37 = load %struct.netent*, %struct.netent** %4
store %struct.netent* %37, %struct.netent** %2
br label %43
38: ; preds = %28
br label %24
39: ; preds = %24
br label %40
40: ; preds = %39
%41 = call %struct.netent* (...) @getnetent()
store %struct.netent* %41, %struct.netent** %4
br label %8
42: ; preds = %8
store %struct.netent* null, %struct.netent** %2
br label %43
43: ; preds = %42, %36, %18
%44 = load %struct.netent*, %struct.netent** %2
ret %struct.netent* %44
}

LLVM IR (-O2):
%struct.netent = type { i8**, i32 }
define %struct.netent* @getnetbyname(i8* %0) {
%2 = tail call i32 @setnetent(i32 0)
%3 = tail call %struct.netent* (...) @getnetent()
%4 = icmp eq %struct.netent* %3, null
br i1 %4, label %27, label %5
5: ; preds = %1, %24
%6 = phi %struct.netent* [ %25, %24 ], [ %3, %1 ]
%7 = getelementptr inbounds %struct.netent, %struct.netent* %6, i64 0, i32 1
%8 = load i32, i32* %7
%9 = tail call i32 @strcmp(i8* %0, i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %27, label %11
11: ; preds = %5
%12 = getelementptr inbounds %struct.netent, %struct.netent* %6, i64 0, i32 0
%13 = load i8**, i8*** %12
br label %14
14: ; preds = %18, %11
%15 = phi i8** [ %13, %11 ], [ %19, %18 ]
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
br i1 %17, label %24, label %18
18: ; preds = %14
%19 = getelementptr inbounds i8*, i8** %15, i64 1
%20 = ptrtoint i8* %16 to i64
%21 = trunc i64 %20 to i32
%22 = tail call i32 @strcmp(i8* %0, i32 %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %14
24: ; preds = %14
%25 = tail call %struct.netent* (...) @getnetent()
%26 = icmp eq %struct.netent* %25, null
br i1 %26, label %27, label %5
27: ; preds = %24, %5, %18, %1
%28 = phi %struct.netent* [ null, %1 ], [ %6, %18 ], [ null, %24 ], [ %6, %5 ]
ret %struct.netent* %28
}