#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_storage {
  int /*<<< orphan*/ ss_family;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int aeron_ip_addr_resolver(char const *, struct sockaddr_storage *,
                           int /*<<< orphan*/);
scalar_t__ inet_pton(int /*<<< orphan*/, char const *, int /*<<< orphan*/ *);
int aeron_ipv4_addr_resolver(const char *host,
                             struct sockaddr_storage *sockaddr) {
  struct sockaddr_in *addr = (struct sockaddr_in *)sockaddr;
  if (inet_pton(AF_INET, host, &addr->sin_addr)) {
    sockaddr->ss_family = AF_INET;
    return 0;
  }
  return aeron_ip_addr_resolver(host, sockaddr, AF_INET);
}


x86 assembly (clang, -O0):
<aeron_ipv4_addr_resolver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <inet_pton@plt>
cmp    $0x0,%rax
je     1173 <aeron_ipv4_addr_resolver+0x53>
mov    0x2e89(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    118c <aeron_ipv4_addr_resolver+0x6c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
call   1040 <aeron_ip_addr_resolver@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aeron_ipv4_addr_resolver>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2eb6(%rip),%r15
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <inet_pton@plt>
mov    (%r15),%edx
test   %rax,%rax
je     1152 <aeron_ipv4_addr_resolver+0x32>
mov    %edx,(%rbx)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <aeron_ip_addr_resolver@plt>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_in = type { i32 }
@AF_INET = global i32 0
define i32 @aeron_ipv4_addr_resolver(i8* %0, %struct.sockaddr_storage* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.sockaddr_storage*
%6 = alloca %struct.sockaddr_in*
store i8* %0, i8** %4
store %struct.sockaddr_storage* %1, %struct.sockaddr_storage** %5
%7 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%8 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr_in*
store %struct.sockaddr_in* %8, %struct.sockaddr_in** %6
%9 = load i32, i32* @AF_INET
%10 = load i8*, i8** %4
%11 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%13 = call i64 @inet_pton(i32 %9, i8* %10, i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%18 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %17, i32 0, i32 0
store i32 %16, i32* %18
store i32 0, i32* %3
br label %24
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %5
%22 = load i32, i32* @AF_INET
%23 = call i32 @aeron_ip_addr_resolver(i8* %20, %struct.sockaddr_storage* %21, i32 %22)
store i32 %23, i32* %3
br label %24
24: ; preds = %19, %15
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
@AF_INET = global i32 0
define i32 @aeron_ipv4_addr_resolver(i8* %0, %struct.sockaddr_storage* %1) {
%3 = load i32, i32* @AF_INET
%4 = getelementptr %struct.sockaddr_storage, %struct.sockaddr_storage* %1, i64 0, i32 0
%5 = tail call i64 @inet_pton(i32 %3, i8* %0, i32* %4)
%6 = icmp eq i64 %5, 0
%7 = load i32, i32* @AF_INET
br i1 %6, label %9, label %8
8: ; preds = %2
store i32 %7, i32* %4
br label %11
9: ; preds = %2
%10 = tail call i32 @aeron_ip_addr_resolver(i8* %0, %struct.sockaddr_storage* %1, i32 %7)
br label %11
11: ; preds = %9, %8
%12 = phi i32 [ 0, %8 ], [ %10, %9 ]
ret i32 %12
}