#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 /*<<< orphan*/ h_addr;
};

/* Variables and functions */
struct hostent *gethostbyname(char *);
unsigned int inet_addr(char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ memcpy(unsigned int *, int /*<<< orphan*/, int);
unsigned int resolve_it(char *host) {
  unsigned int result = -1;
  struct hostent *hp;
  if (isdigit(host[0])) {
    result = inet_addr(host);
  } else {
    hp = gethostbyname(host);
    if (hp) {
      memcpy(&result, hp->h_addr, sizeof(unsigned int));
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<resolve_it>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     117a <resolve_it+0x3a>
mov    -0x8(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %eax,-0xc(%rbp)
jmp    11ab <resolve_it+0x6b>
mov    -0x8(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a6 <resolve_it+0x66>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
mov    $0x4,%edx
call   1060 <memcpy@plt>
jmp    11ab <resolve_it+0x6b>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_it>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0xffffffff,0xc(%rsp)
ff
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     116a <resolve_it+0x2a>
add    $0x10,%rsp
pop    %rbx
jmp    1040 <inet_addr@plt>
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     118b <resolve_it+0x4b>
mov    (%rax),%esi
lea    0xc(%rsp),%rdi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    0xc(%rsp),%eax
jmp    1190 <resolve_it+0x50>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.hostent = type { i32 }
define i32 @resolve_it(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
%4 = load i8, i8* %0
%5 = tail call i64 @isdigit(i8 signext %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @inet_addr(i8* %0)
br label %17
9: ; preds = %1
%10 = tail call %struct.hostent* @gethostbyname(i8* %0)
%11 = icmp eq %struct.hostent* %10, null
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @memcpy(i32* %2, i32 %14, i32 4)
%16 = load i32, i32* %2
br label %17
17: ; preds = %9, %12, %7
%18 = phi i32 [ -1, %9 ], [ %16, %12 ], [ %8, %7 ]
ret i32 %18
}