#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 */
typedef int /*<<< orphan*/ uint16_t;
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr_storage {
  int dummy;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ INADDR_ANY;
int SUN_LEN(struct sockaddr_un *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ strlcpy(int /*<<< orphan*/, char const *, int);
void makeaddr(const char *path, uint16_t port, struct sockaddr_storage *ss,
              socklen_t *len) {
  struct sockaddr_in *sin;
  struct sockaddr_un *sun;
  if (path == NULL) {
    sin = (struct sockaddr_in *)ss;
    sin->sin_family = AF_INET;
    sin->sin_addr.s_addr = INADDR_ANY;
    sin->sin_port = htons(port);
    *len = sizeof(*sin);
  } else {
    sun = (struct sockaddr_un *)ss;
    sun->sun_family = AF_UNIX;
    strlcpy(sun->sun_path, path, sizeof(sun->sun_path));
    *len = SUN_LEN(sun);
  }
}


x86 assembly (clang, -O0):
<makeaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1199 <makeaddr+0x69>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2e67(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0xc(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0xc,(%rax)
jmp    11d6 <makeaddr+0xa6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1040 <strlcpy@plt>
mov    -0x30(%rbp),%rdi
call   1050 <SUN_LEN@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeaddr>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
test   %rdi,%rdi
je     1167 <makeaddr+0x37>
mov    %rdi,%rax
mov    0x2e97(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rbx)
mov    (%rbx),%edi
mov    %rax,%rsi
mov    $0x4,%edx
call   1040 <strlcpy@plt>
mov    %rbx,%rdi
call   1050 <SUN_LEN@plt>
jmp    118d <makeaddr+0x5d>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    %esi,%edi
call   1030 <htons@plt>
mov    %eax,(%rbx)
mov    $0xc,%eax
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_un = type { i32, i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@AF_UNIX = global i32 0
define void @makeaddr(i8* %0, i32 %1, %struct.sockaddr_storage* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.sockaddr_storage*
%8 = alloca i32*
%9 = alloca %struct.sockaddr_in*
%10 = alloca %struct.sockaddr_un*
store i8* %0, i8** %5
store i32 %1, i32* %6
store %struct.sockaddr_storage* %2, %struct.sockaddr_storage** %7
store i32* %3, i32** %8
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %28
13: ; preds = %4
%14 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %7
%15 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr_in*
store %struct.sockaddr_in* %15, %struct.sockaddr_in** %9
%16 = load i32, i32* @AF_INET
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 2
store i32 %16, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %19, i32* %22
%23 = load i32, i32* %6
%24 = call i32 @htons(i32 %23)
%25 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32*, i32** %8
store i32 12, i32* %27
br label %42
28: ; preds = %4
%29 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %7
%30 = bitcast %struct.sockaddr_storage* %29 to %struct.sockaddr_un*
store %struct.sockaddr_un* %30, %struct.sockaddr_un** %10
%31 = load i32, i32* @AF_UNIX
%32 = load %struct.sockaddr_un*, %struct.sockaddr_un** %10
%33 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %32, i32 0, i32 1
store i32 %31, i32* %33
%34 = load %struct.sockaddr_un*, %struct.sockaddr_un** %10
%35 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = load i8*, i8** %5
%38 = call i32 @strlcpy(i32 %36, i8* %37, i32 4)
%39 = load %struct.sockaddr_un*, %struct.sockaddr_un** %10
%40 = call i32 @SUN_LEN(%struct.sockaddr_un* %39)
%41 = load i32*, i32** %8
store i32 %40, i32* %41
br label %42
42: ; preds = %28, %13
ret void
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_un = type { i32, i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@AF_UNIX = global i32 0
define void @makeaddr(i8* %0, i32 %1, %struct.sockaddr_storage* %2, i32* nocapture writeonly %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %13
6: ; preds = %4
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %2, i64 2, i32 0
store i32 %7, i32* %8
%9 = load i32, i32* @INADDR_ANY
%10 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %2, i64 1, i32 0
store i32 %9, i32* %10
%11 = tail call i32 @htons(i32 %1)
%12 = getelementptr %struct.sockaddr_storage, %struct.sockaddr_storage* %2, i64 0, i32 0
store i32 %11, i32* %12
br label %21
13: ; preds = %4
%14 = bitcast %struct.sockaddr_storage* %2 to %struct.sockaddr_un*
%15 = load i32, i32* @AF_UNIX
%16 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %2, i64 1, i32 0
store i32 %15, i32* %16
%17 = getelementptr %struct.sockaddr_storage, %struct.sockaddr_storage* %2, i64 0, i32 0
%18 = load i32, i32* %17
%19 = tail call i32 @strlcpy(i32 %18, i8* %0, i32 4)
%20 = tail call i32 @SUN_LEN(%struct.sockaddr_un* %14)
br label %21
21: ; preds = %13, %6
%22 = phi i32 [ %20, %13 ], [ 12, %6 ]
store i32 %22, i32* %3
ret void
}