#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  unsigned long s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  void *sin_port;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ atoi(char *);
struct hostent *gethostbyname(char const *);
void *htons(unsigned short);
unsigned long inet_addr(char const *);
int /*<<< orphan*/ isdigit(unsigned char);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
char *strchr(char const *, char);
int Resolve(const char *address, struct sockaddr_in *addr, int defaultport) {
  char *p;
  int i;
  memset(addr, 0, sizeof(struct sockaddr_in));
  addr->sin_family = AF_INET;
  addr->sin_port = htons((unsigned short)defaultport);
  if ((p = strchr(address, ':'))) {
    addr->sin_port = htons((unsigned short)atoi(p + 1));
    *p = 0;
  }
  if (!*address)
    return 0;
  for (i = 0; address[i]; i++)
    if (!isdigit((unsigned char)address[i]) && address[i] != '.')
      break;
  if (address[i]) {
    struct hostent *h;
    h = gethostbyname(address);
    if (!h)
      return 0;
    addr->sin_addr.s_addr = *((unsigned long *)h->h_addr);
    return 1;
  } else {
    addr->sin_addr.s_addr = inet_addr(address);
    if (addr->sin_addr.s_addr)
      return 1;
    else
      return 0;
  }
}


x86 assembly (clang, -O0):
<Resolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x1c(%rbp),%eax
movzwl %ax,%edi
call   1040 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11fc <Resolve+0x8c>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1090 <atoi@plt>
movzwl %ax,%edi
call   1040 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1215 <Resolve+0xa5>
movl   $0x0,-0x4(%rbp)
jmp    12fc <Resolve+0x18c>
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1275 <Resolve+0x105>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1262 <Resolve+0xf2>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     1262 <Resolve+0xf2>
jmp    1275 <Resolve+0x105>
jmp    1267 <Resolve+0xf7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    121c <Resolve+0xac>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     12c8 <Resolve+0x158>
mov    -0x10(%rbp),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12ab <Resolve+0x13b>
movl   $0x0,-0x4(%rbp)
jmp    12fc <Resolve+0x18c>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12fc <Resolve+0x18c>
mov    -0x10(%rbp),%rdi
call   1070 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     12f5 <Resolve+0x185>
movl   $0x1,-0x4(%rbp)
jmp    12fc <Resolve+0x18c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Resolve>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %r14d,%r14d
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rbx)
movzwl %bp,%edi
call   1040 <htons@plt>
mov    %rax,0x8(%rbx)
mov    %r15,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11da <Resolve+0x6a>
mov    %rax,%rbp
mov    %rax,%rdi
add    $0x1,%rdi
call   1090 <atoi@plt>
movzwl %ax,%edi
call   1040 <htons@plt>
mov    %rax,0x8(%rbx)
movb   $0x0,0x0(%rbp)
mov    (%r15),%al
test   %al,%al
je     1229 <Resolve+0xb9>
lea    0x1(%r15),%rbp
jmp    11fc <Resolve+0x8c>
nopw   0x0(%rax,%rax,1)
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
je     1214 <Resolve+0xa4>
movzbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
jne    11f0 <Resolve+0x80>
movzbl -0x1(%rbp),%eax
cmp    $0x2e,%al
je     11f0 <Resolve+0x80>
test   %al,%al
jne    1237 <Resolve+0xc7>
mov    %r15,%rdi
call   1070 <inet_addr@plt>
mov    %rax,(%rbx)
xor    %r14d,%r14d
test   %rax,%rax
setne  %r14b
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     1229 <Resolve+0xb9>
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,(%rbx)
mov    $0x1,%r14d
jmp    1229 <Resolve+0xb9>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.hostent = type { i64 }
@AF_INET = global i32 0
define i32 @Resolve(i8* %0, %struct.sockaddr_in* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.sockaddr_in*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %struct.hostent*
store i8* %0, i8** %5
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %6
store i32 %2, i32* %7
%11 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%12 = call i32 @memset(%struct.sockaddr_in* %11, i32 0, i32 24)
%13 = load i32, i32* @AF_INET
%14 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 2
store i32 %13, i32* %15
%16 = load i32, i32* %7
%17 = trunc i32 %16 to i16
%18 = call i8* @htons(i16 zeroext %17)
%19 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 1
store i8* %18, i8** %20
%21 = load i8*, i8** %5
%22 = call i8* @strchr(i8* %21, i8 signext 58)
store i8* %22, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %33
24: ; preds = %3
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = call i64 @atoi(i8* %26)
%28 = trunc i64 %27 to i16
%29 = call i8* @htons(i16 zeroext %28)
%30 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %30, i32 0, i32 1
store i8* %29, i8** %31
%32 = load i8*, i8** %8
store i8 0, i8* %32
br label %33
33: ; preds = %24, %3
%34 = load i8*, i8** %5
%35 = load i8, i8* %34
%36 = icmp ne i8 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %33
store i32 0, i32* %4
br label %102
38: ; preds = %33
store i32 0, i32* %9
br label %39
39: ; preds = %64, %38
%40 = load i8*, i8** %5
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = icmp ne i8 %44, 0
br i1 %45, label %46, label %67
46: ; preds = %39
%47 = load i8*, i8** %5
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
%52 = call i32 @isdigit(i8 zeroext %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %63, label %54
54: ; preds = %46
%55 = load i8*, i8** %5
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 46
br i1 %61, label %62, label %63
62: ; preds = %54
br label %67
63: ; preds = %54, %46
br label %64
64: ; preds = %63
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %39
67: ; preds = %62, %39
%68 = load i8*, i8** %5
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8, i8* %71
%73 = icmp ne i8 %72, 0
br i1 %73, label %74, label %89
74: ; preds = %67
%75 = load i8*, i8** %5
%76 = call %struct.hostent* @gethostbyname(i8* %75)
store %struct.hostent* %76, %struct.hostent** %10
%77 = load %struct.hostent*, %struct.hostent** %10
%78 = icmp ne %struct.hostent* %77, null
br i1 %78, label %80, label %79
79: ; preds = %74
store i32 0, i32* %4
br label %102
80: ; preds = %74
%81 = load %struct.hostent*, %struct.hostent** %10
%82 = getelementptr inbounds %struct.hostent, %struct.hostent* %81, i32 0, i32 0
%83 = load i64, i64* %82
%84 = inttoptr i64 %83 to i64*
%85 = load i64, i64* %84
%86 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%87 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %86, i32 0, i32 0
%88 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %87, i32 0, i32 0
store i64 %85, i64* %88
store i32 1, i32* %4
br label %102
89: ; preds = %67
%90 = load i8*, i8** %5
%91 = call i64 @inet_addr(i8* %90)
%92 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%93 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %92, i32 0, i32 0
%94 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %93, i32 0, i32 0
store i64 %91, i64* %94
%95 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%96 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %95, i32 0, i32 0
%97 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %96, i32 0, i32 0
%98 = load i64, i64* %97
%99 = icmp ne i64 %98, 0
br i1 %99, label %100, label %101
100: ; preds = %89
store i32 1, i32* %4
br label %102
101: ; preds = %89
store i32 0, i32* %4
br label %102
102: ; preds = %101, %100, %80, %79, %37
%103 = load i32, i32* %4
ret i32 %103
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.hostent = type { i64 }
@AF_INET = global i32 0
define i32 @Resolve(i8* %0, %struct.sockaddr_in* %1, i32 %2) {
%4 = tail call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 24)
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %5, i32* %6
%7 = trunc i32 %2 to i16
%8 = tail call i8* @htons(i16 zeroext %7)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i8* %8, i8** %9
%10 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %3
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = tail call i64 @atoi(i8* %13)
%15 = trunc i64 %14 to i16
%16 = tail call i8* @htons(i16 zeroext %15)
store i8* %16, i8** %9
store i8 0, i8* %10
br label %17
17: ; preds = %12, %3
%18 = load i8, i8* %0
%19 = icmp eq i8 %18, 0
br i1 %19, label %47, label %20
20: ; preds = %17, %28
%21 = phi i64 [ %29, %28 ], [ 0, %17 ]
%22 = phi i8 [ %31, %28 ], [ %18, %17 ]
%23 = phi i8* [ %30, %28 ], [ %0, %17 ]
%24 = tail call i32 @isdigit(i8 zeroext %22)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = load i8, i8* %23
switch i8 %27, label %33 [
i8 46, label %28
i8 0, label %42
]
28: ; preds = %26, %20
%29 = add nuw i64 %21, 1
%30 = getelementptr inbounds i8, i8* %0, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %42, label %20
33: ; preds = %26
%34 = tail call %struct.hostent* @gethostbyname(i8* %0)
%35 = icmp eq %struct.hostent* %34, null
br i1 %35, label %47, label %36
36: ; preds = %33
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i64 0, i32 0
%38 = load i64, i64* %37
%39 = inttoptr i64 %38 to i64*
%40 = load i64, i64* %39
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i64 %40, i64* %41
br label %47
42: ; preds = %28, %26
%43 = tail call i64 @inet_addr(i8* %0)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i64 %43, i64* %44
%45 = icmp ne i64 %43, 0
%46 = zext i1 %45 to i32
br label %47
47: ; preds = %42, %36, %33, %17
%48 = phi i32 [ 0, %17 ], [ 1, %36 ], [ 0, %33 ], [ %46, %42 ]
ret i32 %48
}