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

/* Variables and functions */
int INET6_ADDRSTRLEN;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ psGetSockAddr(struct sockaddr *);
char *strerror(int /*<<< orphan*/);
int socketAccept(int handle) {
  socklen_t iSinSize = sizeof(struct sockaddr_storage);
  struct sockaddr_storage sClientAddress;
  char sClientAddressStr[INET6_ADDRSTRLEN];
  int iClientSocket;
  iClientSocket = accept(handle, (struct sockaddr *)&sClientAddress, &iSinSize);
  if (iClientSocket == -1) {
    printf("socketAccept: failed(%s)\n", strerror(errno));
  } else {
    inet_ntop(sClientAddress.ss_family,
              psGetSockAddr((struct sockaddr *)&sClientAddress),
              sClientAddressStr, INET6_ADDRSTRLEN);
    printf("New client connection from %s\n", sClientAddressStr);
  }
  return (iClientSocket);
}


x86 assembly (clang, -O0):
<socketAccept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0x8(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11cd <socketAccept+0x7d>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
jmp    1203 <socketAccept+0xb3>
mov    -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <psGetSockAddr@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %eax,%esi
mov    0x2dfc(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
mov    -0x30(%rbp),%rsi
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socketAccept>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%r12
movl   $0x4,-0x34(%rbp)
mov    0x2e76(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
je     11c6 <socketAccept+0x76>
mov    -0x30(%rbp),%r15d
lea    -0x30(%rbp),%rdi
call   1050 <psGetSockAddr@plt>
mov    0x0(%r13),%ecx
mov    %r15d,%edi
mov    %eax,%esi
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
lea    0xe59(%rip),%rdi
mov    %rbx,%rsi
jmp    11de <socketAccept+0x8e>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe25(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %r12,%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [26 x i8] c"socketAccept: failed(%s)\0A\00"
@errno = global i32 0
@.str.1 = [31 x i8] c"New client connection from %s\0A\00"
define i32 @socketAccept(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_storage
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %2
store i32 4, i32* %3
%8 = load i32, i32* @INET6_ADDRSTRLEN
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = load i32, i32* %2
%13 = bitcast %struct.sockaddr_storage* %4 to %struct.sockaddr*
%14 = call i32 @accept(i32 %12, %struct.sockaddr* %13, i32* %3)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %1
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %29
21: ; preds = %1
%22 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %4, i32 0, i32 0
%23 = load i32, i32* %22
%24 = bitcast %struct.sockaddr_storage* %4 to %struct.sockaddr*
%25 = call i32 @psGetSockAddr(%struct.sockaddr* %24)
%26 = load i32, i32* @INET6_ADDRSTRLEN
%27 = call i32 @inet_ntop(i32 %23, i32 %25, i8* %11, i32 %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %29
29: ; preds = %21, %17
%30 = load i32, i32* %7
%31 = load i8*, i8** %5
ret i32 %30
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [26 x i8] c"socketAccept: failed(%s)\0A\00"
@errno = global i32 0
@.str.1 = [31 x i8] c"New client connection from %s\0A\00"
define i32 @socketAccept(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_storage
%4 = bitcast i32* %2 to i8*
store i32 4, i32* %2
%5 = bitcast %struct.sockaddr_storage* %3 to i8*
%6 = load i32, i32* @INET6_ADDRSTRLEN
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%11 = call i32 @accept(i32 %0, %struct.sockaddr* %10, i32* %2)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %24
17: ; preds = %1
%18 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @psGetSockAddr(%struct.sockaddr* %10)
%21 = load i32, i32* @INET6_ADDRSTRLEN
%22 = call i32 @inet_ntop(i32 %19, i32 %20, i8* %9, i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %24
24: ; preds = %17, %13
ret i32 %11
}