#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 hostent {
  int dummy;
};

/* Variables and functions */
scalar_t__ gethostbyname2_r(char const *, int, struct hostent *, void *, int,
                            struct hostent **, int /*<<< orphan*/ *);
int /*<<< orphan*/ h_errno;
struct hostent *gethostbyname2(const char *name, int af) {
  static struct hostent h;
  static long buf[512 / sizeof(long)];
  struct hostent *res;
  if (gethostbyname2_r(name, af, &h, (void *)buf, sizeof buf, &res, &h_errno))
    return 0;
  return &h;
}


x86 assembly (clang, -O0):
<gethostbyname2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0x2f13(%rip),%rdx
lea    0x2f1c(%rip),%rcx
mov    $0x200,%r8d
lea    -0x20(%rbp),%r9
mov    0x2ea3(%rip),%rax
mov    %rax,(%rsp)
call   1030 <gethostbyname2_r@plt>
cmp    $0x0,%rax
je     1165 <gethostbyname2+0x55>
movq   $0x0,-0x8(%rbp)
jmp    1170 <gethostbyname2+0x60>
lea    0x2ed4(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethostbyname2>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ecc(%rip),%rax
mov    %rax,(%rsp)
lea    0x2f19(%rip),%rbx
lea    0x2f22(%rip),%rcx
lea    0x8(%rsp),%r9
mov    %rbx,%rdx
mov    $0x200,%r8d
call   1030 <gethostbyname2_r@plt>
xor    %ecx,%ecx
test   %rax,%rax
cmove  %rbx,%rcx
mov    %rcx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i32 }
@gethostbyname2.h = internal global %struct.hostent zeroinitializer
@gethostbyname2.buf = internal global [64 x i64] zeroinitializer
@h_errno = global i32 0
define %struct.hostent* @gethostbyname2(i8* %0, i32 %1) {
%3 = alloca %struct.hostent*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.hostent*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i32, i32* %5
%9 = call i64 @gethostbyname2_r(i8* %7, i32 %8, %struct.hostent* @gethostbyname2.h, i8* bitcast ([64 x i64]* @gethostbyname2.buf to i8*), i32 512, %struct.hostent** %6, i32* @h_errno)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store %struct.hostent* null, %struct.hostent** %3
br label %13
12: ; preds = %2
store %struct.hostent* @gethostbyname2.h, %struct.hostent** %3
br label %13
13: ; preds = %12, %11
%14 = load %struct.hostent*, %struct.hostent** %3
ret %struct.hostent* %14
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@gethostbyname2.h = internal global %struct.hostent zeroinitializer
@gethostbyname2.buf = internal global [64 x i64] zeroinitializer
@h_errno = global i32 0
define %struct.hostent* @gethostbyname2(i8* %0, i32 %1) {
%3 = alloca %struct.hostent*
%4 = bitcast %struct.hostent** %3 to i8*
%5 = call i64 @gethostbyname2_r(i8* %0, i32 %1, %struct.hostent* @gethostbyname2.h, i8* bitcast ([64 x i64]* @gethostbyname2.buf to i8*), i32 512, %struct.hostent** %3, i32* @h_errno)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, %struct.hostent* @gethostbyname2.h, %struct.hostent* null
ret %struct.hostent* %7
}