#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 {
  scalar_t__ h_name;
  scalar_t__ *h_aliases;
};

/* Variables and functions */
scalar_t__ EEXIST;
scalar_t__ errno;
int obstcp_advert_cname_extract(char *, unsigned int *, scalar_t__);
int __attribute__((visibility("default")))
obstcp_advert_hostent_extract(char *output, unsigned *outlen,
                              const struct hostent *hent) {
  unsigned i;
  for (i = 0; hent->h_aliases[i]; ++i) {
    if (!obstcp_advert_cname_extract(output, outlen, hent->h_aliases[i])) {
      if (errno != EEXIST)
        return 0;
    } else {
      return 1;
    }
  }
  if (hent->h_name) {
    return obstcp_advert_cname_extract(output, outlen, hent->h_name);
  } else {
    errno = EEXIST;
    return 0;
  }
}


x86 assembly (clang, -O0):
<obstcp_advert_hostent_extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x24(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
je     11b0 <obstcp_advert_hostent_extract+0xa0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,8),%rdx
call   1030 <obstcp_advert_cname_extract@plt>
cmp    $0x0,%eax
jne    1191 <obstcp_advert_hostent_extract+0x81>
mov    0x2e6b(%rip),%rax
mov    (%rax),%rax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
je     118c <obstcp_advert_hostent_extract+0x7c>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <obstcp_advert_hostent_extract+0xe5>
jmp    119d <obstcp_advert_hostent_extract+0x8d>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <obstcp_advert_hostent_extract+0xe5>
jmp    11a2 <obstcp_advert_hostent_extract+0x92>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112b <obstcp_advert_hostent_extract+0x1b>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11da <obstcp_advert_hostent_extract+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
call   1030 <obstcp_advert_cname_extract@plt>
mov    %eax,-0x4(%rbp)
jmp    11f5 <obstcp_advert_hostent_extract+0xe5>
mov    0x2dff(%rip),%rax
mov    (%rax),%rcx
mov    0x2ded(%rip),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obstcp_advert_hostent_extract>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x8(%rdx),%rax
mov    (%rax),%rdx
test   %rdx,%rdx
je     117d <obstcp_advert_hostent_extract+0x6d>
mov    0x2ea1(%rip),%r13
mov    0x2ea2(%rip),%rbp
mov    $0x1,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <obstcp_advert_cname_extract@plt>
test   %eax,%eax
jne    119e <obstcp_advert_hostent_extract+0x8e>
mov    0x0(%r13),%rax
cmp    0x0(%rbp),%rax
jne    11b9 <obstcp_advert_hostent_extract+0xa9>
mov    0x8(%rbx),%rax
mov    %r12d,%ecx
mov    (%rax,%rcx,8),%rdx
add    $0x1,%r12d
test   %rdx,%rdx
jne    1150 <obstcp_advert_hostent_extract+0x40>
mov    (%rbx),%rdx
test   %rdx,%rdx
je     11a5 <obstcp_advert_hostent_extract+0x95>
mov    %r15,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <obstcp_advert_cname_extract@plt>
mov    $0x1,%eax
jmp    11bb <obstcp_advert_hostent_extract+0xab>
mov    0x2e34(%rip),%rax
mov    (%rax),%rax
mov    0x2e22(%rip),%rcx
mov    %rax,(%rcx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i64, i64* }
@errno = global i64 0
@EEXIST = global i64 0
define i32 @obstcp_advert_hostent_extract(i8* %0, i32* %1, %struct.hostent* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %struct.hostent*
%8 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store %struct.hostent* %2, %struct.hostent** %7
store i32 0, i32* %8
br label %9
9: ; preds = %38, %3
%10 = load %struct.hostent*, %struct.hostent** %7
%11 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i32 0, i32 1
%12 = load i64*, i64** %11
%13 = load i32, i32* %8
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i64, i64* %12, i64 %14
%16 = load i64, i64* %15
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %41
18: ; preds = %9
%19 = load i8*, i8** %5
%20 = load i32*, i32** %6
%21 = load %struct.hostent*, %struct.hostent** %7
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i32 0, i32 1
%23 = load i64*, i64** %22
%24 = load i32, i32* %8
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i64, i64* %23, i64 %25
%27 = load i64, i64* %26
%28 = call i32 @obstcp_advert_cname_extract(i8* %19, i32* %20, i64 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %36, label %30
30: ; preds = %18
%31 = load i64, i64* @errno
%32 = load i64, i64* @EEXIST
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 0, i32* %4
br label %55
35: ; preds = %30
br label %37
36: ; preds = %18
store i32 1, i32* %4
br label %55
37: ; preds = %35
br label %38
38: ; preds = %37
%39 = load i32, i32* %8
%40 = add i32 %39, 1
store i32 %40, i32* %8
br label %9
41: ; preds = %9
%42 = load %struct.hostent*, %struct.hostent** %7
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %42, i32 0, i32 0
%44 = load i64, i64* %43
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %41
%47 = load i8*, i8** %5
%48 = load i32*, i32** %6
%49 = load %struct.hostent*, %struct.hostent** %7
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %49, i32 0, i32 0
%51 = load i64, i64* %50
%52 = call i32 @obstcp_advert_cname_extract(i8* %47, i32* %48, i64 %51)
store i32 %52, i32* %4
br label %55
53: ; preds = %41
%54 = load i64, i64* @EEXIST
store i64 %54, i64* @errno
store i32 0, i32* %4
br label %55
55: ; preds = %53, %46, %36, %34
%56 = load i32, i32* %4
ret i32 %56
}

LLVM IR (-O2):
%struct.hostent = type { i64, i64* }
@errno = global i64 0
@EEXIST = global i64 0
define i32 @obstcp_advert_hostent_extract(i8* %0, i32* %1, %struct.hostent* nocapture %2) {
%4 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 1
%5 = load i64*, i64** %4
%6 = load i64, i64* %5
%7 = icmp eq i64 %6, 0
br i1 %7, label %24, label %14
8: ; preds = %19
%9 = load i64*, i64** %4
%10 = zext i32 %23 to i64
%11 = getelementptr inbounds i64, i64* %9, i64 %10
%12 = load i64, i64* %11
%13 = icmp eq i64 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %3, %8
%15 = phi i64 [ %12, %8 ], [ %6, %3 ]
%16 = phi i32 [ %23, %8 ], [ 0, %3 ]
%17 = tail call i32 @obstcp_advert_cname_extract(i8* %0, i32* %1, i64 %15)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %14
%20 = load i64, i64* @errno
%21 = load i64, i64* @EEXIST
%22 = icmp eq i64 %20, %21
%23 = add i32 %16, 1
br i1 %22, label %8, label %32
24: ; preds = %8, %3
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%26 = load i64, i64* %25
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = tail call i32 @obstcp_advert_cname_extract(i8* %0, i32* %1, i64 %26)
br label %32
30: ; preds = %24
%31 = load i64, i64* @EEXIST
store i64 %31, i64* @errno
br label %32
32: ; preds = %14, %19, %30, %28
%33 = phi i32 [ %29, %28 ], [ 0, %30 ], [ 1, %14 ], [ 0, %19 ]
ret i32 %33
}