#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 int /*<<< orphan*/ uint32_t;
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
struct hostent *gethostbyname(char const *);
scalar_t__ parseip(char const *, int /*<<< orphan*/ *);
int mco_lookup(const char *name, uint32_t *ip) {
  struct hostent *he;
  if (parseip(name, ip) >= 0)
    return 0;
  if ((he = gethostbyname(name)) != 0) {
    *ip = *(uint32_t *)he->h_addr;
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<mco_lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <parseip@plt>
cmp    $0x0,%rax
jl     1153 <mco_lookup+0x33>
movl   $0x0,-0x4(%rbp)
jmp    118c <mco_lookup+0x6c>
mov    -0x10(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1185 <mco_lookup+0x65>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    118c <mco_lookup+0x6c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mco_lookup>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1040 <parseip@plt>
xor    %r14d,%r14d
test   %rax,%rax
jns    1153 <mco_lookup+0x33>
mov    %rbp,%rdi
call   1030 <gethostbyname@plt>
test   %rax,%rax
je     114d <mco_lookup+0x2d>
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
jmp    1153 <mco_lookup+0x33>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i64 }
define i32 @mco_lookup(i8* %0, i32* %1) {
%3 = alloca i32
%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 @parseip(i8* %7, i32* %8)
%10 = icmp sge i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %24
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call %struct.hostent* @gethostbyname(i8* %13)
store %struct.hostent* %14, %struct.hostent** %6
%15 = icmp ne %struct.hostent* %14, null
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load %struct.hostent*, %struct.hostent** %6
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to i32*
%21 = load i32, i32* %20
%22 = load i32*, i32** %5
store i32 %21, i32* %22
store i32 0, i32* %3
br label %24
23: ; preds = %12
store i32 -1, i32* %3
br label %24
24: ; preds = %23, %16, %11
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.hostent = type { i64 }
define i32 @mco_lookup(i8* %0, i32* %1) {
%3 = tail call i64 @parseip(i8* %0, i32* %1)
%4 = icmp sgt i64 %3, -1
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = tail call %struct.hostent* @gethostbyname(i8* %0)
%7 = icmp eq %struct.hostent* %6, null
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %6, i64 0, i32 0
%10 = load i64, i64* %9
%11 = inttoptr i64 %10 to i32*
%12 = load i32, i32* %11
store i32 %12, i32* %1
br label %13
13: ; preds = %5, %2, %8
%14 = phi i32 [ 0, %8 ], [ 0, %2 ], [ -1, %5 ]
ret i32 %14
}