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

/* Variables and functions */
int getsockname(int, struct sockaddr *, int *);
char *inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void get_sockinfo(int sock, char **addr, int *port) {
  struct sockaddr_in my_addr;
  socklen_t sockaddr_len = sizeof(struct sockaddr);
  int rv;
  rv = getsockname(sock, (struct sockaddr *)&my_addr, &sockaddr_len);
  if (rv == -1) {
    perror("getname");
    return;
  }
  *addr = inet_ntoa(my_addr.sin_addr);
  *port = ntohs(my_addr.sin_port);
}


x86 assembly (clang, -O0):
<get_sockinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1060 <getsockname@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1188 <get_sockinfo+0x48>
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
jmp    11aa <get_sockinfo+0x6a>
mov    -0x1c(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%edi
call   1040 <ntohs@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sockinfo>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1060 <getsockname@plt>
cmp    $0xffffffff,%eax
je     1189 <get_sockinfo+0x49>
mov    0x14(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,(%rbx)
mov    0x10(%rsp),%edi
call   1040 <ntohs@plt>
mov    %eax,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe70(%rip),%rdi
call   1050 <perror@plt>
jmp    1181 <get_sockinfo+0x41>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"getname\00"
define void @get_sockinfo(i32 %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
store i32 4, i32* %8
%10 = load i32, i32* %4
%11 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%12 = call i32 @getsockname(i32 %10, %struct.sockaddr* %11, i32* %8)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %26
17: ; preds = %3
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%19 = load i32, i32* %18
%20 = call i8* @inet_ntoa(i32 %19)
%21 = load i8**, i8*** %5
store i8* %20, i8** %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @ntohs(i32 %23)
%25 = load i32*, i32** %6
store i32 %24, i32* %25
br label %26
26: ; preds = %17, %15
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"getname\00"
define void @get_sockinfo(i32 %0, i8** nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 4, i32* %5
%8 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%9 = call i32 @getsockname(i32 %0, %struct.sockaddr* %8, i32* %5)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %20
13: ; preds = %3
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%15 = load i32, i32* %14
%16 = call i8* @inet_ntoa(i32 %15)
store i8* %16, i8** %1
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @ntohs(i32 %18)
store i32 %19, i32* %2
br label %20
20: ; preds = %13, %11
ret void
}