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

/* Variables and functions */
int /*<<< orphan*/ assert(struct sockaddr_in const *);
struct sockaddr_in *malloc(int);
int /*<<< orphan*/ memcpy(struct sockaddr_in *, struct sockaddr_in const *,
                          int);
struct sockaddr_in *tow_internet_socket_address_alloc_copy(
    struct sockaddr_in const *socket_address) {
  assert(socket_address);
  struct sockaddr_in *copy = malloc(sizeof(struct sockaddr_in));
  if (!copy)
    return NULL;
  memcpy(copy, socket_address, sizeof(struct sockaddr_in));
  return copy;
}


x86 assembly (clang, -O0):
<tow_internet_socket_address_alloc_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116b <tow_internet_socket_address_alloc_copy+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    1185 <tow_internet_socket_address_alloc_copy+0x55>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tow_internet_socket_address_alloc_copy>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <assert@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     115e <tow_internet_socket_address_alloc_copy+0x2e>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
define %struct.sockaddr_in* @tow_internet_socket_address_alloc_copy(%struct.sockaddr_in* %0) {
%2 = alloca %struct.sockaddr_in*
%3 = alloca %struct.sockaddr_in*
%4 = alloca %struct.sockaddr_in*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %3
%5 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%6 = call i32 @assert(%struct.sockaddr_in* %5)
%7 = call %struct.sockaddr_in* @malloc(i32 4)
store %struct.sockaddr_in* %7, %struct.sockaddr_in** %4
%8 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%9 = icmp ne %struct.sockaddr_in* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store %struct.sockaddr_in* null, %struct.sockaddr_in** %2
br label %16
11: ; preds = %1
%12 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %3
%14 = call i32 @memcpy(%struct.sockaddr_in* %12, %struct.sockaddr_in* %13, i32 4)
%15 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
store %struct.sockaddr_in* %15, %struct.sockaddr_in** %2
br label %16
16: ; preds = %11, %10
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
ret %struct.sockaddr_in* %17
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
define %struct.sockaddr_in* @tow_internet_socket_address_alloc_copy(%struct.sockaddr_in* %0) {
%2 = tail call i32 @assert(%struct.sockaddr_in* %0)
%3 = tail call %struct.sockaddr_in* @malloc(i32 4)
%4 = icmp eq %struct.sockaddr_in* %3, null
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @memcpy(%struct.sockaddr_in* %3, %struct.sockaddr_in* %0, i32 4)
br label %7
7: ; preds = %1, %5
ret %struct.sockaddr_in* %3
}