#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_storage {
  int dummy;
};
struct sockaddr_in {
  int sin_family;
  int /*<<< orphan*/ sin_port;
};
typedef int socklen_t;
typedef int sa_family_t;
typedef int /*<<< orphan*/ in_port_t;

/* Variables and functions */
#define AF_INET 128
int /*<<< orphan*/ EPFNOSUPPORT;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ memset(struct sockaddr_storage *, int /*<<< orphan*/, int);
bool kcn_sockaddr_init(struct sockaddr_storage *ss, socklen_t *sslenp,
                       sa_family_t family, in_port_t port) {
  struct sockaddr_in *sin = (struct sockaddr_in *)ss;
  memset(ss, 0, sizeof(*ss));
  switch (family) {
  case AF_INET:
    sin->sin_family = AF_INET;
    *sslenp = sizeof(*sin);
    sin->sin_port = port;
    break;
  default:
    errno = EPFNOSUPPORT;
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<kcn_sockaddr_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x1c(%rbp),%eax
sub    $0x80,%eax
jne    1174 <kcn_sockaddr_init+0x64>
jmp    1151 <kcn_sockaddr_init+0x41>
mov    -0x28(%rbp),%rax
movl   $0x80,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x8,(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
jmp    1192 <kcn_sockaddr_init+0x82>
mov    0x2e6d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e54(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1199 <kcn_sockaddr_init+0x89>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kcn_sockaddr_init>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%rbp
xor    %r12d,%r12d
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
cmp    $0x80,%ebx
jne    1154 <kcn_sockaddr_init+0x44>
movl   $0x80,0x0(%rbp)
movl   $0x8,(%r15)
mov    %r14d,0x4(%rbp)
mov    $0x1,%r12d
jmp    1166 <kcn_sockaddr_init+0x56>
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    0x2e74(%rip),%rcx
mov    %eax,(%rcx)
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_in = type { i32, i32 }
@EPFNOSUPPORT = global i32 0
@errno = global i32 0
define i32 @kcn_sockaddr_init(%struct.sockaddr_storage* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.sockaddr_storage*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in*
store %struct.sockaddr_storage* %0, %struct.sockaddr_storage** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %6
%12 = bitcast %struct.sockaddr_storage* %11 to %struct.sockaddr_in*
store %struct.sockaddr_in* %12, %struct.sockaddr_in** %10
%13 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %6
%14 = call i32 @memset(%struct.sockaddr_storage* %13, i32 0, i32 4)
%15 = load i32, i32* %8
switch i32 %15, label %23 [
i32 128, label %16
]
16: ; preds = %4
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
store i32 128, i32* %18
%19 = load i32*, i32** %7
store i32 8, i32* %19
%20 = load i32, i32* %9
%21 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 1
store i32 %20, i32* %22
br label %25
23: ; preds = %4
%24 = load i32, i32* @EPFNOSUPPORT
store i32 %24, i32* @errno
store i32 0, i32* %5
br label %26
25: ; preds = %16
store i32 1, i32* %5
br label %26
26: ; preds = %25, %23
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
@EPFNOSUPPORT = global i32 0
@errno = global i32 0
define i32 @kcn_sockaddr_init(%struct.sockaddr_storage* %0, i32* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = tail call i32 @memset(%struct.sockaddr_storage* %0, i32 0, i32 4)
%6 = icmp eq i32 %2, 128
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = getelementptr %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 0, i32 0
store i32 128, i32* %8
store i32 8, i32* %1
%9 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %0, i64 1, i32 0
store i32 %3, i32* %9
br label %12
10: ; preds = %4
%11 = load i32, i32* @EPFNOSUPPORT
store i32 %11, i32* @errno
br label %12
12: ; preds = %7, %10
%13 = phi i32 [ 1, %7 ], [ 0, %10 ]
ret i32 %13
}