#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 sockaddr_in {
  unsigned char sin_family;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct in_addr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int _StrToAddr(struct sockaddr_in *addr, unsigned char family, char *hostname,
               int port) {
  if (!inet_aton(hostname, &addr->sin_addr)) {
    struct hostent *hp;
    if ((hp = gethostbyname(hostname)) == 0)
      return 0;
    memcpy(&addr->sin_addr, hp->h_addr, sizeof(struct in_addr));
  }
  addr->sin_family = family;
  addr->sin_port = htons(port);
  return 1;
}


x86 assembly (clang, -O0):
<_StrToAddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1060 <inet_aton@plt>
cmp    $0x0,%eax
jne    11ae <_StrToAddr+0x6e>
mov    -0x20(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1196 <_StrToAddr+0x56>
movl   $0x0,-0x4(%rbp)
jmp    11cf <_StrToAddr+0x8f>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    -0x11(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x24(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_StrToAddr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%rbp
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0x8(%rdi),%r12
mov    %rdx,%rdi
mov    %r12,%rsi
call   1060 <inet_aton@plt>
test   %eax,%eax
jne    1183 <_StrToAddr+0x43>
mov    %rbp,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     119f <_StrToAddr+0x5f>
mov    (%rax),%esi
mov    %r12,%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    %r15b,(%rbx)
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    1196 <_StrToAddr+0x56>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8, i32, i32 }
%struct.hostent = type { i32 }
define i32 @_StrToAddr(%struct.sockaddr_in* %0, i8 zeroext %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.sockaddr_in*
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %struct.hostent*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %6
store i8 %1, i8* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i8*, i8** %8
%12 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
%14 = call i32 @inet_aton(i8* %11, i32* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %28, label %16
16: ; preds = %4
%17 = load i8*, i8** %8
%18 = call %struct.hostent* @gethostbyname(i8* %17)
store %struct.hostent* %18, %struct.hostent** %10
%19 = icmp eq %struct.hostent* %18, null
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %5
br label %36
21: ; preds = %16
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 2
%24 = load %struct.hostent*, %struct.hostent** %10
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @memcpy(i32* %23, i32 %26, i32 4)
br label %28
28: ; preds = %21, %4
%29 = load i8, i8* %7
%30 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %30, i32 0, i32 0
store i8 %29, i8* %31
%32 = load i32, i32* %9
%33 = call i32 @htons(i32 %32)
%34 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %34, i32 0, i32 1
store i32 %33, i32* %35
store i32 1, i32* %5
br label %36
36: ; preds = %28, %20
%37 = load i32, i32* %5
ret i32 %37
}

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