#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 {
  scalar_t__ n_addrtype;
  scalar_t__ n_net;
};
struct in_addr {
  int /*<<< orphan*/ s_addr;
};

/* Variables and functions */
scalar_t__ AF_INET;
struct netent *getnetbyname(char const *);
int /*<<< orphan*/ htonl(unsigned long);
struct in_addr *network_to_addr(const char *name) {
  struct netent *net;
  static struct in_addr addr;
  if ((net = getnetbyname(name)) != NULL) {
    if (net->n_addrtype != AF_INET)
      return (struct in_addr *)NULL;
    addr.s_addr = htonl((unsigned long)net->n_net);
    return &addr;
  } else
    return (struct in_addr *)NULL;
}


x86 assembly (clang, -O0):
<network_to_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getnetbyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     118a <network_to_addr+0x6a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e97(%rip),%rcx
cmp    (%rcx),%rax
je     1167 <network_to_addr+0x47>
movq   $0x0,-0x8(%rbp)
jmp    1192 <network_to_addr+0x72>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <htonl@plt>
mov    %eax,0x2ebe(%rip)
lea    0x2eb7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1192 <network_to_addr+0x72>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<network_to_addr>:
push   %rax
call   1030 <getnetbyname@plt>
test   %rax,%rax
je     1152 <network_to_addr+0x32>
mov    (%rax),%rcx
mov    0x2eb3(%rip),%rdx
cmp    (%rdx),%rcx
jne    1152 <network_to_addr+0x32>
mov    0x8(%rax),%rdi
call   1040 <htonl@plt>
mov    %eax,0x2eef(%rip)
lea    0x2ee8(%rip),%rax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.netent = type { i64, i64 }
@network_to_addr.addr = internal global %struct.in_addr zeroinitializer
@AF_INET = global i64 0
define %struct.in_addr* @network_to_addr(i8* %0) {
%2 = alloca %struct.in_addr*
%3 = alloca i8*
%4 = alloca %struct.netent*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call %struct.netent* @getnetbyname(i8* %5)
store %struct.netent* %6, %struct.netent** %4
%7 = icmp ne %struct.netent* %6, null
br i1 %7, label %8, label %20
8: ; preds = %1
%9 = load %struct.netent*, %struct.netent** %4
%10 = getelementptr inbounds %struct.netent, %struct.netent* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @AF_INET
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %8
store %struct.in_addr* null, %struct.in_addr** %2
br label %21
15: ; preds = %8
%16 = load %struct.netent*, %struct.netent** %4
%17 = getelementptr inbounds %struct.netent, %struct.netent* %16, i32 0, i32 1
%18 = load i64, i64* %17
%19 = call i32 @htonl(i64 %18)
store i32 %19, i32* getelementptr inbounds (%struct.in_addr, %struct.in_addr* @network_to_addr.addr, i32 0, i32 0)
store %struct.in_addr* @network_to_addr.addr, %struct.in_addr** %2
br label %21
20: ; preds = %1
store %struct.in_addr* null, %struct.in_addr** %2
br label %21
21: ; preds = %20, %15, %14
%22 = load %struct.in_addr*, %struct.in_addr** %2
ret %struct.in_addr* %22
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.netent = type { i64, i64 }
@network_to_addr.addr = internal global %struct.in_addr zeroinitializer
@AF_INET = global i64 0
define %struct.in_addr* @network_to_addr(i8* %0) {
%2 = tail call %struct.netent* @getnetbyname(i8* %0)
%3 = icmp eq %struct.netent* %2, null
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.netent, %struct.netent* %2, i64 0, i32 0
%6 = load i64, i64* %5
%7 = load i64, i64* @AF_INET
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = getelementptr inbounds %struct.netent, %struct.netent* %2, i64 0, i32 1
%11 = load i64, i64* %10
%12 = tail call i32 @htonl(i64 %11)
store i32 %12, i32* getelementptr inbounds (%struct.in_addr, %struct.in_addr* @network_to_addr.addr, i64 0, i32 0)
br label %13
13: ; preds = %1, %4, %9
%14 = phi %struct.in_addr* [ @network_to_addr.addr, %9 ], [ null, %4 ], [ null, %1 ]
ret %struct.in_addr* %14
}