#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 char u_char;
struct in_addr {
  int s_addr;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
unsigned long INADDR_ANY;
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
struct hostent *gethostbyname(char *);
int inet_addr(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcasecmp(char *, char *);
char *strerror(int /*<<< orphan*/);
unsigned long getlongbyname(u_char *host) {
  struct in_addr addr;
  struct hostent *host_ent;
  if (strcasecmp(host, "any") == 0)
    return INADDR_ANY;
  if ((addr.s_addr = inet_addr(host)) == -1) {
    if ((host_ent = gethostbyname(host)) == NULL)
      fprintf(stderr, "'%s': gethostbyname() or inet_addr() err: %s", host,
              strerror(errno));
    bcopy(host_ent->h_addr, (char *)&addr.s_addr, host_ent->h_length);
  }
  return addr.s_addr;
}


x86 assembly (clang, -O0):
<getlongbyname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1199 <getlongbyname+0x39>
mov    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    121b <getlongbyname+0xbb>
mov    -0x10(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1213 <getlongbyname+0xb3>
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11fd <getlongbyname+0x9d>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe0c(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1070 <bcopy@plt>
movslq -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getlongbyname>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xe8e(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11e1 <getlongbyname+0x81>
mov    %rbx,%rdi
call   1040 <inet_addr@plt>
mov    %eax,0x8(%rsp)
cmp    $0xffffffff,%eax
jne    11dd <getlongbyname+0x7d>
mov    %rbx,%rdi
call   1050 <gethostbyname@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11c8 <getlongbyname+0x68>
mov    0x2e34(%rip),%rax
mov    (%rax),%ebp
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe49(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    (%r14),%edx
mov    0x4(%r14),%edi
lea    0x8(%rsp),%rsi
call   1070 <bcopy@plt>
mov    0x8(%rsp),%eax
cltq
jmp    11eb <getlongbyname+0x8b>
mov    0x2e00(%rip),%rax
mov    (%rax),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32 }
@.str = [4 x i8] c"any\00"
@INADDR_ANY = global i64 0
@stderr = global i32 0
@.str.1 = [45 x i8] c"'%s': gethostbyname() or inet_addr() err: %s\00"
@errno = global i32 0
define i64 @getlongbyname(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca %struct.in_addr
%5 = alloca %struct.hostent*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i64, i64* @INADDR_ANY
store i64 %10, i64* %2
br label %40
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @inet_addr(i8* %12)
%14 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
store i32 %13, i32* %14
%15 = icmp eq i32 %13, -1
br i1 %15, label %16, label %36
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = call %struct.hostent* @gethostbyname(i8* %17)
store %struct.hostent* %18, %struct.hostent** %5
%19 = icmp eq %struct.hostent* %18, null
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %3
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %24)
br label %26
26: ; preds = %20, %16
%27 = load %struct.hostent*, %struct.hostent** %5
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
%31 = bitcast i32* %30 to i8*
%32 = load %struct.hostent*, %struct.hostent** %5
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @bcopy(i32 %29, i8* %31, i32 %34)
br label %36
36: ; preds = %26, %11
%37 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
%38 = load i32, i32* %37
%39 = sext i32 %38 to i64
store i64 %39, i64* %2
br label %40
40: ; preds = %36, %9
%41 = load i64, i64* %2
ret i64 %41
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32 }
@.str = [4 x i8] c"any\00"
@INADDR_ANY = global i64 0
@stderr = global i32 0
@.str.1 = [45 x i8] c"'%s': gethostbyname() or inet_addr() err: %s\00"
@errno = global i32 0
define i64 @getlongbyname(i8* %0) {
%2 = alloca %struct.in_addr
%3 = bitcast %struct.in_addr* %2 to i8*
%4 = tail call i64 @strcasecmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = load i64, i64* @INADDR_ANY
br label %30
8: ; preds = %1
%9 = tail call i32 @inet_addr(i8* %0)
%10 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
store i32 %9, i32* %10
%11 = icmp eq i32 %9, -1
br i1 %11, label %12, label %27
12: ; preds = %8
%13 = tail call %struct.hostent* @gethostbyname(i8* %0)
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %18)
br label %20
20: ; preds = %15, %12
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @bcopy(i32 %22, i8* %3, i32 %24)
%26 = load i32, i32* %10
br label %27
27: ; preds = %20, %8
%28 = phi i32 [ %26, %20 ], [ %9, %8 ]
%29 = sext i32 %28 to i64
br label %30
30: ; preds = %27, %6
%31 = phi i64 [ %7, %6 ], [ %29, %27 ]
ret i64 %31
}