#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 {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EINVAL;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int);
int inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int make_remote_addr(char *hostname, struct sockaddr *out_raddr,
                     socklen_t *out_raddr_len) {
  int ret;
  struct sockaddr_in *raddr_in;
  raddr_in = (struct sockaddr_in *)out_raddr;
  memset(out_raddr, 0, sizeof *out_raddr);
  raddr_in->sin_family = AF_INET;
  raddr_in->sin_port = htons(69);
  ret = inet_aton(hostname, &raddr_in->sin_addr);
  if (!ret) {
    fprintf(stderr, "Can't parse remote address '%s`\n", hostname);
    return -EINVAL;
  }
  *out_raddr_len = sizeof *raddr_in;
  return 0;
}


x86 assembly (clang, -O0):
<make_remote_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    $0x45,%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <inet_aton@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11d5 <make_remote_addr+0x95>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe43(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
mov    0x2e05(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e6 <make_remote_addr+0xa6>
mov    -0x20(%rbp),%rax
movl   $0xc,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_remote_addr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %ebp,%ebp
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    $0x45,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <inet_aton@plt>
test   %eax,%eax
je     1192 <make_remote_addr+0x52>
movl   $0xc,(%r15)
jmp    11b5 <make_remote_addr+0x75>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    0x2e1f(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"Can't parse remote address '%s`\0A\00"
@EINVAL = global i32 0
define i32 @make_remote_addr(i8* %0, %struct.sockaddr* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.sockaddr*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca %struct.sockaddr_in*
store i8* %0, i8** %5
store %struct.sockaddr* %1, %struct.sockaddr** %6
store i32* %2, i32** %7
%10 = load %struct.sockaddr*, %struct.sockaddr** %6
%11 = bitcast %struct.sockaddr* %10 to %struct.sockaddr_in*
store %struct.sockaddr_in* %11, %struct.sockaddr_in** %9
%12 = load %struct.sockaddr*, %struct.sockaddr** %6
%13 = call i32 @memset(%struct.sockaddr* %12, i32 0, i32 4)
%14 = load i32, i32* @AF_INET
%15 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 2
store i32 %14, i32* %16
%17 = call i32 @htons(i32 69)
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 1
store i32 %17, i32* %19
%20 = load i8*, i8** %5
%21 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 0
%23 = call i32 @inet_aton(i8* %20, i32* %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %3
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %5
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EINVAL
%31 = sub nsw i32 0, %30
store i32 %31, i32* %4
br label %34
32: ; preds = %3
%33 = load i32*, i32** %7
store i32 12, i32* %33
store i32 0, i32* %4
br label %34
34: ; preds = %32, %26
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"Can't parse remote address '%s`\0A\00"
@EINVAL = global i32 0
define i32 @make_remote_addr(i8* %0, %struct.sockaddr* %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @memset(%struct.sockaddr* %1, i32 0, i32 4)
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 2, i32 0
store i32 %5, i32* %6
%7 = tail call i32 @htons(i32 69)
%8 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 1, i32 0
store i32 %7, i32* %8
%9 = getelementptr %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%10 = tail call i32 @inet_aton(i8* %0, i32* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
%15 = load i32, i32* @EINVAL
%16 = sub nsw i32 0, %15
br label %18
17: ; preds = %3
store i32 12, i32* %2
br label %18
18: ; preds = %17, %12
%19 = phi i32 [ 0, %17 ], [ %16, %12 ]
ret i32 %19
}