#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void fill_struct(char *server_hostname, int portno,
                 struct sockaddr_in *serv_addr, int addrlen) {
  memset((char *)serv_addr, 0, addrlen);
  serv_addr->sin_family = AF_INET;
  serv_addr->sin_port = htons(portno);
  if (inet_aton(server_hostname, &(serv_addr->sin_addr)) == 0) {
    fprintf(stderr, "inet_aton() failed\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<fill_struct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0xc(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <inet_aton@plt>
cmp    $0x0,%rax
jne    11cb <fill_struct+0x7b>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_struct>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    %rdx,%rdi
xor    %esi,%esi
mov    %ecx,%edx
call   1040 <memset@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    %ebp,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <inet_aton@plt>
test   %rax,%rax
je     1193 <fill_struct+0x43>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"inet_aton() failed\0A\00"
define void @fill_struct(i8* %0, i32 %1, %struct.sockaddr_in* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.sockaddr_in*
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store %struct.sockaddr_in* %2, %struct.sockaddr_in** %7
store i32 %3, i32* %8
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%10 = bitcast %struct.sockaddr_in* %9 to i8*
%11 = load i32, i32* %8
%12 = call i32 @memset(i8* %10, i32 0, i32 %11)
%13 = load i32, i32* @AF_INET
%14 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 2
store i32 %13, i32* %15
%16 = load i32, i32* %6
%17 = call i32 @htons(i32 %16)
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%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** %7
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 0
%23 = call i64 @inet_aton(i8* %20, i32* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %4
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %4
ret void
}

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