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

/* Variables and functions */
int /*<<< orphan*/ getpeername(int, struct sockaddr *, void *);
int /*<<< orphan*/ inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
char *strdup(char *);
char *clientaddr(int fd) {
  struct sockaddr_in cli_addr;
  char address[250] = "\0";
  int len;
  len = sizeof(cli_addr);
  getpeername(fd, (struct sockaddr *)&cli_addr, (void *)&len);
  strcpy(address, inet_ntoa(cli_addr.sin_addr));
  return strdup(address);
}


x86 assembly (clang, -O0):
<clientaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa,%edx
call   1060 <memset@plt>
movl   $0x4,-0x114(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0x114(%rbp),%rdx
call   1050 <getpeername@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x120(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
call   1070 <strdup@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clientaddr>:
push   %rbx
sub    $0x110,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0xfa(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x4,0xc(%rsp)
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1050 <getpeername@plt>
mov    0x8(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strdup@plt>
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define i8* @clientaddr(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [250 x i8]
%5 = alloca i32
store i32 %0, i32* %2
%6 = bitcast [250 x i8]* %4 to i8*
store i32 4, i32* %5
%7 = load i32, i32* %2
%8 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%9 = bitcast i32* %5 to i8*
%10 = call i32 @getpeername(i32 %7, %struct.sockaddr* %8, i8* %9)
%11 = getelementptr inbounds [250 x i8], [250 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @inet_ntoa(i32 %13)
%15 = call i32 @strcpy(i8* %11, i32 %14)
%16 = getelementptr inbounds [250 x i8], [250 x i8]* %4, i64 0, i64 0
%17 = call i8* @strdup(i8* %16)
ret i8* %17
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define noalias i8* @clientaddr(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca [250 x i8]
%4 = alloca i32
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = getelementptr inbounds [250 x i8], [250 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%8 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%9 = call i32 @getpeername(i32 %0, %struct.sockaddr* %8, i8* %7)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 @inet_ntoa(i32 %11)
%13 = call i32 @strcpy(i8* %6, i32 %12)
%14 = call i8* @strdup(i8* %6)
ret i8* %14
}