#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_in6 {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ localAddr;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getsockname(int, struct sockaddr *, int *);
int /*<<< orphan*/ memset(struct sockaddr_in6 *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printSocketAddress(struct sockaddr_in6);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ sysWarn(char *);
void getSockName(int localSock) {
  struct sockaddr_in6 localAddr;
  socklen_t localAddrLen = sizeof(localAddr);
  memset(&localAddr, 0, localAddrLen);
  if (getsockname(localSock, (struct sockaddr *)&localAddr, &localAddrLen) <
      0) {
    sysWarn("failed to get local address");
    return;
  }
  fprintf(stdout, "Binded to ");
  printSocketAddress(localAddr);
}


x86 assembly (clang, -O0):
<getSockName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0xc(%rbp),%edx
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <getsockname@plt>
cmp    $0x0,%rax
jge    119b <getSockName+0x4b>
lea    0xe6f(%rip),%rdi
call   1040 <sysWarn@plt>
jmp    11b8 <getSockName+0x68>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%edi
call   1070 <printSocketAddress@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSockName>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movl   $0x4,0x4(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <getsockname@plt>
test   %rax,%rax
js     11a3 <getSockName+0x53>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%rsp),%edi
call   1070 <printSocketAddress@plt>
jmp    11af <getSockName+0x5f>
lea    0xe56(%rip),%rdi
call   1040 <sysWarn@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [28 x i8] c"failed to get local address\00"
@stdout = global i32 0
@.str.1 = [11 x i8] c"Binded to \00"
define void @getSockName(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in6
%4 = alloca i32
store i32 %0, i32* %2
store i32 4, i32* %4
%5 = load i32, i32* %4
%6 = call i32 @memset(%struct.sockaddr_in6* %3, i32 0, i32 %5)
%7 = load i32, i32* %2
%8 = bitcast %struct.sockaddr_in6* %3 to %struct.sockaddr*
%9 = call i64 @getsockname(i32 %7, %struct.sockaddr* %8, i32* %4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @sysWarn(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %19
13: ; preds = %1
%14 = load i32, i32* @stdout
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @printSocketAddress(i32 %17)
br label %19
19: ; preds = %13, %11
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [28 x i8] c"failed to get local address\00"
@stdout = global i32 0
@.str.1 = [11 x i8] c"Binded to \00"
define void @getSockName(i32 %0) {
%2 = alloca %struct.sockaddr_in6
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in6* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%6 = call i32 @memset(%struct.sockaddr_in6* %2, i32 0, i32 4)
%7 = bitcast %struct.sockaddr_in6* %2 to %struct.sockaddr*
%8 = call i64 @getsockname(i32 %0, %struct.sockaddr* %7, i32* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @sysWarn(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %18
12: ; preds = %1
%13 = load i32, i32* @stdout
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @printSocketAddress(i32 %16)
br label %18
18: ; preds = %12, %10
ret void
}