#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int s_addr;
};
struct sockaddr_in {
  short sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ atoi(char const *);
short htons(int /*<<< orphan*/);
int inet_addr(char const *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
struct sockaddr *makeAddr(const char *addr, const char *port) {
  struct sockaddr_in *this_sockaddr =
      (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
  if (this_sockaddr) {
    int this_addr = inet_addr(addr);
    short this_port = htons(atoi(port));
    memset((char *)this_sockaddr, 0, sizeof(struct sockaddr_in));
    this_sockaddr->sin_family = AF_INET;
    this_sockaddr->sin_addr.s_addr = this_addr;
    this_sockaddr->sin_port = this_port;
  }
  return (struct sockaddr *)this_sockaddr;
}


x86 assembly (clang, -O0):
<makeAddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ce <makeAddr+0x7e>
mov    -0x8(%rbp),%rdi
call   1050 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %ax,-0x1e(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x1e(%rbp),%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeAddr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ad <makeAddr+0x5d>
mov    %r15,%rdi
call   1050 <inet_addr@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    %r15d,0x4(%rbx)
mov    %bp,(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i16, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
define %struct.sockaddr* @makeAddr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.sockaddr_in*
%6 = alloca i32
%7 = alloca i16
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = call i64 @malloc(i32 12)
%9 = inttoptr i64 %8 to %struct.sockaddr_in*
store %struct.sockaddr_in* %9, %struct.sockaddr_in** %5
%10 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%11 = icmp ne %struct.sockaddr_in* %10, null
br i1 %11, label %12, label %31
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @inet_addr(i8* %13)
store i32 %14, i32* %6
%15 = load i8*, i8** %4
%16 = call i32 @atoi(i8* %15)
%17 = call signext i16 @htons(i32 %16)
store i16 %17, i16* %7
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%19 = bitcast %struct.sockaddr_in* %18 to i8*
%20 = call i32 @memset(i8* %19, i32 0, i32 12)
%21 = load i32, i32* @AF_INET
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 2
store i32 %21, i32* %23
%24 = load i32, i32* %6
%25 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %25, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %24, i32* %27
%28 = load i16, i16* %7
%29 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %29, i32 0, i32 0
store i16 %28, i16* %30
br label %31
31: ; preds = %12, %2
%32 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%33 = bitcast %struct.sockaddr_in* %32 to %struct.sockaddr*
ret %struct.sockaddr* %33
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i16, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
define %struct.sockaddr* @makeAddr(i8* %0, i8* nocapture %1) {
%3 = tail call i64 @malloc(i32 12)
%4 = inttoptr i64 %3 to %struct.sockaddr_in*
%5 = icmp eq i64 %3, 0
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = tail call i32 @inet_addr(i8* %0)
%8 = tail call i32 @atoi(i8* %1)
%9 = tail call signext i16 @htons(i32 %8)
%10 = inttoptr i64 %3 to i8*
%11 = tail call i32 @memset(i8* %10, i32 0, i32 12)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %7, i32* %14
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i16 %9, i16* %15
br label %16
16: ; preds = %6, %2
%17 = inttoptr i64 %3 to %struct.sockaddr*
ret %struct.sockaddr* %17
}