#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 */
typedef int /*<<< orphan*/ uint32_t;
struct sockaddr_in {
  int /*<<< orphan*/ member_0;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ clientName;

/* Variables and functions */
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *boxUnsigned(int /*<<< orphan*/, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ unboxUnsigned(int /*<<< orphan*/ *);
uint32_t *socketAccept(uint32_t context_len, uint32_t *hptr) {
  int sd;
  int new_sd;
  struct sockaddr_in clientName = {0};
  int clientLength = sizeof(clientName);
  sd = (int)unboxUnsigned(hptr);
  (void)memset(&clientName, 0, sizeof(clientName));
  new_sd =
      accept(sd, (struct sockaddr *)&clientName, (uint32_t *)&clientLength);
  if (-1 == new_sd) {
    perror("accept()");
    exit(1);
  }
  return boxUnsigned(context_len, new_sd);
}


x86 assembly (clang, -O0):
<socketAccept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
movl   $0x4,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <unboxUnsigned@plt>
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1070 <accept@plt>
mov    %eax,-0x18(%rbp)
mov    $0xffffffff,%eax
cmp    -0x18(%rbp),%eax
jne    11d9 <socketAccept+0x79>
lea    0xe36(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <boxUnsigned@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socketAccept>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
movl   $0x0,0x8(%rsp)
movl   $0x4,0xc(%rsp)
mov    %rsi,%rdi
call   1050 <unboxUnsigned@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1070 <accept@plt>
cmp    $0xffffffff,%eax
je     11c1 <socketAccept+0x61>
mov    %r14d,%edi
mov    %eax,%esi
call   1030 <boxUnsigned@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe38(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [9 x i8] c"accept()\00"
define i32* @socketAccept(i32 %0, i32* %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 0, i32* %6
%7 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%8 = tail call i64 @unboxUnsigned(i32* %1)
%9 = trunc i64 %8 to i32
%10 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 4)
%11 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%12 = call i32 @accept(i32 %9, %struct.sockaddr* %11, i32* %4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = call i32* @boxUnsigned(i32 %0, i32 %12)
ret i32* %18
}