#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*/ uint16_t;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int inet_pton(int /*<<< orphan*/, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void fill_socketaddr_in(struct sockaddr_in *sock_address, uint16_t port,
                        const char *ip_address) {
  sock_address->sin_family = AF_INET;
  sock_address->sin_port = htons(port);
  if (inet_pton(AF_INET, ip_address, &sock_address->sin_addr) != 1) {
    fprintf(stderr, "Not a valid address: %s\n", ip_address);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<fill_socketaddr_in>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0xc(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x1,%eax
je     11b6 <fill_socketaddr_in+0x76>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe59(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_socketaddr_in>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%rbx
mov    0x2e96(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x8(%rdi)
mov    %esi,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <inet_pton@plt>
cmp    $0x1,%eax
jne    117b <fill_socketaddr_in+0x3b>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"Not a valid address: %s\0A\00"
define void @fill_socketaddr_in(%struct.sockaddr_in* %0, i32 %1, i8* %2) {
%4 = alloca %struct.sockaddr_in*
%5 = alloca i32
%6 = alloca i8*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = load i32, i32* @AF_INET
%8 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %7, i32* %9
%10 = load i32, i32* %5
%11 = call i32 @htons(i32 %10)
%12 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i32 %11, i32* %13
%14 = load i32, i32* @AF_INET
%15 = load i8*, i8** %6
%16 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
%18 = call i32 @inet_pton(i32 %14, i8* %15, i32* %17)
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %25
20: ; preds = %3
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %6
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %3
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"Not a valid address: %s\0A\00"
define void @fill_socketaddr_in(%struct.sockaddr_in* %0, i32 %1, i8* %2) {
%4 = load i32, i32* @AF_INET
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 2
store i32 %4, i32* %5
%6 = tail call i32 @htons(i32 %1)
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
%10 = tail call i32 @inet_pton(i32 %8, i8* %2, i32* %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %2)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %3
ret void
}